PARSING src/test/java/dk/camelot64/kickc/test/kc/liverange.kc
byte i=0;

void main() {
   byte a=4;
   a=a+inci();
   a=a+inci();
   byte* SCREEN = $400;
   *SCREEN = i;
   *(SCREEN+1) = a;
}

byte inci() {
  i = i+7;
  return i;
}

STATEMENTS
  (byte) i ← (byte/signed byte/word/signed word/dword/signed dword) 0
proc (void()) main()
  (byte) main::a ← (byte/signed byte/word/signed word/dword/signed dword) 4
  (byte~) main::$0 ← call inci 
  (byte/word~) main::$1 ← (byte) main::a + (byte~) main::$0
  (byte) main::a ← (byte/word~) main::$1
  (byte~) main::$2 ← call inci 
  (byte/word~) main::$3 ← (byte) main::a + (byte~) main::$2
  (byte) main::a ← (byte/word~) main::$3
  (byte*) main::SCREEN ← (word/signed word/dword/signed dword) 1024
  *((byte*) main::SCREEN) ← (byte) i
  (byte*~) main::$4 ← (byte*) main::SCREEN + (byte/signed byte/word/signed word/dword/signed dword) 1
  *((byte*~) main::$4) ← (byte) main::a
main::@return:
  return 
endproc // main()
proc (byte()) inci()
  (byte/word~) inci::$0 ← (byte) i + (byte/signed byte/word/signed word/dword/signed dword) 7
  (byte) i ← (byte/word~) inci::$0
  (byte) inci::return ← (byte) i
  goto inci::@return
inci::@return:
  (byte) inci::return ← (byte) inci::return
  return (byte) inci::return
endproc // inci()
  call main 

SYMBOLS
(byte) i
(byte()) inci()
(byte/word~) inci::$0
(label) inci::@return
(byte) inci::return
(void()) main()
(byte~) main::$0
(byte/word~) main::$1
(byte~) main::$2
(byte/word~) main::$3
(byte*~) main::$4
(label) main::@return
(byte*) main::SCREEN
(byte) main::a

Promoting word/signed word/dword/signed dword to byte* in main::SCREEN ← ((byte*)) 1024
INITIAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  (byte) i ← (byte/signed byte/word/signed word/dword/signed dword) 0
  to:@1
main: scope:[main]  from
  (byte) main::a ← (byte/signed byte/word/signed word/dword/signed dword) 4
  (byte~) main::$0 ← call inci 
  (byte/word~) main::$1 ← (byte) main::a + (byte~) main::$0
  (byte) main::a ← (byte/word~) main::$1
  (byte~) main::$2 ← call inci 
  (byte/word~) main::$3 ← (byte) main::a + (byte~) main::$2
  (byte) main::a ← (byte/word~) main::$3
  (byte*) main::SCREEN ← ((byte*)) (word/signed word/dword/signed dword) 1024
  *((byte*) main::SCREEN) ← (byte) i
  (byte*~) main::$4 ← (byte*) main::SCREEN + (byte/signed byte/word/signed word/dword/signed dword) 1
  *((byte*~) main::$4) ← (byte) main::a
  to:main::@return
main::@return: scope:[main]  from main
  return 
  to:@return
@1: scope:[]  from @begin
  to:@2
inci: scope:[inci]  from
  (byte/word~) inci::$0 ← (byte) i + (byte/signed byte/word/signed word/dword/signed dword) 7
  (byte) i ← (byte/word~) inci::$0
  (byte) inci::return ← (byte) i
  to:inci::@return
inci::@return: scope:[inci]  from inci inci::@1
  (byte) inci::return ← (byte) inci::return
  return (byte) inci::return
  to:@return
inci::@1: scope:[inci]  from
  to:inci::@return
@2: scope:[]  from @1
  call main 
  to:@end
@end: scope:[]  from @2

Removing empty block @1
Removing empty block inci::@1
PROCEDURE MODIFY VARIABLE ANALYSIS
main modifies i
inci modifies i

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

CONTROL FLOW GRAPH SSA WITH ASSIGNMENT CALL & RETURN
@begin: scope:[]  from
  (byte) i#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0
  to:@2
main: scope:[main]  from @2
  (byte) i#13 ← phi( @2/(byte) i#14 )
  (byte) main::a#0 ← (byte/signed byte/word/signed word/dword/signed dword) 4
  call inci param-assignment
  (byte) inci::return#0 ← (byte) inci::return#3
  to:main::@1
main::@1: scope:[main]  from main
  (byte) main::a#3 ← phi( main/(byte) main::a#0 )
  (byte) i#7 ← phi( main/(byte) i#5 )
  (byte) inci::return#4 ← phi( main/(byte) inci::return#0 )
  (byte~) main::$0 ← (byte) inci::return#4
  (byte) i#1 ← (byte) i#7
  (byte/word~) main::$1 ← (byte) main::a#3 + (byte~) main::$0
  (byte) main::a#1 ← (byte/word~) main::$1
  call inci param-assignment
  (byte) inci::return#1 ← (byte) inci::return#3
  to:main::@2
main::@2: scope:[main]  from main::@1
  (byte) main::a#4 ← phi( main::@1/(byte) main::a#1 )
  (byte) i#8 ← phi( main::@1/(byte) i#5 )
  (byte) inci::return#5 ← phi( main::@1/(byte) inci::return#1 )
  (byte~) main::$2 ← (byte) inci::return#5
  (byte) i#2 ← (byte) i#8
  (byte/word~) main::$3 ← (byte) main::a#4 + (byte~) main::$2
  (byte) main::a#2 ← (byte/word~) main::$3
  (byte*) main::SCREEN#0 ← ((byte*)) (word/signed word/dword/signed dword) 1024
  *((byte*) main::SCREEN#0) ← (byte) i#2
  (byte*~) main::$4 ← (byte*) main::SCREEN#0 + (byte/signed byte/word/signed word/dword/signed dword) 1
  *((byte*~) main::$4) ← (byte) main::a#2
  to:main::@return
main::@return: scope:[main]  from main::@2
  (byte) i#9 ← phi( main::@2/(byte) i#2 )
  (byte) i#3 ← (byte) i#9
  return 
  to:@return
inci: scope:[inci]  from main main::@1
  (byte) i#10 ← phi( main/(byte) i#13 main::@1/(byte) i#1 )
  (byte/word~) inci::$0 ← (byte) i#10 + (byte/signed byte/word/signed word/dword/signed dword) 7
  (byte) i#4 ← (byte/word~) inci::$0
  (byte) inci::return#2 ← (byte) i#4
  to:inci::@return
inci::@return: scope:[inci]  from inci
  (byte) i#11 ← phi( inci/(byte) i#4 )
  (byte) inci::return#6 ← phi( inci/(byte) inci::return#2 )
  (byte) inci::return#3 ← (byte) inci::return#6
  (byte) i#5 ← (byte) i#11
  return 
  to:@return
@2: scope:[]  from @begin
  (byte) i#14 ← phi( @begin/(byte) i#0 )
  call main param-assignment
  to:@3
@3: scope:[]  from @2
  (byte) i#12 ← phi( @2/(byte) i#3 )
  (byte) i#6 ← (byte) i#12
  to:@end
@end: scope:[]  from @3

SYMBOL TABLE SSA
(label) @2
(label) @3
(label) @begin
(label) @end
(byte) i
(byte) i#0
(byte) i#1
(byte) i#10
(byte) i#11
(byte) i#12
(byte) i#13
(byte) i#14
(byte) i#2
(byte) i#3
(byte) i#4
(byte) i#5
(byte) i#6
(byte) i#7
(byte) i#8
(byte) i#9
(byte()) inci()
(byte/word~) inci::$0
(label) inci::@return
(byte) inci::return
(byte) inci::return#0
(byte) inci::return#1
(byte) inci::return#2
(byte) inci::return#3
(byte) inci::return#4
(byte) inci::return#5
(byte) inci::return#6
(void()) main()
(byte~) main::$0
(byte/word~) main::$1
(byte~) main::$2
(byte/word~) main::$3
(byte*~) main::$4
(label) main::@1
(label) main::@2
(label) main::@return
(byte*) main::SCREEN
(byte*) main::SCREEN#0
(byte) main::a
(byte) main::a#0
(byte) main::a#1
(byte) main::a#2
(byte) main::a#3
(byte) main::a#4

OPTIMIZING CONTROL FLOW GRAPH
Not aliassing across scopes: i#13 i#14
Not aliassing across scopes: inci::return#0 inci::return#3
Not aliassing across scopes: i#7 i#5
Not aliassing across scopes: main::$0 inci::return#4
Not aliassing across scopes: inci::return#1 inci::return#3
Not aliassing across scopes: i#8 i#5
Not aliassing across scopes: main::$2 inci::return#5
Not aliassing across scopes: i#10 i#13
Not aliassing across scopes: inci::return#2 i#4
Not aliassing across scopes: i#12 i#3
Alias (byte) inci::return#0 = (byte) inci::return#4 
Alias (byte) main::a#0 = (byte) main::a#3 
Alias (byte) i#1 = (byte) i#7 
Alias (byte) main::a#1 = (byte/word~) main::$1 (byte) main::a#4 
Alias (byte) inci::return#1 = (byte) inci::return#5 
Alias (byte) i#2 = (byte) i#8 (byte) i#9 (byte) i#3 
Alias (byte) main::a#2 = (byte/word~) main::$3 
Alias (byte) i#11 = (byte) i#4 (byte/word~) inci::$0 (byte) i#5 
Alias (byte) inci::return#2 = (byte) inci::return#6 (byte) inci::return#3 
Alias (byte) i#0 = (byte) i#14 
Alias (byte) i#12 = (byte) i#6 
Succesful SSA optimization Pass2AliasElimination
Not aliassing across scopes: i#13 i#0
Not aliassing across scopes: inci::return#0 inci::return#2
Not aliassing across scopes: i#1 i#11
Not aliassing across scopes: main::$0 inci::return#0
Not aliassing across scopes: inci::return#1 inci::return#2
Not aliassing across scopes: i#2 i#11
Not aliassing across scopes: main::$2 inci::return#1
Not aliassing across scopes: i#10 i#13
Not aliassing across scopes: inci::return#2 i#11
Not aliassing across scopes: i#12 i#2
Redundant Phi (byte) i#13 (byte) i#0
Redundant Phi (byte) i#1 (byte) i#11
Redundant Phi (byte) i#2 (byte) i#11
Redundant Phi (byte) i#12 (byte) i#2
Succesful SSA optimization Pass2RedundantPhiElimination
Constant (const byte) i#0 = 0
Constant (const byte) main::a#0 = 4
Constant (const byte*) main::SCREEN#0 = ((byte*))1024
Succesful SSA optimization Pass2ConstantIdentification
Constant (const byte*) main::$4 = main::SCREEN#0+1
Succesful SSA optimization Pass2ConstantIdentification
Culled Empty Block (label) @3
Succesful SSA optimization Pass2CullEmptyBlocks
Not aliassing across scopes: inci::return#0 inci::return#2
Not aliassing across scopes: main::$0 inci::return#0
Not aliassing across scopes: inci::return#1 inci::return#2
Not aliassing across scopes: main::$2 inci::return#1
Not aliassing across scopes: inci::return#2 i#11
Not aliassing across scopes: inci::return#0 inci::return#2
Not aliassing across scopes: main::$0 inci::return#0
Not aliassing across scopes: inci::return#1 inci::return#2
Not aliassing across scopes: main::$2 inci::return#1
Not aliassing across scopes: inci::return#2 i#11
OPTIMIZING CONTROL FLOW GRAPH
Inlining constant with var siblings (const byte) main::a#0
Inlining constant with var siblings (const byte) main::a#0
Inlining constant with var siblings (const byte) i#0
Inlining constant with var siblings (const byte) i#0
Constant inlined main::a#0 = (byte/signed byte/word/signed word/dword/signed dword) 4
Constant inlined main::$4 = (const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 1
Constant inlined i#0 = (byte/signed byte/word/signed word/dword/signed dword) 0
Succesful SSA optimization Pass2ConstantInlining
Block Sequence Planned @begin @2 @end main main::@1 main::@2 main::@return inci inci::@return 
Block Sequence Planned @begin @2 @end main main::@1 main::@2 main::@return inci inci::@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 inci:5 inci:10 

Propagating live ranges...
Propagating live ranges...
Propagating live ranges...
Propagating live ranges...
Propagating live ranges...
Propagating live ranges...
Created 1 initial phi equivalence classes
Coalesced [9] i#15 ← i#11
Coalesced down to 1 phi equivalence classes
Block Sequence Planned @begin @2 @end main main::@1 main::@2 main::@return inci inci::@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...

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 inci param-assignment [ inci::return#2 i#11 ] ( main:2 [ inci::return#2 i#11 ] )
  [6] (byte) inci::return#0 ← (byte) inci::return#2 [ inci::return#0 i#11 ] ( main:2 [ inci::return#0 i#11 ] )
  to:main::@1
main::@1: scope:[main]  from main
  [7] (byte~) main::$0 ← (byte) inci::return#0 [ main::$0 i#11 ] ( main:2 [ main::$0 i#11 ] )
  [8] (byte) main::a#1 ← (byte/signed byte/word/signed word/dword/signed dword) 4 + (byte~) main::$0 [ main::a#1 i#11 ] ( main:2 [ main::a#1 i#11 ] )
  [9] call inci param-assignment [ inci::return#2 main::a#1 i#11 ] ( main:2 [ inci::return#2 main::a#1 i#11 ] )
  [10] (byte) inci::return#1 ← (byte) inci::return#2 [ main::a#1 inci::return#1 i#11 ] ( main:2 [ main::a#1 inci::return#1 i#11 ] )
  to:main::@2
main::@2: scope:[main]  from main::@1
  [11] (byte~) main::$2 ← (byte) inci::return#1 [ main::a#1 main::$2 i#11 ] ( main:2 [ main::a#1 main::$2 i#11 ] )
  [12] (byte) main::a#2 ← (byte) main::a#1 + (byte~) main::$2 [ main::a#2 i#11 ] ( main:2 [ main::a#2 i#11 ] )
  [13] *((const byte*) main::SCREEN#0) ← (byte) i#11 [ main::a#2 ] ( main:2 [ main::a#2 ] )
  [14] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (byte) main::a#2 [ ] ( main:2 [ ] )
  to:main::@return
main::@return: scope:[main]  from main::@2
  [15] return  [ ] ( main:2 [ ] )
  to:@return
inci: scope:[inci]  from main main::@1
  [16] (byte) i#10 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@1/(byte) i#11 ) [ i#10 ] ( main:2::inci:5 [ i#10 ] main:2::inci:9 [ main::a#1 i#10 ] )
  [17] (byte) i#11 ← (byte) i#10 + (byte/signed byte/word/signed word/dword/signed dword) 7 [ i#11 ] ( main:2::inci:5 [ i#11 ] main:2::inci:9 [ main::a#1 i#11 ] )
  [18] (byte) inci::return#2 ← (byte) i#11 [ inci::return#2 i#11 ] ( main:2::inci:5 [ inci::return#2 i#11 ] main:2::inci:9 [ main::a#1 inci::return#2 i#11 ] )
  to:inci::@return
inci::@return: scope:[inci]  from inci
  [19] return  [ inci::return#2 i#11 ] ( main:2::inci:5 [ inci::return#2 i#11 ] main:2::inci:9 [ main::a#1 inci::return#2 i#11 ] )
  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::@return dominated by  main::@return @2 @begin main::@1 main::@2 main 
inci dominated by  @2 @begin main inci 
inci::@return dominated by  inci::@return @2 @begin main inci 

NATURAL LOOPS

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


VARIABLE REGISTER WEIGHTS
(byte) i
(byte) i#10 4.0
(byte) i#11 0.7272727272727273
(byte()) inci()
(byte) inci::return
(byte) inci::return#0 4.0
(byte) inci::return#1 4.0
(byte) inci::return#2 1.5
(void()) main()
(byte~) main::$0 4.0
(byte~) main::$2 4.0
(byte*) main::SCREEN
(byte) main::a
(byte) main::a#1 1.0
(byte) main::a#2 2.0

Initial phi equivalence classes
[ i#10 i#11 ]
Added variable inci::return#0 to zero page equivalence class [ inci::return#0 ]
Added variable main::$0 to zero page equivalence class [ main::$0 ]
Added variable main::a#1 to zero page equivalence class [ main::a#1 ]
Added variable inci::return#1 to zero page equivalence class [ inci::return#1 ]
Added variable main::$2 to zero page equivalence class [ main::$2 ]
Added variable main::a#2 to zero page equivalence class [ main::a#2 ]
Added variable inci::return#2 to zero page equivalence class [ inci::return#2 ]
Complete equivalence classes
[ i#10 i#11 ]
[ inci::return#0 ]
[ main::$0 ]
[ main::a#1 ]
[ inci::return#1 ]
[ main::$2 ]
[ main::a#2 ]
[ inci::return#2 ]
Allocated zp ZP_BYTE:2 [ i#10 i#11 ]
Allocated zp ZP_BYTE:3 [ inci::return#0 ]
Allocated zp ZP_BYTE:4 [ main::$0 ]
Allocated zp ZP_BYTE:5 [ main::a#1 ]
Allocated zp ZP_BYTE:6 [ inci::return#1 ]
Allocated zp ZP_BYTE:7 [ main::$2 ]
Allocated zp ZP_BYTE:8 [ main::a#2 ]
Allocated zp ZP_BYTE:9 [ inci::return#2 ]

INITIAL ASM
//SEG0 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG1 Global Constants & labels
  .label i = 2
//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 SCREEN = $400
    .label _0 = 4
    .label _2 = 7
    .label a = 5
    .label a_2 = 8
  //SEG10 [5] call inci param-assignment [ inci::return#2 i#11 ] ( main:2 [ inci::return#2 i#11 ] )
  //SEG11 [16] phi from main to inci [phi:main->inci]
  inci_from_main:
  //SEG12 [16] phi (byte) i#10 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->inci#0] -- vbuz1=vbuc1 
    lda #0
    sta i
    jsr inci
  //SEG13 [6] (byte) inci::return#0 ← (byte) inci::return#2 [ inci::return#0 i#11 ] ( main:2 [ inci::return#0 i#11 ] ) -- vbuz1=vbuz2 
    lda inci.return_2
    sta inci.return
    jmp b1
  //SEG14 main::@1
  b1:
  //SEG15 [7] (byte~) main::$0 ← (byte) inci::return#0 [ main::$0 i#11 ] ( main:2 [ main::$0 i#11 ] ) -- vbuz1=vbuz2 
    lda inci.return
    sta _0
  //SEG16 [8] (byte) main::a#1 ← (byte/signed byte/word/signed word/dword/signed dword) 4 + (byte~) main::$0 [ main::a#1 i#11 ] ( main:2 [ main::a#1 i#11 ] ) -- vbuz1=vbuc1_plus_vbuz2 
    lda #4
    clc
    adc _0
    sta a
  //SEG17 [9] call inci param-assignment [ inci::return#2 main::a#1 i#11 ] ( main:2 [ inci::return#2 main::a#1 i#11 ] )
  //SEG18 [16] phi from main::@1 to inci [phi:main::@1->inci]
  inci_from_b1:
  //SEG19 [16] phi (byte) i#10 = (byte) i#11 [phi:main::@1->inci#0] -- register_copy 
    jsr inci
  //SEG20 [10] (byte) inci::return#1 ← (byte) inci::return#2 [ main::a#1 inci::return#1 i#11 ] ( main:2 [ main::a#1 inci::return#1 i#11 ] ) -- vbuz1=vbuz2 
    lda inci.return_2
    sta inci.return_1
    jmp b2
  //SEG21 main::@2
  b2:
  //SEG22 [11] (byte~) main::$2 ← (byte) inci::return#1 [ main::a#1 main::$2 i#11 ] ( main:2 [ main::a#1 main::$2 i#11 ] ) -- vbuz1=vbuz2 
    lda inci.return_1
    sta _2
  //SEG23 [12] (byte) main::a#2 ← (byte) main::a#1 + (byte~) main::$2 [ main::a#2 i#11 ] ( main:2 [ main::a#2 i#11 ] ) -- vbuz1=vbuz2_plus_vbuz3 
    lda a
    clc
    adc _2
    sta a_2
  //SEG24 [13] *((const byte*) main::SCREEN#0) ← (byte) i#11 [ main::a#2 ] ( main:2 [ main::a#2 ] ) -- _deref_pbuc1=vbuz1 
    lda i
    sta SCREEN
  //SEG25 [14] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (byte) main::a#2 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuz1 
    lda a_2
    sta SCREEN+1
    jmp breturn
  //SEG26 main::@return
  breturn:
  //SEG27 [15] return  [ ] ( main:2 [ ] )
    rts
}
//SEG28 inci
inci: {
    .label return = 3
    .label return_1 = 6
    .label return_2 = 9
  //SEG29 [17] (byte) i#11 ← (byte) i#10 + (byte/signed byte/word/signed word/dword/signed dword) 7 [ i#11 ] ( main:2::inci:5 [ i#11 ] main:2::inci:9 [ main::a#1 i#11 ] ) -- vbuz1=vbuz1_plus_vbuc1 
    lda #7
    clc
    adc i
    sta i
  //SEG30 [18] (byte) inci::return#2 ← (byte) i#11 [ inci::return#2 i#11 ] ( main:2::inci:5 [ inci::return#2 i#11 ] main:2::inci:9 [ main::a#1 inci::return#2 i#11 ] ) -- vbuz1=vbuz2 
    lda i
    sta return_2
    jmp breturn
  //SEG31 inci::@return
  breturn:
  //SEG32 [19] return  [ inci::return#2 i#11 ] ( main:2::inci:5 [ inci::return#2 i#11 ] main:2::inci:9 [ main::a#1 inci::return#2 i#11 ] )
    rts
}

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [8] (byte) main::a#1 ← (byte/signed byte/word/signed word/dword/signed dword) 4 + (byte~) main::$0 [ main::a#1 i#11 ] ( main:2 [ main::a#1 i#11 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:2 [ i#10 i#11 ]
Statement [17] (byte) i#11 ← (byte) i#10 + (byte/signed byte/word/signed word/dword/signed dword) 7 [ i#11 ] ( main:2::inci:5 [ i#11 ] main:2::inci:9 [ main::a#1 i#11 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:5 [ main::a#1 ]
Statement [8] (byte) main::a#1 ← (byte/signed byte/word/signed word/dword/signed dword) 4 + (byte~) main::$0 [ main::a#1 i#11 ] ( main:2 [ main::a#1 i#11 ] ) always clobbers reg byte a 
Statement [12] (byte) main::a#2 ← (byte) main::a#1 + (byte~) main::$2 [ main::a#2 i#11 ] ( main:2 [ main::a#2 i#11 ] ) always clobbers reg byte a 
Statement [17] (byte) i#11 ← (byte) i#10 + (byte/signed byte/word/signed word/dword/signed dword) 7 [ i#11 ] ( main:2::inci:5 [ i#11 ] main:2::inci:9 [ main::a#1 i#11 ] ) always clobbers reg byte a 
Potential registers zp ZP_BYTE:2 [ i#10 i#11 ] : zp ZP_BYTE:2 , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:3 [ inci::return#0 ] : zp ZP_BYTE:3 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:4 [ main::$0 ] : zp ZP_BYTE:4 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:5 [ main::a#1 ] : zp ZP_BYTE:5 , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:6 [ inci::return#1 ] : 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 [ main::a#2 ] : zp ZP_BYTE:8 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:9 [ inci::return#2 ] : zp ZP_BYTE:9 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 4: zp ZP_BYTE:4 [ main::$0 ] 4: zp ZP_BYTE:7 [ main::$2 ] 2: zp ZP_BYTE:8 [ main::a#2 ] 1: zp ZP_BYTE:5 [ main::a#1 ] 
Uplift Scope [inci] 4: zp ZP_BYTE:3 [ inci::return#0 ] 4: zp ZP_BYTE:6 [ inci::return#1 ] 1.5: zp ZP_BYTE:9 [ inci::return#2 ] 
Uplift Scope [] 4.73: zp ZP_BYTE:2 [ i#10 i#11 ] 

Uplifting [main] best 112 combination reg byte a [ main::$0 ] reg byte a [ main::$2 ] reg byte x [ main::a#2 ] zp ZP_BYTE:5 [ main::a#1 ] 
Uplifting [inci] best 91 combination reg byte a [ inci::return#0 ] reg byte a [ inci::return#1 ] reg byte a [ inci::return#2 ] 
Uplifting [] best 82 combination reg byte y [ i#10 i#11 ] 
Attempting to uplift remaining variables inzp ZP_BYTE:5 [ main::a#1 ]
Uplifting [main] best 82 combination zp ZP_BYTE:5 [ main::a#1 ] 
Allocated (was zp ZP_BYTE:5) zp ZP_BYTE:2 [ main::a#1 ]

ASSEMBLER BEFORE OPTIMIZATION
//SEG0 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG1 Global Constants & labels
//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 SCREEN = $400
    .label a = 2
  //SEG10 [5] call inci param-assignment [ inci::return#2 i#11 ] ( main:2 [ inci::return#2 i#11 ] )
  //SEG11 [16] phi from main to inci [phi:main->inci]
  inci_from_main:
  //SEG12 [16] phi (byte) i#10 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->inci#0] -- vbuyy=vbuc1 
    ldy #0
    jsr inci
  //SEG13 [6] (byte) inci::return#0 ← (byte) inci::return#2 [ inci::return#0 i#11 ] ( main:2 [ inci::return#0 i#11 ] )
    // (byte) inci::return#0 = (byte) inci::return#2  // register copy reg byte a
    jmp b1
  //SEG14 main::@1
  b1:
  //SEG15 [7] (byte~) main::$0 ← (byte) inci::return#0 [ main::$0 i#11 ] ( main:2 [ main::$0 i#11 ] )
    // (byte~) main::$0 = (byte) inci::return#0  // register copy reg byte a
  //SEG16 [8] (byte) main::a#1 ← (byte/signed byte/word/signed word/dword/signed dword) 4 + (byte~) main::$0 [ main::a#1 i#11 ] ( main:2 [ main::a#1 i#11 ] ) -- vbuz1=vbuc1_plus_vbuaa 
    clc
    adc #4
    sta a
  //SEG17 [9] call inci param-assignment [ inci::return#2 main::a#1 i#11 ] ( main:2 [ inci::return#2 main::a#1 i#11 ] )
  //SEG18 [16] phi from main::@1 to inci [phi:main::@1->inci]
  inci_from_b1:
  //SEG19 [16] phi (byte) i#10 = (byte) i#11 [phi:main::@1->inci#0] -- register_copy 
    jsr inci
  //SEG20 [10] (byte) inci::return#1 ← (byte) inci::return#2 [ main::a#1 inci::return#1 i#11 ] ( main:2 [ main::a#1 inci::return#1 i#11 ] )
    // (byte) inci::return#1 = (byte) inci::return#2  // register copy reg byte a
    jmp b2
  //SEG21 main::@2
  b2:
  //SEG22 [11] (byte~) main::$2 ← (byte) inci::return#1 [ main::a#1 main::$2 i#11 ] ( main:2 [ main::a#1 main::$2 i#11 ] )
    // (byte~) main::$2 = (byte) inci::return#1  // register copy reg byte a
  //SEG23 [12] (byte) main::a#2 ← (byte) main::a#1 + (byte~) main::$2 [ main::a#2 i#11 ] ( main:2 [ main::a#2 i#11 ] ) -- vbuxx=vbuz1_plus_vbuaa 
    clc
    adc a
    tax
  //SEG24 [13] *((const byte*) main::SCREEN#0) ← (byte) i#11 [ main::a#2 ] ( main:2 [ main::a#2 ] ) -- _deref_pbuc1=vbuyy 
    sty SCREEN
  //SEG25 [14] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (byte) main::a#2 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuxx 
    stx SCREEN+1
    jmp breturn
  //SEG26 main::@return
  breturn:
  //SEG27 [15] return  [ ] ( main:2 [ ] )
    rts
}
//SEG28 inci
inci: {
  //SEG29 [17] (byte) i#11 ← (byte) i#10 + (byte/signed byte/word/signed word/dword/signed dword) 7 [ i#11 ] ( main:2::inci:5 [ i#11 ] main:2::inci:9 [ main::a#1 i#11 ] ) -- vbuyy=vbuyy_plus_vbuc1 
    tya
    clc
    adc #7
    tay
  //SEG30 [18] (byte) inci::return#2 ← (byte) i#11 [ inci::return#2 i#11 ] ( main:2::inci:5 [ inci::return#2 i#11 ] main:2::inci:9 [ main::a#1 inci::return#2 i#11 ] ) -- vbuaa=vbuyy 
    tya
    jmp breturn
  //SEG31 inci::@return
  breturn:
  //SEG32 [19] return  [ inci::return#2 i#11 ] ( main:2::inci:5 [ inci::return#2 i#11 ] main:2::inci:9 [ main::a#1 inci::return#2 i#11 ] )
    rts
}

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b2
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp b2
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 inci_from_main:
Removing instruction b1:
Removing instruction inci_from_b1:
Removing instruction b2:
Removing instruction breturn:
Removing instruction breturn:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @2
(label) @begin
(label) @end
(byte) i
(byte) i#10 reg byte y 4.0
(byte) i#11 reg byte y 0.7272727272727273
(byte()) inci()
(label) inci::@return
(byte) inci::return
(byte) inci::return#0 reg byte a 4.0
(byte) inci::return#1 reg byte a 4.0
(byte) inci::return#2 reg byte a 1.5
(void()) main()
(byte~) main::$0 reg byte a 4.0
(byte~) main::$2 reg byte a 4.0
(label) main::@1
(label) main::@2
(label) main::@return
(byte*) main::SCREEN
(const byte*) main::SCREEN#0 SCREEN = ((byte*))(word/signed word/dword/signed dword) 1024
(byte) main::a
(byte) main::a#1 a zp ZP_BYTE:2 1.0
(byte) main::a#2 reg byte x 2.0

reg byte y [ i#10 i#11 ]
reg byte a [ inci::return#0 ]
reg byte a [ main::$0 ]
zp ZP_BYTE:2 [ main::a#1 ]
reg byte a [ inci::return#1 ]
reg byte a [ main::$2 ]
reg byte x [ main::a#2 ]
reg byte a [ inci::return#2 ]


FINAL ASSEMBLER
Score: 64

//SEG0 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG1 Global Constants & labels
//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 SCREEN = $400
    .label a = 2
  //SEG10 [5] call inci param-assignment [ inci::return#2 i#11 ] ( main:2 [ inci::return#2 i#11 ] )
  //SEG11 [16] phi from main to inci [phi:main->inci]
  //SEG12 [16] phi (byte) i#10 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->inci#0] -- vbuyy=vbuc1 
    ldy #0
    jsr inci
  //SEG13 [6] (byte) inci::return#0 ← (byte) inci::return#2 [ inci::return#0 i#11 ] ( main:2 [ inci::return#0 i#11 ] )
    // (byte) inci::return#0 = (byte) inci::return#2  // register copy reg byte a
  //SEG14 main::@1
  //SEG15 [7] (byte~) main::$0 ← (byte) inci::return#0 [ main::$0 i#11 ] ( main:2 [ main::$0 i#11 ] )
    // (byte~) main::$0 = (byte) inci::return#0  // register copy reg byte a
  //SEG16 [8] (byte) main::a#1 ← (byte/signed byte/word/signed word/dword/signed dword) 4 + (byte~) main::$0 [ main::a#1 i#11 ] ( main:2 [ main::a#1 i#11 ] ) -- vbuz1=vbuc1_plus_vbuaa 
    clc
    adc #4
    sta a
  //SEG17 [9] call inci param-assignment [ inci::return#2 main::a#1 i#11 ] ( main:2 [ inci::return#2 main::a#1 i#11 ] )
  //SEG18 [16] phi from main::@1 to inci [phi:main::@1->inci]
  //SEG19 [16] phi (byte) i#10 = (byte) i#11 [phi:main::@1->inci#0] -- register_copy 
    jsr inci
  //SEG20 [10] (byte) inci::return#1 ← (byte) inci::return#2 [ main::a#1 inci::return#1 i#11 ] ( main:2 [ main::a#1 inci::return#1 i#11 ] )
    // (byte) inci::return#1 = (byte) inci::return#2  // register copy reg byte a
  //SEG21 main::@2
  //SEG22 [11] (byte~) main::$2 ← (byte) inci::return#1 [ main::a#1 main::$2 i#11 ] ( main:2 [ main::a#1 main::$2 i#11 ] )
    // (byte~) main::$2 = (byte) inci::return#1  // register copy reg byte a
  //SEG23 [12] (byte) main::a#2 ← (byte) main::a#1 + (byte~) main::$2 [ main::a#2 i#11 ] ( main:2 [ main::a#2 i#11 ] ) -- vbuxx=vbuz1_plus_vbuaa 
    clc
    adc a
    tax
  //SEG24 [13] *((const byte*) main::SCREEN#0) ← (byte) i#11 [ main::a#2 ] ( main:2 [ main::a#2 ] ) -- _deref_pbuc1=vbuyy 
    sty SCREEN
  //SEG25 [14] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (byte) main::a#2 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuxx 
    stx SCREEN+1
  //SEG26 main::@return
  //SEG27 [15] return  [ ] ( main:2 [ ] )
    rts
}
//SEG28 inci
inci: {
  //SEG29 [17] (byte) i#11 ← (byte) i#10 + (byte/signed byte/word/signed word/dword/signed dword) 7 [ i#11 ] ( main:2::inci:5 [ i#11 ] main:2::inci:9 [ main::a#1 i#11 ] ) -- vbuyy=vbuyy_plus_vbuc1 
    tya
    clc
    adc #7
    tay
  //SEG30 [18] (byte) inci::return#2 ← (byte) i#11 [ inci::return#2 i#11 ] ( main:2::inci:5 [ inci::return#2 i#11 ] main:2::inci:9 [ main::a#1 inci::return#2 i#11 ] ) -- vbuaa=vbuyy 
    tya
  //SEG31 inci::@return
  //SEG32 [19] return  [ inci::return#2 i#11 ] ( main:2::inci:5 [ inci::return#2 i#11 ] main:2::inci:9 [ main::a#1 inci::return#2 i#11 ] )
    rts
}

