Culled Empty Block (label) main::@2
Culled Empty Block (label) @1
Culled Empty Block (label) c::@2

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  to:@2
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
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
@2: scope:[]  from @begin
  (byte*) SCREEN#0 ← ((byte*)) (number) $400
  to:@3
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 )
  *((byte*) SCREEN#0 + (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 @2
  call main 
  to:@4
@4: scope:[]  from @3
  to:@end
@end: scope:[]  from @4

SYMBOL TABLE SSA
(label) @2
(label) @3
(label) @4
(label) @begin
(label) @end
(byte*) SCREEN
(byte*) SCREEN#0
(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

Inlining cast (byte*) SCREEN#0 ← (byte*)(number) $400
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Successful SSA optimization PassNCastSimplification
Alias (byte) main::i#2 = (byte) main::i#3 
Successful SSA optimization Pass2AliasElimination
Self Phi Eliminated (byte) c::i#1
Successful SSA optimization Pass2SelfPhiElimination
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 [20] 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*) SCREEN#0 = (byte*) 1024
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 [18] c::j#1 ← ++ c::j#2 to ++
Resolved ranged comparison value [20] 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 @2
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:3 
Calls in [main] to b:9 
Calls in [b] to c:15 

Created 2 initial phi equivalence classes
Coalesced [13] main::i#4 ← main::i#1
Coalesced [24] c::j#3 ← c::j#1
Coalesced down to 2 phi equivalence classes
Culled Empty Block (label) @2
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()
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
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
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#0 + (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
(byte*) SCREEN
(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 zero page equivalence class [ b::i#0 ]
Added variable c::i#0 to zero page 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 ZP_BYTE:2 [ main::i#2 main::i#1 ]
Allocated zp ZP_BYTE:3 [ c::j#2 c::j#1 ]
Allocated zp ZP_BYTE:4 [ b::i#0 ]
Allocated zp ZP_BYTE:5 [ c::i#0 ]

INITIAL ASM
  // File Comments
  // Basic 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 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 i
    sta 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 i
    // [9] if((byte) main::i#1!=(byte) $65) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #$65
    cmp i
    bne b1_from_b2
    jmp breturn
    // main::@return
  breturn:
    // [10] return 
    rts
}
  // b
// b(byte zeropage(4) i)
b: {
    .label i = 4
    // [11] (byte) c::i#0 ← (byte) b::i#0 -- vbuz1=vbuz2 
    lda i
    sta 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 zeropage(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 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#0 + (byte) c::j#2) ← (byte) c::i#0 -- pbuc1_derefidx_vbuz1=vbuz2 
    lda i
    ldy j
    sta SCREEN,y
    // [17] (byte) c::j#1 ← ++ (byte) c::j#2 -- vbuz1=_inc_vbuz1 
    inc j
    // [18] if((byte) c::j#1!=(byte) $65) goto c::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #$65
    cmp j
    bne b1_from_b1
    jmp breturn
    // c::@return
  breturn:
    // [19] return 
    rts
}
  // File Data

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

REGISTER UPLIFT SCOPES
Uplift Scope [c] 303: zp ZP_BYTE:3 [ c::j#2 c::j#1 ] 17.17: zp ZP_BYTE:5 [ c::i#0 ] 
Uplift Scope [main] 27.5: zp ZP_BYTE:2 [ main::i#2 main::i#1 ] 
Uplift Scope [b] 13: zp ZP_BYTE: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
  // Basic 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#0 + (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 b1_from_b2 with b1
Replacing label b1_from_b1 with b1
Removing instruction b1_from_bbegin:
Removing instruction b1:
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 bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(byte*) SCREEN
(const byte*) SCREEN#0 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
  // Basic 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#0 + (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

