Identified constant variable (byte) a
Culled Empty Block (label) main::@2
Culled Empty Block (label) @1
Culled Empty Block (label) sum::@1

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (byte*) SCREEN#0 ← ((byte*)) (number) $400
  (byte) a#0 ← (byte) 'a'
  to:@2
main: scope:[main]  from @2
  (byte) main::i#0 ← (number) 0
  (byte) main::b#0 ← (byte) 0
  to:main::@1
main::@1: scope:[main]  from main main::@3
  (byte) main::i#3 ← phi( main/(byte) main::i#0 main::@3/(byte) main::i#1 )
  (byte) main::b#2 ← phi( main/(byte) main::b#0 main::@3/(byte) main::b#1 )
  (byte) sum::a#0 ← (byte) a#0
  (byte) sum::b#0 ← (byte) main::b#2
  call sum 
  (byte) sum::return#0 ← (byte) sum::return#2
  to:main::@3
main::@3: scope:[main]  from main::@1
  (byte) main::b#3 ← phi( main::@1/(byte) main::b#2 )
  (byte) main::i#2 ← phi( main::@1/(byte) main::i#3 )
  (byte) sum::return#3 ← phi( main::@1/(byte) sum::return#0 )
  (byte~) main::$0 ← (byte) sum::return#3
  *((byte*) SCREEN#0 + (byte) main::i#2) ← (byte~) main::$0
  (byte) main::i#1 ← ++ (byte) main::i#2
  (byte) main::b#1 ← (byte) main::b#3 + rangenext(0,$a)
  (bool~) main::$1 ← (byte) main::b#1 != rangelast(0,$a)
  if((bool~) main::$1) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@3
  return 
  to:@return
sum: scope:[sum]  from main::@1
  (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::r#0 ← (byte~) sum::$0
  (byte) sum::return#1 ← (byte) sum::r#0
  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
@2: scope:[]  from @begin
  call main 
  to:@3
@3: scope:[]  from @2
  to:@end
@end: scope:[]  from @3

SYMBOL TABLE SSA
(label) @2
(label) @3
(label) @begin
(label) @end
(byte*) SCREEN
(byte*) SCREEN#0
(byte) a
(byte) a#0
(void()) main()
(byte~) main::$0
(bool~) main::$1
(label) main::@1
(label) main::@3
(label) main::@return
(byte) main::b
(byte) main::b#0
(byte) main::b#1
(byte) main::b#2
(byte) main::b#3
(byte) main::i
(byte) main::i#0
(byte) main::i#1
(byte) main::i#2
(byte) main::i#3
(byte()) sum((byte) sum::a , (byte) sum::b)
(byte~) sum::$0
(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::r
(byte) sum::r#0
(byte) sum::return
(byte) sum::return#0
(byte) sum::return#1
(byte) sum::return#2
(byte) sum::return#3
(byte) sum::return#4

Adding number conversion cast (unumber) 0 in (byte) main::i#0 ← (number) 0
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte*) SCREEN#0 ← (byte*)(number) $400
Inlining cast (byte) main::i#0 ← (unumber)(number) 0
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias (byte) sum::return#0 = (byte) sum::return#3 
Alias (byte) main::i#2 = (byte) main::i#3 
Alias (byte) main::b#2 = (byte) main::b#3 
Alias (byte) sum::return#1 = (byte) sum::r#0 (byte~) sum::$0 (byte) sum::return#4 (byte) sum::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
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition (bool~) main::$1 [15] if((byte) main::b#1!=rangelast(0,$a)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte*) SCREEN#0 = (byte*) 1024
Constant (const byte) a#0 = 'a'
Constant (const byte) main::i#0 = 0
Constant (const byte) main::b#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Constant (const byte) sum::a#0 = a#0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [13] main::b#1 ← ++ main::b#2 to ++
Resolved ranged comparison value [15] if(main::b#1!=rangelast(0,$a)) goto main::@1 to (number) $b
Adding number conversion cast (unumber) $b in if((byte) main::b#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
Inlining constant with var siblings (const byte) main::b#0
Constant inlined main::i#0 = (byte) 0
Constant inlined sum::a#0 = (const byte) a#0
Constant inlined main::b#0 = (byte) 0
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@4(between main::@3 and main::@1)
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @2
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:8 

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


VARIABLE REGISTER WEIGHTS
(byte*) SCREEN
(byte) a
(void()) main()
(byte~) main::$0 22.0
(byte) main::b
(byte) main::b#1 16.5
(byte) main::b#2 4.714285714285714
(byte) main::i
(byte) main::i#1 7.333333333333333
(byte) main::i#2 5.5
(byte()) sum((byte) sum::a , (byte) sum::b)
(byte) sum::a
(byte) sum::b
(byte) sum::b#0 13.0
(byte) sum::r
(byte) sum::return
(byte) sum::return#0 22.0
(byte) sum::return#1 4.333333333333333

Initial phi equivalence classes
[ main::b#2 main::b#1 ]
[ main::i#2 main::i#1 ]
Added variable sum::b#0 to zero page equivalence class [ sum::b#0 ]
Added variable sum::return#0 to zero page equivalence class [ sum::return#0 ]
Added variable main::$0 to zero page equivalence class [ main::$0 ]
Added variable sum::return#1 to zero page equivalence class [ sum::return#1 ]
Complete equivalence classes
[ main::b#2 main::b#1 ]
[ main::i#2 main::i#1 ]
[ sum::b#0 ]
[ sum::return#0 ]
[ main::$0 ]
[ sum::return#1 ]
Allocated zp ZP_BYTE:2 [ main::b#2 main::b#1 ]
Allocated zp ZP_BYTE:3 [ main::i#2 main::i#1 ]
Allocated zp ZP_BYTE:4 [ sum::b#0 ]
Allocated zp ZP_BYTE:5 [ sum::return#0 ]
Allocated zp ZP_BYTE:6 [ main::$0 ]
Allocated zp ZP_BYTE:7 [ sum::return#1 ]

INITIAL ASM
Target platform is c64basic
  // File Comments
/* Tests that block comments are compiled correctly
 * Has a bunch of comments that will be moved into the generated ASM
 */
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  // The C64 screen
  .label SCREEN = $400
  // One of the bytes used for addition
  .const a = '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
/* The program entry point */
main: {
    .label _0 = 6
    .label i = 3
    .label b = 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
    // [5] phi (byte) main::b#2 = (byte) 0 [phi:main->main::@1#1] -- vbuz1=vbuc1 
    lda #0
    sta.z b
    jmp b1
  // Do some sums
    // [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
  b1_from_b2:
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@2->main::@1#0] -- register_copy 
    // [5] phi (byte) main::b#2 = (byte) main::b#1 [phi:main::@2->main::@1#1] -- register_copy 
    jmp b1
    // main::@1
  b1:
    // [6] (byte) sum::b#0 ← (byte) main::b#2 -- vbuz1=vbuz2 
    lda.z b
    sta.z sum.b
    // [7] call sum 
    jsr sum
    // [8] (byte) sum::return#0 ← (byte) sum::return#1 -- vbuz1=vbuz2 
    lda.z sum.return_1
    sta.z sum.return
    jmp b2
    // main::@2
  b2:
    // [9] (byte~) main::$0 ← (byte) sum::return#0 -- vbuz1=vbuz2 
    lda.z sum.return
    sta.z _0
    // [10] *((const byte*) SCREEN#0 + (byte) main::i#2) ← (byte~) main::$0 -- pbuc1_derefidx_vbuz1=vbuz2 
    // Output the result on the screen
    lda.z _0
    ldy.z i
    sta SCREEN,y
    // [11] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [12] (byte) main::b#1 ← ++ (byte) main::b#2 -- vbuz1=_inc_vbuz1 
    inc.z b
    // [13] if((byte) main::b#1!=(byte) $b) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #$b
    cmp.z b
    bne b1_from_b2
    jmp breturn
    // main::@return
  breturn:
    // [14] return 
    rts
}
  // sum
/** Adds up two bytes and returns the result
 * a - the first byte
 * b - the second byte
 * Returns the sum pf the two bytes
 */
// sum(byte zeropage(4) b)
sum: {
    .label b = 4
    .label return = 5
    .label return_1 = 7
    // [15] (byte) sum::return#1 ← (const byte) a#0 + (byte) sum::b#0 -- vbuz1=vbuc1_plus_vbuz2 
    lax.z b
    axs #-[a]
    stx.z return_1
    jmp breturn
    // sum::@return
  breturn:
    // [16] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Potential registers zp ZP_BYTE:2 [ main::b#2 main::b#1 ] : zp ZP_BYTE:2 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:3 [ main::i#2 main::i#1 ] : zp ZP_BYTE:3 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:4 [ sum::b#0 ] : zp ZP_BYTE:4 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:5 [ sum::return#0 ] : zp ZP_BYTE:5 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:6 [ main::$0 ] : zp ZP_BYTE:6 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:7 [ sum::return#1 ] : zp ZP_BYTE:7 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 22: zp ZP_BYTE:6 [ main::$0 ] 21.21: zp ZP_BYTE:2 [ main::b#2 main::b#1 ] 12.83: zp ZP_BYTE:3 [ main::i#2 main::i#1 ] 
Uplift Scope [sum] 22: zp ZP_BYTE:5 [ sum::return#0 ] 13: zp ZP_BYTE:4 [ sum::b#0 ] 4.33: zp ZP_BYTE:7 [ sum::return#1 ] 
Uplift Scope [] 

Uplifting [main] best 630 combination reg byte a [ main::$0 ] zp ZP_BYTE:2 [ main::b#2 main::b#1 ] reg byte y [ main::i#2 main::i#1 ] 
Uplifting [sum] best 506 combination reg byte a [ sum::return#0 ] reg byte a [ sum::b#0 ] reg byte a [ sum::return#1 ] 
Uplifting [] best 506 combination 
Attempting to uplift remaining variables inzp ZP_BYTE:2 [ main::b#2 main::b#1 ]
Uplifting [main] best 406 combination reg byte x [ main::b#2 main::b#1 ] 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
/* Tests that block comments are compiled correctly
 * Has a bunch of comments that will be moved into the generated ASM
 */
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  // The C64 screen
  .label SCREEN = $400
  // One of the bytes used for addition
  .const a = '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
/* The program entry point */
main: {
    // [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] -- vbuyy=vbuc1 
    ldy #0
    // [5] phi (byte) main::b#2 = (byte) 0 [phi:main->main::@1#1] -- vbuxx=vbuc1 
    ldx #0
    jmp b1
  // Do some sums
    // [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
  b1_from_b2:
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@2->main::@1#0] -- register_copy 
    // [5] phi (byte) main::b#2 = (byte) main::b#1 [phi:main::@2->main::@1#1] -- register_copy 
    jmp b1
    // main::@1
  b1:
    // [6] (byte) sum::b#0 ← (byte) main::b#2 -- vbuaa=vbuxx 
    txa
    // [7] call sum 
    jsr sum
    // [8] (byte) sum::return#0 ← (byte) sum::return#1
    jmp b2
    // main::@2
  b2:
    // [9] (byte~) main::$0 ← (byte) sum::return#0
    // [10] *((const byte*) SCREEN#0 + (byte) main::i#2) ← (byte~) main::$0 -- pbuc1_derefidx_vbuyy=vbuaa 
    // Output the result on the screen
    sta SCREEN,y
    // [11] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuyy=_inc_vbuyy 
    iny
    // [12] (byte) main::b#1 ← ++ (byte) main::b#2 -- vbuxx=_inc_vbuxx 
    inx
    // [13] if((byte) main::b#1!=(byte) $b) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$b
    bne b1_from_b2
    jmp breturn
    // main::@return
  breturn:
    // [14] return 
    rts
}
  // sum
/** Adds up two bytes and returns the result
 * a - the first byte
 * b - the second byte
 * Returns the sum pf the two bytes
 */
// sum(byte register(A) b)
sum: {
    // [15] (byte) sum::return#1 ← (const byte) a#0 + (byte) sum::b#0 -- vbuaa=vbuc1_plus_vbuaa 
    clc
    adc #a
    jmp breturn
    // sum::@return
  breturn:
    // [16] 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 breturn
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label b1_from_b2 with b1
Removing instruction b1_from_bbegin:
Removing instruction b1:
Removing instruction main_from_b1:
Removing instruction bend_from_b1:
Removing instruction b1_from_b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
Removing instruction b1_from_main:
Removing instruction b2:
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) @1
(label) @begin
(label) @end
(byte*) SCREEN
(const byte*) SCREEN#0 SCREEN = (byte*) 1024
(byte) a
(const byte) a#0 a = (byte) 'a'
(void()) main()
(byte~) main::$0 reg byte a 22.0
(label) main::@1
(label) main::@2
(label) main::@return
(byte) main::b
(byte) main::b#1 reg byte x 16.5
(byte) main::b#2 reg byte x 4.714285714285714
(byte) main::i
(byte) main::i#1 reg byte y 7.333333333333333
(byte) main::i#2 reg byte y 5.5
(byte()) sum((byte) sum::a , (byte) sum::b)
(label) sum::@return
(byte) sum::a
(byte) sum::b
(byte) sum::b#0 reg byte a 13.0
(byte) sum::r
(byte) sum::return
(byte) sum::return#0 reg byte a 22.0
(byte) sum::return#1 reg byte a 4.333333333333333

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


FINAL ASSEMBLER
Score: 271

  // File Comments
/* Tests that block comments are compiled correctly
 * Has a bunch of comments that will be moved into the generated ASM
 */
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  // The C64 screen
  .label SCREEN = $400
  // One of the bytes used for addition
  .const a = '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
/* The program entry point */
main: {
    // [5] phi from main to main::@1 [phi:main->main::@1]
    // [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuyy=vbuc1 
    ldy #0
    // [5] phi (byte) main::b#2 = (byte) 0 [phi:main->main::@1#1] -- vbuxx=vbuc1 
    ldx #0
  // Do some sums
    // [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@2->main::@1#0] -- register_copy 
    // [5] phi (byte) main::b#2 = (byte) main::b#1 [phi:main::@2->main::@1#1] -- register_copy 
    // main::@1
  b1:
    // sum(a, b)
    // [6] (byte) sum::b#0 ← (byte) main::b#2 -- vbuaa=vbuxx 
    txa
    // [7] call sum 
    jsr sum
    // [8] (byte) sum::return#0 ← (byte) sum::return#1
    // main::@2
    // [9] (byte~) main::$0 ← (byte) sum::return#0
    // SCREEN[i++] = sum(a, b)
    // [10] *((const byte*) SCREEN#0 + (byte) main::i#2) ← (byte~) main::$0 -- pbuc1_derefidx_vbuyy=vbuaa 
    // Output the result on the screen
    sta SCREEN,y
    // SCREEN[i++] = sum(a, b);
    // [11] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuyy=_inc_vbuyy 
    iny
    // for(byte b: 0..10 )
    // [12] (byte) main::b#1 ← ++ (byte) main::b#2 -- vbuxx=_inc_vbuxx 
    inx
    // [13] if((byte) main::b#1!=(byte) $b) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$b
    bne b1
    // main::@return
    // }
    // [14] return 
    rts
}
  // sum
/** Adds up two bytes and returns the result
 * a - the first byte
 * b - the second byte
 * Returns the sum pf the two bytes
 */
// sum(byte register(A) b)
sum: {
    // a+b
    // [15] (byte) sum::return#1 ← (const byte) a#0 + (byte) sum::b#0 -- vbuaa=vbuc1_plus_vbuaa 
    clc
    adc #a
    // sum::@return
    // }
    // [16] return 
    rts
}
  // File Data

