
CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  to:@1
main: scope:[main]  from @1
  (byte*) main::screen#0 ← ((byte*)) (word/signed word/dword/signed dword) 1024
  (byte*~) main::$0 ← (byte*) main::screen#0 + (byte/signed byte/word/signed word/dword/signed dword) 80
  (byte) main::a#0 ← *((byte*~) main::$0)
  (byte) main::i#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0
  to:main::@1
main::@1: scope:[main]  from main main::@1
  (byte) main::i#2 ← phi( main/(byte) main::i#0 main::@1/(byte) main::i#1 )
  (byte*) main::screen#1 ← phi( main/(byte*) main::screen#0 main::@1/(byte*) main::screen#1 )
  (byte*~) main::$1 ← (byte*) main::screen#1 + (byte/signed byte/word/signed word/dword/signed dword) 40
  (byte*~) main::$2 ← (byte*~) main::$1 + (byte) main::i#2
  *((byte*) main::screen#1 + (byte) main::i#2) ← *((byte*~) main::$2)
  (byte) main::i#1 ← (byte) main::i#2 + rangenext(0,10)
  (bool~) main::$3 ← (byte) main::i#1 != rangelast(0,10)
  if((bool~) main::$3) goto main::@1
  to:main::@3
main::@3: scope:[main]  from main::@1
  (byte*) main::screen#2 ← phi( main::@1/(byte*) main::screen#1 )
  (byte*~) main::$4 ← (byte*) main::screen#2 + (byte/signed byte/word/signed word/dword/signed dword) 81
  (byte*) main::sc2#0 ← (byte*~) main::$4
  (byte*~) main::$5 ← (byte*) main::screen#2 + (byte/signed byte/word/signed word/dword/signed dword) 121
  *((byte*) main::sc2#0) ← *((byte*~) main::$5)
  (byte*~) main::$6 ← (byte*) main::screen#2 + (byte/signed byte/word/signed word/dword/signed dword) 82
  (byte*~) main::$7 ← (byte*) main::screen#2 + (byte/signed byte/word/signed word/dword/signed dword) 122
  *((byte*~) main::$6) ← *((byte*~) main::$7)
  (byte) main::j#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0
  to:main::@2
main::@2: scope:[main]  from main::@2 main::@3
  (byte) main::j#2 ← phi( main::@2/(byte) main::j#1 main::@3/(byte) main::j#0 )
  (byte*) main::screen#3 ← phi( main::@2/(byte*) main::screen#3 main::@3/(byte*) main::screen#2 )
  (byte*~) main::$8 ← (byte*) main::screen#3 + (byte/word/signed word/dword/signed dword) 160
  (byte*~) main::$9 ← (byte*~) main::$8 + (byte) main::j#2
  (byte*~) main::$10 ← (byte*) main::screen#3 + (byte/word/signed word/dword/signed dword) 200
  (byte*~) main::$11 ← (byte*~) main::$10 + (byte) main::j#2
  *((byte*~) main::$9) ← *((byte*~) main::$11)
  (byte) main::j#1 ← (byte) main::j#2 + rangenext(0,10)
  (bool~) main::$12 ← (byte) main::j#1 != rangelast(0,10)
  if((bool~) main::$12) goto main::@2
  to:main::@4
main::@4: scope:[main]  from main::@2
  (byte*~) main::$13 ← ((byte*)) (word/dword/signed dword) 53280
  *((byte*~) main::$13) ← ++ *((byte*~) main::$13)
  (byte*~) main::$14 ← ((byte*)) (word/dword/signed dword) 53280
  (byte*~) main::$15 ← ((byte*)) (word/dword/signed dword) 53280
  (word/dword/signed dword~) main::$16 ← (word/dword/signed dword) 53248 + (byte/signed byte/word/signed word/dword/signed dword) 33
  (byte*~) main::$17 ← ((byte*)) (word/dword/signed dword~) main::$16
  *((byte*~) main::$17) ← -- *((byte*~) main::$17)
  (word/dword/signed dword~) main::$18 ← (word/dword/signed dword) 53248 + (byte/signed byte/word/signed word/dword/signed dword) 33
  (byte*~) main::$19 ← ((byte*)) (word/dword/signed dword~) main::$18
  (word/dword/signed dword~) main::$20 ← (word/dword/signed dword) 53248 + (byte/signed byte/word/signed word/dword/signed dword) 33
  (byte*~) main::$21 ← ((byte*)) (word/dword/signed dword~) main::$20
  (byte*) main::BGCOL#0 ← ((byte*)) (word/dword/signed dword) 53280
  *((byte*) main::BGCOL#0) ← ++ *((byte*) main::BGCOL#0)
  to:main::@return
main::@return: scope:[main]  from main::@4
  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
(void()) main()
(byte*~) main::$0
(byte*~) main::$1
(byte*~) main::$10
(byte*~) main::$11
(bool~) main::$12
(byte*~) main::$13
(byte*~) main::$14
(byte*~) main::$15
(word/dword/signed dword~) main::$16
(byte*~) main::$17
(word/dword/signed dword~) main::$18
(byte*~) main::$19
(byte*~) main::$2
(word/dword/signed dword~) main::$20
(byte*~) main::$21
(bool~) main::$3
(byte*~) main::$4
(byte*~) main::$5
(byte*~) main::$6
(byte*~) main::$7
(byte*~) main::$8
(byte*~) main::$9
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@4
(label) main::@return
(byte*) main::BGCOL
(byte*) main::BGCOL#0
(byte) main::a
(byte) main::a#0
(byte) main::i
(byte) main::i#0
(byte) main::i#1
(byte) main::i#2
(byte) main::j
(byte) main::j#0
(byte) main::j#1
(byte) main::j#2
(byte*) main::sc2
(byte*) main::sc2#0
(byte*) main::screen
(byte*) main::screen#0
(byte*) main::screen#1
(byte*) main::screen#2
(byte*) main::screen#3

Culled Empty Block (label) @2
Successful SSA optimization Pass2CullEmptyBlocks
Alias (byte*) main::screen#1 = (byte*) main::screen#2 
Alias (byte*) main::sc2#0 = (byte*~) main::$4 
Successful SSA optimization Pass2AliasElimination
Self Phi Eliminated (byte*) main::screen#1
Self Phi Eliminated (byte*) main::screen#3
Successful SSA optimization Pass2SelfPhiElimination
Redundant Phi (byte*) main::screen#1 (byte*) main::screen#0
Redundant Phi (byte*) main::screen#3 (byte*) main::screen#1
Successful SSA optimization Pass2RedundantPhiElimination
Simple Condition (bool~) main::$3 [10] if((byte) main::i#1!=rangelast(0,10)) goto main::@1
Simple Condition (bool~) main::$12 [28] if((byte) main::j#1!=rangelast(0,10)) goto main::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte*) main::screen#0 = ((byte*))1024
Constant (const byte) main::i#0 = 0
Constant (const byte) main::j#0 = 0
Constant (const byte*) main::$13 = ((byte*))53280
Constant (const byte*) main::$14 = ((byte*))53280
Constant (const byte*) main::$15 = ((byte*))53280
Constant (const word/dword/signed dword) main::$16 = 53248+33
Constant (const word/dword/signed dword) main::$18 = 53248+33
Constant (const word/dword/signed dword) main::$20 = 53248+33
Constant (const byte*) main::BGCOL#0 = ((byte*))53280
Successful SSA optimization Pass2ConstantIdentification
Constant (const byte*) main::$0 = main::screen#0+80
Constant (const byte*) main::$1 = main::screen#0+40
Constant (const byte*) main::sc2#0 = main::screen#0+81
Constant (const byte*) main::$5 = main::screen#0+121
Constant (const byte*) main::$6 = main::screen#0+82
Constant (const byte*) main::$7 = main::screen#0+122
Constant (const byte*) main::$8 = main::screen#0+160
Constant (const byte*) main::$10 = main::screen#0+200
Constant (const byte*) main::$17 = ((byte*))main::$16
Constant (const byte*) main::$19 = ((byte*))main::$18
Constant (const byte*) main::$21 = ((byte*))main::$20
Successful SSA optimization Pass2ConstantIdentification
Successful SSA optimization PassNEliminateUnusedVars
Successful SSA optimization PassNEliminateUnusedVars
Resolved ranged next value main::i#1 ← ++ main::i#2 to ++
Resolved ranged comparison value if(main::i#1!=rangelast(0,10)) goto main::@1 to (byte/signed byte/word/signed word/dword/signed dword) 11
Resolved ranged next value main::j#1 ← ++ main::j#2 to ++
Resolved ranged comparison value if(main::j#1!=rangelast(0,10)) goto main::@2 to (byte/signed byte/word/signed word/dword/signed dword) 11
Inlining constant with var siblings (const byte) main::i#0
Inlining constant with var siblings (const byte) main::j#0
Constant inlined main::$16 = (word/dword/signed dword) 53248+(byte/signed byte/word/signed word/dword/signed dword) 33
Constant inlined main::$1 = (const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 40
Constant inlined main::$17 = ((byte*))(word/dword/signed dword) 53248+(byte/signed byte/word/signed word/dword/signed dword) 33
Constant inlined main::$0 = (const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 80
Constant inlined main::$5 = (const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 121
Constant inlined main::i#0 = (byte/signed byte/word/signed word/dword/signed dword) 0
Constant inlined main::$13 = ((byte*))(word/dword/signed dword) 53280
Constant inlined main::$6 = (const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 82
Constant inlined main::j#0 = (byte/signed byte/word/signed word/dword/signed dword) 0
Constant inlined main::$7 = (const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 122
Constant inlined main::$10 = (const byte*) main::screen#0+(byte/word/signed word/dword/signed dword) 200
Constant inlined main::$8 = (const byte*) main::screen#0+(byte/word/signed word/dword/signed dword) 160
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@5(between main::@1 and main::@1)
Added new block during phi lifting main::@6(between main::@2 and main::@2)
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
CALL GRAPH
Calls in [] to main:2 

Created 2 initial phi equivalence classes
Coalesced [22] main::j#3 ← main::j#1
Coalesced [23] main::i#3 ← main::i#1
Coalesced down to 2 phi equivalence classes
Culled Empty Block (label) main::@6
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

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::a#0 ← *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 80)
  to:main::@1
main::@1: scope:[main]  from main main::@1
  [5] (byte) main::i#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@1/(byte) main::i#1 )
  [6] (byte*~) main::$2 ← (const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 40 + (byte) main::i#2
  [7] *((const byte*) main::screen#0 + (byte) main::i#2) ← *((byte*~) main::$2)
  [8] (byte) main::i#1 ← ++ (byte) main::i#2
  [9] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) 11) goto main::@1
  to:main::@3
main::@3: scope:[main]  from main::@1
  [10] *((const byte*) main::sc2#0) ← *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 121)
  [11] *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 82) ← *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 122)
  to:main::@2
main::@2: scope:[main]  from main::@2 main::@3
  [12] (byte) main::j#2 ← phi( main::@2/(byte) main::j#1 main::@3/(byte/signed byte/word/signed word/dword/signed dword) 0 )
  [13] (byte*~) main::$9 ← (const byte*) main::screen#0+(byte/word/signed word/dword/signed dword) 160 + (byte) main::j#2
  [14] (byte*~) main::$11 ← (const byte*) main::screen#0+(byte/word/signed word/dword/signed dword) 200 + (byte) main::j#2
  [15] *((byte*~) main::$9) ← *((byte*~) main::$11)
  [16] (byte) main::j#1 ← ++ (byte) main::j#2
  [17] if((byte) main::j#1!=(byte/signed byte/word/signed word/dword/signed dword) 11) goto main::@2
  to:main::@4
main::@4: scope:[main]  from main::@2
  [18] *(((byte*))(word/dword/signed dword) 53280) ← ++ *(((byte*))(word/dword/signed dword) 53280)
  [19] *(((byte*))(word/dword/signed dword) 53248+(byte/signed byte/word/signed word/dword/signed dword) 33) ← -- *(((byte*))(word/dword/signed dword) 53248+(byte/signed byte/word/signed word/dword/signed dword) 33)
  [20] *((const byte*) main::BGCOL#0) ← ++ *((const byte*) main::BGCOL#0)
  to:main::@return
main::@return: scope:[main]  from main::@4
  [21] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte*~) main::$11 22.0
(byte*~) main::$2 22.0
(byte*~) main::$9 11.0
(byte*) main::BGCOL
(byte) main::a
(byte) main::a#0 20.0
(byte) main::i
(byte) main::i#1 16.5
(byte) main::i#2 14.666666666666666
(byte) main::j
(byte) main::j#1 16.5
(byte) main::j#2 11.0
(byte*) main::sc2
(byte*) main::screen

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
[ main::j#2 main::j#1 ]
Added variable main::a#0 to zero page equivalence class [ main::a#0 ]
Added variable main::$2 to zero page equivalence class [ main::$2 ]
Added variable main::$9 to zero page equivalence class [ main::$9 ]
Added variable main::$11 to zero page equivalence class [ main::$11 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ main::j#2 main::j#1 ]
[ main::a#0 ]
[ main::$2 ]
[ main::$9 ]
[ main::$11 ]
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 [ main::a#0 ]
Allocated zp ZP_WORD:5 [ main::$2 ]
Allocated zp ZP_WORD:7 [ main::$9 ]
Allocated zp ZP_WORD:9 [ main::$11 ]

INITIAL ASM
//SEG0 File Comments
// Test some complex pointers
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
//SEG3 @begin
bbegin:
//SEG4 [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
  jmp b1
//SEG5 @1
b1:
//SEG6 [2] call main 
  jsr main
//SEG7 [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
  jmp bend
//SEG8 @end
bend:
//SEG9 main
main: {
    // RValue pointer expression (constant)
    .label screen = $400
    // Increment on a const named pointer
    .label BGCOL = $d020
    .label sc2 = screen+$51
    .label _2 = 5
    .label _9 = 7
    .label _11 = 9
    .label a = 4
    .label i = 2
    .label j = 3
  //SEG10 [4] (byte) main::a#0 ← *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 80) -- vbuz1=_deref_pbuc1 
    lda screen+$50
    sta a
  //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
  // RValue pointer expression (variable)
  //SEG13 [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  b1_from_b1:
  //SEG14 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    jmp b1
  //SEG15 main::@1
  b1:
  //SEG16 [6] (byte*~) main::$2 ← (const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 40 + (byte) main::i#2 -- pbuz1=pbuc1_plus_vbuz2 
    lda i
    clc
    adc #<screen+$28
    sta _2
    lda #>screen+$28
    adc #0
    sta _2+1
  //SEG17 [7] *((const byte*) main::screen#0 + (byte) main::i#2) ← *((byte*~) main::$2) -- pbuc1_derefidx_vbuz1=_deref_pbuz2 
    ldx i
    ldy #0
    lda (_2),y
    sta screen,x
  //SEG18 [8] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc i
  //SEG19 [9] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) 11) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda i
    cmp #$b
    bne b1_from_b1
    jmp b3
  //SEG20 main::@3
  b3:
  //SEG21 [10] *((const byte*) main::sc2#0) ← *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 121) -- _deref_pbuc1=_deref_pbuc2 
    lda screen+$79
    sta sc2
  //SEG22 [11] *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 82) ← *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 122) -- _deref_pbuc1=_deref_pbuc2 
    // LValue pointer expression (constant - directly)
    lda screen+$7a
    sta screen+$52
  //SEG23 [12] phi from main::@3 to main::@2 [phi:main::@3->main::@2]
  b2_from_b3:
  //SEG24 [12] phi (byte) main::j#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main::@3->main::@2#0] -- vbuz1=vbuc1 
    lda #0
    sta j
    jmp b2
  // LValue pointer expression (variable - directly)
  //SEG25 [12] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
  b2_from_b2:
  //SEG26 [12] phi (byte) main::j#2 = (byte) main::j#1 [phi:main::@2->main::@2#0] -- register_copy 
    jmp b2
  //SEG27 main::@2
  b2:
  //SEG28 [13] (byte*~) main::$9 ← (const byte*) main::screen#0+(byte/word/signed word/dword/signed dword) 160 + (byte) main::j#2 -- pbuz1=pbuc1_plus_vbuz2 
    lda j
    clc
    adc #<screen+$a0
    sta _9
    lda #>screen+$a0
    adc #0
    sta _9+1
  //SEG29 [14] (byte*~) main::$11 ← (const byte*) main::screen#0+(byte/word/signed word/dword/signed dword) 200 + (byte) main::j#2 -- pbuz1=pbuc1_plus_vbuz2 
    lda j
    clc
    adc #<screen+$c8
    sta _11
    lda #>screen+$c8
    adc #0
    sta _11+1
  //SEG30 [15] *((byte*~) main::$9) ← *((byte*~) main::$11) -- _deref_pbuz1=_deref_pbuz2 
    ldy #0
    lda (_11),y
    ldy #0
    sta (_9),y
  //SEG31 [16] (byte) main::j#1 ← ++ (byte) main::j#2 -- vbuz1=_inc_vbuz1 
    inc j
  //SEG32 [17] if((byte) main::j#1!=(byte/signed byte/word/signed word/dword/signed dword) 11) goto main::@2 -- vbuz1_neq_vbuc1_then_la1 
    lda j
    cmp #$b
    bne b2_from_b2
    jmp b4
  //SEG33 main::@4
  b4:
  //SEG34 [18] *(((byte*))(word/dword/signed dword) 53280) ← ++ *(((byte*))(word/dword/signed dword) 53280) -- _deref_pbuc1=_inc__deref_pbuc1 
    inc $d020
  //SEG35 [19] *(((byte*))(word/dword/signed dword) 53248+(byte/signed byte/word/signed word/dword/signed dword) 33) ← -- *(((byte*))(word/dword/signed dword) 53248+(byte/signed byte/word/signed word/dword/signed dword) 33) -- _deref_pbuc1=_dec__deref_pbuc1 
    dec $d000+$21
  //SEG36 [20] *((const byte*) main::BGCOL#0) ← ++ *((const byte*) main::BGCOL#0) -- _deref_pbuc1=_inc__deref_pbuc1 
    inc BGCOL
    jmp breturn
  //SEG37 main::@return
  breturn:
  //SEG38 [21] return 
    rts
}

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [6] (byte*~) main::$2 ← (const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 40 + (byte) main::i#2 [ main::i#2 main::$2 ] ( main:2 [ main::i#2 main::$2 ] ) 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 ]
Statement [7] *((const byte*) main::screen#0 + (byte) main::i#2) ← *((byte*~) main::$2) [ main::i#2 ] ( main:2 [ main::i#2 ] ) always clobbers reg byte a reg byte y 
Removing always clobbered register reg byte y as potential for zp ZP_BYTE:2 [ main::i#2 main::i#1 ]
Statement [10] *((const byte*) main::sc2#0) ← *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 121) [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [11] *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 82) ← *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 122) [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [13] (byte*~) main::$9 ← (const byte*) main::screen#0+(byte/word/signed word/dword/signed dword) 160 + (byte) main::j#2 [ main::j#2 main::$9 ] ( main:2 [ main::j#2 main::$9 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:3 [ main::j#2 main::j#1 ]
Statement [14] (byte*~) main::$11 ← (const byte*) main::screen#0+(byte/word/signed word/dword/signed dword) 200 + (byte) main::j#2 [ main::j#2 main::$9 main::$11 ] ( main:2 [ main::j#2 main::$9 main::$11 ] ) always clobbers reg byte a 
Statement [15] *((byte*~) main::$9) ← *((byte*~) main::$11) [ main::j#2 ] ( main:2 [ main::j#2 ] ) always clobbers reg byte a reg byte y 
Removing always clobbered register reg byte y as potential for zp ZP_BYTE:3 [ main::j#2 main::j#1 ]
Statement [6] (byte*~) main::$2 ← (const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 40 + (byte) main::i#2 [ main::i#2 main::$2 ] ( main:2 [ main::i#2 main::$2 ] ) always clobbers reg byte a 
Statement [7] *((const byte*) main::screen#0 + (byte) main::i#2) ← *((byte*~) main::$2) [ main::i#2 ] ( main:2 [ main::i#2 ] ) always clobbers reg byte a reg byte y 
Statement [10] *((const byte*) main::sc2#0) ← *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 121) [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [11] *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 82) ← *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 122) [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [13] (byte*~) main::$9 ← (const byte*) main::screen#0+(byte/word/signed word/dword/signed dword) 160 + (byte) main::j#2 [ main::j#2 main::$9 ] ( main:2 [ main::j#2 main::$9 ] ) always clobbers reg byte a 
Statement [14] (byte*~) main::$11 ← (const byte*) main::screen#0+(byte/word/signed word/dword/signed dword) 200 + (byte) main::j#2 [ main::j#2 main::$9 main::$11 ] ( main:2 [ main::j#2 main::$9 main::$11 ] ) always clobbers reg byte a 
Statement [15] *((byte*~) main::$9) ← *((byte*~) main::$11) [ main::j#2 ] ( main:2 [ main::j#2 ] ) always clobbers reg byte a reg byte y 
Potential registers zp ZP_BYTE:2 [ main::i#2 main::i#1 ] : zp ZP_BYTE:2 , reg byte x , 
Potential registers zp ZP_BYTE:3 [ main::j#2 main::j#1 ] : zp ZP_BYTE:3 , reg byte x , 
Potential registers zp ZP_BYTE:4 [ main::a#0 ] : zp ZP_BYTE:4 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_WORD:5 [ main::$2 ] : zp ZP_WORD:5 , 
Potential registers zp ZP_WORD:7 [ main::$9 ] : zp ZP_WORD:7 , 
Potential registers zp ZP_WORD:9 [ main::$11 ] : zp ZP_WORD:9 , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 31.17: zp ZP_BYTE:2 [ main::i#2 main::i#1 ] 27.5: zp ZP_BYTE:3 [ main::j#2 main::j#1 ] 22: zp ZP_WORD:5 [ main::$2 ] 22: zp ZP_WORD:9 [ main::$11 ] 20: zp ZP_BYTE:4 [ main::a#0 ] 11: zp ZP_WORD:7 [ main::$9 ] 
Uplift Scope [] 

Uplifting [main] best 1169 combination reg byte x [ main::i#2 main::i#1 ] reg byte x [ main::j#2 main::j#1 ] zp ZP_WORD:5 [ main::$2 ] zp ZP_WORD:9 [ main::$11 ] reg byte a [ main::a#0 ] zp ZP_WORD:7 [ main::$9 ] 
Uplifting [] best 1169 combination 
Coalescing zero page register [ zp ZP_WORD:5 [ main::$2 ] ] with [ zp ZP_WORD:7 [ main::$9 ] ]
Allocated (was zp ZP_WORD:5) zp ZP_WORD:2 [ main::$2 main::$9 ]
Allocated (was zp ZP_WORD:9) zp ZP_WORD:4 [ main::$11 ]

ASSEMBLER BEFORE OPTIMIZATION
//SEG0 File Comments
// Test some complex pointers
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
//SEG3 @begin
bbegin:
//SEG4 [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
  jmp b1
//SEG5 @1
b1:
//SEG6 [2] call main 
  jsr main
//SEG7 [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
  jmp bend
//SEG8 @end
bend:
//SEG9 main
main: {
    // RValue pointer expression (constant)
    .label screen = $400
    // Increment on a const named pointer
    .label BGCOL = $d020
    .label sc2 = screen+$51
    .label _2 = 2
    .label _9 = 2
    .label _11 = 4
  //SEG10 [4] (byte) main::a#0 ← *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 80) -- vbuaa=_deref_pbuc1 
    lda screen+$50
  //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
  // RValue pointer expression (variable)
  //SEG13 [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  b1_from_b1:
  //SEG14 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    jmp b1
  //SEG15 main::@1
  b1:
  //SEG16 [6] (byte*~) main::$2 ← (const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 40 + (byte) main::i#2 -- pbuz1=pbuc1_plus_vbuxx 
    txa
    clc
    adc #<screen+$28
    sta _2
    lda #>screen+$28
    adc #0
    sta _2+1
  //SEG17 [7] *((const byte*) main::screen#0 + (byte) main::i#2) ← *((byte*~) main::$2) -- pbuc1_derefidx_vbuxx=_deref_pbuz1 
    ldy #0
    lda (_2),y
    sta screen,x
  //SEG18 [8] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx 
    inx
  //SEG19 [9] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) 11) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$b
    bne b1_from_b1
    jmp b3
  //SEG20 main::@3
  b3:
  //SEG21 [10] *((const byte*) main::sc2#0) ← *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 121) -- _deref_pbuc1=_deref_pbuc2 
    lda screen+$79
    sta sc2
  //SEG22 [11] *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 82) ← *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 122) -- _deref_pbuc1=_deref_pbuc2 
    // LValue pointer expression (constant - directly)
    lda screen+$7a
    sta screen+$52
  //SEG23 [12] phi from main::@3 to main::@2 [phi:main::@3->main::@2]
  b2_from_b3:
  //SEG24 [12] phi (byte) main::j#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main::@3->main::@2#0] -- vbuxx=vbuc1 
    ldx #0
    jmp b2
  // LValue pointer expression (variable - directly)
  //SEG25 [12] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
  b2_from_b2:
  //SEG26 [12] phi (byte) main::j#2 = (byte) main::j#1 [phi:main::@2->main::@2#0] -- register_copy 
    jmp b2
  //SEG27 main::@2
  b2:
  //SEG28 [13] (byte*~) main::$9 ← (const byte*) main::screen#0+(byte/word/signed word/dword/signed dword) 160 + (byte) main::j#2 -- pbuz1=pbuc1_plus_vbuxx 
    txa
    clc
    adc #<screen+$a0
    sta _9
    lda #>screen+$a0
    adc #0
    sta _9+1
  //SEG29 [14] (byte*~) main::$11 ← (const byte*) main::screen#0+(byte/word/signed word/dword/signed dword) 200 + (byte) main::j#2 -- pbuz1=pbuc1_plus_vbuxx 
    txa
    clc
    adc #<screen+$c8
    sta _11
    lda #>screen+$c8
    adc #0
    sta _11+1
  //SEG30 [15] *((byte*~) main::$9) ← *((byte*~) main::$11) -- _deref_pbuz1=_deref_pbuz2 
    ldy #0
    lda (_11),y
    ldy #0
    sta (_9),y
  //SEG31 [16] (byte) main::j#1 ← ++ (byte) main::j#2 -- vbuxx=_inc_vbuxx 
    inx
  //SEG32 [17] if((byte) main::j#1!=(byte/signed byte/word/signed word/dword/signed dword) 11) goto main::@2 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$b
    bne b2_from_b2
    jmp b4
  //SEG33 main::@4
  b4:
  //SEG34 [18] *(((byte*))(word/dword/signed dword) 53280) ← ++ *(((byte*))(word/dword/signed dword) 53280) -- _deref_pbuc1=_inc__deref_pbuc1 
    inc $d020
  //SEG35 [19] *(((byte*))(word/dword/signed dword) 53248+(byte/signed byte/word/signed word/dword/signed dword) 33) ← -- *(((byte*))(word/dword/signed dword) 53248+(byte/signed byte/word/signed word/dword/signed dword) 33) -- _deref_pbuc1=_dec__deref_pbuc1 
    dec $d000+$21
  //SEG36 [20] *((const byte*) main::BGCOL#0) ← ++ *((const byte*) main::BGCOL#0) -- _deref_pbuc1=_inc__deref_pbuc1 
    inc BGCOL
    jmp breturn
  //SEG37 main::@return
  breturn:
  //SEG38 [21] return 
    rts
}

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp b3
Removing instruction jmp b2
Removing instruction jmp b4
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction ldy #0
Succesful ASM optimization Pass5UnnecesaryLoadElimination
Replacing label b1_from_b1 with b1
Replacing label b2_from_b2 with b2
Removing instruction b1_from_bbegin:
Removing instruction b1:
Removing instruction bend_from_b1:
Removing instruction b1_from_b1:
Removing instruction b2_from_b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
Removing instruction b1_from_main:
Removing instruction b3:
Removing instruction b2_from_b3:
Removing instruction b4:
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) @1
(label) @begin
(label) @end
(void()) main()
(byte*~) main::$11 $11 zp ZP_WORD:4 22.0
(byte*~) main::$2 $2 zp ZP_WORD:2 22.0
(byte*~) main::$9 $9 zp ZP_WORD:2 11.0
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@4
(label) main::@return
(byte*) main::BGCOL
(const byte*) main::BGCOL#0 BGCOL = ((byte*))(word/dword/signed dword) 53280
(byte) main::a
(byte) main::a#0 reg byte a 20.0
(byte) main::i
(byte) main::i#1 reg byte x 16.5
(byte) main::i#2 reg byte x 14.666666666666666
(byte) main::j
(byte) main::j#1 reg byte x 16.5
(byte) main::j#2 reg byte x 11.0
(byte*) main::sc2
(const byte*) main::sc2#0 sc2 = (const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 81
(byte*) main::screen
(const byte*) main::screen#0 screen = ((byte*))(word/signed word/dword/signed dword) 1024

reg byte x [ main::i#2 main::i#1 ]
reg byte x [ main::j#2 main::j#1 ]
reg byte a [ main::a#0 ]
zp ZP_WORD:2 [ main::$2 main::$9 ]
zp ZP_WORD:4 [ main::$11 ]


FINAL ASSEMBLER
Score: 954

//SEG0 File Comments
// Test some complex pointers
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG2 Global Constants & labels
//SEG3 @begin
//SEG4 [1] phi from @begin to @1 [phi:@begin->@1]
//SEG5 @1
//SEG6 [2] call main 
//SEG7 [3] phi from @1 to @end [phi:@1->@end]
//SEG8 @end
//SEG9 main
main: {
    // RValue pointer expression (constant)
    .label screen = $400
    // Increment on a const named pointer
    .label BGCOL = $d020
    .label sc2 = screen+$51
    .label _2 = 2
    .label _9 = 2
    .label _11 = 4
  //SEG10 [4] (byte) main::a#0 ← *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 80) -- vbuaa=_deref_pbuc1 
    lda screen+$50
  //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
  // RValue pointer expression (variable)
  //SEG13 [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  //SEG14 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
  //SEG15 main::@1
  b1:
  //SEG16 [6] (byte*~) main::$2 ← (const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 40 + (byte) main::i#2 -- pbuz1=pbuc1_plus_vbuxx 
    txa
    clc
    adc #<screen+$28
    sta _2
    lda #>screen+$28
    adc #0
    sta _2+1
  //SEG17 [7] *((const byte*) main::screen#0 + (byte) main::i#2) ← *((byte*~) main::$2) -- pbuc1_derefidx_vbuxx=_deref_pbuz1 
    ldy #0
    lda (_2),y
    sta screen,x
  //SEG18 [8] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx 
    inx
  //SEG19 [9] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) 11) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$b
    bne b1
  //SEG20 main::@3
  //SEG21 [10] *((const byte*) main::sc2#0) ← *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 121) -- _deref_pbuc1=_deref_pbuc2 
    lda screen+$79
    sta sc2
  //SEG22 [11] *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 82) ← *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 122) -- _deref_pbuc1=_deref_pbuc2 
    // LValue pointer expression (constant - directly)
    lda screen+$7a
    sta screen+$52
  //SEG23 [12] phi from main::@3 to main::@2 [phi:main::@3->main::@2]
  //SEG24 [12] phi (byte) main::j#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main::@3->main::@2#0] -- vbuxx=vbuc1 
    ldx #0
  // LValue pointer expression (variable - directly)
  //SEG25 [12] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
  //SEG26 [12] phi (byte) main::j#2 = (byte) main::j#1 [phi:main::@2->main::@2#0] -- register_copy 
  //SEG27 main::@2
  b2:
  //SEG28 [13] (byte*~) main::$9 ← (const byte*) main::screen#0+(byte/word/signed word/dword/signed dword) 160 + (byte) main::j#2 -- pbuz1=pbuc1_plus_vbuxx 
    txa
    clc
    adc #<screen+$a0
    sta _9
    lda #>screen+$a0
    adc #0
    sta _9+1
  //SEG29 [14] (byte*~) main::$11 ← (const byte*) main::screen#0+(byte/word/signed word/dword/signed dword) 200 + (byte) main::j#2 -- pbuz1=pbuc1_plus_vbuxx 
    txa
    clc
    adc #<screen+$c8
    sta _11
    lda #>screen+$c8
    adc #0
    sta _11+1
  //SEG30 [15] *((byte*~) main::$9) ← *((byte*~) main::$11) -- _deref_pbuz1=_deref_pbuz2 
    ldy #0
    lda (_11),y
    sta (_9),y
  //SEG31 [16] (byte) main::j#1 ← ++ (byte) main::j#2 -- vbuxx=_inc_vbuxx 
    inx
  //SEG32 [17] if((byte) main::j#1!=(byte/signed byte/word/signed word/dword/signed dword) 11) goto main::@2 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$b
    bne b2
  //SEG33 main::@4
  //SEG34 [18] *(((byte*))(word/dword/signed dword) 53280) ← ++ *(((byte*))(word/dword/signed dword) 53280) -- _deref_pbuc1=_inc__deref_pbuc1 
    inc $d020
  //SEG35 [19] *(((byte*))(word/dword/signed dword) 53248+(byte/signed byte/word/signed word/dword/signed dword) 33) ← -- *(((byte*))(word/dword/signed dword) 53248+(byte/signed byte/word/signed word/dword/signed dword) 33) -- _deref_pbuc1=_dec__deref_pbuc1 
    dec $d000+$21
  //SEG36 [20] *((const byte*) main::BGCOL#0) ← ++ *((const byte*) main::BGCOL#0) -- _deref_pbuc1=_inc__deref_pbuc1 
    inc BGCOL
  //SEG37 main::@return
  //SEG38 [21] return 
    rts
}

