Inlined call call __init
Eliminating unused variable with no statement main::$0
Eliminating unused variable with no statement main::$1
Eliminating unused variable with no statement main::$2
Eliminating unused variable with no statement main::$4

CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start::@1
  sum::a#0 = 1
  sum::b#0 = 2
  call sum
  sum::return#0 = sum::return#4
  to:main::@1
main::@1: scope:[main]  from main
  sum::return#5 = phi( main/sum::return#0 )
  main::s1#0 = sum::return#5
  sum::a#1 = 3
  sum::b#1 = 4
  call sum
  sum::return#1 = sum::return#4
  to:main::@2
main::@2: scope:[main]  from main::@1
  main::s1#2 = phi( main::@1/main::s1#0 )
  sum::return#6 = phi( main::@1/sum::return#1 )
  main::s2#0 = sum::return#6
  sum::a#2 = 9
  sum::b#2 = $d
  call sum
  sum::return#2 = sum::return#4
  to:main::@3
main::@3: scope:[main]  from main::@2
  main::s2#1 = phi( main::@2/main::s2#0 )
  main::s1#1 = phi( main::@2/main::s1#2 )
  sum::return#7 = phi( main::@2/sum::return#2 )
  main::s3#0 = sum::return#7
  main::$3 = main::s1#1 + main::s2#1
  main::s4#0 = main::$3 + main::s3#0
  *screen = main::s4#0
  to:main::@return
main::@return: scope:[main]  from main::@3
  return 
  to:@return

char sum(char a , char b)
sum: scope:[sum]  from main main::@1 main::@2
  sum::b#3 = phi( main/sum::b#0, main::@1/sum::b#1, main::@2/sum::b#2 )
  sum::a#3 = phi( main/sum::a#0, main::@1/sum::a#1, main::@2/sum::a#2 )
  sum::$0 = sum::a#3 + sum::b#3
  sum::return#3 = sum::$0
  to:sum::@return
sum::@return: scope:[sum]  from sum
  sum::return#8 = phi( sum/sum::return#3 )
  sum::return#4 = sum::return#8
  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
void __start()
void main()
char main::$3
char main::s1
char main::s1#0
char main::s1#1
char main::s1#2
char main::s2
char main::s2#0
char main::s2#1
char main::s3
char main::s3#0
char main::s4
char main::s4#0
__constant char *screen = (char *)$400
char sum(char a , char b)
char sum::$0
char sum::a
char sum::a#0
char sum::a#1
char sum::a#2
char sum::a#3
char sum::b
char sum::b#0
char sum::b#1
char sum::b#2
char sum::b#3
char sum::return
char sum::return#0
char sum::return#1
char sum::return#2
char sum::return#3
char sum::return#4
char sum::return#5
char sum::return#6
char sum::return#7
char sum::return#8

Adding number conversion cast (unumber) 1 in sum::a#0 = 1
Adding number conversion cast (unumber) 2 in sum::b#0 = 2
Adding number conversion cast (unumber) 3 in sum::a#1 = 3
Adding number conversion cast (unumber) 4 in sum::b#1 = 4
Adding number conversion cast (unumber) 9 in sum::a#2 = 9
Adding number conversion cast (unumber) $d in sum::b#2 = $d
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast sum::a#0 = (unumber)1
Inlining cast sum::b#0 = (unumber)2
Inlining cast sum::a#1 = (unumber)3
Inlining cast sum::b#1 = (unumber)4
Inlining cast sum::a#2 = (unumber)9
Inlining cast sum::b#2 = (unumber)$d
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast 1
Simplifying constant integer cast 2
Simplifying constant integer cast 3
Simplifying constant integer cast 4
Simplifying constant integer cast 9
Simplifying constant integer cast $d
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) 2
Finalized unsigned number type (char) 3
Finalized unsigned number type (char) 4
Finalized unsigned number type (char) 9
Finalized unsigned number type (char) $d
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias sum::return#0 = sum::return#5 
Alias sum::return#1 = sum::return#6 
Alias main::s1#0 = main::s1#2 main::s1#1 
Alias sum::return#2 = sum::return#7 
Alias main::s2#0 = main::s2#1 
Alias sum::return#3 = sum::$0 sum::return#8 sum::return#4 
Successful SSA optimization Pass2AliasElimination
Constant sum::a#0 = 1
Constant sum::b#0 = 2
Constant sum::a#1 = 3
Constant sum::b#1 = 4
Constant sum::a#2 = 9
Constant sum::b#2 = $d
Successful SSA optimization Pass2ConstantIdentification
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
Inlining constant with var siblings sum::a#0
Inlining constant with var siblings sum::b#0
Inlining constant with var siblings sum::a#1
Inlining constant with var siblings sum::b#1
Inlining constant with var siblings sum::a#2
Inlining constant with var siblings sum::b#2
Constant inlined sum::b#1 = 4
Constant inlined sum::a#2 = 9
Constant inlined sum::b#0 = 2
Constant inlined sum::a#1 = 3
Constant inlined sum::b#2 = $d
Constant inlined sum::a#0 = 1
Successful SSA optimization Pass2ConstantInlining
Adding NOP phi() at start of main
CALL GRAPH
Calls in [main] to sum:1 sum:4 sum:7 

Created 2 initial phi equivalence classes
Coalesced down to 2 phi equivalence classes
Adding NOP phi() at start of main

FINAL CONTROL FLOW GRAPH

void main()
main: scope:[main]  from
  [0] phi()
  [1] call sum
  [2] sum::return#0 = sum::return#3
  to:main::@1
main::@1: scope:[main]  from main
  [3] main::s1#0 = sum::return#0
  [4] call sum
  [5] sum::return#1 = sum::return#3
  to:main::@2
main::@2: scope:[main]  from main::@1
  [6] main::s2#0 = sum::return#1
  [7] call sum
  [8] sum::return#2 = sum::return#3
  to:main::@3
main::@3: scope:[main]  from main::@2
  [9] main::s3#0 = sum::return#2
  [10] main::$3 = main::s1#0 + main::s2#0
  [11] main::s4#0 = main::$3 + main::s3#0
  [12] *screen = main::s4#0
  to:main::@return
main::@return: scope:[main]  from main::@3
  [13] return 
  to:@return

char sum(char a , char b)
sum: scope:[sum]  from main main::@1 main::@2
  [14] sum::b#3 = phi( main/2, main::@1/4, main::@2/$d )
  [14] sum::a#3 = phi( main/1, main::@1/3, main::@2/9 )
  [15] sum::return#3 = sum::a#3 + sum::b#3
  to:sum::@return
sum::@return: scope:[sum]  from sum
  [16] return 
  to:@return


VARIABLE REGISTER WEIGHTS
void main()
char main::$3 // 4.0
char main::s1
char main::s1#0 // 0.5714285714285714
char main::s2
char main::s2#0 // 1.0
char main::s3
char main::s3#0 // 2.0
char main::s4
char main::s4#0 // 4.0
char sum(char a , char b)
char sum::a
char sum::a#3 // 11.0
char sum::b
char sum::b#3 // 11.0
char sum::return
char sum::return#0 // 4.0
char sum::return#1 // 4.0
char sum::return#2 // 4.0
char sum::return#3 // 3.4000000000000004

Initial phi equivalence classes
[ sum::a#3 ]
[ sum::b#3 ]
Added variable sum::return#0 to live range equivalence class [ sum::return#0 ]
Added variable main::s1#0 to live range equivalence class [ main::s1#0 ]
Added variable sum::return#1 to live range equivalence class [ sum::return#1 ]
Added variable main::s2#0 to live range equivalence class [ main::s2#0 ]
Added variable sum::return#2 to live range equivalence class [ sum::return#2 ]
Added variable main::s3#0 to live range equivalence class [ main::s3#0 ]
Added variable main::$3 to live range equivalence class [ main::$3 ]
Added variable main::s4#0 to live range equivalence class [ main::s4#0 ]
Added variable sum::return#3 to live range equivalence class [ sum::return#3 ]
Complete equivalence classes
[ sum::a#3 ]
[ sum::b#3 ]
[ sum::return#0 ]
[ main::s1#0 ]
[ sum::return#1 ]
[ main::s2#0 ]
[ sum::return#2 ]
[ main::s3#0 ]
[ main::$3 ]
[ main::s4#0 ]
[ sum::return#3 ]
Allocated zp[1]:2 [ sum::a#3 ]
Allocated zp[1]:3 [ sum::b#3 ]
Allocated zp[1]:4 [ sum::return#0 ]
Allocated zp[1]:5 [ sum::return#1 ]
Allocated zp[1]:6 [ sum::return#2 ]
Allocated zp[1]:7 [ main::$3 ]
Allocated zp[1]:8 [ main::s4#0 ]
Allocated zp[1]:9 [ sum::return#3 ]
Allocated zp[1]:10 [ main::s3#0 ]
Allocated zp[1]:11 [ main::s2#0 ]
Allocated zp[1]:12 [ main::s1#0 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [10] main::$3 = main::s1#0 + main::s2#0 [ main::s3#0 main::$3 ] (  [ main::s3#0 main::$3 ] { }  ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:10 [ main::s3#0 ]
Statement [11] main::s4#0 = main::$3 + main::s3#0 [ main::s4#0 ] (  [ main::s4#0 ] { }  ) always clobbers reg byte a 
Statement [15] sum::return#3 = sum::a#3 + sum::b#3 [ sum::return#3 ] ( sum:1 [ sum::return#3 ] { { sum::return#0 = sum::return#3 } }  sum:4 [ main::s1#0 sum::return#3 ] { { sum::return#1 = sum::return#3 } }  sum:7 [ main::s1#0 main::s2#0 sum::return#3 ] { { sum::return#2 = sum::return#3 } }  ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:12 [ main::s1#0 ]
Removing always clobbered register reg byte a as potential for zp[1]:11 [ main::s2#0 ]
Statement [10] main::$3 = main::s1#0 + main::s2#0 [ main::s3#0 main::$3 ] (  [ main::s3#0 main::$3 ] { }  ) always clobbers reg byte a 
Statement [11] main::s4#0 = main::$3 + main::s3#0 [ main::s4#0 ] (  [ main::s4#0 ] { }  ) always clobbers reg byte a 
Statement [15] sum::return#3 = sum::a#3 + sum::b#3 [ sum::return#3 ] ( sum:1 [ sum::return#3 ] { { sum::return#0 = sum::return#3 } }  sum:4 [ main::s1#0 sum::return#3 ] { { sum::return#1 = sum::return#3 } }  sum:7 [ main::s1#0 main::s2#0 sum::return#3 ] { { sum::return#2 = sum::return#3 } }  ) always clobbers reg byte a 
Potential registers zp[1]:2 [ sum::a#3 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:3 [ sum::b#3 ] : zp[1]:3 , 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]:12 [ main::s1#0 ] : zp[1]:12 , reg byte x , reg byte y , 
Potential registers zp[1]:5 [ sum::return#1 ] : zp[1]:5 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:11 [ main::s2#0 ] : zp[1]:11 , reg byte x , reg byte y , 
Potential registers zp[1]:6 [ sum::return#2 ] : zp[1]:6 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:10 [ main::s3#0 ] : zp[1]:10 , reg byte x , reg byte y , 
Potential registers zp[1]:7 [ main::$3 ] : zp[1]:7 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:8 [ main::s4#0 ] : zp[1]:8 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:9 [ sum::return#3 ] : zp[1]:9 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [sum] 11: zp[1]:2 [ sum::a#3 ] 11: zp[1]:3 [ sum::b#3 ] 4: zp[1]:4 [ sum::return#0 ] 4: zp[1]:5 [ sum::return#1 ] 4: zp[1]:6 [ sum::return#2 ] 3.4: zp[1]:9 [ sum::return#3 ] 
Uplift Scope [main] 4: zp[1]:7 [ main::$3 ] 4: zp[1]:8 [ main::s4#0 ] 2: zp[1]:10 [ main::s3#0 ] 1: zp[1]:11 [ main::s2#0 ] 0.57: zp[1]:12 [ main::s1#0 ] 
Uplift Scope [] 

Uplifting [sum] best 121 combination reg byte x [ sum::a#3 ] reg byte a [ sum::b#3 ] reg byte a [ sum::return#0 ] reg byte a [ sum::return#1 ] zp[1]:6 [ sum::return#2 ] zp[1]:9 [ sum::return#3 ] 
Limited combination testing to 100 combinations of 4096 possible.
Uplifting [main] best 109 combination reg byte a [ main::$3 ] reg byte a [ main::s4#0 ] zp[1]:10 [ main::s3#0 ] zp[1]:11 [ main::s2#0 ] zp[1]:12 [ main::s1#0 ] 
Limited combination testing to 100 combinations of 432 possible.
Uplifting [] best 109 combination 
Attempting to uplift remaining variables inzp[1]:6 [ sum::return#2 ]
Uplifting [sum] best 103 combination reg byte a [ sum::return#2 ] 
Attempting to uplift remaining variables inzp[1]:9 [ sum::return#3 ]
Uplifting [sum] best 91 combination reg byte a [ sum::return#3 ] 
Attempting to uplift remaining variables inzp[1]:10 [ main::s3#0 ]
Uplifting [main] best 91 combination zp[1]:10 [ main::s3#0 ] 
Attempting to uplift remaining variables inzp[1]:11 [ main::s2#0 ]
Uplifting [main] best 89 combination reg byte y [ main::s2#0 ] 
Attempting to uplift remaining variables inzp[1]:12 [ main::s1#0 ]
Uplifting [main] best 89 combination zp[1]:12 [ main::s1#0 ] 
Allocated (was zp[1]:10) zp[1]:2 [ main::s3#0 ]
Allocated (was zp[1]:12) zp[1]:3 [ main::s1#0 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
  // Upstart
  // Commodore 64 PRG executable file
.file [name="summin.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
  .label screen = $400
.segment Code
  // main
main: {
    .label s1 = 3
    .label s3 = 2
    // [1] call sum
    // [14] phi from main to sum [phi:main->sum]
  sum_from_main:
    // [14] phi sum::b#3 = 2 [phi:main->sum#0] -- vbuaa=vbuc1 
    lda #2
    // [14] phi sum::a#3 = 1 [phi:main->sum#1] -- vbuxx=vbuc1 
    ldx #1
    jsr sum
    // [2] sum::return#0 = sum::return#3
    jmp __b1
    // main::@1
  __b1:
    // [3] main::s1#0 = sum::return#0 -- vbuz1=vbuaa 
    sta.z s1
    // [4] call sum
    // [14] phi from main::@1 to sum [phi:main::@1->sum]
  sum_from___b1:
    // [14] phi sum::b#3 = 4 [phi:main::@1->sum#0] -- vbuaa=vbuc1 
    lda #4
    // [14] phi sum::a#3 = 3 [phi:main::@1->sum#1] -- vbuxx=vbuc1 
    ldx #3
    jsr sum
    // [5] sum::return#1 = sum::return#3
    jmp __b2
    // main::@2
  __b2:
    // [6] main::s2#0 = sum::return#1 -- vbuyy=vbuaa 
    tay
    // [7] call sum
    // [14] phi from main::@2 to sum [phi:main::@2->sum]
  sum_from___b2:
    // [14] phi sum::b#3 = $d [phi:main::@2->sum#0] -- vbuaa=vbuc1 
    lda #$d
    // [14] phi sum::a#3 = 9 [phi:main::@2->sum#1] -- vbuxx=vbuc1 
    ldx #9
    jsr sum
    // [8] sum::return#2 = sum::return#3
    jmp __b3
    // main::@3
  __b3:
    // [9] main::s3#0 = sum::return#2 -- vbuz1=vbuaa 
    sta.z s3
    // [10] main::$3 = main::s1#0 + main::s2#0 -- vbuaa=vbuz1_plus_vbuyy 
    tya
    clc
    adc.z s1
    // [11] main::s4#0 = main::$3 + main::s3#0 -- vbuaa=vbuaa_plus_vbuz1 
    clc
    adc.z s3
    // [12] *screen = main::s4#0 -- _deref_pbuc1=vbuaa 
    sta screen
    jmp __breturn
    // main::@return
  __breturn:
    // [13] return 
    rts
}
  // sum
// __register(A) char sum(__register(X) char a, __register(A) char b)
sum: {
    // [15] sum::return#3 = sum::a#3 + sum::b#3 -- vbuaa=vbuxx_plus_vbuaa 
    stx.z $ff
    clc
    adc.z $ff
    jmp __breturn
    // sum::@return
  __breturn:
    // [16] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __b2
Removing instruction jmp __b3
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction sum_from_main:
Removing instruction __b1:
Removing instruction sum_from___b1:
Removing instruction __b2:
Removing instruction sum_from___b2:
Removing instruction __b3:
Removing instruction __breturn:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
void main()
char main::$3 // reg byte a 4.0
char main::s1
char main::s1#0 // s1 zp[1]:3 0.5714285714285714
char main::s2
char main::s2#0 // reg byte y 1.0
char main::s3
char main::s3#0 // s3 zp[1]:2 2.0
char main::s4
char main::s4#0 // reg byte a 4.0
__constant char *screen = (char *) 1024
char sum(char a , char b)
char sum::a
char sum::a#3 // reg byte x 11.0
char sum::b
char sum::b#3 // reg byte a 11.0
char sum::return
char sum::return#0 // reg byte a 4.0
char sum::return#1 // reg byte a 4.0
char sum::return#2 // reg byte a 4.0
char sum::return#3 // reg byte a 3.4000000000000004

reg byte x [ sum::a#3 ]
reg byte a [ sum::b#3 ]
reg byte a [ sum::return#0 ]
zp[1]:3 [ main::s1#0 ]
reg byte a [ sum::return#1 ]
reg byte y [ main::s2#0 ]
reg byte a [ sum::return#2 ]
zp[1]:2 [ main::s3#0 ]
reg byte a [ main::$3 ]
reg byte a [ main::s4#0 ]
reg byte a [ sum::return#3 ]


FINAL ASSEMBLER
Score: 74

  // File Comments
  // Upstart
  // Commodore 64 PRG executable file
.file [name="summin.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
  .label screen = $400
.segment Code
  // main
main: {
    .label s1 = 3
    .label s3 = 2
    // byte s1=sum(1,2)
    // [1] call sum
    // [14] phi from main to sum [phi:main->sum]
    // [14] phi sum::b#3 = 2 [phi:main->sum#0] -- vbuaa=vbuc1 
    lda #2
    // [14] phi sum::a#3 = 1 [phi:main->sum#1] -- vbuxx=vbuc1 
    ldx #1
    jsr sum
    // byte s1=sum(1,2)
    // [2] sum::return#0 = sum::return#3
    // main::@1
    // [3] main::s1#0 = sum::return#0 -- vbuz1=vbuaa 
    sta.z s1
    // byte s2=sum(3,4)
    // [4] call sum
    // [14] phi from main::@1 to sum [phi:main::@1->sum]
    // [14] phi sum::b#3 = 4 [phi:main::@1->sum#0] -- vbuaa=vbuc1 
    lda #4
    // [14] phi sum::a#3 = 3 [phi:main::@1->sum#1] -- vbuxx=vbuc1 
    ldx #3
    jsr sum
    // byte s2=sum(3,4)
    // [5] sum::return#1 = sum::return#3
    // main::@2
    // [6] main::s2#0 = sum::return#1 -- vbuyy=vbuaa 
    tay
    // byte s3=sum(9,13)
    // [7] call sum
    // [14] phi from main::@2 to sum [phi:main::@2->sum]
    // [14] phi sum::b#3 = $d [phi:main::@2->sum#0] -- vbuaa=vbuc1 
    lda #$d
    // [14] phi sum::a#3 = 9 [phi:main::@2->sum#1] -- vbuxx=vbuc1 
    ldx #9
    jsr sum
    // byte s3=sum(9,13)
    // [8] sum::return#2 = sum::return#3
    // main::@3
    // [9] main::s3#0 = sum::return#2 -- vbuz1=vbuaa 
    sta.z s3
    // s1+s2
    // [10] main::$3 = main::s1#0 + main::s2#0 -- vbuaa=vbuz1_plus_vbuyy 
    tya
    clc
    adc.z s1
    // byte s4=s1+s2+s3
    // [11] main::s4#0 = main::$3 + main::s3#0 -- vbuaa=vbuaa_plus_vbuz1 
    clc
    adc.z s3
    // *screen = s4
    // [12] *screen = main::s4#0 -- _deref_pbuc1=vbuaa 
    sta screen
    // main::@return
    // }
    // [13] return 
    rts
}
  // sum
// __register(A) char sum(__register(X) char a, __register(A) char b)
sum: {
    // a+b
    // [15] sum::return#3 = sum::a#3 + sum::b#3 -- vbuaa=vbuxx_plus_vbuaa 
    stx.z $ff
    clc
    adc.z $ff
    // sum::@return
    // }
    // [16] return 
    rts
}
  // File Data

