Setting inferred volatile on symbol affected by address-of (byte**~) main::$0 ← & (byte*) main::text
Culled Empty Block (label) main::@5
Culled Empty Block (label) main::@6
Culled Empty Block (label) main::@7
Culled Empty Block (label) main::@8
Culled Empty Block (label) nexttext::@2
Culled Empty Block (label) nexttext::@4

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  to:@1
main: scope:[main]  from @2
  (byte) textid#16 ← phi( @2/(byte) textid#15 )
  (byte*) main::screen#0 ← ((byte*)) (number) $400
  (byte*) main::text#0 ← (byte*) 0
  (byte) main::i#0 ← (byte) 0
  to:main::@1
main::@1: scope:[main]  from main main::@4
  (byte) main::i#6 ← phi( main/(byte) main::i#0 main::@4/(byte) main::i#1 )
  (byte*) main::screen#5 ← phi( main/(byte*) main::screen#0 main::@4/(byte*) main::screen#6 )
  (byte) textid#11 ← phi( main/(byte) textid#16 main::@4/(byte) textid#12 )
  (byte*) main::text#2 ← phi( main/(byte*) main::text#0 main::@4/(byte*) main::text#5 )
  (byte**~) main::$0 ← & (byte*) main::text#2
  (byte**) nexttext::textp#0 ← (byte**~) main::$0
  call nexttext 
  to:main::@9
main::@9: scope:[main]  from main::@1
  (byte) main::i#5 ← phi( main::@1/(byte) main::i#6 )
  (byte*) main::screen#4 ← phi( main::@1/(byte*) main::screen#5 )
  (byte*) main::text#6 ← phi( main::@1/(byte*) main::text#2 )
  (byte) textid#6 ← phi( main::@1/(byte) textid#4 )
  (byte) textid#0 ← (byte) textid#6
  to:main::@2
main::@2: scope:[main]  from main::@3 main::@9
  (byte) textid#17 ← phi( main::@3/(byte) textid#18 main::@9/(byte) textid#0 )
  (byte) main::i#3 ← phi( main::@3/(byte) main::i#4 main::@9/(byte) main::i#5 )
  (byte*) main::screen#3 ← phi( main::@3/(byte*) main::screen#1 main::@9/(byte*) main::screen#4 )
  (byte*) main::text#3 ← phi( main::@3/(byte*) main::text#1 main::@9/(byte*) main::text#6 )
  (bool~) main::$2 ← *((byte*) main::text#3) != (byte) '@'
  if((bool~) main::$2) goto main::@3
  to:main::@4
main::@3: scope:[main]  from main::@2
  (byte) textid#18 ← phi( main::@2/(byte) textid#17 )
  (byte) main::i#4 ← phi( main::@2/(byte) main::i#3 )
  (byte*) main::screen#2 ← phi( main::@2/(byte*) main::screen#3 )
  (byte*) main::text#4 ← phi( main::@2/(byte*) main::text#3 )
  *((byte*) main::screen#2) ← *((byte*) main::text#4)
  (byte*) main::screen#1 ← ++ (byte*) main::screen#2
  (byte*) main::text#1 ← ++ (byte*) main::text#4
  to:main::@2
main::@4: scope:[main]  from main::@2
  (byte*) main::screen#6 ← phi( main::@2/(byte*) main::screen#3 )
  (byte) textid#12 ← phi( main::@2/(byte) textid#17 )
  (byte*) main::text#5 ← phi( main::@2/(byte*) main::text#3 )
  (byte) main::i#2 ← phi( main::@2/(byte) main::i#3 )
  (byte) main::i#1 ← (byte) main::i#2 + rangenext(0,$14)
  (bool~) main::$3 ← (byte) main::i#1 != rangelast(0,$14)
  if((bool~) main::$3) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@4
  (byte) textid#7 ← phi( main::@4/(byte) textid#12 )
  (byte) textid#1 ← (byte) textid#7
  return 
  to:@return
@1: scope:[]  from @begin
  (byte[]) text1#0 ← (const string) $0
  (byte[]) text2#0 ← (const string) $1
  (byte) textid#2 ← (number) 0
  to:@2
nexttext: scope:[nexttext]  from main::@1
  (byte**) nexttext::textp#3 ← phi( main::@1/(byte**) nexttext::textp#0 )
  (byte) textid#8 ← phi( main::@1/(byte) textid#11 )
  (number~) nexttext::$0 ← (byte) textid#8 & (number) 1
  (bool~) nexttext::$1 ← (number~) nexttext::$0 == (number) 0
  (byte) textid#3 ← ++ (byte) textid#8
  if((bool~) nexttext::$1) goto nexttext::@1
  to:nexttext::@3
nexttext::@1: scope:[nexttext]  from nexttext
  (byte) textid#13 ← phi( nexttext/(byte) textid#3 )
  (byte**) nexttext::textp#1 ← phi( nexttext/(byte**) nexttext::textp#3 )
  *((byte**) nexttext::textp#1) ← (byte[]) text1#0
  to:nexttext::@return
nexttext::@3: scope:[nexttext]  from nexttext
  (byte) textid#14 ← phi( nexttext/(byte) textid#3 )
  (byte**) nexttext::textp#2 ← phi( nexttext/(byte**) nexttext::textp#3 )
  *((byte**) nexttext::textp#2) ← (byte[]) text2#0
  to:nexttext::@return
nexttext::@return: scope:[nexttext]  from nexttext::@1 nexttext::@3
  (byte) textid#9 ← phi( nexttext::@1/(byte) textid#13 nexttext::@3/(byte) textid#14 )
  (byte) textid#4 ← (byte) textid#9
  return 
  to:@return
@2: scope:[]  from @1
  (byte) textid#15 ← phi( @1/(byte) textid#2 )
  call main 
  to:@3
@3: scope:[]  from @2
  (byte) textid#10 ← phi( @2/(byte) textid#1 )
  (byte) textid#5 ← (byte) textid#10
  to:@end
@end: scope:[]  from @3

SYMBOL TABLE SSA
(const string) $0 = (string) "camelot @"
(const string) $1 = (string) "rex @"
(label) @1
(label) @2
(label) @3
(label) @begin
(label) @end
(void()) main()
(byte**~) main::$0
(bool~) main::$2
(bool~) main::$3
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@4
(label) main::@9
(label) main::@return
(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::i#5
(byte) main::i#6
(byte*) main::screen
(byte*) main::screen#0
(byte*) main::screen#1
(byte*) main::screen#2
(byte*) main::screen#3
(byte*) main::screen#4
(byte*) main::screen#5
(byte*) main::screen#6
(byte*) main::text
(byte*) main::text#0
(byte*) main::text#1
(byte*) main::text#2
(byte*) main::text#3
(byte*) main::text#4
(byte*) main::text#5
(byte*) main::text#6
(void()) nexttext((byte**) nexttext::textp)
(number~) nexttext::$0
(bool~) nexttext::$1
(label) nexttext::@1
(label) nexttext::@3
(label) nexttext::@return
(byte**) nexttext::textp
(byte**) nexttext::textp#0
(byte**) nexttext::textp#1
(byte**) nexttext::textp#2
(byte**) nexttext::textp#3
(byte[]) text1
(byte[]) text1#0
(byte[]) text2
(byte[]) text2#0
(byte) textid
(byte) textid#0
(byte) textid#1
(byte) textid#10
(byte) textid#11
(byte) textid#12
(byte) textid#13
(byte) textid#14
(byte) textid#15
(byte) textid#16
(byte) textid#17
(byte) textid#18
(byte) textid#2
(byte) textid#3
(byte) textid#4
(byte) textid#5
(byte) textid#6
(byte) textid#7
(byte) textid#8
(byte) textid#9

Adding number conversion cast (unumber) 0 in (byte) textid#2 ← (number) 0
Adding number conversion cast (unumber) 1 in (number~) nexttext::$0 ← (byte) textid#8 & (number) 1
Adding number conversion cast (unumber) nexttext::$0 in (number~) nexttext::$0 ← (byte) textid#8 & (unumber)(number) 1
Adding number conversion cast (unumber) 0 in (bool~) nexttext::$1 ← (unumber~) nexttext::$0 == (number) 0
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte*) main::screen#0 ← (byte*)(number) $400
Inlining cast (byte) textid#2 ← (unumber)(number) 0
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 0
Simplifying constant integer cast 1
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to byte in (unumber~) nexttext::$0 ← (byte) textid#8 & (byte) 1
Alias (byte**) nexttext::textp#0 = (byte**~) main::$0 
Alias (byte*) main::text#2 = (byte*) main::text#6 
Alias (byte*) main::screen#4 = (byte*) main::screen#5 
Alias (byte) main::i#5 = (byte) main::i#6 
Alias (byte) textid#0 = (byte) textid#6 
Alias (byte*) main::text#3 = (byte*) main::text#4 (byte*) main::text#5 
Alias (byte*) main::screen#2 = (byte*) main::screen#3 (byte*) main::screen#6 
Alias (byte) main::i#2 = (byte) main::i#4 (byte) main::i#3 
Alias (byte) textid#1 = (byte) textid#18 (byte) textid#17 (byte) textid#12 (byte) textid#7 
Alias (byte**) nexttext::textp#1 = (byte**) nexttext::textp#3 (byte**) nexttext::textp#2 
Alias (byte) textid#13 = (byte) textid#3 (byte) textid#14 
Alias (byte) textid#4 = (byte) textid#9 
Alias (byte) textid#15 = (byte) textid#2 
Alias (byte) textid#10 = (byte) textid#5 
Successful SSA optimization Pass2AliasElimination
Alias (byte) textid#13 = (byte) textid#4 
Successful SSA optimization Pass2AliasElimination
Self Phi Eliminated (byte) main::i#2
Self Phi Eliminated (byte) textid#1
Successful SSA optimization Pass2SelfPhiElimination
Identical Phi Values (byte) textid#16 (byte) textid#15
Identical Phi Values (byte) textid#0 (byte) textid#13
Identical Phi Values (byte) main::i#2 (byte) main::i#5
Identical Phi Values (byte) textid#1 (byte) textid#0
Identical Phi Values (byte) textid#8 (byte) textid#11
Identical Phi Values (byte**) nexttext::textp#1 (byte**) nexttext::textp#0
Identical Phi Values (byte) textid#10 (byte) textid#1
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition (bool~) main::$2 [12] if(*((byte*) main::text#3)!=(byte) '@') goto main::@3
Simple Condition (bool~) main::$3 [20] if((byte) main::i#1!=rangelast(0,$14)) goto main::@1
Simple Condition (bool~) nexttext::$1 [31] if((byte~) nexttext::$0==(byte) 0) goto nexttext::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant right-side identified [5] (byte**) nexttext::textp#0 ← & (byte*) main::text#2
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const byte*) main::screen#0 = (byte*) 1024
Constant (const byte) main::i#0 = 0
Constant (const byte**) nexttext::textp#0 = &main::text#2
Constant (const byte[]) text1#0 = $0
Constant (const byte[]) text2#0 = $1
Constant (const byte) textid#15 = 0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [18] main::i#1 ← ++ main::i#5 to ++
Resolved ranged comparison value [20] if(main::i#1!=rangelast(0,$14)) goto main::@1 to (number) $15
Adding number conversion cast (unumber) $15 in if((byte) main::i#1!=(number) $15) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast $15
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $15
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining constant with var siblings (const byte*) main::screen#0
Inlining constant with var siblings (const byte) main::i#0
Inlining constant with var siblings (const byte) textid#15
Constant inlined main::screen#0 = (byte*) 1024
Constant inlined main::i#0 = (byte) 0
Constant inlined textid#15 = (byte) 0
Constant inlined $0 = (const byte[]) text1#0
Constant inlined $1 = (const byte[]) text2#0
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@10(between main::@4 and main::@1)
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 @3
Adding NOP phi() at start of @end
CALL GRAPH
Calls in [] to main:3 
Calls in [main] to nexttext:9 

Created 6 initial phi equivalence classes
Coalesced [7] main::text#7 ← main::text#0
Coalesced [10] main::text#10 ← main::text#2
Coalesced [11] main::screen#9 ← main::screen#4
Coalesced (already) [17] main::text#8 ← main::text#3
Coalesced [18] textid#19 ← textid#13
Coalesced (already) [19] main::screen#7 ← main::screen#2
Coalesced [20] main::i#7 ← main::i#1
Coalesced [24] main::text#9 ← main::text#1
Coalesced [25] main::screen#8 ← main::screen#1
Coalesced down to 4 phi equivalence classes
Culled Empty Block (label) @1
Culled Empty Block (label) @3
Culled Empty Block (label) main::@9
Culled Empty Block (label) main::@10
Renumbering block @2 to @1
Renumbering block nexttext::@3 to nexttext::@2
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end

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] (byte*) main::text#0 ← (byte*) 0
  to:main::@1
main::@1: scope:[main]  from main main::@4
  [5] (byte) main::i#5 ← phi( main/(byte) 0 main::@4/(byte) main::i#1 )
  [5] (byte*) main::screen#4 ← phi( main/(byte*) 1024 main::@4/(byte*) main::screen#2 )
  [5] (byte) textid#11 ← phi( main/(byte) 0 main::@4/(byte) textid#13 )
  [5] (byte*) main::text#2 ← phi( main/(byte*) main::text#0 main::@4/(byte*) main::text#3 )
  [6] call nexttext 
  to:main::@2
main::@2: scope:[main]  from main::@1 main::@3
  [7] (byte*) main::screen#2 ← phi( main::@3/(byte*) main::screen#1 main::@1/(byte*) main::screen#4 )
  [7] (byte*) main::text#3 ← phi( main::@3/(byte*) main::text#1 main::@1/(byte*) main::text#2 )
  [8] if(*((byte*) main::text#3)!=(byte) '@') goto main::@3
  to:main::@4
main::@4: scope:[main]  from main::@2
  [9] (byte) main::i#1 ← ++ (byte) main::i#5
  [10] if((byte) main::i#1!=(byte) $15) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@4
  [11] return 
  to:@return
main::@3: scope:[main]  from main::@2
  [12] *((byte*) main::screen#2) ← *((byte*) main::text#3)
  [13] (byte*) main::screen#1 ← ++ (byte*) main::screen#2
  [14] (byte*) main::text#1 ← ++ (byte*) main::text#3
  to:main::@2
nexttext: scope:[nexttext]  from main::@1
  [15] (byte~) nexttext::$0 ← (byte) textid#11 & (byte) 1
  [16] (byte) textid#13 ← ++ (byte) textid#11
  [17] if((byte~) nexttext::$0==(byte) 0) goto nexttext::@1
  to:nexttext::@2
nexttext::@2: scope:[nexttext]  from nexttext
  [18] *((const byte**) nexttext::textp#0) ← (const byte[]) text2#0
  to:nexttext::@return
nexttext::@return: scope:[nexttext]  from nexttext::@1 nexttext::@2
  [19] return 
  to:@return
nexttext::@1: scope:[nexttext]  from nexttext
  [20] *((const byte**) nexttext::textp#0) ← (const byte[]) text1#0
  to:nexttext::@return


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte) main::i
(byte) main::i#1 16.5
(byte) main::i#5 3.142857142857143
(byte*) main::screen
(byte*) main::screen#1 101.0
(byte*) main::screen#2 65.0
(byte*) main::screen#4 11.0
(byte*) main::text
(byte*) main::text#0 4.0
(byte*) main::text#1 202.0
(byte*) main::text#2 12.0
(byte*) main::text#3 70.99999999999999
(void()) nexttext((byte**) nexttext::textp)
(byte~) nexttext::$0 2.0
(byte**) nexttext::textp
(byte[]) text1
(byte[]) text2
(byte) textid
(byte) textid#11 7.5
(byte) textid#13 1.0

Initial phi equivalence classes
[ main::text#2 main::text#0 main::text#3 main::text#1 ]
[ textid#11 textid#13 ]
[ main::screen#4 main::screen#2 main::screen#1 ]
[ main::i#5 main::i#1 ]
Added variable nexttext::$0 to zero page equivalence class [ nexttext::$0 ]
Complete equivalence classes
[ main::text#2 main::text#0 main::text#3 main::text#1 ]
[ textid#11 textid#13 ]
[ main::screen#4 main::screen#2 main::screen#1 ]
[ main::i#5 main::i#1 ]
[ nexttext::$0 ]
Allocated zp ZP_WORD:2 [ main::text#2 main::text#0 main::text#3 main::text#1 ]
Allocated zp ZP_BYTE:4 [ textid#11 textid#13 ]
Allocated zp ZP_WORD:5 [ main::screen#4 main::screen#2 main::screen#1 ]
Allocated zp ZP_BYTE:7 [ main::i#5 main::i#1 ]
Allocated zp ZP_BYTE:8 [ nexttext::$0 ]

INITIAL ASM
  // File Comments
// Tests pointer to pointer in a more complex setup
  // Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label textid = 4
  // @begin
bbegin:
  // [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
  jmp b1
  // @1
b1:
  // [2] call main 
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
  jmp bend
  // @end
bend:
  // main
main: {
    .label text = 2
    .label screen = 5
    .label i = 7
    // [4] (byte*) main::text#0 ← (byte*) 0 -- pbuz1=pbuc1 
    lda #<0
    sta text
    lda #>0
    sta text+1
    // [5] phi from main to main::@1 [phi:main->main::@1]
  b1_from_main:
    // [5] phi (byte) main::i#5 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta i
    // [5] phi (byte*) main::screen#4 = (byte*) 1024 [phi:main->main::@1#1] -- pbuz1=pbuc1 
    lda #<$400
    sta screen
    lda #>$400
    sta screen+1
    // [5] phi (byte) textid#11 = (byte) 0 [phi:main->main::@1#2] -- vbuz1=vbuc1 
    lda #0
    sta textid
    // [5] phi (byte*) main::text#2 = (byte*) main::text#0 [phi:main->main::@1#3] -- register_copy 
    jmp b1
    // [5] phi from main::@4 to main::@1 [phi:main::@4->main::@1]
  b1_from_b4:
    // [5] phi (byte) main::i#5 = (byte) main::i#1 [phi:main::@4->main::@1#0] -- register_copy 
    // [5] phi (byte*) main::screen#4 = (byte*) main::screen#2 [phi:main::@4->main::@1#1] -- register_copy 
    // [5] phi (byte) textid#11 = (byte) textid#13 [phi:main::@4->main::@1#2] -- register_copy 
    // [5] phi (byte*) main::text#2 = (byte*) main::text#3 [phi:main::@4->main::@1#3] -- register_copy 
    jmp b1
    // main::@1
  b1:
    // [6] call nexttext 
    jsr nexttext
    // [7] phi from main::@1 main::@3 to main::@2 [phi:main::@1/main::@3->main::@2]
  b2_from_b1:
  b2_from_b3:
    // [7] phi (byte*) main::screen#2 = (byte*) main::screen#4 [phi:main::@1/main::@3->main::@2#0] -- register_copy 
    // [7] phi (byte*) main::text#3 = (byte*) main::text#2 [phi:main::@1/main::@3->main::@2#1] -- register_copy 
    jmp b2
    // main::@2
  b2:
    // [8] if(*((byte*) main::text#3)!=(byte) '@') goto main::@3 -- _deref_pbuz1_neq_vbuc1_then_la1 
    ldy #0
    lda (text),y
    cmp #'@'
    bne b3
    jmp b4
    // main::@4
  b4:
    // [9] (byte) main::i#1 ← ++ (byte) main::i#5 -- vbuz1=_inc_vbuz1 
    inc i
    // [10] if((byte) main::i#1!=(byte) $15) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #$15
    cmp i
    bne b1_from_b4
    jmp breturn
    // main::@return
  breturn:
    // [11] return 
    rts
    // main::@3
  b3:
    // [12] *((byte*) main::screen#2) ← *((byte*) main::text#3) -- _deref_pbuz1=_deref_pbuz2 
    ldy #0
    lda (text),y
    ldy #0
    sta (screen),y
    // [13] (byte*) main::screen#1 ← ++ (byte*) main::screen#2 -- pbuz1=_inc_pbuz1 
    inc screen
    bne !+
    inc screen+1
  !:
    // [14] (byte*) main::text#1 ← ++ (byte*) main::text#3 -- pbuz1=_inc_pbuz1 
    inc text
    bne !+
    inc text+1
  !:
    jmp b2_from_b3
}
  // nexttext
// Choose the next text to show - by updating the text pointer pointed to by the passed pointer to a pointer
nexttext: {
    .label textp = main.text
    .label _0 = 8
    // [15] (byte~) nexttext::$0 ← (byte) textid#11 & (byte) 1 -- vbuz1=vbuz2_band_vbuc1 
    lda #1
    and textid
    sta _0
    // [16] (byte) textid#13 ← ++ (byte) textid#11 -- vbuz1=_inc_vbuz1 
    inc textid
    // [17] if((byte~) nexttext::$0==(byte) 0) goto nexttext::@1 -- vbuz1_eq_0_then_la1 
    lda _0
    cmp #0
    beq b1
    jmp b2
    // nexttext::@2
  b2:
    // [18] *((const byte**) nexttext::textp#0) ← (const byte[]) text2#0 -- _deref_pptc1=pbuc2 
    lda #<text2
    sta textp
    lda #>text2
    sta textp+1
    jmp breturn
    // nexttext::@return
  breturn:
    // [19] return 
    rts
    // nexttext::@1
  b1:
    // [20] *((const byte**) nexttext::textp#0) ← (const byte[]) text1#0 -- _deref_pptc1=pbuc2 
    lda #<text1
    sta textp
    lda #>text1
    sta textp+1
    jmp breturn
}
  // File Data
  text1: .text "camelot @"
  text2: .text "rex @"

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] (byte*) main::text#0 ← (byte*) 0 [ main::text#0 ] ( main:2 [ main::text#0 ] ) always clobbers reg byte a 
Statement [8] if(*((byte*) main::text#3)!=(byte) '@') goto main::@3 [ main::i#5 main::text#3 textid#13 main::screen#2 ] ( main:2 [ main::i#5 main::text#3 textid#13 main::screen#2 ] ) always clobbers reg byte a reg byte y 
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:7 [ main::i#5 main::i#1 ]
Removing always clobbered register reg byte y as potential for zp ZP_BYTE:7 [ main::i#5 main::i#1 ]
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:4 [ textid#11 textid#13 ]
Removing always clobbered register reg byte y as potential for zp ZP_BYTE:4 [ textid#11 textid#13 ]
Statement [12] *((byte*) main::screen#2) ← *((byte*) main::text#3) [ main::i#5 main::text#3 textid#13 main::screen#2 ] ( main:2 [ main::i#5 main::text#3 textid#13 main::screen#2 ] ) always clobbers reg byte a reg byte y 
Statement [15] (byte~) nexttext::$0 ← (byte) textid#11 & (byte) 1 [ textid#11 nexttext::$0 ] ( main:2::nexttext:6 [ main::text#2 main::screen#4 main::i#5 textid#11 nexttext::$0 ] ) always clobbers reg byte a 
Statement [18] *((const byte**) nexttext::textp#0) ← (const byte[]) text2#0 [ textid#13 ] ( main:2::nexttext:6 [ main::text#2 main::screen#4 main::i#5 textid#13 ] ) always clobbers reg byte a 
Statement [20] *((const byte**) nexttext::textp#0) ← (const byte[]) text1#0 [ textid#13 ] ( main:2::nexttext:6 [ main::text#2 main::screen#4 main::i#5 textid#13 ] ) always clobbers reg byte a 
Statement [4] (byte*) main::text#0 ← (byte*) 0 [ main::text#0 ] ( main:2 [ main::text#0 ] ) always clobbers reg byte a 
Statement [8] if(*((byte*) main::text#3)!=(byte) '@') goto main::@3 [ main::i#5 main::text#3 textid#13 main::screen#2 ] ( main:2 [ main::i#5 main::text#3 textid#13 main::screen#2 ] ) always clobbers reg byte a reg byte y 
Statement [12] *((byte*) main::screen#2) ← *((byte*) main::text#3) [ main::i#5 main::text#3 textid#13 main::screen#2 ] ( main:2 [ main::i#5 main::text#3 textid#13 main::screen#2 ] ) always clobbers reg byte a reg byte y 
Statement [15] (byte~) nexttext::$0 ← (byte) textid#11 & (byte) 1 [ textid#11 nexttext::$0 ] ( main:2::nexttext:6 [ main::text#2 main::screen#4 main::i#5 textid#11 nexttext::$0 ] ) always clobbers reg byte a 
Statement [18] *((const byte**) nexttext::textp#0) ← (const byte[]) text2#0 [ textid#13 ] ( main:2::nexttext:6 [ main::text#2 main::screen#4 main::i#5 textid#13 ] ) always clobbers reg byte a 
Statement [20] *((const byte**) nexttext::textp#0) ← (const byte[]) text1#0 [ textid#13 ] ( main:2::nexttext:6 [ main::text#2 main::screen#4 main::i#5 textid#13 ] ) always clobbers reg byte a 
Potential registers zp ZP_WORD:2 [ main::text#2 main::text#0 main::text#3 main::text#1 ] : zp ZP_WORD:2 , 
Potential registers zp ZP_BYTE:4 [ textid#11 textid#13 ] : zp ZP_BYTE:4 , reg byte x , 
Potential registers zp ZP_WORD:5 [ main::screen#4 main::screen#2 main::screen#1 ] : zp ZP_WORD:5 , 
Potential registers zp ZP_BYTE:7 [ main::i#5 main::i#1 ] : zp ZP_BYTE:7 , reg byte x , 
Potential registers zp ZP_BYTE:8 [ nexttext::$0 ] : zp ZP_BYTE:8 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 289: zp ZP_WORD:2 [ main::text#2 main::text#0 main::text#3 main::text#1 ] 177: zp ZP_WORD:5 [ main::screen#4 main::screen#2 main::screen#1 ] 19.64: zp ZP_BYTE:7 [ main::i#5 main::i#1 ] 
Uplift Scope [] 8.5: zp ZP_BYTE:4 [ textid#11 textid#13 ] 
Uplift Scope [nexttext] 2: zp ZP_BYTE:8 [ nexttext::$0 ] 

Uplifting [main] best 6622 combination zp ZP_WORD:2 [ main::text#2 main::text#0 main::text#3 main::text#1 ] zp ZP_WORD:5 [ main::screen#4 main::screen#2 main::screen#1 ] reg byte x [ main::i#5 main::i#1 ] 
Uplifting [] best 6622 combination zp ZP_BYTE:4 [ textid#11 textid#13 ] 
Uplifting [nexttext] best 6616 combination reg byte a [ nexttext::$0 ] 
Attempting to uplift remaining variables inzp ZP_BYTE:4 [ textid#11 textid#13 ]
Uplifting [] best 6616 combination zp ZP_BYTE:4 [ textid#11 textid#13 ] 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests pointer to pointer in a more complex setup
  // Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label textid = 4
  // @begin
bbegin:
  // [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
  jmp b1
  // @1
b1:
  // [2] call main 
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
  jmp bend
  // @end
bend:
  // main
main: {
    .label text = 2
    .label screen = 5
    // [4] (byte*) main::text#0 ← (byte*) 0 -- pbuz1=pbuc1 
    lda #<0
    sta text
    lda #>0
    sta text+1
    // [5] phi from main to main::@1 [phi:main->main::@1]
  b1_from_main:
    // [5] phi (byte) main::i#5 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // [5] phi (byte*) main::screen#4 = (byte*) 1024 [phi:main->main::@1#1] -- pbuz1=pbuc1 
    lda #<$400
    sta screen
    lda #>$400
    sta screen+1
    // [5] phi (byte) textid#11 = (byte) 0 [phi:main->main::@1#2] -- vbuz1=vbuc1 
    lda #0
    sta textid
    // [5] phi (byte*) main::text#2 = (byte*) main::text#0 [phi:main->main::@1#3] -- register_copy 
    jmp b1
    // [5] phi from main::@4 to main::@1 [phi:main::@4->main::@1]
  b1_from_b4:
    // [5] phi (byte) main::i#5 = (byte) main::i#1 [phi:main::@4->main::@1#0] -- register_copy 
    // [5] phi (byte*) main::screen#4 = (byte*) main::screen#2 [phi:main::@4->main::@1#1] -- register_copy 
    // [5] phi (byte) textid#11 = (byte) textid#13 [phi:main::@4->main::@1#2] -- register_copy 
    // [5] phi (byte*) main::text#2 = (byte*) main::text#3 [phi:main::@4->main::@1#3] -- register_copy 
    jmp b1
    // main::@1
  b1:
    // [6] call nexttext 
    jsr nexttext
    // [7] phi from main::@1 main::@3 to main::@2 [phi:main::@1/main::@3->main::@2]
  b2_from_b1:
  b2_from_b3:
    // [7] phi (byte*) main::screen#2 = (byte*) main::screen#4 [phi:main::@1/main::@3->main::@2#0] -- register_copy 
    // [7] phi (byte*) main::text#3 = (byte*) main::text#2 [phi:main::@1/main::@3->main::@2#1] -- register_copy 
    jmp b2
    // main::@2
  b2:
    // [8] if(*((byte*) main::text#3)!=(byte) '@') goto main::@3 -- _deref_pbuz1_neq_vbuc1_then_la1 
    ldy #0
    lda (text),y
    cmp #'@'
    bne b3
    jmp b4
    // main::@4
  b4:
    // [9] (byte) main::i#1 ← ++ (byte) main::i#5 -- vbuxx=_inc_vbuxx 
    inx
    // [10] if((byte) main::i#1!=(byte) $15) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$15
    bne b1_from_b4
    jmp breturn
    // main::@return
  breturn:
    // [11] return 
    rts
    // main::@3
  b3:
    // [12] *((byte*) main::screen#2) ← *((byte*) main::text#3) -- _deref_pbuz1=_deref_pbuz2 
    ldy #0
    lda (text),y
    ldy #0
    sta (screen),y
    // [13] (byte*) main::screen#1 ← ++ (byte*) main::screen#2 -- pbuz1=_inc_pbuz1 
    inc screen
    bne !+
    inc screen+1
  !:
    // [14] (byte*) main::text#1 ← ++ (byte*) main::text#3 -- pbuz1=_inc_pbuz1 
    inc text
    bne !+
    inc text+1
  !:
    jmp b2_from_b3
}
  // nexttext
// Choose the next text to show - by updating the text pointer pointed to by the passed pointer to a pointer
nexttext: {
    .label textp = main.text
    // [15] (byte~) nexttext::$0 ← (byte) textid#11 & (byte) 1 -- vbuaa=vbuz1_band_vbuc1 
    lda #1
    and textid
    // [16] (byte) textid#13 ← ++ (byte) textid#11 -- vbuz1=_inc_vbuz1 
    inc textid
    // [17] if((byte~) nexttext::$0==(byte) 0) goto nexttext::@1 -- vbuaa_eq_0_then_la1 
    cmp #0
    beq b1
    jmp b2
    // nexttext::@2
  b2:
    // [18] *((const byte**) nexttext::textp#0) ← (const byte[]) text2#0 -- _deref_pptc1=pbuc2 
    lda #<text2
    sta textp
    lda #>text2
    sta textp+1
    jmp breturn
    // nexttext::@return
  breturn:
    // [19] return 
    rts
    // nexttext::@1
  b1:
    // [20] *((const byte**) nexttext::textp#0) ← (const byte[]) text1#0 -- _deref_pptc1=pbuc2 
    lda #<text1
    sta textp
    lda #>text1
    sta textp+1
    jmp breturn
}
  // File Data
  text1: .text "camelot @"
  text2: .text "rex @"

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp b2
Removing instruction jmp b4
Removing instruction jmp breturn
Removing instruction jmp b2
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction lda #>0
Replacing instruction lda #0 with TXA
Removing instruction ldy #0
Succesful ASM optimization Pass5UnnecesaryLoadElimination
Replacing label b1_from_b4 with b1
Replacing label b2_from_b3 with b2
Removing instruction b1_from_bbegin:
Removing instruction b1:
Removing instruction bend_from_b1:
Removing instruction b1_from_b4:
Removing instruction b2_from_b1:
Removing instruction b2_from_b3:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
Removing instruction b1_from_main:
Removing instruction b4:
Removing instruction breturn:
Removing instruction b2:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Replacing jump to rts with rts in jmp breturn
Succesful ASM optimization Pass5DoubleJumpElimination
Removing instruction jmp b1
Succesful ASM optimization Pass5NextJumpElimination
Replacing instruction ldx #0 with TAX
Removing instruction bbegin:
Removing instruction breturn:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(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 x 16.5
(byte) main::i#5 reg byte x 3.142857142857143
(byte*) main::screen
(byte*) main::screen#1 screen zp ZP_WORD:5 101.0
(byte*) main::screen#2 screen zp ZP_WORD:5 65.0
(byte*) main::screen#4 screen zp ZP_WORD:5 11.0
(byte*) main::text
(byte*) main::text#0 text zp ZP_WORD:2 4.0
(byte*) main::text#1 text zp ZP_WORD:2 202.0
(byte*) main::text#2 text zp ZP_WORD:2 12.0
(byte*) main::text#3 text zp ZP_WORD:2 70.99999999999999
(void()) nexttext((byte**) nexttext::textp)
(byte~) nexttext::$0 reg byte a 2.0
(label) nexttext::@1
(label) nexttext::@2
(label) nexttext::@return
(byte**) nexttext::textp
(const byte**) nexttext::textp#0 textp = &(byte*) main::text#2
(byte[]) text1
(const byte[]) text1#0 text1 = (string) "camelot @"
(byte[]) text2
(const byte[]) text2#0 text2 = (string) "rex @"
(byte) textid
(byte) textid#11 textid zp ZP_BYTE:4 7.5
(byte) textid#13 textid zp ZP_BYTE:4 1.0

zp ZP_WORD:2 [ main::text#2 main::text#0 main::text#3 main::text#1 ]
zp ZP_BYTE:4 [ textid#11 textid#13 ]
zp ZP_WORD:5 [ main::screen#4 main::screen#2 main::screen#1 ]
reg byte x [ main::i#5 main::i#1 ]
reg byte a [ nexttext::$0 ]


FINAL ASSEMBLER
Score: 5709

  // File Comments
// Tests pointer to pointer in a more complex setup
  // Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  .label textid = 4
  // @begin
  // [1] phi from @begin to @1 [phi:@begin->@1]
  // @1
  // [2] call main 
  // [3] phi from @1 to @end [phi:@1->@end]
  // @end
  // main
main: {
    .label text = 2
    .label screen = 5
    // text
    // [4] (byte*) main::text#0 ← (byte*) 0 -- pbuz1=pbuc1 
    lda #<0
    sta text
    sta text+1
    // [5] phi from main to main::@1 [phi:main->main::@1]
    // [5] phi (byte) main::i#5 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    tax
    // [5] phi (byte*) main::screen#4 = (byte*) 1024 [phi:main->main::@1#1] -- pbuz1=pbuc1 
    lda #<$400
    sta screen
    lda #>$400
    sta screen+1
    // [5] phi (byte) textid#11 = (byte) 0 [phi:main->main::@1#2] -- vbuz1=vbuc1 
    txa
    sta textid
    // [5] phi (byte*) main::text#2 = (byte*) main::text#0 [phi:main->main::@1#3] -- register_copy 
    // [5] phi from main::@4 to main::@1 [phi:main::@4->main::@1]
    // [5] phi (byte) main::i#5 = (byte) main::i#1 [phi:main::@4->main::@1#0] -- register_copy 
    // [5] phi (byte*) main::screen#4 = (byte*) main::screen#2 [phi:main::@4->main::@1#1] -- register_copy 
    // [5] phi (byte) textid#11 = (byte) textid#13 [phi:main::@4->main::@1#2] -- register_copy 
    // [5] phi (byte*) main::text#2 = (byte*) main::text#3 [phi:main::@4->main::@1#3] -- register_copy 
    // main::@1
  b1:
    // nexttext(&text)
    // [6] call nexttext 
    jsr nexttext
    // [7] phi from main::@1 main::@3 to main::@2 [phi:main::@1/main::@3->main::@2]
    // [7] phi (byte*) main::screen#2 = (byte*) main::screen#4 [phi:main::@1/main::@3->main::@2#0] -- register_copy 
    // [7] phi (byte*) main::text#3 = (byte*) main::text#2 [phi:main::@1/main::@3->main::@2#1] -- register_copy 
    // main::@2
  b2:
    // while(*text!='@')
    // [8] if(*((byte*) main::text#3)!=(byte) '@') goto main::@3 -- _deref_pbuz1_neq_vbuc1_then_la1 
    ldy #0
    lda (text),y
    cmp #'@'
    bne b3
    // main::@4
    // for(byte i: 0..20)
    // [9] (byte) main::i#1 ← ++ (byte) main::i#5 -- vbuxx=_inc_vbuxx 
    inx
    // [10] if((byte) main::i#1!=(byte) $15) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$15
    bne b1
    // main::@return
    // }
    // [11] return 
    rts
    // main::@3
  b3:
    // *screen++ = *text++
    // [12] *((byte*) main::screen#2) ← *((byte*) main::text#3) -- _deref_pbuz1=_deref_pbuz2 
    ldy #0
    lda (text),y
    sta (screen),y
    // *screen++ = *text++;
    // [13] (byte*) main::screen#1 ← ++ (byte*) main::screen#2 -- pbuz1=_inc_pbuz1 
    inc screen
    bne !+
    inc screen+1
  !:
    // [14] (byte*) main::text#1 ← ++ (byte*) main::text#3 -- pbuz1=_inc_pbuz1 
    inc text
    bne !+
    inc text+1
  !:
    jmp b2
}
  // nexttext
// Choose the next text to show - by updating the text pointer pointed to by the passed pointer to a pointer
nexttext: {
    .label textp = main.text
    // textid++&1
    // [15] (byte~) nexttext::$0 ← (byte) textid#11 & (byte) 1 -- vbuaa=vbuz1_band_vbuc1 
    lda #1
    and textid
    // if((textid++&1)==0)
    // [16] (byte) textid#13 ← ++ (byte) textid#11 -- vbuz1=_inc_vbuz1 
    inc textid
    // [17] if((byte~) nexttext::$0==(byte) 0) goto nexttext::@1 -- vbuaa_eq_0_then_la1 
    cmp #0
    beq b1
    // nexttext::@2
    // *textp = text2
    // [18] *((const byte**) nexttext::textp#0) ← (const byte[]) text2#0 -- _deref_pptc1=pbuc2 
    lda #<text2
    sta textp
    lda #>text2
    sta textp+1
    // nexttext::@return
    // }
    // [19] return 
    rts
    // nexttext::@1
  b1:
    // *textp = text1
    // [20] *((const byte**) nexttext::textp#0) ← (const byte[]) text1#0 -- _deref_pptc1=pbuc2 
    lda #<text1
    sta textp
    lda #>text1
    sta textp+1
    rts
}
  // File Data
  text1: .text "camelot @"
  text2: .text "rex @"

