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

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

(void()) main()
main: scope:[main]  from @1
  (byte*) main::nxt#0 ← (const byte*) TEXT
  (byte) main::i#0 ← (byte) 0
  to:main::@1
main::@1: scope:[main]  from main main::@2
  (byte) main::i#3 ← phi( main/(byte) main::i#0 main::@2/(byte) main::i#1 )
  (byte*) main::nxt#3 ← phi( main/(byte*) main::nxt#0 main::@2/(byte*) main::nxt#1 )
  (byte) main::c#0 ← *((byte*) main::nxt#3)
  (bool~) main::$0 ← (byte) main::c#0 == (number) 0
  (bool~) main::$1 ← ! (bool~) main::$0
  if((bool~) main::$1) goto main::@2
  to:main::@3
main::@2: scope:[main]  from main::@1 main::@3
  (byte*) main::nxt#4 ← phi( main::@1/(byte*) main::nxt#3 main::@3/(byte*) main::nxt#2 )
  (byte) main::c#2 ← phi( main::@1/(byte) main::c#0 main::@3/(byte) main::c#1 )
  (byte) main::i#2 ← phi( main::@1/(byte) main::i#3 main::@3/(byte) main::i#4 )
  (byte) main::i#1 ← ++ (byte) main::i#2
  *((const byte*) SCREEN + (byte) main::i#1) ← (byte) main::c#2
  (byte*) main::nxt#1 ← ++ (byte*) main::nxt#4
  if(true) goto main::@1
  to:main::@return
main::@3: scope:[main]  from main::@1
  (byte) main::i#4 ← phi( main::@1/(byte) main::i#3 )
  (byte*) main::nxt#2 ← (const byte*) TEXT
  (byte) main::c#1 ← *((byte*) main::nxt#2)
  to:main::@2
main::@return: scope:[main]  from main::@2
  return 
  to:@return
@1: scope:[]  from @begin
  call main 
  to:@2
@2: scope:[]  from @1
  to:@end
@end: scope:[]  from @2

SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*)(number) $400
(const byte*) TEXT[]  = (string) "01234567"
(void()) main()
(bool~) main::$0
(bool~) main::$1
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@return
(byte) main::c
(byte) main::c#0
(byte) main::c#1
(byte) main::c#2
(byte) main::i
(byte) main::i#0
(byte) main::i#1
(byte) main::i#2
(byte) main::i#3
(byte) main::i#4
(byte*) main::nxt
(byte*) main::nxt#0
(byte*) main::nxt#1
(byte*) main::nxt#2
(byte*) main::nxt#3
(byte*) main::nxt#4

Adding number conversion cast (unumber) 0 in (bool~) main::$0 ← (byte) main::c#0 == (number) 0
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inversing boolean not [5] (bool~) main::$1 ← (byte) main::c#0 != (byte) 0 from [4] (bool~) main::$0 ← (byte) main::c#0 == (byte) 0
Successful SSA optimization Pass2UnaryNotSimplification
Alias (byte) main::i#3 = (byte) main::i#4 
Successful SSA optimization Pass2AliasElimination
Alias (byte) main::i#2 = (byte) main::i#3 
Successful SSA optimization Pass2AliasElimination
Simple Condition (bool~) main::$1 [6] if((byte) main::c#0!=(byte) 0) goto main::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte*) main::nxt#0 = TEXT
Constant (const byte) main::i#0 = 0
Constant (const byte*) main::nxt#2 = TEXT
Successful SSA optimization Pass2ConstantIdentification
if() condition always true - replacing block destination [11] if(true) goto main::@1
Successful SSA optimization Pass2ConstantIfs
Removing unused block main::@return
Successful SSA optimization Pass2EliminateUnusedBlocks
Inlining constant with var siblings (const byte*) main::nxt#0
Inlining constant with var siblings (const byte) main::i#0
Inlining constant with var siblings (const byte*) main::nxt#2
Constant inlined main::i#0 = (byte) 0
Constant inlined main::nxt#0 = (const byte*) TEXT
Constant inlined main::nxt#2 = (const byte*) TEXT
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@5(between main::@1 and main::@2)
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
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 

Created 4 initial phi equivalence classes
Coalesced [10] main::c#4 ← main::c#1
Coalesced [15] main::nxt#5 ← main::nxt#1
Coalesced [16] main::i#5 ← main::i#1
Coalesced [17] main::c#3 ← main::c#0
Coalesced [18] main::nxt#6 ← main::nxt#3
Coalesced down to 3 phi equivalence classes
Culled Empty Block (label) @2
Culled Empty Block (label) main::@5
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::@2
  [5] (byte) main::i#2 ← phi( main/(byte) 0 main::@2/(byte) main::i#1 )
  [5] (byte*) main::nxt#3 ← phi( main/(const byte*) TEXT main::@2/(byte*) main::nxt#1 )
  [6] (byte) main::c#0 ← *((byte*) main::nxt#3)
  [7] if((byte) main::c#0!=(byte) 0) goto main::@2
  to:main::@3
main::@3: scope:[main]  from main::@1
  [8] (byte) main::c#1 ← *((const byte*) TEXT)
  to:main::@2
main::@2: scope:[main]  from main::@1 main::@3
  [9] (byte*) main::nxt#4 ← phi( main::@1/(byte*) main::nxt#3 main::@3/(const byte*) TEXT )
  [9] (byte) main::c#2 ← phi( main::@1/(byte) main::c#0 main::@3/(byte) main::c#1 )
  [10] (byte) main::i#1 ← ++ (byte) main::i#2
  [11] *((const byte*) SCREEN + (byte) main::i#1) ← (byte) main::c#2
  [12] (byte*) main::nxt#1 ← ++ (byte*) main::nxt#4
  to:main::@1


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte) main::c
(byte) main::c#0 16.5
(byte) main::c#1 22.0
(byte) main::c#2 16.5
(byte) main::i
(byte) main::i#1 11.0
(byte) main::i#2 4.4
(byte*) main::nxt
(byte*) main::nxt#1 22.0
(byte*) main::nxt#3 11.0
(byte*) main::nxt#4 7.333333333333333

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
[ main::c#2 main::c#0 main::c#1 ]
[ main::nxt#4 main::nxt#3 main::nxt#1 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ main::c#2 main::c#0 main::c#1 ]
[ main::nxt#4 main::nxt#3 main::nxt#1 ]
Allocated zp[1]:2 [ main::i#2 main::i#1 ]
Allocated zp[1]:3 [ main::c#2 main::c#0 main::c#1 ]
Allocated zp[2]:4 [ main::nxt#4 main::nxt#3 main::nxt#1 ]

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 c = 3
    .label i = 2
    .label nxt = 4
    // [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
    // [5] phi (byte*) main::nxt#3 = (const byte*) TEXT [phi:main->main::@1#1] -- pbuz1=pbuc1 
    lda #<TEXT
    sta.z nxt
    lda #>TEXT
    sta.z nxt+1
    jmp __b1
    // main::@1
  __b1:
    // [6] (byte) main::c#0 ← *((byte*) main::nxt#3) -- vbuz1=_deref_pbuz2 
    ldy #0
    lda (nxt),y
    sta.z c
    // [7] if((byte) main::c#0!=(byte) 0) goto main::@2 -- vbuz1_neq_0_then_la1 
    lda.z c
    cmp #0
    bne __b2_from___b1
    jmp __b3
    // main::@3
  __b3:
    // [8] (byte) main::c#1 ← *((const byte*) TEXT) -- vbuz1=_deref_pbuc1 
    lda TEXT
    sta.z c
    // [9] phi from main::@3 to main::@2 [phi:main::@3->main::@2]
  __b2_from___b3:
    // [9] phi (byte*) main::nxt#4 = (const byte*) TEXT [phi:main::@3->main::@2#0] -- pbuz1=pbuc1 
    lda #<TEXT
    sta.z nxt
    lda #>TEXT
    sta.z nxt+1
    // [9] phi (byte) main::c#2 = (byte) main::c#1 [phi:main::@3->main::@2#1] -- register_copy 
    jmp __b2
    // [9] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  __b2_from___b1:
    // [9] phi (byte*) main::nxt#4 = (byte*) main::nxt#3 [phi:main::@1->main::@2#0] -- register_copy 
    // [9] phi (byte) main::c#2 = (byte) main::c#0 [phi:main::@1->main::@2#1] -- register_copy 
    jmp __b2
    // main::@2
  __b2:
    // [10] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [11] *((const byte*) SCREEN + (byte) main::i#1) ← (byte) main::c#2 -- pbuc1_derefidx_vbuz1=vbuz2 
    lda.z c
    ldy.z i
    sta SCREEN,y
    // [12] (byte*) main::nxt#1 ← ++ (byte*) main::nxt#4 -- pbuz1=_inc_pbuz1 
    inc.z nxt
    bne !+
    inc.z nxt+1
  !:
    // [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 
    // [5] phi (byte*) main::nxt#3 = (byte*) main::nxt#1 [phi:main::@2->main::@1#1] -- register_copy 
    jmp __b1
}
  // File Data
  TEXT: .text "01234567"
  .byte 0

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [6] (byte) main::c#0 ← *((byte*) main::nxt#3) [ main::nxt#3 main::i#2 main::c#0 ] ( main:2 [ main::nxt#3 main::i#2 main::c#0 ] ) always clobbers reg byte a reg byte y 
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 y as potential for zp[1]:2 [ main::i#2 main::i#1 ]
Statement [6] (byte) main::c#0 ← *((byte*) main::nxt#3) [ main::nxt#3 main::i#2 main::c#0 ] ( main:2 [ main::nxt#3 main::i#2 main::c#0 ] ) always clobbers reg byte a reg byte y 
Potential registers zp[1]:2 [ main::i#2 main::i#1 ] : zp[1]:2 , reg byte x , 
Potential registers zp[1]:3 [ main::c#2 main::c#0 main::c#1 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[2]:4 [ main::nxt#4 main::nxt#3 main::nxt#1 ] : zp[2]:4 , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 55: zp[1]:3 [ main::c#2 main::c#0 main::c#1 ] 40.33: zp[2]:4 [ main::nxt#4 main::nxt#3 main::nxt#1 ] 15.4: zp[1]:2 [ main::i#2 main::i#1 ] 
Uplift Scope [] 

Uplifting [main] best 777 combination reg byte y [ main::c#2 main::c#0 main::c#1 ] zp[2]:4 [ main::nxt#4 main::nxt#3 main::nxt#1 ] reg byte x [ main::i#2 main::i#1 ] 
Uplifting [] best 777 combination 
Allocated (was zp[2]:4) zp[2]:2 [ main::nxt#4 main::nxt#3 main::nxt#1 ]

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: {
    .label nxt = 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] -- vbuxx=vbuc1 
    ldx #0
    // [5] phi (byte*) main::nxt#3 = (const byte*) TEXT [phi:main->main::@1#1] -- pbuz1=pbuc1 
    lda #<TEXT
    sta.z nxt
    lda #>TEXT
    sta.z nxt+1
    jmp __b1
    // main::@1
  __b1:
    // [6] (byte) main::c#0 ← *((byte*) main::nxt#3) -- vbuyy=_deref_pbuz1 
    ldy #0
    lda (nxt),y
    tay
    // [7] if((byte) main::c#0!=(byte) 0) goto main::@2 -- vbuyy_neq_0_then_la1 
    cpy #0
    bne __b2_from___b1
    jmp __b3
    // main::@3
  __b3:
    // [8] (byte) main::c#1 ← *((const byte*) TEXT) -- vbuyy=_deref_pbuc1 
    ldy TEXT
    // [9] phi from main::@3 to main::@2 [phi:main::@3->main::@2]
  __b2_from___b3:
    // [9] phi (byte*) main::nxt#4 = (const byte*) TEXT [phi:main::@3->main::@2#0] -- pbuz1=pbuc1 
    lda #<TEXT
    sta.z nxt
    lda #>TEXT
    sta.z nxt+1
    // [9] phi (byte) main::c#2 = (byte) main::c#1 [phi:main::@3->main::@2#1] -- register_copy 
    jmp __b2
    // [9] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  __b2_from___b1:
    // [9] phi (byte*) main::nxt#4 = (byte*) main::nxt#3 [phi:main::@1->main::@2#0] -- register_copy 
    // [9] phi (byte) main::c#2 = (byte) main::c#0 [phi:main::@1->main::@2#1] -- register_copy 
    jmp __b2
    // main::@2
  __b2:
    // [10] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [11] *((const byte*) SCREEN + (byte) main::i#1) ← (byte) main::c#2 -- pbuc1_derefidx_vbuxx=vbuyy 
    tya
    sta SCREEN,x
    // [12] (byte*) main::nxt#1 ← ++ (byte*) main::nxt#4 -- pbuz1=_inc_pbuz1 
    inc.z nxt
    bne !+
    inc.z nxt+1
  !:
    // [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 
    // [5] phi (byte*) main::nxt#3 = (byte*) main::nxt#1 [phi:main::@2->main::@1#1] -- register_copy 
    jmp __b1
}
  // File Data
  TEXT: .text "01234567"
  .byte 0

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __b3
Removing instruction jmp __b2
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Replacing label __b2_from___b1 with __b2
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Removing instruction __b2_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __b1_from_main:
Removing instruction __b3:
Removing instruction __b2_from___b3:
Removing instruction __b1_from___b2:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
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
(const byte*) TEXT[]  = (string) "01234567"
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@3
(byte) main::c
(byte) main::c#0 reg byte y 16.5
(byte) main::c#1 reg byte y 22.0
(byte) main::c#2 reg byte y 16.5
(byte) main::i
(byte) main::i#1 reg byte x 11.0
(byte) main::i#2 reg byte x 4.4
(byte*) main::nxt
(byte*) main::nxt#1 nxt zp[2]:2 22.0
(byte*) main::nxt#3 nxt zp[2]:2 11.0
(byte*) main::nxt#4 nxt zp[2]:2 7.333333333333333

reg byte x [ main::i#2 main::i#1 ]
reg byte y [ main::c#2 main::c#0 main::c#1 ]
zp[2]:2 [ main::nxt#4 main::nxt#3 main::nxt#1 ]


FINAL ASSEMBLER
Score: 645

  // 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: {
    .label nxt = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
    // [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // [5] phi (byte*) main::nxt#3 = (const byte*) TEXT [phi:main->main::@1#1] -- pbuz1=pbuc1 
    lda #<TEXT
    sta.z nxt
    lda #>TEXT
    sta.z nxt+1
    // main::@1
  __b1:
    // c = *nxt
    // [6] (byte) main::c#0 ← *((byte*) main::nxt#3) -- vbuyy=_deref_pbuz1 
    ldy #0
    lda (nxt),y
    tay
    // if(c==0)
    // [7] if((byte) main::c#0!=(byte) 0) goto main::@2 -- vbuyy_neq_0_then_la1 
    cpy #0
    bne __b2
    // main::@3
    // c = *nxt
    // [8] (byte) main::c#1 ← *((const byte*) TEXT) -- vbuyy=_deref_pbuc1 
    ldy TEXT
    // [9] phi from main::@3 to main::@2 [phi:main::@3->main::@2]
    // [9] phi (byte*) main::nxt#4 = (const byte*) TEXT [phi:main::@3->main::@2#0] -- pbuz1=pbuc1 
    lda #<TEXT
    sta.z nxt
    lda #>TEXT
    sta.z nxt+1
    // [9] phi (byte) main::c#2 = (byte) main::c#1 [phi:main::@3->main::@2#1] -- register_copy 
    // [9] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
    // [9] phi (byte*) main::nxt#4 = (byte*) main::nxt#3 [phi:main::@1->main::@2#0] -- register_copy 
    // [9] phi (byte) main::c#2 = (byte) main::c#0 [phi:main::@1->main::@2#1] -- register_copy 
    // main::@2
  __b2:
    // SCREEN[++i] = c;
    // [10] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // SCREEN[++i] = c
    // [11] *((const byte*) SCREEN + (byte) main::i#1) ← (byte) main::c#2 -- pbuc1_derefidx_vbuxx=vbuyy 
    tya
    sta SCREEN,x
    // nxt++;
    // [12] (byte*) main::nxt#1 ← ++ (byte*) main::nxt#4 -- pbuz1=_inc_pbuz1 
    inc.z nxt
    bne !+
    inc.z nxt+1
  !:
    // [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 
    // [5] phi (byte*) main::nxt#3 = (byte*) main::nxt#1 [phi:main::@2->main::@1#1] -- register_copy 
    jmp __b1
}
  // File Data
  TEXT: .text "01234567"
  .byte 0

