Identified constant variable (byte*) SCREEN
Culled Empty Block (label) main::@4
Culled Empty Block (label) @1
Culled Empty Block (label) @2

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  to:@3

(void()) main()
main: scope:[main]  from @3
  (byte) main::i#0 ← (byte) 0
  to:main::@1
main::@1: scope:[main]  from main main::@5
  (byte) main::i#2 ← phi( main/(byte) main::i#0 main::@5/(byte) main::i#1 )
  (byte) line::l#0 ← (byte) main::i#2
  call line 
  to:main::@5
main::@5: scope:[main]  from main::@1
  (byte) main::i#3 ← phi( main::@1/(byte) main::i#2 )
  (byte) main::i#1 ← (byte) main::i#3 + rangenext(0,8)
  (bool~) main::$1 ← (byte) main::i#1 != rangelast(0,8)
  if((bool~) main::$1) goto main::@1
  to:main::@2
main::@2: scope:[main]  from main::@5
  (byte) main::j#0 ← (byte) $a
  to:main::@3
main::@3: scope:[main]  from main::@2 main::@6
  (byte) main::j#2 ← phi( main::@2/(byte) main::j#0 main::@6/(byte) main::j#1 )
  (byte) line::l#1 ← (byte) main::j#2
  call line 
  to:main::@6
main::@6: scope:[main]  from main::@3
  (byte) main::j#3 ← phi( main::@3/(byte) main::j#2 )
  (byte) main::j#1 ← (byte) main::j#3 + rangenext($a,$12)
  (bool~) main::$3 ← (byte) main::j#1 != rangelast($a,$12)
  if((bool~) main::$3) goto main::@3
  to:main::@return
main::@return: scope:[main]  from main::@6
  return 
  to:@return

(void()) line((byte) line::l)
line: scope:[line]  from main::@1 main::@3
  (byte) line::l#2 ← phi( main::@1/(byte) line::l#0 main::@3/(byte) line::l#1 )
  (byte) plot::x#0 ← (byte) line::l#2
  call plot 
  to:line::@1
line::@1: scope:[line]  from line
  (byte) line::l#3 ← phi( line/(byte) line::l#2 )
  (number~) line::$1 ← (byte) line::l#3 + (number) $14
  (byte) plot::x#1 ← (number~) line::$1
  call plot 
  to:line::@2
line::@2: scope:[line]  from line::@1
  to:line::@return
line::@return: scope:[line]  from line::@2
  return 
  to:@return

(void()) plot((byte) plot::x)
plot: scope:[plot]  from line line::@1
  (byte) plot::x#2 ← phi( line/(byte) plot::x#0 line::@1/(byte) plot::x#1 )
  *((const byte*) SCREEN + (byte) plot::x#2) ← (byte) '*'
  to:plot::@return
plot::@return: scope:[plot]  from plot
  return 
  to:@return
@3: scope:[]  from @begin
  call main 
  to:@4
@4: scope:[]  from @3
  to:@end
@end: scope:[]  from @4

SYMBOL TABLE SSA
(label) @3
(label) @4
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*)(number) $400
(void()) line((byte) line::l)
(number~) line::$1
(label) line::@1
(label) line::@2
(label) line::@return
(byte) line::l
(byte) line::l#0
(byte) line::l#1
(byte) line::l#2
(byte) line::l#3
(void()) main()
(bool~) main::$1
(bool~) main::$3
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@5
(label) main::@6
(label) main::@return
(byte) main::i
(byte) main::i#0
(byte) main::i#1
(byte) main::i#2
(byte) main::i#3
(byte) main::j
(byte) main::j#0
(byte) main::j#1
(byte) main::j#2
(byte) main::j#3
(void()) plot((byte) plot::x)
(label) plot::@return
(byte) plot::x
(byte) plot::x#0
(byte) plot::x#1
(byte) plot::x#2

Adding number conversion cast (unumber) $14 in (number~) line::$1 ← (byte) line::l#3 + (number) $14
Adding number conversion cast (unumber) line::$1 in (number~) line::$1 ← (byte) line::l#3 + (unumber)(number) $14
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast $14
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $14
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to byte in (unumber~) line::$1 ← (byte) line::l#3 + (byte) $14
Alias (byte) main::i#2 = (byte) main::i#3 
Alias (byte) main::j#2 = (byte) main::j#3 
Alias (byte) line::l#2 = (byte) line::l#3 
Alias (byte) plot::x#1 = (byte~) line::$1 
Successful SSA optimization Pass2AliasElimination
Simple Condition (bool~) main::$1 [7] if((byte) main::i#1!=rangelast(0,8)) goto main::@1
Simple Condition (bool~) main::$3 [15] if((byte) main::j#1!=rangelast($a,$12)) goto main::@3
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte) main::i#0 = 0
Constant (const byte) main::j#0 = $a
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [5] main::i#1 ← ++ main::i#2 to ++
Resolved ranged comparison value [7] if(main::i#1!=rangelast(0,8)) goto main::@1 to (number) 9
Resolved ranged next value [13] main::j#1 ← ++ main::j#2 to ++
Resolved ranged comparison value [15] if(main::j#1!=rangelast($a,$12)) goto main::@3 to (number) $13
Adding number conversion cast (unumber) 9 in if((byte) main::i#1!=(number) 9) goto main::@1
Adding number conversion cast (unumber) $13 in if((byte) main::j#1!=(number) $13) goto main::@3
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast 9
Simplifying constant integer cast $13
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 9
Finalized unsigned number type (byte) $13
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining constant with var siblings (const byte) main::i#0
Inlining constant with var siblings (const byte) main::j#0
Constant inlined main::i#0 = (byte) 0
Constant inlined main::j#0 = (byte) $a
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@7(between main::@5 and main::@1)
Added new block during phi lifting main::@8(between main::@6 and main::@3)
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @3
Adding NOP phi() at start of @4
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@2
Adding NOP phi() at start of line::@2
CALL GRAPH
Calls in [] to main:2 
Calls in [main] to line:9 line:16 
Calls in [line] to plot:25 plot:28 

Created 4 initial phi equivalence classes
Coalesced [8] line::l#4 ← line::l#0
Coalesced [15] line::l#5 ← line::l#1
Coalesced [20] main::j#4 ← main::j#1
Coalesced [21] main::i#4 ← main::i#1
Coalesced [24] plot::x#3 ← plot::x#0
Coalesced [27] plot::x#4 ← plot::x#1
Coalesced down to 4 phi equivalence classes
Culled Empty Block (label) @4
Culled Empty Block (label) main::@2
Culled Empty Block (label) main::@8
Culled Empty Block (label) main::@7
Culled Empty Block (label) line::@2
Renumbering block @3 to @1
Renumbering block main::@3 to main::@2
Renumbering block main::@5 to main::@3
Renumbering block main::@6 to main::@4
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
Adding NOP phi() at start of main

FINAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  [0] phi()
  to:@1
@1: scope:[]  from @begin
  [1] phi()
  [2] call main 
  to:@end
@end: scope:[]  from @1
  [3] phi()

(void()) main()
main: scope:[main]  from @1
  [4] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@3
  [5] (byte) main::i#2 ← phi( main/(byte) 0 main::@3/(byte) main::i#1 )
  [6] (byte) line::l#0 ← (byte) main::i#2
  [7] call line 
  to:main::@3
main::@3: scope:[main]  from main::@1
  [8] (byte) main::i#1 ← ++ (byte) main::i#2
  [9] if((byte) main::i#1!=(byte) 9) goto main::@1
  to:main::@2
main::@2: scope:[main]  from main::@3 main::@4
  [10] (byte) main::j#2 ← phi( main::@3/(byte) $a main::@4/(byte) main::j#1 )
  [11] (byte) line::l#1 ← (byte) main::j#2
  [12] call line 
  to:main::@4
main::@4: scope:[main]  from main::@2
  [13] (byte) main::j#1 ← ++ (byte) main::j#2
  [14] if((byte) main::j#1!=(byte) $13) goto main::@2
  to:main::@return
main::@return: scope:[main]  from main::@4
  [15] return 
  to:@return

(void()) line((byte) line::l)
line: scope:[line]  from main::@1 main::@2
  [16] (byte) line::l#2 ← phi( main::@1/(byte) line::l#0 main::@2/(byte) line::l#1 )
  [17] (byte) plot::x#0 ← (byte) line::l#2
  [18] call plot 
  to:line::@1
line::@1: scope:[line]  from line
  [19] (byte) plot::x#1 ← (byte) line::l#2 + (byte) $14
  [20] call plot 
  to:line::@return
line::@return: scope:[line]  from line::@1
  [21] return 
  to:@return

(void()) plot((byte) plot::x)
plot: scope:[plot]  from line line::@1
  [22] (byte) plot::x#2 ← phi( line/(byte) plot::x#0 line::@1/(byte) plot::x#1 )
  [23] *((const byte*) SCREEN + (byte) plot::x#2) ← (byte) '*'
  to:plot::@return
plot::@return: scope:[plot]  from plot
  [24] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) line((byte) line::l)
(byte) line::l
(byte) line::l#0 22.0
(byte) line::l#1 22.0
(byte) line::l#2 8.666666666666666
(void()) main()
(byte) main::i
(byte) main::i#1 16.5
(byte) main::i#2 11.0
(byte) main::j
(byte) main::j#1 16.5
(byte) main::j#2 11.0
(void()) plot((byte) plot::x)
(byte) plot::x
(byte) plot::x#0 4.0
(byte) plot::x#1 4.0
(byte) plot::x#2 6.0

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
[ main::j#2 main::j#1 ]
[ line::l#2 line::l#0 line::l#1 ]
[ plot::x#2 plot::x#0 plot::x#1 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ main::j#2 main::j#1 ]
[ line::l#2 line::l#0 line::l#1 ]
[ plot::x#2 plot::x#0 plot::x#1 ]
Allocated zp[1]:2 [ main::i#2 main::i#1 ]
Allocated zp[1]:3 [ main::j#2 main::j#1 ]
Allocated zp[1]:4 [ line::l#2 line::l#0 line::l#1 ]
Allocated zp[1]:5 [ plot::x#2 plot::x#0 plot::x#1 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Two levels of functions to test that register allocation handles live ranges and call-ranges optimally to allocate the fewest possible ZP-variables
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  // @begin
__bbegin:
  // [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
  jmp __b1
  // @1
__b1:
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
main_from___b1:
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
  jmp __bend
  // @end
__bend:
  // main
main: {
    .label i = 2
    .label j = 3
    // [5] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z i
    jmp __b1
    // [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
  __b1_from___b3:
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@3->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [6] (byte) line::l#0 ← (byte) main::i#2 -- vbuz1=vbuz2 
    lda.z i
    sta.z line.l
    // [7] call line 
    // [16] phi from main::@1 to line [phi:main::@1->line]
  line_from___b1:
    // [16] phi (byte) line::l#2 = (byte) line::l#0 [phi:main::@1->line#0] -- register_copy 
    jsr line
    jmp __b3
    // main::@3
  __b3:
    // [8] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [9] if((byte) main::i#1!=(byte) 9) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #9
    cmp.z i
    bne __b1_from___b3
    // [10] phi from main::@3 to main::@2 [phi:main::@3->main::@2]
  __b2_from___b3:
    // [10] phi (byte) main::j#2 = (byte) $a [phi:main::@3->main::@2#0] -- vbuz1=vbuc1 
    lda #$a
    sta.z j
    jmp __b2
    // [10] phi from main::@4 to main::@2 [phi:main::@4->main::@2]
  __b2_from___b4:
    // [10] phi (byte) main::j#2 = (byte) main::j#1 [phi:main::@4->main::@2#0] -- register_copy 
    jmp __b2
    // main::@2
  __b2:
    // [11] (byte) line::l#1 ← (byte) main::j#2 -- vbuz1=vbuz2 
    lda.z j
    sta.z line.l
    // [12] call line 
    // [16] phi from main::@2 to line [phi:main::@2->line]
  line_from___b2:
    // [16] phi (byte) line::l#2 = (byte) line::l#1 [phi:main::@2->line#0] -- register_copy 
    jsr line
    jmp __b4
    // main::@4
  __b4:
    // [13] (byte) main::j#1 ← ++ (byte) main::j#2 -- vbuz1=_inc_vbuz1 
    inc.z j
    // [14] if((byte) main::j#1!=(byte) $13) goto main::@2 -- vbuz1_neq_vbuc1_then_la1 
    lda #$13
    cmp.z j
    bne __b2_from___b4
    jmp __breturn
    // main::@return
  __breturn:
    // [15] return 
    rts
}
  // line
// line(byte zp(4) l)
line: {
    .label l = 4
    // [17] (byte) plot::x#0 ← (byte) line::l#2 -- vbuz1=vbuz2 
    lda.z l
    sta.z plot.x
    // [18] call plot 
    // [22] phi from line to plot [phi:line->plot]
  plot_from_line:
    // [22] phi (byte) plot::x#2 = (byte) plot::x#0 [phi:line->plot#0] -- register_copy 
    jsr plot
    jmp __b1
    // line::@1
  __b1:
    // [19] (byte) plot::x#1 ← (byte) line::l#2 + (byte) $14 -- vbuz1=vbuz2_plus_vbuc1 
    lax.z l
    axs #-[$14]
    stx.z plot.x
    // [20] call plot 
    // [22] phi from line::@1 to plot [phi:line::@1->plot]
  plot_from___b1:
    // [22] phi (byte) plot::x#2 = (byte) plot::x#1 [phi:line::@1->plot#0] -- register_copy 
    jsr plot
    jmp __breturn
    // line::@return
  __breturn:
    // [21] return 
    rts
}
  // plot
// plot(byte zp(5) x)
plot: {
    .label x = 5
    // [23] *((const byte*) SCREEN + (byte) plot::x#2) ← (byte) '*' -- pbuc1_derefidx_vbuz1=vbuc2 
    lda #'*'
    ldy.z x
    sta SCREEN,y
    jmp __breturn
    // plot::@return
  __breturn:
    // [24] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [23] *((const byte*) SCREEN + (byte) plot::x#2) ← (byte) '*' [ ] ( main:2::line:7::plot:18 [ main::i#2 line::l#2 ] main:2::line:12::plot:18 [ main::j#2 line::l#2 ] main:2::line:7::plot:20 [ main::i#2 ] main:2::line:12::plot:20 [ main::j#2 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::i#2 main::i#1 ]
Removing always clobbered register reg byte a as potential for zp[1]:4 [ line::l#2 line::l#0 line::l#1 ]
Removing always clobbered register reg byte a as potential for zp[1]:3 [ main::j#2 main::j#1 ]
Statement [19] (byte) plot::x#1 ← (byte) line::l#2 + (byte) $14 [ plot::x#1 ] ( main:2::line:7 [ main::i#2 plot::x#1 ] main:2::line:12 [ main::j#2 plot::x#1 ] ) always clobbers reg byte a 
Statement [23] *((const byte*) SCREEN + (byte) plot::x#2) ← (byte) '*' [ ] ( main:2::line:7::plot:18 [ main::i#2 line::l#2 ] main:2::line:12::plot:18 [ main::j#2 line::l#2 ] main:2::line:7::plot:20 [ main::i#2 ] main:2::line:12::plot:20 [ main::j#2 ] ) always clobbers reg byte a 
Potential registers zp[1]:2 [ main::i#2 main::i#1 ] : zp[1]:2 , reg byte x , reg byte y , 
Potential registers zp[1]:3 [ main::j#2 main::j#1 ] : zp[1]:3 , reg byte x , reg byte y , 
Potential registers zp[1]:4 [ line::l#2 line::l#0 line::l#1 ] : zp[1]:4 , reg byte x , reg byte y , 
Potential registers zp[1]:5 [ plot::x#2 plot::x#0 plot::x#1 ] : zp[1]:5 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 27.5: zp[1]:2 [ main::i#2 main::i#1 ] 27.5: zp[1]:3 [ main::j#2 main::j#1 ] 
Uplift Scope [line] 52.67: zp[1]:4 [ line::l#2 line::l#0 line::l#1 ] 
Uplift Scope [plot] 14: zp[1]:5 [ plot::x#2 plot::x#0 plot::x#1 ] 
Uplift Scope [] 

Uplifting [main] best 713 combination zp[1]:2 [ main::i#2 main::i#1 ] zp[1]:3 [ main::j#2 main::j#1 ] 
Uplifting [line] best 649 combination reg byte x [ line::l#2 line::l#0 line::l#1 ] 
Uplifting [plot] best 640 combination reg byte x [ plot::x#2 plot::x#0 plot::x#1 ] 
Uplifting [] best 640 combination 
Attempting to uplift remaining variables inzp[1]:2 [ main::i#2 main::i#1 ]
Uplifting [main] best 560 combination reg byte y [ main::i#2 main::i#1 ] 
Attempting to uplift remaining variables inzp[1]:3 [ main::j#2 main::j#1 ]
Uplifting [main] best 480 combination reg byte y [ main::j#2 main::j#1 ] 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Two levels of functions to test that register allocation handles live ranges and call-ranges optimally to allocate the fewest possible ZP-variables
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  // @begin
__bbegin:
  // [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
  jmp __b1
  // @1
__b1:
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
main_from___b1:
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
  jmp __bend
  // @end
__bend:
  // main
main: {
    // [5] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuyy=vbuc1 
    ldy #0
    jmp __b1
    // [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
  __b1_from___b3:
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@3->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [6] (byte) line::l#0 ← (byte) main::i#2 -- vbuxx=vbuyy 
    tya
    tax
    // [7] call line 
    // [16] phi from main::@1 to line [phi:main::@1->line]
  line_from___b1:
    // [16] phi (byte) line::l#2 = (byte) line::l#0 [phi:main::@1->line#0] -- register_copy 
    jsr line
    jmp __b3
    // main::@3
  __b3:
    // [8] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuyy=_inc_vbuyy 
    iny
    // [9] if((byte) main::i#1!=(byte) 9) goto main::@1 -- vbuyy_neq_vbuc1_then_la1 
    cpy #9
    bne __b1_from___b3
    // [10] phi from main::@3 to main::@2 [phi:main::@3->main::@2]
  __b2_from___b3:
    // [10] phi (byte) main::j#2 = (byte) $a [phi:main::@3->main::@2#0] -- vbuyy=vbuc1 
    ldy #$a
    jmp __b2
    // [10] phi from main::@4 to main::@2 [phi:main::@4->main::@2]
  __b2_from___b4:
    // [10] phi (byte) main::j#2 = (byte) main::j#1 [phi:main::@4->main::@2#0] -- register_copy 
    jmp __b2
    // main::@2
  __b2:
    // [11] (byte) line::l#1 ← (byte) main::j#2 -- vbuxx=vbuyy 
    tya
    tax
    // [12] call line 
    // [16] phi from main::@2 to line [phi:main::@2->line]
  line_from___b2:
    // [16] phi (byte) line::l#2 = (byte) line::l#1 [phi:main::@2->line#0] -- register_copy 
    jsr line
    jmp __b4
    // main::@4
  __b4:
    // [13] (byte) main::j#1 ← ++ (byte) main::j#2 -- vbuyy=_inc_vbuyy 
    iny
    // [14] if((byte) main::j#1!=(byte) $13) goto main::@2 -- vbuyy_neq_vbuc1_then_la1 
    cpy #$13
    bne __b2_from___b4
    jmp __breturn
    // main::@return
  __breturn:
    // [15] return 
    rts
}
  // line
// line(byte register(X) l)
line: {
    // [17] (byte) plot::x#0 ← (byte) line::l#2
    // [18] call plot 
    // [22] phi from line to plot [phi:line->plot]
  plot_from_line:
    // [22] phi (byte) plot::x#2 = (byte) plot::x#0 [phi:line->plot#0] -- register_copy 
    jsr plot
    jmp __b1
    // line::@1
  __b1:
    // [19] (byte) plot::x#1 ← (byte) line::l#2 + (byte) $14 -- vbuxx=vbuxx_plus_vbuc1 
    txa
    axs #-[$14]
    // [20] call plot 
    // [22] phi from line::@1 to plot [phi:line::@1->plot]
  plot_from___b1:
    // [22] phi (byte) plot::x#2 = (byte) plot::x#1 [phi:line::@1->plot#0] -- register_copy 
    jsr plot
    jmp __breturn
    // line::@return
  __breturn:
    // [21] return 
    rts
}
  // plot
// plot(byte register(X) x)
plot: {
    // [23] *((const byte*) SCREEN + (byte) plot::x#2) ← (byte) '*' -- pbuc1_derefidx_vbuxx=vbuc2 
    lda #'*'
    sta SCREEN,x
    jmp __breturn
    // plot::@return
  __breturn:
    // [24] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __b3
Removing instruction jmp __b2
Removing instruction jmp __b4
Removing instruction jmp __breturn
Removing instruction jmp __b1
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Replacing label __b1_from___b3 with __b1
Replacing label __b2_from___b4 with __b2
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Removing instruction __b1_from___b3:
Removing instruction __b2_from___b4:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __b1_from_main:
Removing instruction line_from___b1:
Removing instruction __b3:
Removing instruction __b2_from___b3:
Removing instruction line_from___b2:
Removing instruction __b4:
Removing instruction __breturn:
Removing instruction plot_from_line:
Removing instruction __b1:
Removing instruction plot_from___b1:
Removing instruction __breturn:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction jmp __b1
Removing instruction jmp __b2
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*) 1024
(void()) line((byte) line::l)
(label) line::@1
(label) line::@return
(byte) line::l
(byte) line::l#0 reg byte x 22.0
(byte) line::l#1 reg byte x 22.0
(byte) line::l#2 reg byte x 8.666666666666666
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@4
(label) main::@return
(byte) main::i
(byte) main::i#1 reg byte y 16.5
(byte) main::i#2 reg byte y 11.0
(byte) main::j
(byte) main::j#1 reg byte y 16.5
(byte) main::j#2 reg byte y 11.0
(void()) plot((byte) plot::x)
(label) plot::@return
(byte) plot::x
(byte) plot::x#0 reg byte x 4.0
(byte) plot::x#1 reg byte x 4.0
(byte) plot::x#2 reg byte x 6.0

reg byte y [ main::i#2 main::i#1 ]
reg byte y [ main::j#2 main::j#1 ]
reg byte x [ line::l#2 line::l#0 line::l#1 ]
reg byte x [ plot::x#2 plot::x#0 plot::x#1 ]


FINAL ASSEMBLER
Score: 303

  // File Comments
// Two levels of functions to test that register allocation handles live ranges and call-ranges optimally to allocate the fewest possible ZP-variables
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  // @begin
  // [1] phi from @begin to @1 [phi:@begin->@1]
  // @1
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
  // [3] phi from @1 to @end [phi:@1->@end]
  // @end
  // main
main: {
    // [5] phi from main to main::@1 [phi:main->main::@1]
    // [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuyy=vbuc1 
    ldy #0
    // [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@3->main::@1#0] -- register_copy 
    // main::@1
  __b1:
    // line(i)
    // [6] (byte) line::l#0 ← (byte) main::i#2 -- vbuxx=vbuyy 
    tya
    tax
    // [7] call line 
    // [16] phi from main::@1 to line [phi:main::@1->line]
    // [16] phi (byte) line::l#2 = (byte) line::l#0 [phi:main::@1->line#0] -- register_copy 
    jsr line
    // main::@3
    // for(byte i : 0..8)
    // [8] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuyy=_inc_vbuyy 
    iny
    // [9] if((byte) main::i#1!=(byte) 9) goto main::@1 -- vbuyy_neq_vbuc1_then_la1 
    cpy #9
    bne __b1
    // [10] phi from main::@3 to main::@2 [phi:main::@3->main::@2]
    // [10] phi (byte) main::j#2 = (byte) $a [phi:main::@3->main::@2#0] -- vbuyy=vbuc1 
    ldy #$a
    // [10] phi from main::@4 to main::@2 [phi:main::@4->main::@2]
    // [10] phi (byte) main::j#2 = (byte) main::j#1 [phi:main::@4->main::@2#0] -- register_copy 
    // main::@2
  __b2:
    // line(j)
    // [11] (byte) line::l#1 ← (byte) main::j#2 -- vbuxx=vbuyy 
    tya
    tax
    // [12] call line 
    // [16] phi from main::@2 to line [phi:main::@2->line]
    // [16] phi (byte) line::l#2 = (byte) line::l#1 [phi:main::@2->line#0] -- register_copy 
    jsr line
    // main::@4
    // for(byte j : 10..18)
    // [13] (byte) main::j#1 ← ++ (byte) main::j#2 -- vbuyy=_inc_vbuyy 
    iny
    // [14] if((byte) main::j#1!=(byte) $13) goto main::@2 -- vbuyy_neq_vbuc1_then_la1 
    cpy #$13
    bne __b2
    // main::@return
    // }
    // [15] return 
    rts
}
  // line
// line(byte register(X) l)
line: {
    // plot(l)
    // [17] (byte) plot::x#0 ← (byte) line::l#2
    // [18] call plot 
    // [22] phi from line to plot [phi:line->plot]
    // [22] phi (byte) plot::x#2 = (byte) plot::x#0 [phi:line->plot#0] -- register_copy 
    jsr plot
    // line::@1
    // plot(l+20)
    // [19] (byte) plot::x#1 ← (byte) line::l#2 + (byte) $14 -- vbuxx=vbuxx_plus_vbuc1 
    txa
    axs #-[$14]
    // [20] call plot 
    // [22] phi from line::@1 to plot [phi:line::@1->plot]
    // [22] phi (byte) plot::x#2 = (byte) plot::x#1 [phi:line::@1->plot#0] -- register_copy 
    jsr plot
    // line::@return
    // }
    // [21] return 
    rts
}
  // plot
// plot(byte register(X) x)
plot: {
    // SCREEN[x] = '*'
    // [23] *((const byte*) SCREEN + (byte) plot::x#2) ← (byte) '*' -- pbuc1_derefidx_vbuxx=vbuc2 
    lda #'*'
    sta SCREEN,x
    // plot::@return
    // }
    // [24] return 
    rts
}
  // File Data

