
CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (byte*) SCREEN#0 ← ((byte*)) (word/signed word/dword/signed dword) 1024
  (word/signed word/dword/signed dword~) $0 ← (word/signed word/dword/signed dword) 1024 + (byte/signed byte/word/signed word/dword/signed dword) 40
  (byte*) SCREEN2#0 ← ((byte*)) (word/signed word/dword/signed dword~) $0
  to:@3
main: scope:[main]  from @3
  (byte*) SCREEN2#4 ← phi( @3/(byte*) SCREEN2#5 )
  (byte*) SCREEN#3 ← phi( @3/(byte*) SCREEN#5 )
  (byte) main::i#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0
  to:main::@1
main::@1: scope:[main]  from main main::@4
  (byte*) SCREEN2#3 ← phi( main/(byte*) SCREEN2#4 main::@4/(byte*) SCREEN2#1 )
  (byte*) SCREEN#2 ← phi( main/(byte*) SCREEN#3 main::@4/(byte*) SCREEN#4 )
  (byte) main::i#2 ← phi( main/(byte) main::i#0 main::@4/(byte) main::i#1 )
  (byte/signed word/word/dword/signed dword~) main::$0 ← (byte) main::i#2 + (byte/signed byte/word/signed word/dword/signed dword) 1
  (byte/signed word/word/dword/signed dword~) main::$1 ← (byte) main::i#2 + (byte/signed byte/word/signed word/dword/signed dword) 2
  (byte) sum::a#0 ← (byte) main::i#2
  (byte) sum::b#0 ← (byte/signed word/word/dword/signed dword~) main::$0
  (byte) sum::c#0 ← (byte/signed word/word/dword/signed dword~) main::$1
  call sum 
  (byte) sum::return#0 ← (byte) sum::return#2
  to:main::@3
main::@3: scope:[main]  from main::@1
  (byte*) SCREEN2#2 ← phi( main::@1/(byte*) SCREEN2#3 )
  (byte) main::i#3 ← phi( main::@1/(byte) main::i#2 )
  (byte*) SCREEN#1 ← phi( main::@1/(byte*) SCREEN#2 )
  (byte) sum::return#3 ← phi( main::@1/(byte) sum::return#0 )
  (byte~) main::$2 ← (byte) sum::return#3
  *((byte*) SCREEN#1 + (byte) main::i#3) ← (byte~) main::$2
  (byte/signed word/word/dword/signed dword~) main::$3 ← (byte) main::i#3 + (byte/signed byte/word/signed word/dword/signed dword) 1
  (byte/signed word/word/dword/signed dword~) main::$4 ← (byte) main::i#3 + (byte/signed byte/word/signed word/dword/signed dword) 2
  (byte) sum2::a#0 ← (byte) main::i#3
  (byte) sum2::b#0 ← (byte/signed word/word/dword/signed dword~) main::$3
  (byte) sum2::c#0 ← (byte/signed word/word/dword/signed dword~) main::$4
  call sum2 
  (byte) sum2::return#0 ← (byte) sum2::return#2
  to:main::@4
main::@4: scope:[main]  from main::@3
  (byte*) SCREEN#4 ← phi( main::@3/(byte*) SCREEN#1 )
  (byte) main::i#4 ← phi( main::@3/(byte) main::i#3 )
  (byte*) SCREEN2#1 ← phi( main::@3/(byte*) SCREEN2#2 )
  (byte) sum2::return#3 ← phi( main::@3/(byte) sum2::return#0 )
  (byte~) main::$5 ← (byte) sum2::return#3
  *((byte*) SCREEN2#1 + (byte) main::i#4) ← (byte~) main::$5
  (byte) main::i#1 ← (byte) main::i#4 + rangenext(0,10)
  (bool~) main::$6 ← (byte) main::i#1 != rangelast(0,10)
  if((bool~) main::$6) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@4
  return 
  to:@return
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
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
  (byte*) SCREEN2#5 ← phi( @begin/(byte*) SCREEN2#0 )
  (byte*) SCREEN#5 ← phi( @begin/(byte*) SCREEN#0 )
  call main 
  to:@4
@4: scope:[]  from @3
  to:@end
@end: scope:[]  from @4

SYMBOL TABLE SSA
(word/signed word/dword/signed dword~) $0
(label) @3
(label) @4
(label) @begin
(label) @end
(byte*) SCREEN
(byte*) SCREEN#0
(byte*) SCREEN#1
(byte*) SCREEN#2
(byte*) SCREEN#3
(byte*) SCREEN#4
(byte*) SCREEN#5
(byte*) SCREEN2
(byte*) SCREEN2#0
(byte*) SCREEN2#1
(byte*) SCREEN2#2
(byte*) SCREEN2#3
(byte*) SCREEN2#4
(byte*) SCREEN2#5
(void()) main()
(byte/signed word/word/dword/signed dword~) main::$0
(byte/signed word/word/dword/signed dword~) main::$1
(byte~) main::$2
(byte/signed word/word/dword/signed dword~) main::$3
(byte/signed word/word/dword/signed dword~) 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

Culled Empty Block (label) @4
Successful SSA optimization Pass2CullEmptyBlocks
Alias (byte) sum::b#0 = (byte/signed word/word/dword/signed dword~) main::$0 
Alias (byte) sum::c#0 = (byte/signed word/word/dword/signed dword~) main::$1 
Alias (byte) sum::return#0 = (byte) sum::return#3 
Alias (byte*) SCREEN#1 = (byte*) SCREEN#2 (byte*) SCREEN#4 
Alias (byte) main::i#2 = (byte) main::i#3 (byte) main::i#4 
Alias (byte*) SCREEN2#1 = (byte*) SCREEN2#2 (byte*) SCREEN2#3 
Alias (byte) sum2::b#0 = (byte/signed word/word/dword/signed dword~) main::$3 
Alias (byte) sum2::c#0 = (byte/signed word/word/dword/signed dword~) 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 
Alias (byte*) SCREEN#0 = (byte*) SCREEN#5 
Alias (byte*) SCREEN2#0 = (byte*) SCREEN2#5 
Successful SSA optimization Pass2AliasElimination
Self Phi Eliminated (byte*) SCREEN#1
Self Phi Eliminated (byte*) SCREEN2#1
Successful SSA optimization Pass2SelfPhiElimination
Redundant Phi (byte*) SCREEN#3 (byte*) SCREEN#0
Redundant Phi (byte*) SCREEN2#4 (byte*) SCREEN2#0
Redundant Phi (byte*) SCREEN#1 (byte*) SCREEN#3
Redundant Phi (byte*) SCREEN2#1 (byte*) SCREEN2#4
Redundant Phi (byte) sum::a#1 (byte) sum::a#0
Redundant Phi (byte) sum::b#1 (byte) sum::b#0
Redundant Phi (byte) sum::c#1 (byte) sum::c#0
Redundant Phi (byte) sum2::a#1 (byte) sum2::a#0
Redundant Phi (byte) sum2::b#1 (byte) sum2::b#0
Redundant Phi (byte) sum2::c#1 (byte) sum2::c#0
Successful SSA optimization Pass2RedundantPhiElimination
Simple Condition (bool~) main::$6 [28] if((byte) main::i#1!=rangelast(0,10)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte*) SCREEN#0 = ((byte*))1024
Constant (const word/signed word/dword/signed dword) $0 = 1024+40
Constant (const byte) main::i#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Constant (const byte*) SCREEN2#0 = ((byte*))$0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value main::i#1 ← ++ main::i#2 to ++
Resolved ranged comparison value if(main::i#1!=rangelast(0,10)) goto main::@1 to (byte/signed byte/word/signed word/dword/signed dword) 11
Inlining constant with var siblings (const byte) main::i#0
Constant inlined $0 = (word/signed word/dword/signed dword) 1024+(byte/signed byte/word/signed word/dword/signed dword) 40
Constant inlined main::i#0 = (byte/signed byte/word/signed word/dword/signed dword) 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 @end
Adding NOP phi() at start of main
CALL GRAPH
Calls in [] to main:2 
Calls in [main] to sum:9 sum2:16 

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

FINAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  [0] phi()
  to:@3
@3: scope:[]  from @begin
  [1] phi()
  [2] call main 
  to:@end
@end: scope:[]  from @3
  [3] phi()
main: scope:[main]  from @3
  [4] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@4
  [5] (byte) main::i#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@4/(byte) main::i#1 )
  [6] (byte) sum::b#0 ← (byte) main::i#2 + (byte/signed byte/word/signed word/dword/signed dword) 1
  [7] (byte) sum::c#0 ← (byte) main::i#2 + (byte/signed byte/word/signed word/dword/signed dword) 2
  [8] (byte) sum::a#0 ← (byte) main::i#2
  [9] call sum 
  [10] (byte) sum::return#0 ← (byte) sum::return#1
  to:main::@3
main::@3: scope:[main]  from main::@1
  [11] (byte~) main::$2 ← (byte) sum::return#0
  [12] *((const byte*) SCREEN#0 + (byte) main::i#2) ← (byte~) main::$2
  [13] (byte) sum2::b#0 ← (byte) main::i#2 + (byte/signed byte/word/signed word/dword/signed dword) 1
  [14] (byte) sum2::c#0 ← (byte) main::i#2 + (byte/signed byte/word/signed word/dword/signed dword) 2
  [15] (byte) sum2::a#0 ← (byte) main::i#2
  [16] call sum2 
  [17] (byte) sum2::return#0 ← (byte) sum2::return#1
  to:main::@4
main::@4: scope:[main]  from main::@3
  [18] (byte~) main::$5 ← (byte) sum2::return#0
  [19] *((const byte*) SCREEN2#0 + (byte) main::i#2) ← (byte~) main::$5
  [20] (byte) main::i#1 ← ++ (byte) main::i#2
  [21] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) 11) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@4
  [22] return 
  to:@return
sum2: scope:[sum2]  from main::@3
  [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
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
(byte*) SCREEN
(byte*) SCREEN2
(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 zero page equivalence class [ sum::b#0 ]
Added variable sum::c#0 to zero page equivalence class [ sum::c#0 ]
Added variable sum::a#0 to zero page equivalence class [ sum::a#0 ]
Added variable sum::return#0 to zero page equivalence class [ sum::return#0 ]
Added variable main::$2 to zero page equivalence class [ main::$2 ]
Added variable sum2::b#0 to zero page equivalence class [ sum2::b#0 ]
Added variable sum2::c#0 to zero page equivalence class [ sum2::c#0 ]
Added variable sum2::a#0 to zero page equivalence class [ sum2::a#0 ]
Added variable sum2::return#0 to zero page equivalence class [ sum2::return#0 ]
Added variable main::$5 to zero page equivalence class [ main::$5 ]
Added variable sum2::$0 to zero page equivalence class [ sum2::$0 ]
Added variable sum2::return#1 to zero page equivalence class [ sum2::return#1 ]
Added variable sum::$0 to zero page equivalence class [ sum::$0 ]
Added variable sum::return#1 to zero page 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 ZP_BYTE:2 [ main::i#2 main::i#1 ]
Allocated zp ZP_BYTE:3 [ sum::b#0 ]
Allocated zp ZP_BYTE:4 [ sum::c#0 ]
Allocated zp ZP_BYTE:5 [ sum::a#0 ]
Allocated zp ZP_BYTE:6 [ sum::return#0 ]
Allocated zp ZP_BYTE:7 [ main::$2 ]
Allocated zp ZP_BYTE:8 [ sum2::b#0 ]
Allocated zp ZP_BYTE:9 [ sum2::c#0 ]
Allocated zp ZP_BYTE:10 [ sum2::a#0 ]
Allocated zp ZP_BYTE:11 [ sum2::return#0 ]
Allocated zp ZP_BYTE:12 [ main::$5 ]
Allocated zp ZP_BYTE:13 [ sum2::$0 ]
Allocated zp ZP_BYTE:14 [ sum2::return#1 ]
Allocated zp ZP_BYTE:15 [ sum::$0 ]
Allocated zp ZP_BYTE:16 [ sum::return#1 ]

INITIAL ASM
//SEG0 File Comments
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
  .label SCREEN = $400
  .label SCREEN2 = $400+$28
//SEG3 @begin
bbegin:
//SEG4 [1] phi from @begin to @3 [phi:@begin->@3]
b3_from_bbegin:
  jmp b3
//SEG5 @3
b3:
//SEG6 [2] call main 
//SEG7 [4] phi from @3 to main [phi:@3->main]
main_from_b3:
  jsr main
//SEG8 [3] phi from @3 to @end [phi:@3->@end]
bend_from_b3:
  jmp bend
//SEG9 @end
bend:
//SEG10 main
main: {
    .label _2 = 7
    .label _5 = $c
    .label i = 2
  //SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
  b1_from_main:
  //SEG12 [5] phi (byte) main::i#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta i
    jmp b1
  //SEG13 [5] phi from main::@4 to main::@1 [phi:main::@4->main::@1]
  b1_from_b4:
  //SEG14 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@4->main::@1#0] -- register_copy 
    jmp b1
  //SEG15 main::@1
  b1:
  //SEG16 [6] (byte) sum::b#0 ← (byte) main::i#2 + (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuz1=vbuz2_plus_1 
    ldy i
    iny
    sty sum.b
  //SEG17 [7] (byte) sum::c#0 ← (byte) main::i#2 + (byte/signed byte/word/signed word/dword/signed dword) 2 -- vbuz1=vbuz2_plus_2 
    lda i
    clc
    adc #2
    sta sum.c
  //SEG18 [8] (byte) sum::a#0 ← (byte) main::i#2 -- vbuz1=vbuz2 
    lda i
    sta sum.a
  //SEG19 [9] call sum 
    jsr sum
  //SEG20 [10] (byte) sum::return#0 ← (byte) sum::return#1 -- vbuz1=vbuz2 
    lda sum.return_1
    sta sum.return
    jmp b3
  //SEG21 main::@3
  b3:
  //SEG22 [11] (byte~) main::$2 ← (byte) sum::return#0 -- vbuz1=vbuz2 
    lda sum.return
    sta _2
  //SEG23 [12] *((const byte*) SCREEN#0 + (byte) main::i#2) ← (byte~) main::$2 -- pbuc1_derefidx_vbuz1=vbuz2 
    lda _2
    ldy i
    sta SCREEN,y
  //SEG24 [13] (byte) sum2::b#0 ← (byte) main::i#2 + (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuz1=vbuz2_plus_1 
    ldy i
    iny
    sty sum2.b
  //SEG25 [14] (byte) sum2::c#0 ← (byte) main::i#2 + (byte/signed byte/word/signed word/dword/signed dword) 2 -- vbuz1=vbuz2_plus_2 
    lda i
    clc
    adc #2
    sta sum2.c
  //SEG26 [15] (byte) sum2::a#0 ← (byte) main::i#2 -- vbuz1=vbuz2 
    lda i
    sta sum2.a
  //SEG27 [16] call sum2 
    jsr sum2
  //SEG28 [17] (byte) sum2::return#0 ← (byte) sum2::return#1 -- vbuz1=vbuz2 
    lda sum2.return_1
    sta sum2.return
    jmp b4
  //SEG29 main::@4
  b4:
  //SEG30 [18] (byte~) main::$5 ← (byte) sum2::return#0 -- vbuz1=vbuz2 
    lda sum2.return
    sta _5
  //SEG31 [19] *((const byte*) SCREEN2#0 + (byte) main::i#2) ← (byte~) main::$5 -- pbuc1_derefidx_vbuz1=vbuz2 
    lda _5
    ldy i
    sta SCREEN2,y
  //SEG32 [20] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc i
  //SEG33 [21] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) 11) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda i
    cmp #$b
    bne b1_from_b4
    jmp breturn
  //SEG34 main::@return
  breturn:
  //SEG35 [22] return 
    rts
}
//SEG36 sum2
// sum2(byte zeropage($a) a, byte zeropage(8) b, byte zeropage(9) c)
sum2: {
    .label _0 = $d
    .label a = $a
    .label b = 8
    .label c = 9
    .label return = $b
    .label return_1 = $e
  //SEG37 [23] (byte~) sum2::$0 ← (byte) sum2::a#0 + (byte) sum2::b#0 -- vbuz1=vbuz2_plus_vbuz3 
    lda a
    clc
    adc b
    sta _0
  //SEG38 [24] (byte) sum2::return#1 ← (byte~) sum2::$0 + (byte) sum2::c#0 -- vbuz1=vbuz2_plus_vbuz3 
    lda _0
    clc
    adc c
    sta return_1
    jmp breturn
  //SEG39 sum2::@return
  breturn:
  //SEG40 [25] return 
    rts
}
//SEG41 sum
// sum(byte zeropage(5) a, byte zeropage(3) b, byte zeropage(4) c)
sum: {
    .label _0 = $f
    .label a = 5
    .label b = 3
    .label c = 4
    .label return = 6
    .label return_1 = $10
  //SEG42 [26] (byte~) sum::$0 ← (byte) sum::a#0 + (byte) sum::b#0 -- vbuz1=vbuz2_plus_vbuz3 
    lda a
    clc
    adc b
    sta _0
  //SEG43 [27] (byte) sum::return#1 ← (byte~) sum::$0 + (byte) sum::c#0 -- vbuz1=vbuz2_plus_vbuz3 
    lda _0
    clc
    adc c
    sta return_1
    jmp breturn
  //SEG44 sum::@return
  breturn:
  //SEG45 [28] return 
    rts
}

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 ZP_BYTE:2 [ main::i#2 main::i#1 ]
Removing always clobbered register reg byte a as potential for zp ZP_BYTE: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 ZP_BYTE: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 ZP_BYTE:2 [ main::i#2 main::i#1 ] : zp ZP_BYTE:2 , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:3 [ sum::b#0 ] : zp ZP_BYTE:3 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:4 [ sum::c#0 ] : zp ZP_BYTE:4 , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:5 [ sum::a#0 ] : zp ZP_BYTE:5 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:6 [ sum::return#0 ] : zp ZP_BYTE:6 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:7 [ main::$2 ] : zp ZP_BYTE:7 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:8 [ sum2::b#0 ] : zp ZP_BYTE:8 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:9 [ sum2::c#0 ] : zp ZP_BYTE:9 , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:10 [ sum2::a#0 ] : zp ZP_BYTE:10 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:11 [ sum2::return#0 ] : zp ZP_BYTE:11 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:12 [ main::$5 ] : zp ZP_BYTE:12 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:13 [ sum2::$0 ] : zp ZP_BYTE:13 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:14 [ sum2::return#1 ] : zp ZP_BYTE:14 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:15 [ sum::$0 ] : zp ZP_BYTE:15 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:16 [ sum::return#1 ] : zp ZP_BYTE:16 , reg byte a , reg byte x , reg byte y , 

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

Uplifting [main] best 1345 combination zp ZP_BYTE: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 ZP_BYTE:16 [ sum::return#1 ] zp ZP_BYTE: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 ZP_BYTE:14 [ sum2::return#1 ] zp ZP_BYTE:13 [ sum2::$0 ] 
Limited combination testing to 100 combinations of 3072 possible.
Uplifting [] best 1083 combination 
Attempting to uplift remaining variables inzp ZP_BYTE:2 [ main::i#2 main::i#1 ]
Uplifting [main] best 1083 combination zp ZP_BYTE:2 [ main::i#2 main::i#1 ] 
Attempting to uplift remaining variables inzp ZP_BYTE:14 [ sum2::return#1 ]
Uplifting [sum2] best 1050 combination reg byte a [ sum2::return#1 ] 
Attempting to uplift remaining variables inzp ZP_BYTE:16 [ sum::return#1 ]
Uplifting [sum] best 1017 combination reg byte a [ sum::return#1 ] 
Attempting to uplift remaining variables inzp ZP_BYTE:13 [ sum2::$0 ]
Uplifting [sum2] best 1015 combination reg byte a [ sum2::$0 ] 
Attempting to uplift remaining variables inzp ZP_BYTE:15 [ sum::$0 ]
Uplifting [sum] best 1013 combination reg byte a [ sum::$0 ] 

ASSEMBLER BEFORE OPTIMIZATION
//SEG0 File Comments
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
  .label SCREEN = $400
  .label SCREEN2 = $400+$28
//SEG3 @begin
bbegin:
//SEG4 [1] phi from @begin to @3 [phi:@begin->@3]
b3_from_bbegin:
  jmp b3
//SEG5 @3
b3:
//SEG6 [2] call main 
//SEG7 [4] phi from @3 to main [phi:@3->main]
main_from_b3:
  jsr main
//SEG8 [3] phi from @3 to @end [phi:@3->@end]
bend_from_b3:
  jmp bend
//SEG9 @end
bend:
//SEG10 main
main: {
    .label i = 2
  //SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
  b1_from_main:
  //SEG12 [5] phi (byte) main::i#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta i
    jmp b1
  //SEG13 [5] phi from main::@4 to main::@1 [phi:main::@4->main::@1]
  b1_from_b4:
  //SEG14 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@4->main::@1#0] -- register_copy 
    jmp b1
  //SEG15 main::@1
  b1:
  //SEG16 [6] (byte) sum::b#0 ← (byte) main::i#2 + (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuz1_plus_1 
    lda i
    clc
    adc #1
  //SEG17 [7] (byte) sum::c#0 ← (byte) main::i#2 + (byte/signed byte/word/signed word/dword/signed dword) 2 -- vbuxx=vbuz1_plus_2 
    ldx i
    inx
    inx
  //SEG18 [8] (byte) sum::a#0 ← (byte) main::i#2 -- vbuyy=vbuz1 
    ldy i
  //SEG19 [9] call sum 
    jsr sum
  //SEG20 [10] (byte) sum::return#0 ← (byte) sum::return#1
    jmp b3
  //SEG21 main::@3
  b3:
  //SEG22 [11] (byte~) main::$2 ← (byte) sum::return#0
  //SEG23 [12] *((const byte*) SCREEN#0 + (byte) main::i#2) ← (byte~) main::$2 -- pbuc1_derefidx_vbuz1=vbuaa 
    ldy i
    sta SCREEN,y
  //SEG24 [13] (byte) sum2::b#0 ← (byte) main::i#2 + (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuz1_plus_1 
    lda i
    clc
    adc #1
  //SEG25 [14] (byte) sum2::c#0 ← (byte) main::i#2 + (byte/signed byte/word/signed word/dword/signed dword) 2 -- vbuxx=vbuz1_plus_2 
    ldx i
    inx
    inx
  //SEG26 [15] (byte) sum2::a#0 ← (byte) main::i#2 -- vbuyy=vbuz1 
    ldy i
  //SEG27 [16] call sum2 
    jsr sum2
  //SEG28 [17] (byte) sum2::return#0 ← (byte) sum2::return#1
    jmp b4
  //SEG29 main::@4
  b4:
  //SEG30 [18] (byte~) main::$5 ← (byte) sum2::return#0
  //SEG31 [19] *((const byte*) SCREEN2#0 + (byte) main::i#2) ← (byte~) main::$5 -- pbuc1_derefidx_vbuz1=vbuaa 
    ldy i
    sta SCREEN2,y
  //SEG32 [20] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc i
  //SEG33 [21] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) 11) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda i
    cmp #$b
    bne b1_from_b4
    jmp breturn
  //SEG34 main::@return
  breturn:
  //SEG35 [22] return 
    rts
}
//SEG36 sum2
// sum2(byte register(Y) a, byte register(A) b, byte register(X) c)
sum2: {
  //SEG37 [23] (byte~) sum2::$0 ← (byte) sum2::a#0 + (byte) sum2::b#0 -- vbuaa=vbuyy_plus_vbuaa 
    sty $ff
    clc
    adc $ff
  //SEG38 [24] (byte) sum2::return#1 ← (byte~) sum2::$0 + (byte) sum2::c#0 -- vbuaa=vbuaa_plus_vbuxx 
    stx $ff
    clc
    adc $ff
    jmp breturn
  //SEG39 sum2::@return
  breturn:
  //SEG40 [25] return 
    rts
}
//SEG41 sum
// sum(byte register(Y) a, byte register(A) b, byte register(X) c)
sum: {
  //SEG42 [26] (byte~) sum::$0 ← (byte) sum::a#0 + (byte) sum::b#0 -- vbuaa=vbuyy_plus_vbuaa 
    sty $ff
    clc
    adc $ff
  //SEG43 [27] (byte) sum::return#1 ← (byte~) sum::$0 + (byte) sum::c#0 -- vbuaa=vbuaa_plus_vbuxx 
    stx $ff
    clc
    adc $ff
    jmp breturn
  //SEG44 sum::@return
  breturn:
  //SEG45 [28] return 
    rts
}

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b3
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp b3
Removing instruction jmp b4
Removing instruction jmp breturn
Removing instruction jmp breturn
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing instruction lda i with TYA
Removing instruction ldy i
Succesful ASM optimization Pass5UnnecesaryLoadElimination
Replacing label b1_from_b4 with b1
Removing instruction b3_from_bbegin:
Removing instruction b3:
Removing instruction main_from_b3:
Removing instruction bend_from_b3:
Removing instruction b1_from_b4:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
Removing instruction b1_from_main:
Removing instruction b3:
Removing instruction b4:
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 bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @3
(label) @begin
(label) @end
(byte*) SCREEN
(const byte*) SCREEN#0 SCREEN = ((byte*))(word/signed word/dword/signed dword) 1024
(byte*) SCREEN2
(const byte*) SCREEN2#0 SCREEN2 = ((byte*))(word/signed word/dword/signed dword) 1024+(byte/signed byte/word/signed word/dword/signed dword) 40
(void()) main()
(byte~) main::$2 reg byte a 22.0
(byte~) main::$5 reg byte a 22.0
(label) main::@1
(label) main::@3
(label) main::@4
(label) main::@return
(byte) main::i
(byte) main::i#1 i zp ZP_BYTE:2 16.5
(byte) main::i#2 i zp ZP_BYTE: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 ZP_BYTE: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

//SEG0 File Comments
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG2 Global Constants & labels
  .label SCREEN = $400
  .label SCREEN2 = $400+$28
//SEG3 @begin
//SEG4 [1] phi from @begin to @3 [phi:@begin->@3]
//SEG5 @3
//SEG6 [2] call main 
//SEG7 [4] phi from @3 to main [phi:@3->main]
//SEG8 [3] phi from @3 to @end [phi:@3->@end]
//SEG9 @end
//SEG10 main
main: {
    .label i = 2
  //SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
  //SEG12 [5] phi (byte) main::i#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta i
  //SEG13 [5] phi from main::@4 to main::@1 [phi:main::@4->main::@1]
  //SEG14 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@4->main::@1#0] -- register_copy 
  //SEG15 main::@1
  b1:
  //SEG16 [6] (byte) sum::b#0 ← (byte) main::i#2 + (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuz1_plus_1 
    lda i
    clc
    adc #1
  //SEG17 [7] (byte) sum::c#0 ← (byte) main::i#2 + (byte/signed byte/word/signed word/dword/signed dword) 2 -- vbuxx=vbuz1_plus_2 
    ldx i
    inx
    inx
  //SEG18 [8] (byte) sum::a#0 ← (byte) main::i#2 -- vbuyy=vbuz1 
    ldy i
  //SEG19 [9] call sum 
    jsr sum
  //SEG20 [10] (byte) sum::return#0 ← (byte) sum::return#1
  //SEG21 main::@3
  //SEG22 [11] (byte~) main::$2 ← (byte) sum::return#0
  //SEG23 [12] *((const byte*) SCREEN#0 + (byte) main::i#2) ← (byte~) main::$2 -- pbuc1_derefidx_vbuz1=vbuaa 
    ldy i
    sta SCREEN,y
  //SEG24 [13] (byte) sum2::b#0 ← (byte) main::i#2 + (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuz1_plus_1 
    tya
    clc
    adc #1
  //SEG25 [14] (byte) sum2::c#0 ← (byte) main::i#2 + (byte/signed byte/word/signed word/dword/signed dword) 2 -- vbuxx=vbuz1_plus_2 
    ldx i
    inx
    inx
  //SEG26 [15] (byte) sum2::a#0 ← (byte) main::i#2 -- vbuyy=vbuz1 
  //SEG27 [16] call sum2 
    jsr sum2
  //SEG28 [17] (byte) sum2::return#0 ← (byte) sum2::return#1
  //SEG29 main::@4
  //SEG30 [18] (byte~) main::$5 ← (byte) sum2::return#0
  //SEG31 [19] *((const byte*) SCREEN2#0 + (byte) main::i#2) ← (byte~) main::$5 -- pbuc1_derefidx_vbuz1=vbuaa 
    ldy i
    sta SCREEN2,y
  //SEG32 [20] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc i
  //SEG33 [21] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) 11) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda i
    cmp #$b
    bne b1
  //SEG34 main::@return
  //SEG35 [22] return 
    rts
}
//SEG36 sum2
// sum2(byte register(Y) a, byte register(A) b, byte register(X) c)
sum2: {
  //SEG37 [23] (byte~) sum2::$0 ← (byte) sum2::a#0 + (byte) sum2::b#0 -- vbuaa=vbuyy_plus_vbuaa 
    sty $ff
    clc
    adc $ff
  //SEG38 [24] (byte) sum2::return#1 ← (byte~) sum2::$0 + (byte) sum2::c#0 -- vbuaa=vbuaa_plus_vbuxx 
    stx $ff
    clc
    adc $ff
  //SEG39 sum2::@return
  //SEG40 [25] return 
    rts
}
//SEG41 sum
// sum(byte register(Y) a, byte register(A) b, byte register(X) c)
sum: {
  //SEG42 [26] (byte~) sum::$0 ← (byte) sum::a#0 + (byte) sum::b#0 -- vbuaa=vbuyy_plus_vbuaa 
    sty $ff
    clc
    adc $ff
  //SEG43 [27] (byte) sum::return#1 ← (byte~) sum::$0 + (byte) sum::c#0 -- vbuaa=vbuaa_plus_vbuxx 
    stx $ff
    clc
    adc $ff
  //SEG44 sum::@return
  //SEG45 [28] return 
    rts
}

