Identified constant variable (byte*) SCREEN
Culled Empty Block (label) main::@2

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  to:@1

(void()) main()
main: scope:[main]  from @1
  (signed word) main::i#0 ← (signed word) -$a
  to:main::@1
main::@1: scope:[main]  from main main::@1
  (signed word) main::i#2 ← phi( main/(signed word) main::i#0 main::@1/(signed word) main::i#1 )
  (byte*~) main::$0 ← (const byte*) SCREEN + (signed word) main::i#2
  (byte*) main::sc#0 ← (byte*~) main::$0
  (byte~) main::$1 ← ((byte)) (signed word) main::i#2
  *((byte*) main::sc#0) ← (byte~) main::$1
  (signed word) main::i#1 ← (signed word) main::i#2 + rangenext(-$a,$a)
  (bool~) main::$2 ← (signed word) main::i#1 != rangelast(-$a,$a)
  if((bool~) main::$2) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  return 
  to:@return
@1: scope:[]  from @begin
  call main 
  to:@2
@2: scope:[]  from @1
  to:@end
@end: scope:[]  from @2

SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*)(number) $400+(number) $28*(number) $a
(void()) main()
(byte*~) main::$0
(byte~) main::$1
(bool~) main::$2
(label) main::@1
(label) main::@return
(signed word) main::i
(signed word) main::i#0
(signed word) main::i#1
(signed word) main::i#2
(byte*) main::sc
(byte*) main::sc#0

Inlining cast (byte~) main::$1 ← (byte)(signed word) main::i#2
Successful SSA optimization Pass2InlineCast
Alias (byte*) main::sc#0 = (byte*~) main::$0 
Successful SSA optimization Pass2AliasElimination
Simple Condition (bool~) main::$2 [8] if((signed word) main::i#1!=rangelast(-$a,$a)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const signed word) main::i#0 = -$a
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [6] main::i#1 ← ++ main::i#2 to ++
Resolved ranged comparison value [8] if(main::i#1!=rangelast(-$a,$a)) goto main::@1 to (number) $b
Adding number conversion cast (snumber) $b in if((signed word) main::i#1!=(number) $b) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast $b
Successful SSA optimization PassNCastSimplification
Finalized signed number type (signed byte) $b
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining constant with var siblings (const signed word) main::i#0
Constant inlined main::i#0 = (signed word) -$a
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@3(between main::@1 and main::@1)
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @2
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
CALL GRAPH
Calls in [] to main:2 

Created 1 initial phi equivalence classes
Coalesced [13] main::i#3 ← main::i#1
Coalesced down to 1 phi equivalence classes
Culled Empty Block (label) @2
Culled Empty Block (label) main::@3
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
Adding NOP phi() at start of main

FINAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  [0] phi()
  to:@1
@1: scope:[]  from @begin
  [1] phi()
  [2] call main 
  to:@end
@end: scope:[]  from @1
  [3] phi()

(void()) main()
main: scope:[main]  from @1
  [4] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@1
  [5] (signed word) main::i#2 ← phi( main/(signed word) -$a main::@1/(signed word) main::i#1 )
  [6] (byte*) main::sc#0 ← (const byte*) SCREEN + (signed word) main::i#2
  [7] (byte~) main::$1 ← (byte)(signed word) main::i#2
  [8] *((byte*) main::sc#0) ← (byte~) main::$1
  [9] (signed word) main::i#1 ← ++ (signed word) main::i#2
  [10] if((signed word) main::i#1!=(signed byte) $b) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  [11] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte~) main::$1 22.0
(signed word) main::i
(signed word) main::i#1 16.5
(signed word) main::i#2 8.25
(byte*) main::sc
(byte*) main::sc#0 11.0

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
Added variable main::sc#0 to live range equivalence class [ main::sc#0 ]
Added variable main::$1 to live range equivalence class [ main::$1 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ main::sc#0 ]
[ main::$1 ]
Allocated zp[2]:2 [ main::i#2 main::i#1 ]
Allocated zp[2]:4 [ main::sc#0 ]
Allocated zp[1]:6 [ main::$1 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Test adding a signed word to a pointer
// Fragment pbuz1=pbuc1_plus_vwsz1.asm supplied by Richard-William Loerakker
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400+$28*$a
  // @begin
__bbegin:
  // [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
  jmp __b1
  // @1
__b1:
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
main_from___b1:
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
  jmp __bend
  // @end
__bend:
  // main
main: {
    .label __1 = 6
    .label sc = 4
    .label i = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [5] phi (signed word) main::i#2 = (signed word) -$a [phi:main->main::@1#0] -- vwsz1=vwsc1 
    lda #<-$a
    sta.z i
    lda #>-$a
    sta.z i+1
    jmp __b1
    // [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  __b1_from___b1:
    // [5] phi (signed word) main::i#2 = (signed word) main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [6] (byte*) main::sc#0 ← (const byte*) SCREEN + (signed word) main::i#2 -- pbuz1=pbuc1_plus_vwsz2 
    lda #<SCREEN
    clc
    adc.z i
    sta.z sc
    lda #>SCREEN
    adc.z i+1
    sta.z sc+1
    // [7] (byte~) main::$1 ← (byte)(signed word) main::i#2 -- vbuz1=_byte_vwsz2 
    lda.z i
    sta.z __1
    // [8] *((byte*) main::sc#0) ← (byte~) main::$1 -- _deref_pbuz1=vbuz2 
    lda.z __1
    ldy #0
    sta (sc),y
    // [9] (signed word) main::i#1 ← ++ (signed word) main::i#2 -- vwsz1=_inc_vwsz1 
    inc.z i
    bne !+
    inc.z i+1
  !:
    // [10] if((signed word) main::i#1!=(signed byte) $b) goto main::@1 -- vwsz1_neq_vwuc1_then_la1 
    lda.z i+1
    cmp #>$b
    bne __b1_from___b1
    lda.z i
    cmp #<$b
    bne __b1_from___b1
    jmp __breturn
    // main::@return
  __breturn:
    // [11] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [6] (byte*) main::sc#0 ← (const byte*) SCREEN + (signed word) main::i#2 [ main::i#2 main::sc#0 ] ( main:2 [ main::i#2 main::sc#0 ] ) always clobbers reg byte a 
Statement [7] (byte~) main::$1 ← (byte)(signed word) main::i#2 [ main::i#2 main::sc#0 main::$1 ] ( main:2 [ main::i#2 main::sc#0 main::$1 ] ) always clobbers reg byte a 
Statement [8] *((byte*) main::sc#0) ← (byte~) main::$1 [ main::i#2 ] ( main:2 [ main::i#2 ] ) always clobbers reg byte y 
Statement [10] if((signed word) main::i#1!=(signed byte) $b) goto main::@1 [ main::i#1 ] ( main:2 [ main::i#1 ] ) always clobbers reg byte a 
Potential registers zp[2]:2 [ main::i#2 main::i#1 ] : zp[2]:2 , 
Potential registers zp[2]:4 [ main::sc#0 ] : zp[2]:4 , 
Potential registers zp[1]:6 [ main::$1 ] : zp[1]:6 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 24.75: zp[2]:2 [ main::i#2 main::i#1 ] 22: zp[1]:6 [ main::$1 ] 11: zp[2]:4 [ main::sc#0 ] 
Uplift Scope [] 

Uplifting [main] best 773 combination zp[2]:2 [ main::i#2 main::i#1 ] reg byte a [ main::$1 ] zp[2]:4 [ main::sc#0 ] 
Uplifting [] best 773 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Test adding a signed word to a pointer
// Fragment pbuz1=pbuc1_plus_vwsz1.asm supplied by Richard-William Loerakker
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400+$28*$a
  // @begin
__bbegin:
  // [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
  jmp __b1
  // @1
__b1:
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
main_from___b1:
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
  jmp __bend
  // @end
__bend:
  // main
main: {
    .label sc = 4
    .label i = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [5] phi (signed word) main::i#2 = (signed word) -$a [phi:main->main::@1#0] -- vwsz1=vwsc1 
    lda #<-$a
    sta.z i
    lda #>-$a
    sta.z i+1
    jmp __b1
    // [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  __b1_from___b1:
    // [5] phi (signed word) main::i#2 = (signed word) main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [6] (byte*) main::sc#0 ← (const byte*) SCREEN + (signed word) main::i#2 -- pbuz1=pbuc1_plus_vwsz2 
    lda #<SCREEN
    clc
    adc.z i
    sta.z sc
    lda #>SCREEN
    adc.z i+1
    sta.z sc+1
    // [7] (byte~) main::$1 ← (byte)(signed word) main::i#2 -- vbuaa=_byte_vwsz1 
    lda.z i
    // [8] *((byte*) main::sc#0) ← (byte~) main::$1 -- _deref_pbuz1=vbuaa 
    ldy #0
    sta (sc),y
    // [9] (signed word) main::i#1 ← ++ (signed word) main::i#2 -- vwsz1=_inc_vwsz1 
    inc.z i
    bne !+
    inc.z i+1
  !:
    // [10] if((signed word) main::i#1!=(signed byte) $b) goto main::@1 -- vwsz1_neq_vwuc1_then_la1 
    lda.z i+1
    cmp #>$b
    bne __b1_from___b1
    lda.z i
    cmp #<$b
    bne __b1_from___b1
    jmp __breturn
    // main::@return
  __breturn:
    // [11] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Replacing label __b1_from___b1 with __b1
Replacing label __b1_from___b1 with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Removing instruction __b1_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __b1_from_main:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction jmp __b1
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*)(number) $400+(number) $28*(number) $a
(void()) main()
(byte~) main::$1 reg byte a 22.0
(label) main::@1
(label) main::@return
(signed word) main::i
(signed word) main::i#1 i zp[2]:2 16.5
(signed word) main::i#2 i zp[2]:2 8.25
(byte*) main::sc
(byte*) main::sc#0 sc zp[2]:4 11.0

zp[2]:2 [ main::i#2 main::i#1 ]
zp[2]:4 [ main::sc#0 ]
reg byte a [ main::$1 ]


FINAL ASSEMBLER
Score: 671

  // File Comments
// Test adding a signed word to a pointer
// Fragment pbuz1=pbuc1_plus_vwsz1.asm supplied by Richard-William Loerakker
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400+$28*$a
  // @begin
  // [1] phi from @begin to @1 [phi:@begin->@1]
  // @1
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
  // [3] phi from @1 to @end [phi:@1->@end]
  // @end
  // main
main: {
    .label sc = 4
    .label i = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
    // [5] phi (signed word) main::i#2 = (signed word) -$a [phi:main->main::@1#0] -- vwsz1=vwsc1 
    lda #<-$a
    sta.z i
    lda #>-$a
    sta.z i+1
    // [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
    // [5] phi (signed word) main::i#2 = (signed word) main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    // main::@1
  __b1:
    // sc = SCREEN + i
    // [6] (byte*) main::sc#0 ← (const byte*) SCREEN + (signed word) main::i#2 -- pbuz1=pbuc1_plus_vwsz2 
    lda #<SCREEN
    clc
    adc.z i
    sta.z sc
    lda #>SCREEN
    adc.z i+1
    sta.z sc+1
    // (char)i
    // [7] (byte~) main::$1 ← (byte)(signed word) main::i#2 -- vbuaa=_byte_vwsz1 
    lda.z i
    // *sc = (char)i
    // [8] *((byte*) main::sc#0) ← (byte~) main::$1 -- _deref_pbuz1=vbuaa 
    ldy #0
    sta (sc),y
    // for (signed word i : -10..10 )
    // [9] (signed word) main::i#1 ← ++ (signed word) main::i#2 -- vwsz1=_inc_vwsz1 
    inc.z i
    bne !+
    inc.z i+1
  !:
    // [10] if((signed word) main::i#1!=(signed byte) $b) goto main::@1 -- vwsz1_neq_vwuc1_then_la1 
    lda.z i+1
    cmp #>$b
    bne __b1
    lda.z i
    cmp #<$b
    bne __b1
    // main::@return
    // }
    // [11] return 
    rts
}
  // File Data

