Inlined call call __init
Eliminating unused variable with no statement sum::$0

CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start::@1
  main::i#0 = 0
  main::b#0 = 0
  to:main::@1
main::@1: scope:[main]  from main main::@2
  main::i#3 = phi( main/main::i#0, main::@2/main::i#1 )
  main::b#2 = phi( main/main::b#0, main::@2/main::b#1 )
  sum::a#0 = a
  sum::b#0 = main::b#2
  call sum
  sum::return#0 = sum::return#2
  to:main::@2
main::@2: scope:[main]  from main::@1
  main::b#3 = phi( main::@1/main::b#2 )
  main::i#2 = phi( main::@1/main::i#3 )
  sum::return#3 = phi( main::@1/sum::return#0 )
  main::$0 = sum::return#3
  SCREEN[main::i#2] = main::$0
  main::i#1 = ++ main::i#2
  main::b#1 = main::b#3 + rangenext(0,$a)
  main::$1 = main::b#1 != rangelast(0,$a)
  if(main::$1) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@2
  return 
  to:@return

char sum(char a , char b)
sum: scope:[sum]  from main::@1
  sum::b#1 = phi( main::@1/sum::b#0 )
  sum::a#1 = phi( main::@1/sum::a#0 )
  sum::r#0 = sum::a#1 + sum::b#1
  sum::return#1 = sum::r#0
  to:sum::@return
sum::@return: scope:[sum]  from sum
  sum::return#4 = phi( sum/sum::return#1 )
  sum::return#2 = sum::return#4
  return 
  to:@return

void __start()
__start: scope:[__start]  from
  to:__start::__init1
__start::__init1: scope:[__start]  from __start
  to:__start::@1
__start::@1: scope:[__start]  from __start::__init1
  call main
  to:__start::@2
__start::@2: scope:[__start]  from __start::@1
  to:__start::@return
__start::@return: scope:[__start]  from __start::@2
  return 
  to:@return

SYMBOL TABLE SSA
__constant char * const SCREEN = (char *)$400
void __start()
__constant char a = 'a'
void main()
char main::$0
bool main::$1
char main::b
char main::b#0
char main::b#1
char main::b#2
char main::b#3
char main::i
char main::i#0
char main::i#1
char main::i#2
char main::i#3
char sum(char a , char b)
char sum::a
char sum::a#0
char sum::a#1
char sum::b
char sum::b#0
char sum::b#1
char sum::r
char sum::r#0
char sum::return
char sum::return#0
char sum::return#1
char sum::return#2
char sum::return#3
char sum::return#4

Simplifying constant pointer cast (char *) 1024
Successful SSA optimization PassNCastSimplification
Alias sum::return#0 = sum::return#3 
Alias main::i#2 = main::i#3 
Alias main::b#2 = main::b#3 
Alias sum::return#1 = sum::r#0 sum::return#4 sum::return#2 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values sum::a#1 sum::a#0
Identical Phi Values sum::b#1 sum::b#0
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition main::$1 [12] if(main::b#1!=rangelast(0,$a)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant main::i#0 = 0
Constant main::b#0 = 0
Constant sum::a#0 = a
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [10] main::b#1 = ++ main::b#2 to ++
Resolved ranged comparison value [12] if(main::b#1!=rangelast(0,$a)) goto main::@1 to $b
Removing unused procedure __start
Removing unused procedure block __start
Removing unused procedure block __start::__init1
Removing unused procedure block __start::@1
Removing unused procedure block __start::@2
Removing unused procedure block __start::@return
Successful SSA optimization PassNEliminateEmptyStart
Adding number conversion cast (unumber) $b in [8] if(main::b#1!=$b) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast $b
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) $b
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining constant with var siblings main::i#0
Inlining constant with var siblings main::b#0
Constant inlined main::i#0 = 0
Constant inlined sum::a#0 = a
Constant inlined main::b#0 = 0
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@3(between main::@2 and main::@1)
Adding NOP phi() at start of main
CALL GRAPH
Calls in [main] to sum:3 

Created 2 initial phi equivalence classes
Coalesced [11] main::b#4 = main::b#1
Coalesced [12] main::i#4 = main::i#1
Coalesced down to 2 phi equivalence classes
Culled Empty Block label main::@3
Adding NOP phi() at start of main

FINAL CONTROL FLOW GRAPH

void main()
main: scope:[main]  from
  [0] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@2
  [1] main::i#2 = phi( main/0, main::@2/main::i#1 )
  [1] main::b#2 = phi( main/0, main::@2/main::b#1 )
  [2] sum::b#0 = main::b#2
  [3] call sum
  [4] sum::return#0 = sum::return#1
  to:main::@2
main::@2: scope:[main]  from main::@1
  [5] main::$0 = sum::return#0
  [6] SCREEN[main::i#2] = main::$0
  [7] main::i#1 = ++ main::i#2
  [8] main::b#1 = ++ main::b#2
  [9] if(main::b#1!=$b) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@2
  [10] return 
  to:@return

char sum(char a , char b)
sum: scope:[sum]  from main::@1
  [11] sum::return#1 = a + sum::b#0
  to:sum::@return
sum::@return: scope:[sum]  from sum
  [12] return 
  to:@return


VARIABLE REGISTER WEIGHTS
void main()
char main::$0 // 22.0
char main::b
char main::b#1 // 16.5
char main::b#2 // 4.714285714285714
char main::i
char main::i#1 // 7.333333333333333
char main::i#2 // 5.5
char sum(char a , char b)
char sum::a
char sum::b
char sum::b#0 // 112.0
char sum::r
char sum::return
char sum::return#0 // 22.0
char sum::return#1 // 37.33333333333333

Initial phi equivalence classes
[ main::b#2 main::b#1 ]
[ main::i#2 main::i#1 ]
Added variable sum::b#0 to live range equivalence class [ sum::b#0 ]
Added variable sum::return#0 to live range equivalence class [ sum::return#0 ]
Added variable main::$0 to live range equivalence class [ main::$0 ]
Added variable sum::return#1 to live range 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[1]:2 [ sum::b#0 ]
Allocated zp[1]:3 [ sum::return#1 ]
Allocated zp[1]:4 [ sum::return#0 ]
Allocated zp[1]:5 [ main::$0 ]
Allocated zp[1]:6 [ main::b#2 main::b#1 ]
Allocated zp[1]:7 [ main::i#2 main::i#1 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Potential registers zp[1]:6 [ main::b#2 main::b#1 ] : zp[1]:6 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:7 [ main::i#2 main::i#1 ] : zp[1]:7 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:2 [ sum::b#0 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:4 [ sum::return#0 ] : zp[1]:4 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:5 [ main::$0 ] : zp[1]:5 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:3 [ sum::return#1 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y , 

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

Uplifting [sum] best 644 combination reg byte a [ sum::b#0 ] reg byte a [ sum::return#1 ] reg byte a [ sum::return#0 ] 
Uplifting [main] best 394 combination reg byte a [ main::$0 ] reg byte y [ main::b#2 main::b#1 ] reg byte x [ main::i#2 main::i#1 ] 
Uplifting [] best 394 combination 

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
  // Commodore 64 PRG executable file
.file [name="test-comments-block.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(main)
  // Global Constants & labels
  // One of the bytes used for addition
  .const a = 'a'
  // The C64 screen
  .label SCREEN = $400
.segment Code
  // main
/* The program entry point */
main: {
    // [1] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [1] phi main::i#2 = 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // [1] phi main::b#2 = 0 [phi:main->main::@1#1] -- vbuyy=vbuc1 
    ldy #0
    jmp __b1
  // Do some sums
    // [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
  __b1_from___b2:
    // [1] phi main::i#2 = main::i#1 [phi:main::@2->main::@1#0] -- register_copy 
    // [1] phi main::b#2 = main::b#1 [phi:main::@2->main::@1#1] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [2] sum::b#0 = main::b#2 -- vbuaa=vbuyy 
    tya
    // [3] call sum
    jsr sum
    // [4] sum::return#0 = sum::return#1
    jmp __b2
    // main::@2
  __b2:
    // [5] main::$0 = sum::return#0
    // [6] SCREEN[main::i#2] = main::$0 -- pbuc1_derefidx_vbuxx=vbuaa 
    // Output the result on the screen
    sta SCREEN,x
    // [7] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [8] main::b#1 = ++ main::b#2 -- vbuyy=_inc_vbuyy 
    iny
    // [9] if(main::b#1!=$b) goto main::@1 -- vbuyy_neq_vbuc1_then_la1 
    cpy #$b
    bne __b1_from___b2
    jmp __breturn
    // main::@return
  __breturn:
    // [10] 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
 */
// __register(A) char sum(char a, __register(A) char b)
sum: {
    // [11] sum::return#1 = a + sum::b#0 -- vbuaa=vbuc1_plus_vbuaa 
    // calculate the sum
    clc
    adc #@a
    jmp __breturn
    // sum::@return
  __breturn:
    // [12] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
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___b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __b1_from_main:
Removing instruction __b2:
Removing instruction __breturn:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Removing instruction jmp __b1
Succesful ASM optimization Pass5NextJumpElimination

FINAL SYMBOL TABLE
__constant char * const SCREEN = (char *) 1024
__constant char a = 'a'
void main()
char main::$0 // reg byte a 22.0
char main::b
char main::b#1 // reg byte y 16.5
char main::b#2 // reg byte y 4.714285714285714
char main::i
char main::i#1 // reg byte x 7.333333333333333
char main::i#2 // reg byte x 5.5
char sum(char a , char b)
char sum::a
char sum::b
char sum::b#0 // reg byte a 112.0
char sum::r
char sum::return
char sum::return#0 // reg byte a 22.0
char sum::return#1 // reg byte a 37.33333333333333

reg byte y [ main::b#2 main::b#1 ]
reg byte x [ 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
  // Commodore 64 PRG executable file
.file [name="test-comments-block.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(main)
  // Global Constants & labels
  // One of the bytes used for addition
  .const a = 'a'
  // The C64 screen
  .label SCREEN = $400
.segment Code
  // main
/* The program entry point */
main: {
    // [1] phi from main to main::@1 [phi:main->main::@1]
    // [1] phi main::i#2 = 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // [1] phi main::b#2 = 0 [phi:main->main::@1#1] -- vbuyy=vbuc1 
    ldy #0
  // Do some sums
    // [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
    // [1] phi main::i#2 = main::i#1 [phi:main::@2->main::@1#0] -- register_copy 
    // [1] phi main::b#2 = main::b#1 [phi:main::@2->main::@1#1] -- register_copy 
    // main::@1
  __b1:
    // sum(a, b)
    // [2] sum::b#0 = main::b#2 -- vbuaa=vbuyy 
    tya
    // [3] call sum
    jsr sum
    // [4] sum::return#0 = sum::return#1
    // main::@2
    // [5] main::$0 = sum::return#0
    // SCREEN[i++] = sum(a, b)
    // [6] SCREEN[main::i#2] = main::$0 -- pbuc1_derefidx_vbuxx=vbuaa 
    // Output the result on the screen
    sta SCREEN,x
    // SCREEN[i++] = sum(a, b);
    // [7] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // for(byte b: 0..10 )
    // [8] main::b#1 = ++ main::b#2 -- vbuyy=_inc_vbuyy 
    iny
    // [9] if(main::b#1!=$b) goto main::@1 -- vbuyy_neq_vbuc1_then_la1 
    cpy #$b
    bne __b1
    // main::@return
    // }
    // [10] 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
 */
// __register(A) char sum(char a, __register(A) char b)
sum: {
    // byte r = a+b
    // [11] sum::return#1 = a + sum::b#0 -- vbuaa=vbuc1_plus_vbuaa 
    // calculate the sum
    clc
    adc #@a
    // sum::@return
    // }
    // [12] return 
    rts
}
  // File Data

