Culled Empty Block (label) main::@2
Culled Empty Block (label) @1
Culled Empty Block (label) @2
Culled Empty Block (label) c::@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::@3
  (byte) main::i#2 ← phi( main/(byte) main::i#0 main::@3/(byte) main::i#1 )
  (byte) b::i#0 ← (byte) main::i#2
  call b 
  to:main::@3
main::@3: 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,$64)
  (bool~) main::$1 ← (byte) main::i#1 != rangelast(0,$64)
  if((bool~) main::$1) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@3
  return 
  to:@return

(void()) b((byte) b::i)
b: scope:[b]  from main::@1
  (byte) b::i#1 ← phi( main::@1/(byte) b::i#0 )
  (byte) c::i#0 ← (byte) b::i#1
  call c 
  to:b::@1
b::@1: scope:[b]  from b
  to:b::@return
b::@return: scope:[b]  from b::@1
  return 
  to:@return

(void()) c((byte) c::i)
c: scope:[c]  from b
  (byte) c::i#2 ← phi( b/(byte) c::i#0 )
  (byte) c::j#0 ← (byte) 0
  to:c::@1
c::@1: scope:[c]  from c c::@1
  (byte) c::j#2 ← phi( c/(byte) c::j#0 c::@1/(byte) c::j#1 )
  (byte) c::i#1 ← phi( c/(byte) c::i#2 c::@1/(byte) c::i#1 )
  *((const byte*) SCREEN + (byte) c::j#2) ← (byte) c::i#1
  (byte) c::j#1 ← (byte) c::j#2 + rangenext(0,$64)
  (bool~) c::$0 ← (byte) c::j#1 != rangelast(0,$64)
  if((bool~) c::$0) goto c::@1
  to:c::@return
c::@return: scope:[c]  from c::@1
  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()) b((byte) b::i)
(label) b::@1
(label) b::@return
(byte) b::i
(byte) b::i#0
(byte) b::i#1
(void()) c((byte) c::i)
(bool~) c::$0
(label) c::@1
(label) c::@return
(byte) c::i
(byte) c::i#0
(byte) c::i#1
(byte) c::i#2
(byte) c::j
(byte) c::j#0
(byte) c::j#1
(byte) c::j#2
(void()) main()
(bool~) main::$1
(label) main::@1
(label) main::@3
(label) main::@return
(byte) main::i
(byte) main::i#0
(byte) main::i#1
(byte) main::i#2
(byte) main::i#3

Simplifying constant pointer cast (byte*) 1024
Successful SSA optimization PassNCastSimplification
Alias (byte) main::i#2 = (byte) main::i#3 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte) b::i#1 (byte) b::i#0
Identical Phi Values (byte) c::i#2 (byte) c::i#0
Identical Phi Values (byte) c::i#1 (byte) c::i#2
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition (bool~) main::$1 [7] if((byte) main::i#1!=rangelast(0,$64)) goto main::@1
Simple Condition (bool~) c::$0 [19] if((byte) c::j#1!=rangelast(0,$64)) goto c::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte) main::i#0 = 0
Constant (const byte) c::j#0 = 0
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,$64)) goto main::@1 to (number) $65
Resolved ranged next value [17] c::j#1 ← ++ c::j#2 to ++
Resolved ranged comparison value [19] if(c::j#1!=rangelast(0,$64)) goto c::@1 to (number) $65
Adding number conversion cast (unumber) $65 in if((byte) main::i#1!=(number) $65) goto main::@1
Adding number conversion cast (unumber) $65 in if((byte) c::j#1!=(number) $65) goto c::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast $65
Simplifying constant integer cast $65
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $65
Finalized unsigned number type (byte) $65
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining constant with var siblings (const byte) main::i#0
Inlining constant with var siblings (const byte) c::j#0
Constant inlined main::i#0 = (byte) 0
Constant inlined c::j#0 = (byte) 0
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@4(between main::@3 and main::@1)
Added new block during phi lifting c::@3(between c::@1 and c::@1)
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 b::@1
Adding NOP phi() at start of c
CALL GRAPH
Calls in [] to main:2 
Calls in [main] to b:8 
Calls in [b] to c:14 

Created 2 initial phi equivalence classes
Coalesced [12] main::i#4 ← main::i#1
Coalesced [23] c::j#3 ← c::j#1
Coalesced down to 2 phi equivalence classes
Culled Empty Block (label) @4
Culled Empty Block (label) main::@4
Culled Empty Block (label) b::@1
Culled Empty Block (label) c::@3
Renumbering block @3 to @1
Renumbering block main::@3 to main::@2
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
Adding NOP phi() at start of c

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::@2
  [5] (byte) main::i#2 ← phi( main/(byte) 0 main::@2/(byte) main::i#1 )
  [6] (byte) b::i#0 ← (byte) main::i#2
  [7] call b 
  to:main::@2
main::@2: scope:[main]  from main::@1
  [8] (byte) main::i#1 ← ++ (byte) main::i#2
  [9] if((byte) main::i#1!=(byte) $65) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@2
  [10] return 
  to:@return

(void()) b((byte) b::i)
b: scope:[b]  from main::@1
  [11] (byte) c::i#0 ← (byte) b::i#0
  [12] call c 
  to:b::@return
b::@return: scope:[b]  from b
  [13] return 
  to:@return

(void()) c((byte) c::i)
c: scope:[c]  from b
  [14] phi()
  to:c::@1
c::@1: scope:[c]  from c c::@1
  [15] (byte) c::j#2 ← phi( c/(byte) 0 c::@1/(byte) c::j#1 )
  [16] *((const byte*) SCREEN + (byte) c::j#2) ← (byte) c::i#0
  [17] (byte) c::j#1 ← ++ (byte) c::j#2
  [18] if((byte) c::j#1!=(byte) $65) goto c::@1
  to:c::@return
c::@return: scope:[c]  from c::@1
  [19] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) b((byte) b::i)
(byte) b::i
(byte) b::i#0 13.0
(void()) c((byte) c::i)
(byte) c::i
(byte) c::i#0 17.166666666666664
(byte) c::j
(byte) c::j#1 151.5
(byte) c::j#2 151.5
(void()) main()
(byte) main::i
(byte) main::i#1 16.5
(byte) main::i#2 11.0

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
[ c::j#2 c::j#1 ]
Added variable b::i#0 to live range equivalence class [ b::i#0 ]
Added variable c::i#0 to live range equivalence class [ c::i#0 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ c::j#2 c::j#1 ]
[ b::i#0 ]
[ c::i#0 ]
Allocated zp[1]:2 [ main::i#2 main::i#1 ]
Allocated zp[1]:3 [ c::j#2 c::j#1 ]
Allocated zp[1]:4 [ b::i#0 ]
Allocated zp[1]:5 [ c::i#0 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
  // 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
    // [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::@2 to main::@1 [phi:main::@2->main::@1]
  __b1_from___b2:
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@2->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [6] (byte) b::i#0 ← (byte) main::i#2 -- vbuz1=vbuz2 
    lda.z i
    sta.z b.i
    // [7] call b 
    jsr b
    jmp __b2
    // main::@2
  __b2:
    // [8] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [9] if((byte) main::i#1!=(byte) $65) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #$65
    cmp.z i
    bne __b1_from___b2
    jmp __breturn
    // main::@return
  __breturn:
    // [10] return 
    rts
}
  // b
// b(byte zp(4) i)
b: {
    .label i = 4
    // [11] (byte) c::i#0 ← (byte) b::i#0 -- vbuz1=vbuz2 
    lda.z i
    sta.z c.i
    // [12] call c 
    // [14] phi from b to c [phi:b->c]
  c_from_b:
    jsr c
    jmp __breturn
    // b::@return
  __breturn:
    // [13] return 
    rts
}
  // c
// c(byte zp(5) i)
c: {
    .label i = 5
    .label j = 3
    // [15] phi from c to c::@1 [phi:c->c::@1]
  __b1_from_c:
    // [15] phi (byte) c::j#2 = (byte) 0 [phi:c->c::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z j
    jmp __b1
    // [15] phi from c::@1 to c::@1 [phi:c::@1->c::@1]
  __b1_from___b1:
    // [15] phi (byte) c::j#2 = (byte) c::j#1 [phi:c::@1->c::@1#0] -- register_copy 
    jmp __b1
    // c::@1
  __b1:
    // [16] *((const byte*) SCREEN + (byte) c::j#2) ← (byte) c::i#0 -- pbuc1_derefidx_vbuz1=vbuz2 
    lda.z i
    ldy.z j
    sta SCREEN,y
    // [17] (byte) c::j#1 ← ++ (byte) c::j#2 -- vbuz1=_inc_vbuz1 
    inc.z j
    // [18] if((byte) c::j#1!=(byte) $65) goto c::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #$65
    cmp.z j
    bne __b1_from___b1
    jmp __breturn
    // c::@return
  __breturn:
    // [19] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Potential registers zp[1]:2 [ main::i#2 main::i#1 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:3 [ c::j#2 c::j#1 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:4 [ b::i#0 ] : zp[1]:4 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:5 [ c::i#0 ] : zp[1]:5 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [c] 303: zp[1]:3 [ c::j#2 c::j#1 ] 17.17: zp[1]:5 [ c::i#0 ] 
Uplift Scope [main] 27.5: zp[1]:2 [ main::i#2 main::i#1 ] 
Uplift Scope [b] 13: zp[1]:4 [ b::i#0 ] 
Uplift Scope [] 

Uplifting [c] best 2707 combination reg byte x [ c::j#2 c::j#1 ] reg byte a [ c::i#0 ] 
Uplifting [main] best 2587 combination reg byte y [ main::i#2 main::i#1 ] 
Uplifting [b] best 2556 combination reg byte y [ b::i#0 ] 
Uplifting [] best 2556 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
  // 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::@2 to main::@1 [phi:main::@2->main::@1]
  __b1_from___b2:
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@2->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [6] (byte) b::i#0 ← (byte) main::i#2
    // [7] call b 
    jsr b
    jmp __b2
    // main::@2
  __b2:
    // [8] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuyy=_inc_vbuyy 
    iny
    // [9] if((byte) main::i#1!=(byte) $65) goto main::@1 -- vbuyy_neq_vbuc1_then_la1 
    cpy #$65
    bne __b1_from___b2
    jmp __breturn
    // main::@return
  __breturn:
    // [10] return 
    rts
}
  // b
// b(byte register(Y) i)
b: {
    // [11] (byte) c::i#0 ← (byte) b::i#0 -- vbuaa=vbuyy 
    tya
    // [12] call c 
    // [14] phi from b to c [phi:b->c]
  c_from_b:
    jsr c
    jmp __breturn
    // b::@return
  __breturn:
    // [13] return 
    rts
}
  // c
// c(byte register(A) i)
c: {
    // [15] phi from c to c::@1 [phi:c->c::@1]
  __b1_from_c:
    // [15] phi (byte) c::j#2 = (byte) 0 [phi:c->c::@1#0] -- vbuxx=vbuc1 
    ldx #0
    jmp __b1
    // [15] phi from c::@1 to c::@1 [phi:c::@1->c::@1]
  __b1_from___b1:
    // [15] phi (byte) c::j#2 = (byte) c::j#1 [phi:c::@1->c::@1#0] -- register_copy 
    jmp __b1
    // c::@1
  __b1:
    // [16] *((const byte*) SCREEN + (byte) c::j#2) ← (byte) c::i#0 -- pbuc1_derefidx_vbuxx=vbuaa 
    sta SCREEN,x
    // [17] (byte) c::j#1 ← ++ (byte) c::j#2 -- vbuxx=_inc_vbuxx 
    inx
    // [18] if((byte) c::j#1!=(byte) $65) goto c::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$65
    bne __b1_from___b1
    jmp __breturn
    // c::@return
  __breturn:
    // [19] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __b2
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Removing instruction jmp __b1
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Replacing label __b1_from___b2 with __b1
Replacing label __b1_from___b1 with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Removing instruction __b1_from___b2:
Removing instruction __b1_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __b1_from_main:
Removing instruction __b2:
Removing instruction __breturn:
Removing instruction c_from_b:
Removing instruction __breturn:
Removing instruction __b1_from_c:
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 __b1
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()) b((byte) b::i)
(label) b::@return
(byte) b::i
(byte) b::i#0 reg byte y 13.0
(void()) c((byte) c::i)
(label) c::@1
(label) c::@return
(byte) c::i
(byte) c::i#0 reg byte a 17.166666666666664
(byte) c::j
(byte) c::j#1 reg byte x 151.5
(byte) c::j#2 reg byte x 151.5
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@return
(byte) main::i
(byte) main::i#1 reg byte y 16.5
(byte) main::i#2 reg byte y 11.0

reg byte y [ main::i#2 main::i#1 ]
reg byte x [ c::j#2 c::j#1 ]
reg byte y [ b::i#0 ]
reg byte a [ c::i#0 ]


FINAL ASSEMBLER
Score: 1521

  // File Comments
  // 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::@2 to main::@1 [phi:main::@2->main::@1]
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@2->main::@1#0] -- register_copy 
    // main::@1
  __b1:
    // b(i)
    // [6] (byte) b::i#0 ← (byte) main::i#2
    // [7] call b 
    jsr b
    // main::@2
    // for(byte i:0..100)
    // [8] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuyy=_inc_vbuyy 
    iny
    // [9] if((byte) main::i#1!=(byte) $65) goto main::@1 -- vbuyy_neq_vbuc1_then_la1 
    cpy #$65
    bne __b1
    // main::@return
    // }
    // [10] return 
    rts
}
  // b
// b(byte register(Y) i)
b: {
    // c(i)
    // [11] (byte) c::i#0 ← (byte) b::i#0 -- vbuaa=vbuyy 
    tya
    // [12] call c 
    // [14] phi from b to c [phi:b->c]
    jsr c
    // b::@return
    // }
    // [13] return 
    rts
}
  // c
// c(byte register(A) i)
c: {
    // [15] phi from c to c::@1 [phi:c->c::@1]
    // [15] phi (byte) c::j#2 = (byte) 0 [phi:c->c::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // [15] phi from c::@1 to c::@1 [phi:c::@1->c::@1]
    // [15] phi (byte) c::j#2 = (byte) c::j#1 [phi:c::@1->c::@1#0] -- register_copy 
    // c::@1
  __b1:
    // SCREEN[j] = i
    // [16] *((const byte*) SCREEN + (byte) c::j#2) ← (byte) c::i#0 -- pbuc1_derefidx_vbuxx=vbuaa 
    sta SCREEN,x
    // for( byte j: 0..100)
    // [17] (byte) c::j#1 ← ++ (byte) c::j#2 -- vbuxx=_inc_vbuxx 
    inx
    // [18] if((byte) c::j#1!=(byte) $65) goto c::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$65
    bne __b1
    // c::@return
    // }
    // [19] return 
    rts
}
  // File Data

