
CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (byte*) SCREEN#0 ← ((byte*)) (word/signed word/dword/signed dword) 1024
  to:@3
main: scope:[main]  from @3
  (byte*) SCREEN#6 ← phi( @3/(byte*) SCREEN#10 )
  (byte) main::i#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0
  to:main::@1
main::@1: scope:[main]  from main main::@5
  (byte*) SCREEN#4 ← phi( main/(byte*) SCREEN#6 main::@5/(byte*) SCREEN#7 )
  (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*) SCREEN#7 ← phi( main::@1/(byte*) SCREEN#4 )
  (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::@3
main::@3: scope:[main]  from main::@5
  (byte*) SCREEN#8 ← phi( main::@5/(byte*) SCREEN#7 )
  (byte) main::j#0 ← (byte/signed byte/word/signed word/dword/signed dword) 10
  to:main::@2
main::@2: scope:[main]  from main::@3 main::@6
  (byte*) SCREEN#5 ← phi( main::@3/(byte*) SCREEN#8 main::@6/(byte*) SCREEN#9 )
  (byte) main::j#2 ← phi( main::@3/(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::@2
  (byte*) SCREEN#9 ← phi( main::@2/(byte*) SCREEN#5 )
  (byte) main::j#3 ← phi( main::@2/(byte) main::j#2 )
  (byte) main::j#1 ← (byte) main::j#3 + rangenext(10,18)
  (bool~) main::$3 ← (byte) main::j#1 != rangelast(10,18)
  if((bool~) main::$3) goto main::@2
  to:main::@return
main::@return: scope:[main]  from main::@6
  return 
  to:@return
line: scope:[line]  from main::@1 main::@2
  (byte*) SCREEN#2 ← phi( main::@1/(byte*) SCREEN#4 main::@2/(byte*) SCREEN#5 )
  (byte) line::l#2 ← phi( main::@1/(byte) line::l#0 main::@2/(byte) line::l#1 )
  (byte) plot::x#0 ← (byte) line::l#2
  call plot 
  to:line::@1
line::@1: scope:[line]  from line
  (byte*) SCREEN#3 ← phi( line/(byte*) SCREEN#2 )
  (byte) line::l#3 ← phi( line/(byte) line::l#2 )
  (byte/signed word/word/dword/signed dword~) line::$1 ← (byte) line::l#3 + (byte/signed byte/word/signed word/dword/signed dword) 20
  (byte) plot::x#1 ← (byte/signed word/word/dword/signed dword~) 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
plot: scope:[plot]  from line line::@1
  (byte) plot::x#2 ← phi( line/(byte) plot::x#0 line::@1/(byte) plot::x#1 )
  (byte*) SCREEN#1 ← phi( line/(byte*) SCREEN#2 line::@1/(byte*) SCREEN#3 )
  *((byte*) SCREEN#1 + (byte) plot::x#2) ← (byte) '*'
  to:plot::@return
plot::@return: scope:[plot]  from plot
  return 
  to:@return
@3: scope:[]  from @begin
  (byte*) SCREEN#10 ← phi( @begin/(byte*) SCREEN#0 )
  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
(byte*) SCREEN
(byte*) SCREEN#0
(byte*) SCREEN#1
(byte*) SCREEN#10
(byte*) SCREEN#2
(byte*) SCREEN#3
(byte*) SCREEN#4
(byte*) SCREEN#5
(byte*) SCREEN#6
(byte*) SCREEN#7
(byte*) SCREEN#8
(byte*) SCREEN#9
(void()) line((byte) line::l)
(byte/signed word/word/dword/signed dword~) 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

Culled Empty Block (label) line::@2
Culled Empty Block (label) @4
Successful SSA optimization Pass2CullEmptyBlocks
Alias (byte) main::i#2 = (byte) main::i#3 
Alias (byte*) SCREEN#4 = (byte*) SCREEN#7 (byte*) SCREEN#8 
Alias (byte) main::j#2 = (byte) main::j#3 
Alias (byte*) SCREEN#5 = (byte*) SCREEN#9 
Alias (byte) line::l#2 = (byte) line::l#3 
Alias (byte*) SCREEN#2 = (byte*) SCREEN#3 
Alias (byte) plot::x#1 = (byte/signed word/word/dword/signed dword~) line::$1 
Alias (byte*) SCREEN#0 = (byte*) SCREEN#10 
Successful SSA optimization Pass2AliasElimination
Self Phi Eliminated (byte*) SCREEN#4
Self Phi Eliminated (byte*) SCREEN#5
Successful SSA optimization Pass2SelfPhiElimination
Redundant Phi (byte*) SCREEN#6 (byte*) SCREEN#0
Redundant Phi (byte*) SCREEN#4 (byte*) SCREEN#6
Redundant Phi (byte*) SCREEN#5 (byte*) SCREEN#4
Redundant Phi (byte*) SCREEN#1 (byte*) SCREEN#2
Successful SSA optimization Pass2RedundantPhiElimination
Redundant Phi (byte*) SCREEN#2 (byte*) SCREEN#0
Successful SSA optimization Pass2RedundantPhiElimination
Simple Condition (bool~) main::$1 [9] if((byte) main::i#1!=rangelast(0,8)) goto main::@1
Simple Condition (bool~) main::$3 [18] if((byte) main::j#1!=rangelast(10,18)) goto main::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte*) SCREEN#0 = ((byte*))1024
Constant (const byte) main::i#0 = 0
Constant (const byte) main::j#0 = 10
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value main::i#1 ← ++ main::i#2 to ++
Resolved ranged comparison value if(main::i#1!=rangelast(0,8)) goto main::@1 to (byte/signed byte/word/signed word/dword/signed dword) 9
Resolved ranged next value main::j#1 ← ++ main::j#2 to ++
Resolved ranged comparison value if(main::j#1!=rangelast(10,18)) goto main::@2 to (byte/signed byte/word/signed word/dword/signed dword) 19
Culled Empty Block (label) main::@3
Successful SSA optimization Pass2CullEmptyBlocks
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/signed byte/word/signed word/dword/signed dword) 0
Constant inlined main::j#0 = (byte/signed byte/word/signed word/dword/signed dword) 10
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::@2)
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @3
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 line:8 line:14 
Calls in [line] to plot:23 plot:26 

Created 4 initial phi equivalence classes
Coalesced [7] line::l#4 ← line::l#0
Coalesced [13] line::l#5 ← line::l#1
Coalesced [18] main::j#4 ← main::j#1
Coalesced [19] main::i#4 ← main::i#1
Coalesced [22] plot::x#3 ← plot::x#0
Coalesced [25] plot::x#4 ← plot::x#1
Coalesced down to 4 phi equivalence classes
Culled Empty Block (label) main::@8
Culled Empty Block (label) main::@7
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @3
Adding NOP phi() at start of @end
Adding NOP phi() at start of main

FINAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  [0] phi()
  to:@3
@3: scope:[]  from @begin
  [1] phi()
  [2] call main 
  to:@end
@end: scope:[]  from @3
  [3] phi()
main: scope:[main]  from @3
  [4] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@5
  [5] (byte) main::i#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@5/(byte) main::i#1 )
  [6] (byte) line::l#0 ← (byte) main::i#2
  [7] call line 
  to:main::@5
main::@5: scope:[main]  from main::@1
  [8] (byte) main::i#1 ← ++ (byte) main::i#2
  [9] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) 9) goto main::@1
  to:main::@2
main::@2: scope:[main]  from main::@5 main::@6
  [10] (byte) main::j#2 ← phi( main::@5/(byte/signed byte/word/signed word/dword/signed dword) 10 main::@6/(byte) main::j#1 )
  [11] (byte) line::l#1 ← (byte) main::j#2
  [12] call line 
  to:main::@6
main::@6: scope:[main]  from main::@2
  [13] (byte) main::j#1 ← ++ (byte) main::j#2
  [14] if((byte) main::j#1!=(byte/signed byte/word/signed word/dword/signed dword) 19) goto main::@2
  to:main::@return
main::@return: scope:[main]  from main::@6
  [15] return 
  to:@return
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/signed byte/word/signed word/dword/signed dword) 20
  [20] call plot 
  to:line::@return
line::@return: scope:[line]  from line::@1
  [21] return 
  to:@return
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#0 + (byte) plot::x#2) ← (byte) '*'
  to:plot::@return
plot::@return: scope:[plot]  from plot
  [24] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(byte*) SCREEN
(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 ZP_BYTE:2 [ main::i#2 main::i#1 ]
Allocated zp ZP_BYTE:3 [ main::j#2 main::j#1 ]
Allocated zp ZP_BYTE:4 [ line::l#2 line::l#0 line::l#1 ]
Allocated zp ZP_BYTE:5 [ plot::x#2 plot::x#0 plot::x#1 ]

INITIAL ASM
//SEG0 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
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
  .label SCREEN = $400
//SEG3 @begin
bbegin:
//SEG4 [1] phi from @begin to @3 [phi:@begin->@3]
b3_from_bbegin:
  jmp b3
//SEG5 @3
b3:
//SEG6 [2] call main 
//SEG7 [4] phi from @3 to main [phi:@3->main]
main_from_b3:
  jsr main
//SEG8 [3] phi from @3 to @end [phi:@3->@end]
bend_from_b3:
  jmp bend
//SEG9 @end
bend:
//SEG10 main
main: {
    .label i = 2
    .label j = 3
  //SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
  b1_from_main:
  //SEG12 [5] phi (byte) main::i#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta i
    jmp b1
  //SEG13 [5] phi from main::@5 to main::@1 [phi:main::@5->main::@1]
  b1_from_b5:
  //SEG14 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@5->main::@1#0] -- register_copy 
    jmp b1
  //SEG15 main::@1
  b1:
  //SEG16 [6] (byte) line::l#0 ← (byte) main::i#2 -- vbuz1=vbuz2 
    lda i
    sta line.l
  //SEG17 [7] call line 
  //SEG18 [16] phi from main::@1 to line [phi:main::@1->line]
  line_from_b1:
  //SEG19 [16] phi (byte) line::l#2 = (byte) line::l#0 [phi:main::@1->line#0] -- register_copy 
    jsr line
    jmp b5
  //SEG20 main::@5
  b5:
  //SEG21 [8] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc i
  //SEG22 [9] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) 9) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda i
    cmp #9
    bne b1_from_b5
  //SEG23 [10] phi from main::@5 to main::@2 [phi:main::@5->main::@2]
  b2_from_b5:
  //SEG24 [10] phi (byte) main::j#2 = (byte/signed byte/word/signed word/dword/signed dword) 10 [phi:main::@5->main::@2#0] -- vbuz1=vbuc1 
    lda #$a
    sta j
    jmp b2
  //SEG25 [10] phi from main::@6 to main::@2 [phi:main::@6->main::@2]
  b2_from_b6:
  //SEG26 [10] phi (byte) main::j#2 = (byte) main::j#1 [phi:main::@6->main::@2#0] -- register_copy 
    jmp b2
  //SEG27 main::@2
  b2:
  //SEG28 [11] (byte) line::l#1 ← (byte) main::j#2 -- vbuz1=vbuz2 
    lda j
    sta line.l
  //SEG29 [12] call line 
  //SEG30 [16] phi from main::@2 to line [phi:main::@2->line]
  line_from_b2:
  //SEG31 [16] phi (byte) line::l#2 = (byte) line::l#1 [phi:main::@2->line#0] -- register_copy 
    jsr line
    jmp b6
  //SEG32 main::@6
  b6:
  //SEG33 [13] (byte) main::j#1 ← ++ (byte) main::j#2 -- vbuz1=_inc_vbuz1 
    inc j
  //SEG34 [14] if((byte) main::j#1!=(byte/signed byte/word/signed word/dword/signed dword) 19) goto main::@2 -- vbuz1_neq_vbuc1_then_la1 
    lda j
    cmp #$13
    bne b2_from_b6
    jmp breturn
  //SEG35 main::@return
  breturn:
  //SEG36 [15] return 
    rts
}
//SEG37 line
// line(byte zeropage(4) l)
line: {
    .label l = 4
  //SEG38 [17] (byte) plot::x#0 ← (byte) line::l#2 -- vbuz1=vbuz2 
    lda l
    sta plot.x
  //SEG39 [18] call plot 
  //SEG40 [22] phi from line to plot [phi:line->plot]
  plot_from_line:
  //SEG41 [22] phi (byte) plot::x#2 = (byte) plot::x#0 [phi:line->plot#0] -- register_copy 
    jsr plot
    jmp b1
  //SEG42 line::@1
  b1:
  //SEG43 [19] (byte) plot::x#1 ← (byte) line::l#2 + (byte/signed byte/word/signed word/dword/signed dword) 20 -- vbuz1=vbuz2_plus_vbuc1 
    lda #$14
    clc
    adc l
    sta plot.x
  //SEG44 [20] call plot 
  //SEG45 [22] phi from line::@1 to plot [phi:line::@1->plot]
  plot_from_b1:
  //SEG46 [22] phi (byte) plot::x#2 = (byte) plot::x#1 [phi:line::@1->plot#0] -- register_copy 
    jsr plot
    jmp breturn
  //SEG47 line::@return
  breturn:
  //SEG48 [21] return 
    rts
}
//SEG49 plot
// plot(byte zeropage(5) x)
plot: {
    .label x = 5
  //SEG50 [23] *((const byte*) SCREEN#0 + (byte) plot::x#2) ← (byte) '*' -- pbuc1_derefidx_vbuz1=vbuc2 
    ldy x
    lda #'*'
    sta SCREEN,y
    jmp breturn
  //SEG51 plot::@return
  breturn:
  //SEG52 [24] return 
    rts
}

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [19] (byte) plot::x#1 ← (byte) line::l#2 + (byte/signed byte/word/signed word/dword/signed dword) 20 [ 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 
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:2 [ main::i#2 main::i#1 ]
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:3 [ main::j#2 main::j#1 ]
Statement [23] *((const byte*) SCREEN#0 + (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 ZP_BYTE:4 [ line::l#2 line::l#0 line::l#1 ]
Statement [19] (byte) plot::x#1 ← (byte) line::l#2 + (byte/signed byte/word/signed word/dword/signed dword) 20 [ 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#0 + (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 ZP_BYTE:2 [ main::i#2 main::i#1 ] : zp ZP_BYTE:2 , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:3 [ main::j#2 main::j#1 ] : zp ZP_BYTE:3 , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:4 [ line::l#2 line::l#0 line::l#1 ] : zp ZP_BYTE:4 , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:5 [ plot::x#2 plot::x#0 plot::x#1 ] : zp ZP_BYTE:5 , reg byte a , reg byte x , reg byte y , 

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

Uplifting [main] best 475 combination reg byte x [ main::i#2 main::i#1 ] reg byte x [ main::j#2 main::j#1 ] 
Uplifting [line] best 411 combination reg byte x [ line::l#2 line::l#0 line::l#1 ] 
Uplifting [plot] best 406 combination reg byte a [ plot::x#2 plot::x#0 plot::x#1 ] 
Uplifting [] best 406 combination 

ASSEMBLER BEFORE OPTIMIZATION
//SEG0 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
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
  .label SCREEN = $400
//SEG3 @begin
bbegin:
//SEG4 [1] phi from @begin to @3 [phi:@begin->@3]
b3_from_bbegin:
  jmp b3
//SEG5 @3
b3:
//SEG6 [2] call main 
//SEG7 [4] phi from @3 to main [phi:@3->main]
main_from_b3:
  jsr main
//SEG8 [3] phi from @3 to @end [phi:@3->@end]
bend_from_b3:
  jmp bend
//SEG9 @end
bend:
//SEG10 main
main: {
  //SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
  b1_from_main:
  //SEG12 [5] phi (byte) main::i#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    jmp b1
  //SEG13 [5] phi from main::@5 to main::@1 [phi:main::@5->main::@1]
  b1_from_b5:
  //SEG14 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@5->main::@1#0] -- register_copy 
    jmp b1
  //SEG15 main::@1
  b1:
  //SEG16 [6] (byte) line::l#0 ← (byte) main::i#2
  //SEG17 [7] call line 
  //SEG18 [16] phi from main::@1 to line [phi:main::@1->line]
  line_from_b1:
  //SEG19 [16] phi (byte) line::l#2 = (byte) line::l#0 [phi:main::@1->line#0] -- register_copy 
    jsr line
    jmp b5
  //SEG20 main::@5
  b5:
  //SEG21 [8] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx 
    inx
  //SEG22 [9] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) 9) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #9
    bne b1_from_b5
  //SEG23 [10] phi from main::@5 to main::@2 [phi:main::@5->main::@2]
  b2_from_b5:
  //SEG24 [10] phi (byte) main::j#2 = (byte/signed byte/word/signed word/dword/signed dword) 10 [phi:main::@5->main::@2#0] -- vbuxx=vbuc1 
    ldx #$a
    jmp b2
  //SEG25 [10] phi from main::@6 to main::@2 [phi:main::@6->main::@2]
  b2_from_b6:
  //SEG26 [10] phi (byte) main::j#2 = (byte) main::j#1 [phi:main::@6->main::@2#0] -- register_copy 
    jmp b2
  //SEG27 main::@2
  b2:
  //SEG28 [11] (byte) line::l#1 ← (byte) main::j#2
  //SEG29 [12] call line 
  //SEG30 [16] phi from main::@2 to line [phi:main::@2->line]
  line_from_b2:
  //SEG31 [16] phi (byte) line::l#2 = (byte) line::l#1 [phi:main::@2->line#0] -- register_copy 
    jsr line
    jmp b6
  //SEG32 main::@6
  b6:
  //SEG33 [13] (byte) main::j#1 ← ++ (byte) main::j#2 -- vbuxx=_inc_vbuxx 
    inx
  //SEG34 [14] if((byte) main::j#1!=(byte/signed byte/word/signed word/dword/signed dword) 19) goto main::@2 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$13
    bne b2_from_b6
    jmp breturn
  //SEG35 main::@return
  breturn:
  //SEG36 [15] return 
    rts
}
//SEG37 line
// line(byte register(X) l)
line: {
  //SEG38 [17] (byte) plot::x#0 ← (byte) line::l#2 -- vbuaa=vbuxx 
    txa
  //SEG39 [18] call plot 
  //SEG40 [22] phi from line to plot [phi:line->plot]
  plot_from_line:
  //SEG41 [22] phi (byte) plot::x#2 = (byte) plot::x#0 [phi:line->plot#0] -- register_copy 
    jsr plot
    jmp b1
  //SEG42 line::@1
  b1:
  //SEG43 [19] (byte) plot::x#1 ← (byte) line::l#2 + (byte/signed byte/word/signed word/dword/signed dword) 20 -- vbuaa=vbuxx_plus_vbuc1 
    txa
    clc
    adc #$14
  //SEG44 [20] call plot 
  //SEG45 [22] phi from line::@1 to plot [phi:line::@1->plot]
  plot_from_b1:
  //SEG46 [22] phi (byte) plot::x#2 = (byte) plot::x#1 [phi:line::@1->plot#0] -- register_copy 
    jsr plot
    jmp breturn
  //SEG47 line::@return
  breturn:
  //SEG48 [21] return 
    rts
}
//SEG49 plot
// plot(byte register(A) x)
plot: {
  //SEG50 [23] *((const byte*) SCREEN#0 + (byte) plot::x#2) ← (byte) '*' -- pbuc1_derefidx_vbuaa=vbuc2 
    tay
    lda #'*'
    sta SCREEN,y
    jmp breturn
  //SEG51 plot::@return
  breturn:
  //SEG52 [24] return 
    rts
}

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b3
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp b5
Removing instruction jmp b2
Removing instruction jmp b6
Removing instruction jmp breturn
Removing instruction jmp b1
Removing instruction jmp breturn
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label b1_from_b5 with b1
Replacing label b2_from_b6 with b2
Removing instruction b3_from_bbegin:
Removing instruction b3:
Removing instruction main_from_b3:
Removing instruction bend_from_b3:
Removing instruction b1_from_b5:
Removing instruction line_from_b1:
Removing instruction b2_from_b6:
Removing instruction line_from_b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
Removing instruction b1_from_main:
Removing instruction b5:
Removing instruction b2_from_b5:
Removing instruction b6:
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 bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @3
(label) @begin
(label) @end
(byte*) SCREEN
(const byte*) SCREEN#0 SCREEN = ((byte*))(word/signed word/dword/signed dword) 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::@5
(label) main::@6
(label) main::@return
(byte) main::i
(byte) main::i#1 reg byte x 16.5
(byte) main::i#2 reg byte x 11.0
(byte) main::j
(byte) main::j#1 reg byte x 16.5
(byte) main::j#2 reg byte x 11.0
(void()) plot((byte) plot::x)
(label) plot::@return
(byte) plot::x
(byte) plot::x#0 reg byte a 4.0
(byte) plot::x#1 reg byte a 4.0
(byte) plot::x#2 reg byte a 6.0

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


FINAL ASSEMBLER
Score: 229

//SEG0 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
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG2 Global Constants & labels
  .label SCREEN = $400
//SEG3 @begin
//SEG4 [1] phi from @begin to @3 [phi:@begin->@3]
//SEG5 @3
//SEG6 [2] call main 
//SEG7 [4] phi from @3 to main [phi:@3->main]
//SEG8 [3] phi from @3 to @end [phi:@3->@end]
//SEG9 @end
//SEG10 main
main: {
  //SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
  //SEG12 [5] phi (byte) main::i#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
  //SEG13 [5] phi from main::@5 to main::@1 [phi:main::@5->main::@1]
  //SEG14 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@5->main::@1#0] -- register_copy 
  //SEG15 main::@1
  b1:
  //SEG16 [6] (byte) line::l#0 ← (byte) main::i#2
  //SEG17 [7] call line 
  //SEG18 [16] phi from main::@1 to line [phi:main::@1->line]
  //SEG19 [16] phi (byte) line::l#2 = (byte) line::l#0 [phi:main::@1->line#0] -- register_copy 
    jsr line
  //SEG20 main::@5
  //SEG21 [8] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx 
    inx
  //SEG22 [9] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) 9) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #9
    bne b1
  //SEG23 [10] phi from main::@5 to main::@2 [phi:main::@5->main::@2]
  //SEG24 [10] phi (byte) main::j#2 = (byte/signed byte/word/signed word/dword/signed dword) 10 [phi:main::@5->main::@2#0] -- vbuxx=vbuc1 
    ldx #$a
  //SEG25 [10] phi from main::@6 to main::@2 [phi:main::@6->main::@2]
  //SEG26 [10] phi (byte) main::j#2 = (byte) main::j#1 [phi:main::@6->main::@2#0] -- register_copy 
  //SEG27 main::@2
  b2:
  //SEG28 [11] (byte) line::l#1 ← (byte) main::j#2
  //SEG29 [12] call line 
  //SEG30 [16] phi from main::@2 to line [phi:main::@2->line]
  //SEG31 [16] phi (byte) line::l#2 = (byte) line::l#1 [phi:main::@2->line#0] -- register_copy 
    jsr line
  //SEG32 main::@6
  //SEG33 [13] (byte) main::j#1 ← ++ (byte) main::j#2 -- vbuxx=_inc_vbuxx 
    inx
  //SEG34 [14] if((byte) main::j#1!=(byte/signed byte/word/signed word/dword/signed dword) 19) goto main::@2 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$13
    bne b2
  //SEG35 main::@return
  //SEG36 [15] return 
    rts
}
//SEG37 line
// line(byte register(X) l)
line: {
  //SEG38 [17] (byte) plot::x#0 ← (byte) line::l#2 -- vbuaa=vbuxx 
    txa
  //SEG39 [18] call plot 
  //SEG40 [22] phi from line to plot [phi:line->plot]
  //SEG41 [22] phi (byte) plot::x#2 = (byte) plot::x#0 [phi:line->plot#0] -- register_copy 
    jsr plot
  //SEG42 line::@1
  //SEG43 [19] (byte) plot::x#1 ← (byte) line::l#2 + (byte/signed byte/word/signed word/dword/signed dword) 20 -- vbuaa=vbuxx_plus_vbuc1 
    txa
    clc
    adc #$14
  //SEG44 [20] call plot 
  //SEG45 [22] phi from line::@1 to plot [phi:line::@1->plot]
  //SEG46 [22] phi (byte) plot::x#2 = (byte) plot::x#1 [phi:line::@1->plot#0] -- register_copy 
    jsr plot
  //SEG47 line::@return
  //SEG48 [21] return 
    rts
}
//SEG49 plot
// plot(byte register(A) x)
plot: {
  //SEG50 [23] *((const byte*) SCREEN#0 + (byte) plot::x#2) ← (byte) '*' -- pbuc1_derefidx_vbuaa=vbuc2 
    tay
    lda #'*'
    sta SCREEN,y
  //SEG51 plot::@return
  //SEG52 [24] return 
    rts
}

