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

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

(void()) main()
main: scope:[main]  from @3
  (byte) main::i#0 ← (byte) 0
  to:main::@1
main::@1: scope:[main]  from main main::@4
  (byte) main::i#2 ← phi( main/(byte) main::i#0 main::@4/(byte) main::i#1 )
  (number~) main::$0 ← (byte) main::i#2 + (number) 1
  (number~) main::$1 ← (byte) main::i#2 + (number) 2
  (byte) sum::a#0 ← (byte) main::i#2
  (byte) sum::b#0 ← (number~) main::$0
  (byte) sum::c#0 ← (number~) main::$1
  call sum 
  (byte) sum::return#0 ← (byte) sum::return#2
  to:main::@3
main::@3: scope:[main]  from main::@1
  (byte) main::i#3 ← phi( main::@1/(byte) main::i#2 )
  (byte) sum::return#3 ← phi( main::@1/(byte) sum::return#0 )
  (byte~) main::$2 ← (byte) sum::return#3
  *((const byte*) SCREEN + (byte) main::i#3) ← (byte~) main::$2
  (number~) main::$3 ← (byte) main::i#3 + (number) 1
  (number~) main::$4 ← (byte) main::i#3 + (number) 2
  (byte) sum2::a#0 ← (byte) main::i#3
  (byte) sum2::b#0 ← (number~) main::$3
  (byte) sum2::c#0 ← (number~) main::$4
  call sum2 
  (byte) sum2::return#0 ← (byte) sum2::return#2
  to:main::@4
main::@4: scope:[main]  from main::@3
  (byte) main::i#4 ← phi( main::@3/(byte) main::i#3 )
  (byte) sum2::return#3 ← phi( main::@3/(byte) sum2::return#0 )
  (byte~) main::$5 ← (byte) sum2::return#3
  *((const byte*) SCREEN2 + (byte) main::i#4) ← (byte~) main::$5
  (byte) main::i#1 ← (byte) main::i#4 + rangenext(0,$a)
  (bool~) main::$6 ← (byte) main::i#1 != rangelast(0,$a)
  if((bool~) main::$6) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@4
  return 
  to:@return

(byte()) sum((byte) sum::a , (byte) sum::b , (byte) sum::c)
sum: scope:[sum]  from main::@1
  (byte) sum::c#1 ← phi( main::@1/(byte) sum::c#0 )
  (byte) sum::b#1 ← phi( main::@1/(byte) sum::b#0 )
  (byte) sum::a#1 ← phi( main::@1/(byte) sum::a#0 )
  (byte~) sum::$0 ← (byte) sum::a#1 + (byte) sum::b#1
  (byte~) sum::$1 ← (byte~) sum::$0 + (byte) sum::c#1
  (byte) sum::return#1 ← (byte~) sum::$1
  to:sum::@return
sum::@return: scope:[sum]  from sum
  (byte) sum::return#4 ← phi( sum/(byte) sum::return#1 )
  (byte) sum::return#2 ← (byte) sum::return#4
  return 
  to:@return

(byte()) sum2((byte) sum2::a , (byte) sum2::b , (byte) sum2::c)
sum2: scope:[sum2]  from main::@3
  (byte) sum2::c#1 ← phi( main::@3/(byte) sum2::c#0 )
  (byte) sum2::b#1 ← phi( main::@3/(byte) sum2::b#0 )
  (byte) sum2::a#1 ← phi( main::@3/(byte) sum2::a#0 )
  (byte~) sum2::$0 ← (byte) sum2::a#1 + (byte) sum2::b#1
  (byte~) sum2::$1 ← (byte~) sum2::$0 + (byte) sum2::c#1
  (byte) sum2::return#1 ← (byte~) sum2::$1
  to:sum2::@return
sum2::@return: scope:[sum2]  from sum2
  (byte) sum2::return#4 ← phi( sum2/(byte) sum2::return#1 )
  (byte) sum2::return#2 ← (byte) sum2::return#4
  return 
  to:@return
@3: scope:[]  from @begin
  call main 
  to:@4
@4: scope:[]  from @3
  to:@end
@end: scope:[]  from @4

SYMBOL TABLE SSA
(label) @3
(label) @4
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*)(number) $400
(const byte*) SCREEN2 = (byte*)(number) $400+(number) $28
(void()) main()
(number~) main::$0
(number~) main::$1
(byte~) main::$2
(number~) main::$3
(number~) main::$4
(byte~) main::$5
(bool~) main::$6
(label) main::@1
(label) main::@3
(label) main::@4
(label) main::@return
(byte) main::i
(byte) main::i#0
(byte) main::i#1
(byte) main::i#2
(byte) main::i#3
(byte) main::i#4
(byte()) sum((byte) sum::a , (byte) sum::b , (byte) sum::c)
(byte~) sum::$0
(byte~) sum::$1
(label) sum::@return
(byte) sum::a
(byte) sum::a#0
(byte) sum::a#1
(byte) sum::b
(byte) sum::b#0
(byte) sum::b#1
(byte) sum::c
(byte) sum::c#0
(byte) sum::c#1
(byte) sum::return
(byte) sum::return#0
(byte) sum::return#1
(byte) sum::return#2
(byte) sum::return#3
(byte) sum::return#4
(byte()) sum2((byte) sum2::a , (byte) sum2::b , (byte) sum2::c)
(byte~) sum2::$0
(byte~) sum2::$1
(label) sum2::@return
(byte) sum2::a
(byte) sum2::a#0
(byte) sum2::a#1
(byte) sum2::b
(byte) sum2::b#0
(byte) sum2::b#1
(byte) sum2::c
(byte) sum2::c#0
(byte) sum2::c#1
(byte) sum2::return
(byte) sum2::return#0
(byte) sum2::return#1
(byte) sum2::return#2
(byte) sum2::return#3
(byte) sum2::return#4

Adding number conversion cast (unumber) 1 in (number~) main::$0 ← (byte) main::i#2 + (number) 1
Adding number conversion cast (unumber) main::$0 in (number~) main::$0 ← (byte) main::i#2 + (unumber)(number) 1
Adding number conversion cast (unumber) 2 in (number~) main::$1 ← (byte) main::i#2 + (number) 2
Adding number conversion cast (unumber) main::$1 in (number~) main::$1 ← (byte) main::i#2 + (unumber)(number) 2
Adding number conversion cast (unumber) 1 in (number~) main::$3 ← (byte) main::i#3 + (number) 1
Adding number conversion cast (unumber) main::$3 in (number~) main::$3 ← (byte) main::i#3 + (unumber)(number) 1
Adding number conversion cast (unumber) 2 in (number~) main::$4 ← (byte) main::i#3 + (number) 2
Adding number conversion cast (unumber) main::$4 in (number~) main::$4 ← (byte) main::i#3 + (unumber)(number) 2
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 1
Simplifying constant integer cast 2
Simplifying constant integer cast 1
Simplifying constant integer cast 2
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) 2
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) 2
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to byte in (unumber~) main::$0 ← (byte) main::i#2 + (byte) 1
Inferred type updated to byte in (unumber~) main::$1 ← (byte) main::i#2 + (byte) 2
Inferred type updated to byte in (unumber~) main::$3 ← (byte) main::i#3 + (byte) 1
Inferred type updated to byte in (unumber~) main::$4 ← (byte) main::i#3 + (byte) 2
Alias (byte) sum::b#0 = (byte~) main::$0 
Alias (byte) sum::c#0 = (byte~) main::$1 
Alias (byte) sum::return#0 = (byte) sum::return#3 
Alias (byte) main::i#2 = (byte) main::i#3 (byte) main::i#4 
Alias (byte) sum2::b#0 = (byte~) main::$3 
Alias (byte) sum2::c#0 = (byte~) main::$4 
Alias (byte) sum2::return#0 = (byte) sum2::return#3 
Alias (byte) sum::return#1 = (byte~) sum::$1 (byte) sum::return#4 (byte) sum::return#2 
Alias (byte) sum2::return#1 = (byte~) sum2::$1 (byte) sum2::return#4 (byte) sum2::return#2 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte) sum::a#1 (byte) sum::a#0
Identical Phi Values (byte) sum::b#1 (byte) sum::b#0
Identical Phi Values (byte) sum::c#1 (byte) sum::c#0
Identical Phi Values (byte) sum2::a#1 (byte) sum2::a#0
Identical Phi Values (byte) sum2::b#1 (byte) sum2::b#0
Identical Phi Values (byte) sum2::c#1 (byte) sum2::c#0
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition (bool~) main::$6 [18] if((byte) main::i#1!=rangelast(0,$a)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte) main::i#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [16] main::i#1 ← ++ main::i#2 to ++
Resolved ranged comparison value [18] if(main::i#1!=rangelast(0,$a)) goto main::@1 to (number) $b
Adding number conversion cast (unumber) $b in if((byte) main::i#1!=(number) $b) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast $b
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $b
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining constant with var siblings (const byte) main::i#0
Constant inlined main::i#0 = (byte) 0
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@5(between main::@4 and main::@1)
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @3
Adding NOP phi() at start of @4
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
CALL GRAPH
Calls in [] to main:2 
Calls in [main] to sum:10 sum2:17 

Created 1 initial phi equivalence classes
Coalesced [24] main::i#5 ← main::i#1
Coalesced down to 1 phi equivalence classes
Culled Empty Block (label) @4
Culled Empty Block (label) main::@5
Renumbering block @3 to @1
Renumbering block main::@3 to main::@2
Renumbering block main::@4 to 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::@3
  [5] (byte) main::i#2 ← phi( main/(byte) 0 main::@3/(byte) main::i#1 )
  [6] (byte) sum::b#0 ← (byte) main::i#2 + (byte) 1
  [7] (byte) sum::c#0 ← (byte) main::i#2 + (byte) 2
  [8] (byte) sum::a#0 ← (byte) main::i#2
  [9] call sum 
  [10] (byte) sum::return#0 ← (byte) sum::return#1
  to:main::@2
main::@2: scope:[main]  from main::@1
  [11] (byte~) main::$2 ← (byte) sum::return#0
  [12] *((const byte*) SCREEN + (byte) main::i#2) ← (byte~) main::$2
  [13] (byte) sum2::b#0 ← (byte) main::i#2 + (byte) 1
  [14] (byte) sum2::c#0 ← (byte) main::i#2 + (byte) 2
  [15] (byte) sum2::a#0 ← (byte) main::i#2
  [16] call sum2 
  [17] (byte) sum2::return#0 ← (byte) sum2::return#1
  to:main::@3
main::@3: scope:[main]  from main::@2
  [18] (byte~) main::$5 ← (byte) sum2::return#0
  [19] *((const byte*) SCREEN2 + (byte) main::i#2) ← (byte~) main::$5
  [20] (byte) main::i#1 ← ++ (byte) main::i#2
  [21] if((byte) main::i#1!=(byte) $b) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@3
  [22] return 
  to:@return

(byte()) sum2((byte) sum2::a , (byte) sum2::b , (byte) sum2::c)
sum2: scope:[sum2]  from main::@2
  [23] (byte~) sum2::$0 ← (byte) sum2::a#0 + (byte) sum2::b#0
  [24] (byte) sum2::return#1 ← (byte~) sum2::$0 + (byte) sum2::c#0
  to:sum2::@return
sum2::@return: scope:[sum2]  from sum2
  [25] return 
  to:@return

(byte()) sum((byte) sum::a , (byte) sum::b , (byte) sum::c)
sum: scope:[sum]  from main::@1
  [26] (byte~) sum::$0 ← (byte) sum::a#0 + (byte) sum::b#0
  [27] (byte) sum::return#1 ← (byte~) sum::$0 + (byte) sum::c#0
  to:sum::@return
sum::@return: scope:[sum]  from sum
  [28] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte~) main::$2 22.0
(byte~) main::$5 22.0
(byte) main::i
(byte) main::i#1 16.5
(byte) main::i#2 7.333333333333333
(byte()) sum((byte) sum::a , (byte) sum::b , (byte) sum::c)
(byte~) sum::$0 4.0
(byte) sum::a
(byte) sum::a#0 13.0
(byte) sum::b
(byte) sum::b#0 4.333333333333333
(byte) sum::c
(byte) sum::c#0 4.333333333333333
(byte) sum::return
(byte) sum::return#0 22.0
(byte) sum::return#1 4.333333333333333
(byte()) sum2((byte) sum2::a , (byte) sum2::b , (byte) sum2::c)
(byte~) sum2::$0 4.0
(byte) sum2::a
(byte) sum2::a#0 13.0
(byte) sum2::b
(byte) sum2::b#0 4.333333333333333
(byte) sum2::c
(byte) sum2::c#0 4.333333333333333
(byte) sum2::return
(byte) sum2::return#0 22.0
(byte) sum2::return#1 4.333333333333333

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
Added variable sum::b#0 to live range equivalence class [ sum::b#0 ]
Added variable sum::c#0 to live range equivalence class [ sum::c#0 ]
Added variable sum::a#0 to live range equivalence class [ sum::a#0 ]
Added variable sum::return#0 to live range equivalence class [ sum::return#0 ]
Added variable main::$2 to live range equivalence class [ main::$2 ]
Added variable sum2::b#0 to live range equivalence class [ sum2::b#0 ]
Added variable sum2::c#0 to live range equivalence class [ sum2::c#0 ]
Added variable sum2::a#0 to live range equivalence class [ sum2::a#0 ]
Added variable sum2::return#0 to live range equivalence class [ sum2::return#0 ]
Added variable main::$5 to live range equivalence class [ main::$5 ]
Added variable sum2::$0 to live range equivalence class [ sum2::$0 ]
Added variable sum2::return#1 to live range equivalence class [ sum2::return#1 ]
Added variable sum::$0 to live range equivalence class [ sum::$0 ]
Added variable sum::return#1 to live range equivalence class [ sum::return#1 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ sum::b#0 ]
[ sum::c#0 ]
[ sum::a#0 ]
[ sum::return#0 ]
[ main::$2 ]
[ sum2::b#0 ]
[ sum2::c#0 ]
[ sum2::a#0 ]
[ sum2::return#0 ]
[ main::$5 ]
[ sum2::$0 ]
[ sum2::return#1 ]
[ sum::$0 ]
[ sum::return#1 ]
Allocated zp[1]:2 [ main::i#2 main::i#1 ]
Allocated zp[1]:3 [ sum::b#0 ]
Allocated zp[1]:4 [ sum::c#0 ]
Allocated zp[1]:5 [ sum::a#0 ]
Allocated zp[1]:6 [ sum::return#0 ]
Allocated zp[1]:7 [ main::$2 ]
Allocated zp[1]:8 [ sum2::b#0 ]
Allocated zp[1]:9 [ sum2::c#0 ]
Allocated zp[1]:10 [ sum2::a#0 ]
Allocated zp[1]:11 [ sum2::return#0 ]
Allocated zp[1]:12 [ main::$5 ]
Allocated zp[1]:13 [ sum2::$0 ]
Allocated zp[1]:14 [ sum2::return#1 ]
Allocated zp[1]:15 [ sum::$0 ]
Allocated zp[1]:16 [ sum::return#1 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .label SCREEN2 = $400+$28
  // @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 __2 = 7
    .label __5 = $c
    .label i = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z i
    jmp __b1
    // [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
  __b1_from___b3:
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@3->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [6] (byte) sum::b#0 ← (byte) main::i#2 + (byte) 1 -- vbuz1=vbuz2_plus_1 
    ldy.z i
    iny
    sty.z sum.b
    // [7] (byte) sum::c#0 ← (byte) main::i#2 + (byte) 2 -- vbuz1=vbuz2_plus_2 
    lda.z i
    clc
    adc #2
    sta.z sum.c
    // [8] (byte) sum::a#0 ← (byte) main::i#2 -- vbuz1=vbuz2 
    lda.z i
    sta.z sum.a
    // [9] call sum 
    jsr sum
    // [10] (byte) sum::return#0 ← (byte) sum::return#1 -- vbuz1=vbuz2 
    lda.z sum.return_1
    sta.z sum.return
    jmp __b2
    // main::@2
  __b2:
    // [11] (byte~) main::$2 ← (byte) sum::return#0 -- vbuz1=vbuz2 
    lda.z sum.return
    sta.z __2
    // [12] *((const byte*) SCREEN + (byte) main::i#2) ← (byte~) main::$2 -- pbuc1_derefidx_vbuz1=vbuz2 
    lda.z __2
    ldy.z i
    sta SCREEN,y
    // [13] (byte) sum2::b#0 ← (byte) main::i#2 + (byte) 1 -- vbuz1=vbuz2_plus_1 
    ldy.z i
    iny
    sty.z sum2.b
    // [14] (byte) sum2::c#0 ← (byte) main::i#2 + (byte) 2 -- vbuz1=vbuz2_plus_2 
    lda.z i
    clc
    adc #2
    sta.z sum2.c
    // [15] (byte) sum2::a#0 ← (byte) main::i#2 -- vbuz1=vbuz2 
    lda.z i
    sta.z sum2.a
    // [16] call sum2 
    jsr sum2
    // [17] (byte) sum2::return#0 ← (byte) sum2::return#1 -- vbuz1=vbuz2 
    lda.z sum2.return_1
    sta.z sum2.return
    jmp __b3
    // main::@3
  __b3:
    // [18] (byte~) main::$5 ← (byte) sum2::return#0 -- vbuz1=vbuz2 
    lda.z sum2.return
    sta.z __5
    // [19] *((const byte*) SCREEN2 + (byte) main::i#2) ← (byte~) main::$5 -- pbuc1_derefidx_vbuz1=vbuz2 
    lda.z __5
    ldy.z i
    sta SCREEN2,y
    // [20] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [21] if((byte) main::i#1!=(byte) $b) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #$b
    cmp.z i
    bne __b1_from___b3
    jmp __breturn
    // main::@return
  __breturn:
    // [22] return 
    rts
}
  // sum2
// sum2(byte zp($a) a, byte zp(8) b, byte zp(9) c)
sum2: {
    .label __0 = $d
    .label a = $a
    .label b = 8
    .label c = 9
    .label return = $b
    .label return_1 = $e
    // [23] (byte~) sum2::$0 ← (byte) sum2::a#0 + (byte) sum2::b#0 -- vbuz1=vbuz2_plus_vbuz3 
    lda.z a
    clc
    adc.z b
    sta.z __0
    // [24] (byte) sum2::return#1 ← (byte~) sum2::$0 + (byte) sum2::c#0 -- vbuz1=vbuz2_plus_vbuz3 
    lda.z __0
    clc
    adc.z c
    sta.z return_1
    jmp __breturn
    // sum2::@return
  __breturn:
    // [25] return 
    rts
}
  // sum
// sum(byte zp(5) a, byte zp(3) b, byte zp(4) c)
sum: {
    .label __0 = $f
    .label a = 5
    .label b = 3
    .label c = 4
    .label return = 6
    .label return_1 = $10
    // [26] (byte~) sum::$0 ← (byte) sum::a#0 + (byte) sum::b#0 -- vbuz1=vbuz2_plus_vbuz3 
    lda.z a
    clc
    adc.z b
    sta.z __0
    // [27] (byte) sum::return#1 ← (byte~) sum::$0 + (byte) sum::c#0 -- vbuz1=vbuz2_plus_vbuz3 
    lda.z __0
    clc
    adc.z c
    sta.z return_1
    jmp __breturn
    // sum::@return
  __breturn:
    // [28] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [23] (byte~) sum2::$0 ← (byte) sum2::a#0 + (byte) sum2::b#0 [ sum2::c#0 sum2::$0 ] ( main:2::sum2:16 [ main::i#2 sum2::c#0 sum2::$0 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::i#2 main::i#1 ]
Removing always clobbered register reg byte a as potential for zp[1]:9 [ sum2::c#0 ]
Statement [24] (byte) sum2::return#1 ← (byte~) sum2::$0 + (byte) sum2::c#0 [ sum2::return#1 ] ( main:2::sum2:16 [ main::i#2 sum2::return#1 ] ) always clobbers reg byte a 
Statement [26] (byte~) sum::$0 ← (byte) sum::a#0 + (byte) sum::b#0 [ sum::c#0 sum::$0 ] ( main:2::sum:9 [ main::i#2 sum::c#0 sum::$0 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:4 [ sum::c#0 ]
Statement [27] (byte) sum::return#1 ← (byte~) sum::$0 + (byte) sum::c#0 [ sum::return#1 ] ( main:2::sum:9 [ main::i#2 sum::return#1 ] ) always clobbers reg byte a 
Statement [23] (byte~) sum2::$0 ← (byte) sum2::a#0 + (byte) sum2::b#0 [ sum2::c#0 sum2::$0 ] ( main:2::sum2:16 [ main::i#2 sum2::c#0 sum2::$0 ] ) always clobbers reg byte a 
Statement [24] (byte) sum2::return#1 ← (byte~) sum2::$0 + (byte) sum2::c#0 [ sum2::return#1 ] ( main:2::sum2:16 [ main::i#2 sum2::return#1 ] ) always clobbers reg byte a 
Statement [26] (byte~) sum::$0 ← (byte) sum::a#0 + (byte) sum::b#0 [ sum::c#0 sum::$0 ] ( main:2::sum:9 [ main::i#2 sum::c#0 sum::$0 ] ) always clobbers reg byte a 
Statement [27] (byte) sum::return#1 ← (byte~) sum::$0 + (byte) sum::c#0 [ sum::return#1 ] ( main:2::sum:9 [ main::i#2 sum::return#1 ] ) always clobbers reg byte a 
Potential registers zp[1]:2 [ main::i#2 main::i#1 ] : zp[1]:2 , reg byte x , reg byte y , 
Potential registers zp[1]:3 [ sum::b#0 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:4 [ sum::c#0 ] : zp[1]:4 , reg byte x , reg byte y , 
Potential registers zp[1]:5 [ sum::a#0 ] : zp[1]:5 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:6 [ sum::return#0 ] : zp[1]:6 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:7 [ main::$2 ] : zp[1]:7 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:8 [ sum2::b#0 ] : zp[1]:8 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:9 [ sum2::c#0 ] : zp[1]:9 , reg byte x , reg byte y , 
Potential registers zp[1]:10 [ sum2::a#0 ] : zp[1]:10 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:11 [ sum2::return#0 ] : zp[1]:11 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:12 [ main::$5 ] : zp[1]:12 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:13 [ sum2::$0 ] : zp[1]:13 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:14 [ sum2::return#1 ] : zp[1]:14 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:15 [ sum::$0 ] : zp[1]:15 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:16 [ sum::return#1 ] : zp[1]:16 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 23.83: zp[1]:2 [ main::i#2 main::i#1 ] 22: zp[1]:7 [ main::$2 ] 22: zp[1]:12 [ main::$5 ] 
Uplift Scope [sum] 22: zp[1]:6 [ sum::return#0 ] 13: zp[1]:5 [ sum::a#0 ] 4.33: zp[1]:3 [ sum::b#0 ] 4.33: zp[1]:4 [ sum::c#0 ] 4.33: zp[1]:16 [ sum::return#1 ] 4: zp[1]:15 [ sum::$0 ] 
Uplift Scope [sum2] 22: zp[1]:11 [ sum2::return#0 ] 13: zp[1]:10 [ sum2::a#0 ] 4.33: zp[1]:8 [ sum2::b#0 ] 4.33: zp[1]:9 [ sum2::c#0 ] 4.33: zp[1]:14 [ sum2::return#1 ] 4: zp[1]:13 [ sum2::$0 ] 
Uplift Scope [] 

Uplifting [main] best 1345 combination zp[1]:2 [ main::i#2 main::i#1 ] reg byte a [ main::$2 ] reg byte a [ main::$5 ] 
Uplifting [sum] best 1214 combination reg byte a [ sum::return#0 ] reg byte y [ sum::a#0 ] reg byte a [ sum::b#0 ] reg byte x [ sum::c#0 ] zp[1]:16 [ sum::return#1 ] zp[1]:15 [ sum::$0 ] 
Limited combination testing to 100 combinations of 3072 possible.
Uplifting [sum2] best 1083 combination reg byte a [ sum2::return#0 ] reg byte y [ sum2::a#0 ] reg byte a [ sum2::b#0 ] reg byte x [ sum2::c#0 ] zp[1]:14 [ sum2::return#1 ] zp[1]:13 [ sum2::$0 ] 
Limited combination testing to 100 combinations of 3072 possible.
Uplifting [] best 1083 combination 
Attempting to uplift remaining variables inzp[1]:2 [ main::i#2 main::i#1 ]
Uplifting [main] best 1083 combination zp[1]:2 [ main::i#2 main::i#1 ] 
Attempting to uplift remaining variables inzp[1]:14 [ sum2::return#1 ]
Uplifting [sum2] best 1050 combination reg byte a [ sum2::return#1 ] 
Attempting to uplift remaining variables inzp[1]:16 [ sum::return#1 ]
Uplifting [sum] best 1017 combination reg byte a [ sum::return#1 ] 
Attempting to uplift remaining variables inzp[1]:13 [ sum2::$0 ]
Uplifting [sum2] best 1015 combination reg byte a [ sum2::$0 ] 
Attempting to uplift remaining variables inzp[1]:15 [ sum::$0 ]
Uplifting [sum] best 1013 combination reg byte a [ sum::$0 ] 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .label SCREEN2 = $400+$28
  // @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 i = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z i
    jmp __b1
    // [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
  __b1_from___b3:
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@3->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [6] (byte) sum::b#0 ← (byte) main::i#2 + (byte) 1 -- vbuaa=vbuz1_plus_1 
    lda.z i
    clc
    adc #1
    // [7] (byte) sum::c#0 ← (byte) main::i#2 + (byte) 2 -- vbuxx=vbuz1_plus_2 
    ldx.z i
    inx
    inx
    // [8] (byte) sum::a#0 ← (byte) main::i#2 -- vbuyy=vbuz1 
    ldy.z i
    // [9] call sum 
    jsr sum
    // [10] (byte) sum::return#0 ← (byte) sum::return#1
    jmp __b2
    // main::@2
  __b2:
    // [11] (byte~) main::$2 ← (byte) sum::return#0
    // [12] *((const byte*) SCREEN + (byte) main::i#2) ← (byte~) main::$2 -- pbuc1_derefidx_vbuz1=vbuaa 
    ldy.z i
    sta SCREEN,y
    // [13] (byte) sum2::b#0 ← (byte) main::i#2 + (byte) 1 -- vbuaa=vbuz1_plus_1 
    lda.z i
    clc
    adc #1
    // [14] (byte) sum2::c#0 ← (byte) main::i#2 + (byte) 2 -- vbuxx=vbuz1_plus_2 
    ldx.z i
    inx
    inx
    // [15] (byte) sum2::a#0 ← (byte) main::i#2 -- vbuyy=vbuz1 
    ldy.z i
    // [16] call sum2 
    jsr sum2
    // [17] (byte) sum2::return#0 ← (byte) sum2::return#1
    jmp __b3
    // main::@3
  __b3:
    // [18] (byte~) main::$5 ← (byte) sum2::return#0
    // [19] *((const byte*) SCREEN2 + (byte) main::i#2) ← (byte~) main::$5 -- pbuc1_derefidx_vbuz1=vbuaa 
    ldy.z i
    sta SCREEN2,y
    // [20] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [21] if((byte) main::i#1!=(byte) $b) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #$b
    cmp.z i
    bne __b1_from___b3
    jmp __breturn
    // main::@return
  __breturn:
    // [22] return 
    rts
}
  // sum2
// sum2(byte register(Y) a, byte register(A) b, byte register(X) c)
sum2: {
    // [23] (byte~) sum2::$0 ← (byte) sum2::a#0 + (byte) sum2::b#0 -- vbuaa=vbuyy_plus_vbuaa 
    sty.z $ff
    clc
    adc.z $ff
    // [24] (byte) sum2::return#1 ← (byte~) sum2::$0 + (byte) sum2::c#0 -- vbuaa=vbuaa_plus_vbuxx 
    stx.z $ff
    clc
    adc.z $ff
    jmp __breturn
    // sum2::@return
  __breturn:
    // [25] return 
    rts
}
  // sum
// sum(byte register(Y) a, byte register(A) b, byte register(X) c)
sum: {
    // [26] (byte~) sum::$0 ← (byte) sum::a#0 + (byte) sum::b#0 -- vbuaa=vbuyy_plus_vbuaa 
    sty.z $ff
    clc
    adc.z $ff
    // [27] (byte) sum::return#1 ← (byte~) sum::$0 + (byte) sum::c#0 -- vbuaa=vbuaa_plus_vbuxx 
    stx.z $ff
    clc
    adc.z $ff
    jmp __breturn
    // sum::@return
  __breturn:
    // [28] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __b2
Removing instruction jmp __b3
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing instruction lda.z i with TYA
Removing instruction ldy.z i
Succesful ASM optimization Pass5UnnecesaryLoadElimination
Replacing label __bbegin with __b1
Replacing label __b1_from___b3 with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Removing instruction __b1_from___b3:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __b1_from_main:
Removing instruction __b2:
Removing instruction __b3:
Removing instruction __breturn:
Removing instruction __breturn:
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*) 1024
(const byte*) SCREEN2 = (byte*)(number) $400+(number) $28
(void()) main()
(byte~) main::$2 reg byte a 22.0
(byte~) main::$5 reg byte a 22.0
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@return
(byte) main::i
(byte) main::i#1 i zp[1]:2 16.5
(byte) main::i#2 i zp[1]:2 7.333333333333333
(byte()) sum((byte) sum::a , (byte) sum::b , (byte) sum::c)
(byte~) sum::$0 reg byte a 4.0
(label) sum::@return
(byte) sum::a
(byte) sum::a#0 reg byte y 13.0
(byte) sum::b
(byte) sum::b#0 reg byte a 4.333333333333333
(byte) sum::c
(byte) sum::c#0 reg byte x 4.333333333333333
(byte) sum::return
(byte) sum::return#0 reg byte a 22.0
(byte) sum::return#1 reg byte a 4.333333333333333
(byte()) sum2((byte) sum2::a , (byte) sum2::b , (byte) sum2::c)
(byte~) sum2::$0 reg byte a 4.0
(label) sum2::@return
(byte) sum2::a
(byte) sum2::a#0 reg byte y 13.0
(byte) sum2::b
(byte) sum2::b#0 reg byte a 4.333333333333333
(byte) sum2::c
(byte) sum2::c#0 reg byte x 4.333333333333333
(byte) sum2::return
(byte) sum2::return#0 reg byte a 22.0
(byte) sum2::return#1 reg byte a 4.333333333333333

zp[1]:2 [ main::i#2 main::i#1 ]
reg byte a [ sum::b#0 ]
reg byte x [ sum::c#0 ]
reg byte y [ sum::a#0 ]
reg byte a [ sum::return#0 ]
reg byte a [ main::$2 ]
reg byte a [ sum2::b#0 ]
reg byte x [ sum2::c#0 ]
reg byte y [ sum2::a#0 ]
reg byte a [ sum2::return#0 ]
reg byte a [ main::$5 ]
reg byte a [ sum2::$0 ]
reg byte a [ sum2::return#1 ]
reg byte a [ sum::$0 ]
reg byte a [ sum::return#1 ]


FINAL ASSEMBLER
Score: 805

  // File Comments
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .label SCREEN2 = $400+$28
  // @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 i = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
    // [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z i
    // [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@3->main::@1#0] -- register_copy 
    // main::@1
  __b1:
    // sum(i,i+1,i+2)
    // [6] (byte) sum::b#0 ← (byte) main::i#2 + (byte) 1 -- vbuaa=vbuz1_plus_1 
    lda.z i
    clc
    adc #1
    // [7] (byte) sum::c#0 ← (byte) main::i#2 + (byte) 2 -- vbuxx=vbuz1_plus_2 
    ldx.z i
    inx
    inx
    // [8] (byte) sum::a#0 ← (byte) main::i#2 -- vbuyy=vbuz1 
    ldy.z i
    // [9] call sum 
    jsr sum
    // [10] (byte) sum::return#0 ← (byte) sum::return#1
    // main::@2
    // [11] (byte~) main::$2 ← (byte) sum::return#0
    // SCREEN[i] = sum(i,i+1,i+2)
    // [12] *((const byte*) SCREEN + (byte) main::i#2) ← (byte~) main::$2 -- pbuc1_derefidx_vbuz1=vbuaa 
    ldy.z i
    sta SCREEN,y
    // sum2(i,i+1,i+2)
    // [13] (byte) sum2::b#0 ← (byte) main::i#2 + (byte) 1 -- vbuaa=vbuz1_plus_1 
    tya
    clc
    adc #1
    // [14] (byte) sum2::c#0 ← (byte) main::i#2 + (byte) 2 -- vbuxx=vbuz1_plus_2 
    ldx.z i
    inx
    inx
    // [15] (byte) sum2::a#0 ← (byte) main::i#2 -- vbuyy=vbuz1 
    // [16] call sum2 
    jsr sum2
    // [17] (byte) sum2::return#0 ← (byte) sum2::return#1
    // main::@3
    // [18] (byte~) main::$5 ← (byte) sum2::return#0
    // SCREEN2[i] = sum2(i,i+1,i+2)
    // [19] *((const byte*) SCREEN2 + (byte) main::i#2) ← (byte~) main::$5 -- pbuc1_derefidx_vbuz1=vbuaa 
    ldy.z i
    sta SCREEN2,y
    // for(byte i : 0..10)
    // [20] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [21] if((byte) main::i#1!=(byte) $b) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #$b
    cmp.z i
    bne __b1
    // main::@return
    // }
    // [22] return 
    rts
}
  // sum2
// sum2(byte register(Y) a, byte register(A) b, byte register(X) c)
sum2: {
    // a+b
    // [23] (byte~) sum2::$0 ← (byte) sum2::a#0 + (byte) sum2::b#0 -- vbuaa=vbuyy_plus_vbuaa 
    sty.z $ff
    clc
    adc.z $ff
    // a+b+c
    // [24] (byte) sum2::return#1 ← (byte~) sum2::$0 + (byte) sum2::c#0 -- vbuaa=vbuaa_plus_vbuxx 
    stx.z $ff
    clc
    adc.z $ff
    // sum2::@return
    // }
    // [25] return 
    rts
}
  // sum
// sum(byte register(Y) a, byte register(A) b, byte register(X) c)
sum: {
    // a+b
    // [26] (byte~) sum::$0 ← (byte) sum::a#0 + (byte) sum::b#0 -- vbuaa=vbuyy_plus_vbuaa 
    sty.z $ff
    clc
    adc.z $ff
    // a+b+c
    // [27] (byte) sum::return#1 ← (byte~) sum::$0 + (byte) sum::c#0 -- vbuaa=vbuaa_plus_vbuxx 
    stx.z $ff
    clc
    adc.z $ff
    // sum::@return
    // }
    // [28] return 
    rts
}
  // File Data

