PARSING src/test/java/dk/camelot64/kickc/test/kc/summin.kc
byte* screen = $0400;

void main() {
  byte s1=sum(1,2);
  byte s2=sum(3,4);
  byte s3=sum(9,13);
  byte s4=s1+s2+s3;
  *screen = s4;
}

byte sum(byte a, byte b) {
  return a+b;
}


STATEMENTS
  (byte*) screen ← (word/signed word/dword/signed dword) 1024
proc (void()) main()
  (byte~) main::$0 ← call sum (byte/signed byte/word/signed word/dword/signed dword) 1 (byte/signed byte/word/signed word/dword/signed dword) 2 
  (byte) main::s1 ← (byte~) main::$0
  (byte~) main::$1 ← call sum (byte/signed byte/word/signed word/dword/signed dword) 3 (byte/signed byte/word/signed word/dword/signed dword) 4 
  (byte) main::s2 ← (byte~) main::$1
  (byte~) main::$2 ← call sum (byte/signed byte/word/signed word/dword/signed dword) 9 (byte/signed byte/word/signed word/dword/signed dword) 13 
  (byte) main::s3 ← (byte~) main::$2
  (byte/word~) main::$3 ← (byte) main::s1 + (byte) main::s2
  (byte/word~) main::$4 ← (byte/word~) main::$3 + (byte) main::s3
  (byte) main::s4 ← (byte/word~) main::$4
  *((byte*) screen) ← (byte) main::s4
main::@return:
  return 
endproc // main()
proc (byte()) sum((byte) sum::a , (byte) sum::b)
  (byte/word~) sum::$0 ← (byte) sum::a + (byte) sum::b
  (byte) sum::return ← (byte/word~) sum::$0
  goto sum::@return
sum::@return:
  (byte) sum::return ← (byte) sum::return
  return (byte) sum::return
endproc // sum()
  call main 

SYMBOLS
(void()) main()
(byte~) main::$0
(byte~) main::$1
(byte~) main::$2
(byte/word~) main::$3
(byte/word~) main::$4
(label) main::@return
(byte) main::s1
(byte) main::s2
(byte) main::s3
(byte) main::s4
(byte*) screen
(byte()) sum((byte) sum::a , (byte) sum::b)
(byte/word~) sum::$0
(label) sum::@return
(byte) sum::a
(byte) sum::b
(byte) sum::return

Promoting word/signed word/dword/signed dword to byte* in screen ← ((byte*)) 1024
INITIAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  (byte*) screen ← ((byte*)) (word/signed word/dword/signed dword) 1024
  to:@1
main: scope:[main]  from
  (byte~) main::$0 ← call sum (byte/signed byte/word/signed word/dword/signed dword) 1 (byte/signed byte/word/signed word/dword/signed dword) 2 
  (byte) main::s1 ← (byte~) main::$0
  (byte~) main::$1 ← call sum (byte/signed byte/word/signed word/dword/signed dword) 3 (byte/signed byte/word/signed word/dword/signed dword) 4 
  (byte) main::s2 ← (byte~) main::$1
  (byte~) main::$2 ← call sum (byte/signed byte/word/signed word/dword/signed dword) 9 (byte/signed byte/word/signed word/dword/signed dword) 13 
  (byte) main::s3 ← (byte~) main::$2
  (byte/word~) main::$3 ← (byte) main::s1 + (byte) main::s2
  (byte/word~) main::$4 ← (byte/word~) main::$3 + (byte) main::s3
  (byte) main::s4 ← (byte/word~) main::$4
  *((byte*) screen) ← (byte) main::s4
  to:main::@return
main::@return: scope:[main]  from main
  return 
  to:@return
@1: scope:[]  from @begin
  to:@2
sum: scope:[sum]  from
  (byte/word~) sum::$0 ← (byte) sum::a + (byte) sum::b
  (byte) sum::return ← (byte/word~) sum::$0
  to:sum::@return
sum::@return: scope:[sum]  from sum sum::@1
  (byte) sum::return ← (byte) sum::return
  return (byte) sum::return
  to:@return
sum::@1: scope:[sum]  from
  to:sum::@return
@2: scope:[]  from @1
  call main 
  to:@end
@end: scope:[]  from @2

Removing empty block @1
Removing empty block sum::@1
PROCEDURE MODIFY VARIABLE ANALYSIS

Completing Phi functions...
Completing Phi functions...
Completing Phi functions...
Completing Phi functions...
Completing Phi functions...

CONTROL FLOW GRAPH SSA WITH ASSIGNMENT CALL & RETURN
@begin: scope:[]  from
  (byte*) screen#0 ← ((byte*)) (word/signed word/dword/signed dword) 1024
  to:@2
main: scope:[main]  from @2
  (byte*) screen#4 ← phi( @2/(byte*) screen#5 )
  (byte) sum::a#0 ← (byte/signed byte/word/signed word/dword/signed dword) 1
  (byte) sum::b#0 ← (byte/signed byte/word/signed word/dword/signed dword) 2
  call sum param-assignment
  (byte) sum::return#0 ← (byte) sum::return#4
  to:main::@1
main::@1: scope:[main]  from main
  (byte*) screen#3 ← phi( main/(byte*) screen#4 )
  (byte) sum::return#5 ← phi( main/(byte) sum::return#0 )
  (byte~) main::$0 ← (byte) sum::return#5
  (byte) main::s1#0 ← (byte~) main::$0
  (byte) sum::a#1 ← (byte/signed byte/word/signed word/dword/signed dword) 3
  (byte) sum::b#1 ← (byte/signed byte/word/signed word/dword/signed dword) 4
  call sum param-assignment
  (byte) sum::return#1 ← (byte) sum::return#4
  to:main::@2
main::@2: scope:[main]  from main::@1
  (byte*) screen#2 ← phi( main::@1/(byte*) screen#3 )
  (byte) main::s1#2 ← phi( main::@1/(byte) main::s1#0 )
  (byte) sum::return#6 ← phi( main::@1/(byte) sum::return#1 )
  (byte~) main::$1 ← (byte) sum::return#6
  (byte) main::s2#0 ← (byte~) main::$1
  (byte) sum::a#2 ← (byte/signed byte/word/signed word/dword/signed dword) 9
  (byte) sum::b#2 ← (byte/signed byte/word/signed word/dword/signed dword) 13
  call sum param-assignment
  (byte) sum::return#2 ← (byte) sum::return#4
  to:main::@3
main::@3: scope:[main]  from main::@2
  (byte*) screen#1 ← phi( main::@2/(byte*) screen#2 )
  (byte) main::s2#1 ← phi( main::@2/(byte) main::s2#0 )
  (byte) main::s1#1 ← phi( main::@2/(byte) main::s1#2 )
  (byte) sum::return#7 ← phi( main::@2/(byte) sum::return#2 )
  (byte~) main::$2 ← (byte) sum::return#7
  (byte) main::s3#0 ← (byte~) main::$2
  (byte/word~) main::$3 ← (byte) main::s1#1 + (byte) main::s2#1
  (byte/word~) main::$4 ← (byte/word~) main::$3 + (byte) main::s3#0
  (byte) main::s4#0 ← (byte/word~) main::$4
  *((byte*) screen#1) ← (byte) main::s4#0
  to:main::@return
main::@return: scope:[main]  from main::@3
  return 
  to:@return
sum: scope:[sum]  from main main::@1 main::@2
  (byte) sum::b#3 ← phi( main/(byte) sum::b#0 main::@1/(byte) sum::b#1 main::@2/(byte) sum::b#2 )
  (byte) sum::a#3 ← phi( main/(byte) sum::a#0 main::@1/(byte) sum::a#1 main::@2/(byte) sum::a#2 )
  (byte/word~) sum::$0 ← (byte) sum::a#3 + (byte) sum::b#3
  (byte) sum::return#3 ← (byte/word~) sum::$0
  to:sum::@return
sum::@return: scope:[sum]  from sum
  (byte) sum::return#8 ← phi( sum/(byte) sum::return#3 )
  (byte) sum::return#4 ← (byte) sum::return#8
  return 
  to:@return
@2: scope:[]  from @begin
  (byte*) screen#5 ← phi( @begin/(byte*) screen#0 )
  call main param-assignment
  to:@3
@3: scope:[]  from @2
  to:@end
@end: scope:[]  from @3

SYMBOL TABLE SSA
(label) @2
(label) @3
(label) @begin
(label) @end
(void()) main()
(byte~) main::$0
(byte~) main::$1
(byte~) main::$2
(byte/word~) main::$3
(byte/word~) main::$4
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@return
(byte) main::s1
(byte) main::s1#0
(byte) main::s1#1
(byte) main::s1#2
(byte) main::s2
(byte) main::s2#0
(byte) main::s2#1
(byte) main::s3
(byte) main::s3#0
(byte) main::s4
(byte) main::s4#0
(byte*) screen
(byte*) screen#0
(byte*) screen#1
(byte*) screen#2
(byte*) screen#3
(byte*) screen#4
(byte*) screen#5
(byte()) sum((byte) sum::a , (byte) sum::b)
(byte/word~) sum::$0
(label) sum::@return
(byte) sum::a
(byte) sum::a#0
(byte) sum::a#1
(byte) sum::a#2
(byte) sum::a#3
(byte) sum::b
(byte) sum::b#0
(byte) sum::b#1
(byte) sum::b#2
(byte) sum::b#3
(byte) sum::return
(byte) sum::return#0
(byte) sum::return#1
(byte) sum::return#2
(byte) sum::return#3
(byte) sum::return#4
(byte) sum::return#5
(byte) sum::return#6
(byte) sum::return#7
(byte) sum::return#8

OPTIMIZING CONTROL FLOW GRAPH
Culled Empty Block (label) @3
Succesful SSA optimization Pass2CullEmptyBlocks
Not aliassing across scopes: screen#4 screen#5
Not aliassing across scopes: sum::return#0 sum::return#4
Not aliassing across scopes: main::$0 sum::return#5
Not aliassing across scopes: sum::return#1 sum::return#4
Not aliassing across scopes: main::$1 sum::return#6
Not aliassing across scopes: sum::return#2 sum::return#4
Not aliassing across scopes: main::$2 sum::return#7
Not aliassing across scopes: sum::a#3 sum::a#0
Not aliassing across scopes: sum::b#3 sum::b#0
Alias (byte) sum::return#0 = (byte) sum::return#5 
Alias (byte*) screen#1 = (byte*) screen#3 (byte*) screen#4 (byte*) screen#2 
Alias (byte) main::s1#0 = (byte~) main::$0 (byte) main::s1#2 (byte) main::s1#1 
Alias (byte) sum::return#1 = (byte) sum::return#6 
Alias (byte) main::s2#0 = (byte~) main::$1 (byte) main::s2#1 
Alias (byte) sum::return#2 = (byte) sum::return#7 
Alias (byte) main::s3#0 = (byte~) main::$2 
Alias (byte) main::s4#0 = (byte/word~) main::$4 
Alias (byte) sum::return#3 = (byte/word~) sum::$0 (byte) sum::return#8 (byte) sum::return#4 
Alias (byte*) screen#0 = (byte*) screen#5 
Succesful SSA optimization Pass2AliasElimination
Not aliassing across scopes: screen#1 screen#0
Not aliassing across scopes: sum::return#0 sum::return#3
Not aliassing across scopes: main::s1#0 sum::return#0
Not aliassing across scopes: sum::return#1 sum::return#3
Not aliassing across scopes: main::s2#0 sum::return#1
Not aliassing across scopes: sum::return#2 sum::return#3
Not aliassing across scopes: main::s3#0 sum::return#2
Not aliassing across scopes: sum::a#3 sum::a#0
Not aliassing across scopes: sum::b#3 sum::b#0
Redundant Phi (byte*) screen#1 (byte*) screen#0
Succesful SSA optimization Pass2RedundantPhiElimination
Constant (const byte*) screen#0 = ((byte*))1024
Constant (const byte) sum::a#0 = 1
Constant (const byte) sum::b#0 = 2
Constant (const byte) sum::a#1 = 3
Constant (const byte) sum::b#1 = 4
Constant (const byte) sum::a#2 = 9
Constant (const byte) sum::b#2 = 13
Succesful SSA optimization Pass2ConstantIdentification
Not aliassing across scopes: sum::return#0 sum::return#3
Not aliassing across scopes: main::s1#0 sum::return#0
Not aliassing across scopes: sum::return#1 sum::return#3
Not aliassing across scopes: main::s2#0 sum::return#1
Not aliassing across scopes: sum::return#2 sum::return#3
Not aliassing across scopes: main::s3#0 sum::return#2
OPTIMIZING CONTROL FLOW GRAPH
Inlining constant with var siblings (const byte) sum::a#0
Inlining constant with different constant siblings (const byte) sum::a#0
Inlining constant with different constant siblings (const byte) sum::a#0
Inlining constant with var siblings (const byte) sum::b#0
Inlining constant with different constant siblings (const byte) sum::b#0
Inlining constant with different constant siblings (const byte) sum::b#0
Inlining constant with var siblings (const byte) sum::a#1
Inlining constant with different constant siblings (const byte) sum::a#1
Inlining constant with different constant siblings (const byte) sum::a#1
Inlining constant with var siblings (const byte) sum::b#1
Inlining constant with different constant siblings (const byte) sum::b#1
Inlining constant with different constant siblings (const byte) sum::b#1
Inlining constant with var siblings (const byte) sum::a#2
Inlining constant with different constant siblings (const byte) sum::a#2
Inlining constant with different constant siblings (const byte) sum::a#2
Inlining constant with var siblings (const byte) sum::b#2
Inlining constant with different constant siblings (const byte) sum::b#2
Inlining constant with different constant siblings (const byte) sum::b#2
Constant inlined sum::b#1 = (byte/signed byte/word/signed word/dword/signed dword) 4
Constant inlined sum::a#2 = (byte/signed byte/word/signed word/dword/signed dword) 9
Constant inlined sum::b#0 = (byte/signed byte/word/signed word/dword/signed dword) 2
Constant inlined sum::a#1 = (byte/signed byte/word/signed word/dword/signed dword) 3
Constant inlined sum::b#2 = (byte/signed byte/word/signed word/dword/signed dword) 13
Constant inlined sum::a#0 = (byte/signed byte/word/signed word/dword/signed dword) 1
Succesful SSA optimization Pass2ConstantInlining
Block Sequence Planned @begin @2 @end main main::@1 main::@2 main::@3 main::@return sum sum::@return 
Block Sequence Planned @begin @2 @end main main::@1 main::@2 main::@3 main::@return sum sum::@return 
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @2
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:5 sum:8 sum:11 

Propagating live ranges...
Propagating live ranges...
Propagating live ranges...
Propagating live ranges...
Propagating live ranges...
Propagating live ranges...
Propagating live ranges...
Propagating live ranges...
Created 2 initial phi equivalence classes
Coalesced down to 2 phi equivalence classes
Block Sequence Planned @begin @2 @end main main::@1 main::@2 main::@3 main::@return sum sum::@return 
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @2
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
Propagating live ranges...
Propagating live ranges...
Propagating live ranges...
Propagating live ranges...
Propagating live ranges...
Propagating live ranges...
Propagating live ranges...
Propagating live ranges...

FINAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  [0] phi() [ ] ( )
  to:@2
@2: scope:[]  from @begin
  [1] phi() [ ] ( )
  [2] call main param-assignment [ ] ( )
  to:@end
@end: scope:[]  from @2
  [3] phi() [ ] ( )
main: scope:[main]  from @2
  [4] phi() [ ] ( main:2 [ ] )
  [5] call sum param-assignment [ sum::return#3 ] ( main:2 [ sum::return#3 ] )
  [6] (byte) sum::return#0 ← (byte) sum::return#3 [ sum::return#0 ] ( main:2 [ sum::return#0 ] )
  to:main::@1
main::@1: scope:[main]  from main
  [7] (byte) main::s1#0 ← (byte) sum::return#0 [ main::s1#0 ] ( main:2 [ main::s1#0 ] )
  [8] call sum param-assignment [ sum::return#3 main::s1#0 ] ( main:2 [ sum::return#3 main::s1#0 ] )
  [9] (byte) sum::return#1 ← (byte) sum::return#3 [ main::s1#0 sum::return#1 ] ( main:2 [ main::s1#0 sum::return#1 ] )
  to:main::@2
main::@2: scope:[main]  from main::@1
  [10] (byte) main::s2#0 ← (byte) sum::return#1 [ main::s1#0 main::s2#0 ] ( main:2 [ main::s1#0 main::s2#0 ] )
  [11] call sum param-assignment [ sum::return#3 main::s1#0 main::s2#0 ] ( main:2 [ sum::return#3 main::s1#0 main::s2#0 ] )
  [12] (byte) sum::return#2 ← (byte) sum::return#3 [ main::s1#0 main::s2#0 sum::return#2 ] ( main:2 [ main::s1#0 main::s2#0 sum::return#2 ] )
  to:main::@3
main::@3: scope:[main]  from main::@2
  [13] (byte) main::s3#0 ← (byte) sum::return#2 [ main::s1#0 main::s2#0 main::s3#0 ] ( main:2 [ main::s1#0 main::s2#0 main::s3#0 ] )
  [14] (byte/word~) main::$3 ← (byte) main::s1#0 + (byte) main::s2#0 [ main::s3#0 main::$3 ] ( main:2 [ main::s3#0 main::$3 ] )
  [15] (byte) main::s4#0 ← (byte/word~) main::$3 + (byte) main::s3#0 [ main::s4#0 ] ( main:2 [ main::s4#0 ] )
  [16] *((const byte*) screen#0) ← (byte) main::s4#0 [ ] ( main:2 [ ] )
  to:main::@return
main::@return: scope:[main]  from main::@3
  [17] return  [ ] ( main:2 [ ] )
  to:@return
sum: scope:[sum]  from main main::@1 main::@2
  [18] (byte) sum::b#3 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 2 main::@1/(byte/signed byte/word/signed word/dword/signed dword) 4 main::@2/(byte/signed byte/word/signed word/dword/signed dword) 13 ) [ sum::a#3 sum::b#3 ] ( main:2::sum:5 [ sum::a#3 sum::b#3 ] main:2::sum:8 [ main::s1#0 sum::a#3 sum::b#3 ] main:2::sum:11 [ main::s1#0 main::s2#0 sum::a#3 sum::b#3 ] )
  [18] (byte) sum::a#3 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 1 main::@1/(byte/signed byte/word/signed word/dword/signed dword) 3 main::@2/(byte/signed byte/word/signed word/dword/signed dword) 9 ) [ sum::a#3 sum::b#3 ] ( main:2::sum:5 [ sum::a#3 sum::b#3 ] main:2::sum:8 [ main::s1#0 sum::a#3 sum::b#3 ] main:2::sum:11 [ main::s1#0 main::s2#0 sum::a#3 sum::b#3 ] )
  [19] (byte) sum::return#3 ← (byte) sum::a#3 + (byte) sum::b#3 [ sum::return#3 ] ( main:2::sum:5 [ sum::return#3 ] main:2::sum:8 [ main::s1#0 sum::return#3 ] main:2::sum:11 [ main::s1#0 main::s2#0 sum::return#3 ] )
  to:sum::@return
sum::@return: scope:[sum]  from sum
  [20] return  [ sum::return#3 ] ( main:2::sum:5 [ sum::return#3 ] main:2::sum:8 [ main::s1#0 sum::return#3 ] main:2::sum:11 [ main::s1#0 main::s2#0 sum::return#3 ] )
  to:@return

DOMINATORS
@begin dominated by  @begin 
@2 dominated by  @2 @begin 
@end dominated by  @2 @begin @end 
main dominated by  @2 @begin main 
main::@1 dominated by  @2 @begin main::@1 main 
main::@2 dominated by  @2 @begin main::@1 main::@2 main 
main::@3 dominated by  @2 @begin main::@1 main::@2 main main::@3 
main::@return dominated by  main::@return @2 @begin main::@1 main::@2 main main::@3 
sum dominated by  @2 @begin main sum 
sum::@return dominated by  @2 @begin main sum sum::@return 

NATURAL LOOPS

NATURAL LOOPS WITH DEPTH
Found 0 loops in scope []
Found 0 loops in scope [main]
Found 0 loops in scope [sum]


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte/word~) main::$3 4.0
(byte) main::s1
(byte) main::s1#0 0.5714285714285714
(byte) main::s2
(byte) main::s2#0 1.0
(byte) main::s3
(byte) main::s3#0 2.0
(byte) main::s4
(byte) main::s4#0 4.0
(byte*) screen
(byte()) sum((byte) sum::a , (byte) sum::b)
(byte) sum::a
(byte) sum::a#3 2.0
(byte) sum::b
(byte) sum::b#3 2.0
(byte) sum::return
(byte) sum::return#0 4.0
(byte) sum::return#1 4.0
(byte) sum::return#2 4.0
(byte) sum::return#3 1.6

Initial phi equivalence classes
[ sum::a#3 ]
[ sum::b#3 ]
Added variable sum::return#0 to zero page equivalence class [ sum::return#0 ]
Added variable main::s1#0 to zero page equivalence class [ main::s1#0 ]
Added variable sum::return#1 to zero page equivalence class [ sum::return#1 ]
Added variable main::s2#0 to zero page equivalence class [ main::s2#0 ]
Added variable sum::return#2 to zero page equivalence class [ sum::return#2 ]
Added variable main::s3#0 to zero page equivalence class [ main::s3#0 ]
Added variable main::$3 to zero page equivalence class [ main::$3 ]
Added variable main::s4#0 to zero page equivalence class [ main::s4#0 ]
Added variable sum::return#3 to zero page 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 ZP_BYTE:2 [ sum::a#3 ]
Allocated zp ZP_BYTE:3 [ sum::b#3 ]
Allocated zp ZP_BYTE:4 [ sum::return#0 ]
Allocated zp ZP_BYTE:5 [ main::s1#0 ]
Allocated zp ZP_BYTE:6 [ sum::return#1 ]
Allocated zp ZP_BYTE:7 [ main::s2#0 ]
Allocated zp ZP_BYTE:8 [ sum::return#2 ]
Allocated zp ZP_BYTE:9 [ main::s3#0 ]
Allocated zp ZP_BYTE:10 [ main::$3 ]
Allocated zp ZP_BYTE:11 [ main::s4#0 ]
Allocated zp ZP_BYTE:12 [ sum::return#3 ]

INITIAL ASM
//SEG0 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG1 Global Constants & labels
  .label screen = $400
//SEG2 @begin
bbegin:
//SEG3 [1] phi from @begin to @2 [phi:@begin->@2]
b2_from_bbegin:
  jmp b2
//SEG4 @2
b2:
//SEG5 [2] call main param-assignment [ ] ( )
//SEG6 [4] phi from @2 to main [phi:@2->main]
main_from_b2:
  jsr main
//SEG7 [3] phi from @2 to @end [phi:@2->@end]
bend_from_b2:
  jmp bend
//SEG8 @end
bend:
//SEG9 main
main: {
    .label _3 = $a
    .label s1 = 5
    .label s2 = 7
    .label s3 = 9
    .label s4 = $b
  //SEG10 [5] call sum param-assignment [ sum::return#3 ] ( main:2 [ sum::return#3 ] )
  //SEG11 [18] phi from main to sum [phi:main->sum]
  sum_from_main:
  //SEG12 [18] phi (byte) sum::b#3 = (byte/signed byte/word/signed word/dword/signed dword) 2 [phi:main->sum#0] -- vbuz1=vbuc1 
    lda #2
    sta sum.b
  //SEG13 [18] phi (byte) sum::a#3 = (byte/signed byte/word/signed word/dword/signed dword) 1 [phi:main->sum#1] -- vbuz1=vbuc1 
    lda #1
    sta sum.a
    jsr sum
  //SEG14 [6] (byte) sum::return#0 ← (byte) sum::return#3 [ sum::return#0 ] ( main:2 [ sum::return#0 ] ) -- vbuz1=vbuz2 
    lda sum.return_3
    sta sum.return
    jmp b1
  //SEG15 main::@1
  b1:
  //SEG16 [7] (byte) main::s1#0 ← (byte) sum::return#0 [ main::s1#0 ] ( main:2 [ main::s1#0 ] ) -- vbuz1=vbuz2 
    lda sum.return
    sta s1
  //SEG17 [8] call sum param-assignment [ sum::return#3 main::s1#0 ] ( main:2 [ sum::return#3 main::s1#0 ] )
  //SEG18 [18] phi from main::@1 to sum [phi:main::@1->sum]
  sum_from_b1:
  //SEG19 [18] phi (byte) sum::b#3 = (byte/signed byte/word/signed word/dword/signed dword) 4 [phi:main::@1->sum#0] -- vbuz1=vbuc1 
    lda #4
    sta sum.b
  //SEG20 [18] phi (byte) sum::a#3 = (byte/signed byte/word/signed word/dword/signed dword) 3 [phi:main::@1->sum#1] -- vbuz1=vbuc1 
    lda #3
    sta sum.a
    jsr sum
  //SEG21 [9] (byte) sum::return#1 ← (byte) sum::return#3 [ main::s1#0 sum::return#1 ] ( main:2 [ main::s1#0 sum::return#1 ] ) -- vbuz1=vbuz2 
    lda sum.return_3
    sta sum.return_1
    jmp b2
  //SEG22 main::@2
  b2:
  //SEG23 [10] (byte) main::s2#0 ← (byte) sum::return#1 [ main::s1#0 main::s2#0 ] ( main:2 [ main::s1#0 main::s2#0 ] ) -- vbuz1=vbuz2 
    lda sum.return_1
    sta s2
  //SEG24 [11] call sum param-assignment [ sum::return#3 main::s1#0 main::s2#0 ] ( main:2 [ sum::return#3 main::s1#0 main::s2#0 ] )
  //SEG25 [18] phi from main::@2 to sum [phi:main::@2->sum]
  sum_from_b2:
  //SEG26 [18] phi (byte) sum::b#3 = (byte/signed byte/word/signed word/dword/signed dword) 13 [phi:main::@2->sum#0] -- vbuz1=vbuc1 
    lda #$d
    sta sum.b
  //SEG27 [18] phi (byte) sum::a#3 = (byte/signed byte/word/signed word/dword/signed dword) 9 [phi:main::@2->sum#1] -- vbuz1=vbuc1 
    lda #9
    sta sum.a
    jsr sum
  //SEG28 [12] (byte) sum::return#2 ← (byte) sum::return#3 [ main::s1#0 main::s2#0 sum::return#2 ] ( main:2 [ main::s1#0 main::s2#0 sum::return#2 ] ) -- vbuz1=vbuz2 
    lda sum.return_3
    sta sum.return_2
    jmp b3
  //SEG29 main::@3
  b3:
  //SEG30 [13] (byte) main::s3#0 ← (byte) sum::return#2 [ main::s1#0 main::s2#0 main::s3#0 ] ( main:2 [ main::s1#0 main::s2#0 main::s3#0 ] ) -- vbuz1=vbuz2 
    lda sum.return_2
    sta s3
  //SEG31 [14] (byte/word~) main::$3 ← (byte) main::s1#0 + (byte) main::s2#0 [ main::s3#0 main::$3 ] ( main:2 [ main::s3#0 main::$3 ] ) -- vbuz1=vbuz2_plus_vbuz3 
    lda s1
    clc
    adc s2
    sta _3
  //SEG32 [15] (byte) main::s4#0 ← (byte/word~) main::$3 + (byte) main::s3#0 [ main::s4#0 ] ( main:2 [ main::s4#0 ] ) -- vbuz1=vbuz2_plus_vbuz3 
    lda _3
    clc
    adc s3
    sta s4
  //SEG33 [16] *((const byte*) screen#0) ← (byte) main::s4#0 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuz1 
    lda s4
    sta screen
    jmp breturn
  //SEG34 main::@return
  breturn:
  //SEG35 [17] return  [ ] ( main:2 [ ] )
    rts
}
//SEG36 sum
sum: {
    .label return = 4
    .label return_1 = 6
    .label return_2 = 8
    .label return_3 = $c
    .label a = 2
    .label b = 3
  //SEG37 [19] (byte) sum::return#3 ← (byte) sum::a#3 + (byte) sum::b#3 [ sum::return#3 ] ( main:2::sum:5 [ sum::return#3 ] main:2::sum:8 [ main::s1#0 sum::return#3 ] main:2::sum:11 [ main::s1#0 main::s2#0 sum::return#3 ] ) -- vbuz1=vbuz2_plus_vbuz3 
    lda a
    clc
    adc b
    sta return_3
    jmp breturn
  //SEG38 sum::@return
  breturn:
  //SEG39 [20] return  [ sum::return#3 ] ( main:2::sum:5 [ sum::return#3 ] main:2::sum:8 [ main::s1#0 sum::return#3 ] main:2::sum:11 [ main::s1#0 main::s2#0 sum::return#3 ] )
    rts
}

REGISTER UPLIFT POTENTIAL REGISTERS
Potential registers zp ZP_BYTE:2 [ sum::a#3 ] : zp ZP_BYTE:2 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:3 [ sum::b#3 ] : zp ZP_BYTE:3 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:4 [ sum::return#0 ] : zp ZP_BYTE:4 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:5 [ main::s1#0 ] : zp ZP_BYTE:5 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:6 [ sum::return#1 ] : zp ZP_BYTE:6 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:7 [ main::s2#0 ] : zp ZP_BYTE:7 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:8 [ sum::return#2 ] : zp ZP_BYTE:8 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:9 [ main::s3#0 ] : zp ZP_BYTE:9 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:10 [ main::$3 ] : zp ZP_BYTE:10 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:11 [ main::s4#0 ] : zp ZP_BYTE:11 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:12 [ sum::return#3 ] : zp ZP_BYTE:12 , reg byte a , reg byte x , reg byte y , 

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

Uplifting [sum] best 115 combination reg byte a [ sum::return#0 ] reg byte a [ sum::return#1 ] reg byte a [ sum::return#2 ] reg byte x [ sum::a#3 ] reg byte a [ sum::b#3 ] reg byte a [ sum::return#3 ] 
Uplifting [main] best 101 combination reg byte a [ main::$3 ] reg byte a [ main::s4#0 ] zp ZP_BYTE:9 [ main::s3#0 ] reg byte y [ main::s2#0 ] zp ZP_BYTE:5 [ main::s1#0 ] 
Uplifting [] best 101 combination 
Attempting to uplift remaining variables inzp ZP_BYTE:9 [ main::s3#0 ]
Uplifting [main] best 101 combination zp ZP_BYTE:9 [ main::s3#0 ] 
Attempting to uplift remaining variables inzp ZP_BYTE:5 [ main::s1#0 ]
Uplifting [main] best 101 combination zp ZP_BYTE:5 [ main::s1#0 ] 
Allocated (was zp ZP_BYTE:5) zp ZP_BYTE:2 [ main::s1#0 ]
Allocated (was zp ZP_BYTE:9) zp ZP_BYTE:3 [ main::s3#0 ]

ASSEMBLER BEFORE OPTIMIZATION
//SEG0 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG1 Global Constants & labels
  .label screen = $400
//SEG2 @begin
bbegin:
//SEG3 [1] phi from @begin to @2 [phi:@begin->@2]
b2_from_bbegin:
  jmp b2
//SEG4 @2
b2:
//SEG5 [2] call main param-assignment [ ] ( )
//SEG6 [4] phi from @2 to main [phi:@2->main]
main_from_b2:
  jsr main
//SEG7 [3] phi from @2 to @end [phi:@2->@end]
bend_from_b2:
  jmp bend
//SEG8 @end
bend:
//SEG9 main
main: {
    .label s1 = 2
    .label s3 = 3
  //SEG10 [5] call sum param-assignment [ sum::return#3 ] ( main:2 [ sum::return#3 ] )
  //SEG11 [18] phi from main to sum [phi:main->sum]
  sum_from_main:
  //SEG12 [18] phi (byte) sum::b#3 = (byte/signed byte/word/signed word/dword/signed dword) 2 [phi:main->sum#0] -- vbuaa=vbuc1 
    lda #2
  //SEG13 [18] phi (byte) sum::a#3 = (byte/signed byte/word/signed word/dword/signed dword) 1 [phi:main->sum#1] -- vbuxx=vbuc1 
    ldx #1
    jsr sum
  //SEG14 [6] (byte) sum::return#0 ← (byte) sum::return#3 [ sum::return#0 ] ( main:2 [ sum::return#0 ] )
    // (byte) sum::return#0 = (byte) sum::return#3  // register copy reg byte a
    jmp b1
  //SEG15 main::@1
  b1:
  //SEG16 [7] (byte) main::s1#0 ← (byte) sum::return#0 [ main::s1#0 ] ( main:2 [ main::s1#0 ] ) -- vbuz1=vbuaa 
    sta s1
  //SEG17 [8] call sum param-assignment [ sum::return#3 main::s1#0 ] ( main:2 [ sum::return#3 main::s1#0 ] )
  //SEG18 [18] phi from main::@1 to sum [phi:main::@1->sum]
  sum_from_b1:
  //SEG19 [18] phi (byte) sum::b#3 = (byte/signed byte/word/signed word/dword/signed dword) 4 [phi:main::@1->sum#0] -- vbuaa=vbuc1 
    lda #4
  //SEG20 [18] phi (byte) sum::a#3 = (byte/signed byte/word/signed word/dword/signed dword) 3 [phi:main::@1->sum#1] -- vbuxx=vbuc1 
    ldx #3
    jsr sum
  //SEG21 [9] (byte) sum::return#1 ← (byte) sum::return#3 [ main::s1#0 sum::return#1 ] ( main:2 [ main::s1#0 sum::return#1 ] )
    // (byte) sum::return#1 = (byte) sum::return#3  // register copy reg byte a
    jmp b2
  //SEG22 main::@2
  b2:
  //SEG23 [10] (byte) main::s2#0 ← (byte) sum::return#1 [ main::s1#0 main::s2#0 ] ( main:2 [ main::s1#0 main::s2#0 ] ) -- vbuyy=vbuaa 
    tay
  //SEG24 [11] call sum param-assignment [ sum::return#3 main::s1#0 main::s2#0 ] ( main:2 [ sum::return#3 main::s1#0 main::s2#0 ] )
  //SEG25 [18] phi from main::@2 to sum [phi:main::@2->sum]
  sum_from_b2:
  //SEG26 [18] phi (byte) sum::b#3 = (byte/signed byte/word/signed word/dword/signed dword) 13 [phi:main::@2->sum#0] -- vbuaa=vbuc1 
    lda #$d
  //SEG27 [18] phi (byte) sum::a#3 = (byte/signed byte/word/signed word/dword/signed dword) 9 [phi:main::@2->sum#1] -- vbuxx=vbuc1 
    ldx #9
    jsr sum
  //SEG28 [12] (byte) sum::return#2 ← (byte) sum::return#3 [ main::s1#0 main::s2#0 sum::return#2 ] ( main:2 [ main::s1#0 main::s2#0 sum::return#2 ] )
    // (byte) sum::return#2 = (byte) sum::return#3  // register copy reg byte a
    jmp b3
  //SEG29 main::@3
  b3:
  //SEG30 [13] (byte) main::s3#0 ← (byte) sum::return#2 [ main::s1#0 main::s2#0 main::s3#0 ] ( main:2 [ main::s1#0 main::s2#0 main::s3#0 ] ) -- vbuz1=vbuaa 
    sta s3
  //SEG31 [14] (byte/word~) main::$3 ← (byte) main::s1#0 + (byte) main::s2#0 [ main::s3#0 main::$3 ] ( main:2 [ main::s3#0 main::$3 ] ) -- vbuaa=vbuz1_plus_vbuyy 
    tya
    clc
    adc s1
  //SEG32 [15] (byte) main::s4#0 ← (byte/word~) main::$3 + (byte) main::s3#0 [ main::s4#0 ] ( main:2 [ main::s4#0 ] ) -- vbuaa=vbuaa_plus_vbuz1 
    clc
    adc s3
  //SEG33 [16] *((const byte*) screen#0) ← (byte) main::s4#0 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuaa 
    sta screen
    jmp breturn
  //SEG34 main::@return
  breturn:
  //SEG35 [17] return  [ ] ( main:2 [ ] )
    rts
}
//SEG36 sum
sum: {
  //SEG37 [19] (byte) sum::return#3 ← (byte) sum::a#3 + (byte) sum::b#3 [ sum::return#3 ] ( main:2::sum:5 [ sum::return#3 ] main:2::sum:8 [ main::s1#0 sum::return#3 ] main:2::sum:11 [ main::s1#0 main::s2#0 sum::return#3 ] ) -- vbuaa=vbuxx_plus_vbuaa 
    stx $ff
    clc
    adc $ff
    jmp breturn
  //SEG38 sum::@return
  breturn:
  //SEG39 [20] return  [ sum::return#3 ] ( main:2::sum:5 [ sum::return#3 ] main:2::sum:8 [ main::s1#0 sum::return#3 ] main:2::sum:11 [ main::s1#0 main::s2#0 sum::return#3 ] )
    rts
}

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b2
Removing instruction jmp bend
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 bbegin:
Removing instruction b2_from_bbegin:
Removing instruction main_from_b2:
Removing instruction bend_from_b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction b2:
Removing instruction bend:
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
(label) @2
(label) @begin
(label) @end
(void()) main()
(byte/word~) main::$3 reg byte a 4.0
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@return
(byte) main::s1
(byte) main::s1#0 s1 zp ZP_BYTE:2 0.5714285714285714
(byte) main::s2
(byte) main::s2#0 reg byte y 1.0
(byte) main::s3
(byte) main::s3#0 s3 zp ZP_BYTE:3 2.0
(byte) main::s4
(byte) main::s4#0 reg byte a 4.0
(byte*) screen
(const byte*) screen#0 screen = ((byte*))(word/signed word/dword/signed dword) 1024
(byte()) sum((byte) sum::a , (byte) sum::b)
(label) sum::@return
(byte) sum::a
(byte) sum::a#3 reg byte x 2.0
(byte) sum::b
(byte) sum::b#3 reg byte a 2.0
(byte) sum::return
(byte) sum::return#0 reg byte a 4.0
(byte) sum::return#1 reg byte a 4.0
(byte) sum::return#2 reg byte a 4.0
(byte) sum::return#3 reg byte a 1.6

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


FINAL ASSEMBLER
Score: 80

//SEG0 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG1 Global Constants & labels
  .label screen = $400
//SEG2 @begin
//SEG3 [1] phi from @begin to @2 [phi:@begin->@2]
//SEG4 @2
//SEG5 [2] call main param-assignment [ ] ( )
//SEG6 [4] phi from @2 to main [phi:@2->main]
  jsr main
//SEG7 [3] phi from @2 to @end [phi:@2->@end]
//SEG8 @end
//SEG9 main
main: {
    .label s1 = 2
    .label s3 = 3
  //SEG10 [5] call sum param-assignment [ sum::return#3 ] ( main:2 [ sum::return#3 ] )
  //SEG11 [18] phi from main to sum [phi:main->sum]
  //SEG12 [18] phi (byte) sum::b#3 = (byte/signed byte/word/signed word/dword/signed dword) 2 [phi:main->sum#0] -- vbuaa=vbuc1 
    lda #2
  //SEG13 [18] phi (byte) sum::a#3 = (byte/signed byte/word/signed word/dword/signed dword) 1 [phi:main->sum#1] -- vbuxx=vbuc1 
    ldx #1
    jsr sum
  //SEG14 [6] (byte) sum::return#0 ← (byte) sum::return#3 [ sum::return#0 ] ( main:2 [ sum::return#0 ] )
    // (byte) sum::return#0 = (byte) sum::return#3  // register copy reg byte a
  //SEG15 main::@1
  //SEG16 [7] (byte) main::s1#0 ← (byte) sum::return#0 [ main::s1#0 ] ( main:2 [ main::s1#0 ] ) -- vbuz1=vbuaa 
    sta s1
  //SEG17 [8] call sum param-assignment [ sum::return#3 main::s1#0 ] ( main:2 [ sum::return#3 main::s1#0 ] )
  //SEG18 [18] phi from main::@1 to sum [phi:main::@1->sum]
  //SEG19 [18] phi (byte) sum::b#3 = (byte/signed byte/word/signed word/dword/signed dword) 4 [phi:main::@1->sum#0] -- vbuaa=vbuc1 
    lda #4
  //SEG20 [18] phi (byte) sum::a#3 = (byte/signed byte/word/signed word/dword/signed dword) 3 [phi:main::@1->sum#1] -- vbuxx=vbuc1 
    ldx #3
    jsr sum
  //SEG21 [9] (byte) sum::return#1 ← (byte) sum::return#3 [ main::s1#0 sum::return#1 ] ( main:2 [ main::s1#0 sum::return#1 ] )
    // (byte) sum::return#1 = (byte) sum::return#3  // register copy reg byte a
  //SEG22 main::@2
  //SEG23 [10] (byte) main::s2#0 ← (byte) sum::return#1 [ main::s1#0 main::s2#0 ] ( main:2 [ main::s1#0 main::s2#0 ] ) -- vbuyy=vbuaa 
    tay
  //SEG24 [11] call sum param-assignment [ sum::return#3 main::s1#0 main::s2#0 ] ( main:2 [ sum::return#3 main::s1#0 main::s2#0 ] )
  //SEG25 [18] phi from main::@2 to sum [phi:main::@2->sum]
  //SEG26 [18] phi (byte) sum::b#3 = (byte/signed byte/word/signed word/dword/signed dword) 13 [phi:main::@2->sum#0] -- vbuaa=vbuc1 
    lda #$d
  //SEG27 [18] phi (byte) sum::a#3 = (byte/signed byte/word/signed word/dword/signed dword) 9 [phi:main::@2->sum#1] -- vbuxx=vbuc1 
    ldx #9
    jsr sum
  //SEG28 [12] (byte) sum::return#2 ← (byte) sum::return#3 [ main::s1#0 main::s2#0 sum::return#2 ] ( main:2 [ main::s1#0 main::s2#0 sum::return#2 ] )
    // (byte) sum::return#2 = (byte) sum::return#3  // register copy reg byte a
  //SEG29 main::@3
  //SEG30 [13] (byte) main::s3#0 ← (byte) sum::return#2 [ main::s1#0 main::s2#0 main::s3#0 ] ( main:2 [ main::s1#0 main::s2#0 main::s3#0 ] ) -- vbuz1=vbuaa 
    sta s3
  //SEG31 [14] (byte/word~) main::$3 ← (byte) main::s1#0 + (byte) main::s2#0 [ main::s3#0 main::$3 ] ( main:2 [ main::s3#0 main::$3 ] ) -- vbuaa=vbuz1_plus_vbuyy 
    tya
    clc
    adc s1
  //SEG32 [15] (byte) main::s4#0 ← (byte/word~) main::$3 + (byte) main::s3#0 [ main::s4#0 ] ( main:2 [ main::s4#0 ] ) -- vbuaa=vbuaa_plus_vbuz1 
    clc
    adc s3
  //SEG33 [16] *((const byte*) screen#0) ← (byte) main::s4#0 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuaa 
    sta screen
  //SEG34 main::@return
  //SEG35 [17] return  [ ] ( main:2 [ ] )
    rts
}
//SEG36 sum
sum: {
  //SEG37 [19] (byte) sum::return#3 ← (byte) sum::a#3 + (byte) sum::b#3 [ sum::return#3 ] ( main:2::sum:5 [ sum::return#3 ] main:2::sum:8 [ main::s1#0 sum::return#3 ] main:2::sum:11 [ main::s1#0 main::s2#0 sum::return#3 ] ) -- vbuaa=vbuxx_plus_vbuaa 
    stx $ff
    clc
    adc $ff
  //SEG38 sum::@return
  //SEG39 [20] return  [ sum::return#3 ] ( main:2::sum:5 [ sum::return#3 ] main:2::sum:8 [ main::s1#0 sum::return#3 ] main:2::sum:11 [ main::s1#0 main::s2#0 sum::return#3 ] )
    rts
}

