Culled Empty Block (label) main::@4
Culled Empty Block (label) main::@5
Culled Empty Block (label) main::@6
Culled Empty Block (label) main::@10
Culled Empty Block (label) main::@9
Culled Empty Block (label) main::@11
Culled Empty Block (label) main::@12

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

(void()) main()
main: scope:[main]  from @1
  (byte*) main::sc#0 ← (const byte*) main::screen
  to:main::@1
main::@1: scope:[main]  from main main::@2
  (byte*) main::sc#2 ← phi( main/(byte*) main::sc#0 main::@2/(byte*) main::sc#1 )
  (bool~) main::$0 ← (byte*) main::sc#2 <= (const byte*) main::screen+(number) $3e7
  if((bool~) main::$0) goto main::@2
  to:main::@3
main::@2: scope:[main]  from main::@1
  (byte*) main::sc#3 ← phi( main::@1/(byte*) main::sc#2 )
  *((byte*) main::sc#3) ← (byte) 'a'
  (byte*) main::sc#1 ← ++ (byte*) main::sc#3
  to:main::@1
main::@3: scope:[main]  from main::@1
  (byte*) main::cc#0 ← (const byte*) main::cols+(number) $3e7
  to:main::@7
main::@7: scope:[main]  from main::@3 main::@8
  (byte*) main::cc#2 ← phi( main::@3/(byte*) main::cc#0 main::@8/(byte*) main::cc#1 )
  (bool~) main::$1 ← (byte*) main::cc#2 > (const byte*) main::cols-(number) 1
  if((bool~) main::$1) goto main::@8
  to:main::@return
main::@8: scope:[main]  from main::@7
  (byte*) main::cc#3 ← phi( main::@7/(byte*) main::cc#2 )
  *((byte*) main::cc#3) ← (number) 2
  (byte*) main::cc#1 ← -- (byte*) main::cc#3
  to:main::@7
main::@return: scope:[main]  from main::@7
  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()
(bool~) main::$0
(bool~) main::$1
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@7
(label) main::@8
(label) main::@return
(byte*) main::cc
(byte*) main::cc#0
(byte*) main::cc#1
(byte*) main::cc#2
(byte*) main::cc#3
(const byte*) main::cols = (byte*)(number) $d800
(byte*) main::sc
(byte*) main::sc#0
(byte*) main::sc#1
(byte*) main::sc#2
(byte*) main::sc#3
(const byte*) main::screen = (byte*)(number) $400

Adding number conversion cast (unumber) $3e7 in (bool~) main::$0 ← (byte*) main::sc#2 <= (const byte*) main::screen+(number) $3e7
Adding number conversion cast (unumber) $3e7 in (byte*) main::cc#0 ← (const byte*) main::cols+(number) $3e7
Adding number conversion cast (unumber) 1 in (bool~) main::$1 ← (byte*) main::cc#2 > (const byte*) main::cols-(number) 1
Adding number conversion cast (unumber) 2 in *((byte*) main::cc#3) ← (number) 2
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast *((byte*) main::cc#3) ← (unumber)(number) 2
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Simplifying constant pointer cast (byte*) 55296
Simplifying constant integer cast $3e7
Simplifying constant integer cast $3e7
Simplifying constant integer cast 1
Simplifying constant integer cast 2
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (word) $3e7
Finalized unsigned number type (word) $3e7
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) 2
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias (byte*) main::sc#2 = (byte*) main::sc#3 
Alias (byte*) main::cc#2 = (byte*) main::cc#3 
Successful SSA optimization Pass2AliasElimination
Simple Condition (bool~) main::$0 [3] if((byte*) main::sc#2<=(const byte*) main::screen+(word) $3e7) goto main::@2
Simple Condition (bool~) main::$1 [10] if((byte*) main::cc#2>(const byte*) main::cols-(byte) 1) goto main::@8
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte*) main::sc#0 = main::screen
Constant (const byte*) main::cc#0 = main::cols+$3e7
Successful SSA optimization Pass2ConstantIdentification
Inlining constant with var siblings (const byte*) main::sc#0
Inlining constant with var siblings (const byte*) main::cc#0
Constant inlined main::sc#0 = (const byte*) main::screen
Constant inlined main::cc#0 = (const byte*) main::cols+(word) $3e7
Successful SSA optimization Pass2ConstantInlining
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
Adding NOP phi() at start of main::@3
CALL GRAPH
Calls in [] to main:2 

Created 2 initial phi equivalence classes
Coalesced [14] main::cc#4 ← main::cc#1
Coalesced [17] main::sc#4 ← main::sc#1
Coalesced down to 2 phi equivalence classes
Culled Empty Block (label) @2
Culled Empty Block (label) main::@3
Renumbering block main::@7 to main::@3
Renumbering block main::@8 to main::@4
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::sc#2 ← phi( main/(const byte*) main::screen main::@2/(byte*) main::sc#1 )
  [6] if((byte*) main::sc#2<=(const byte*) main::screen+(word) $3e7) goto main::@2
  to:main::@3
main::@3: scope:[main]  from main::@1 main::@4
  [7] (byte*) main::cc#2 ← phi( main::@1/(const byte*) main::cols+(word) $3e7 main::@4/(byte*) main::cc#1 )
  [8] if((byte*) main::cc#2>(const byte*) main::cols-(byte) 1) goto main::@4
  to:main::@return
main::@return: scope:[main]  from main::@3
  [9] return 
  to:@return
main::@4: scope:[main]  from main::@3
  [10] *((byte*) main::cc#2) ← (byte) 2
  [11] (byte*) main::cc#1 ← -- (byte*) main::cc#2
  to:main::@3
main::@2: scope:[main]  from main::@1
  [12] *((byte*) main::sc#2) ← (byte) 'a'
  [13] (byte*) main::sc#1 ← ++ (byte*) main::sc#2
  to:main::@1


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte*) main::cc
(byte*) main::cc#1 22.0
(byte*) main::cc#2 14.666666666666666
(byte*) main::sc
(byte*) main::sc#1 22.0
(byte*) main::sc#2 14.666666666666666

Initial phi equivalence classes
[ main::sc#2 main::sc#1 ]
[ main::cc#2 main::cc#1 ]
Complete equivalence classes
[ main::sc#2 main::sc#1 ]
[ main::cc#2 main::cc#1 ]
Allocated zp[2]:2 [ main::sc#2 main::sc#1 ]
Allocated zp[2]:4 [ main::cc#2 main::cc#1 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Test rewriting of constant comparisons for pointers
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  // @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 screen = $400
    .label cols = $d800
    .label sc = 2
    .label cc = 4
    // [5] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [5] phi (byte*) main::sc#2 = (const byte*) main::screen [phi:main->main::@1#0] -- pbuz1=pbuc1 
    lda #<screen
    sta.z sc
    lda #>screen
    sta.z sc+1
    jmp __b1
    // main::@1
  __b1:
    // [6] if((byte*) main::sc#2<=(const byte*) main::screen+(word) $3e7) goto main::@2 -- pbuz1_le_pbuc1_then_la1 
    lda.z sc+1
    cmp #>screen+$3e7
    bne !+
    lda.z sc
    cmp #<screen+$3e7
  !:
    bcc __b2
    beq __b2
    // [7] phi from main::@1 to main::@3 [phi:main::@1->main::@3]
  __b3_from___b1:
    // [7] phi (byte*) main::cc#2 = (const byte*) main::cols+(word) $3e7 [phi:main::@1->main::@3#0] -- pbuz1=pbuc1 
    lda #<cols+$3e7
    sta.z cc
    lda #>cols+$3e7
    sta.z cc+1
    jmp __b3
    // main::@3
  __b3:
    // [8] if((byte*) main::cc#2>(const byte*) main::cols-(byte) 1) goto main::@4 -- pbuz1_gt_pbuc1_then_la1 
    lda #>cols-1
    cmp.z cc+1
    bcc __b4
    bne !+
    lda #<cols-1
    cmp.z cc
    bcc __b4
  !:
    jmp __breturn
    // main::@return
  __breturn:
    // [9] return 
    rts
    // main::@4
  __b4:
    // [10] *((byte*) main::cc#2) ← (byte) 2 -- _deref_pbuz1=vbuc1 
    lda #2
    ldy #0
    sta (cc),y
    // [11] (byte*) main::cc#1 ← -- (byte*) main::cc#2 -- pbuz1=_dec_pbuz1 
    lda.z cc
    bne !+
    dec.z cc+1
  !:
    dec.z cc
    // [7] phi from main::@4 to main::@3 [phi:main::@4->main::@3]
  __b3_from___b4:
    // [7] phi (byte*) main::cc#2 = (byte*) main::cc#1 [phi:main::@4->main::@3#0] -- register_copy 
    jmp __b3
    // main::@2
  __b2:
    // [12] *((byte*) main::sc#2) ← (byte) 'a' -- _deref_pbuz1=vbuc1 
    lda #'a'
    ldy #0
    sta (sc),y
    // [13] (byte*) main::sc#1 ← ++ (byte*) main::sc#2 -- pbuz1=_inc_pbuz1 
    inc.z sc
    bne !+
    inc.z sc+1
  !:
    // [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
  __b1_from___b2:
    // [5] phi (byte*) main::sc#2 = (byte*) main::sc#1 [phi:main::@2->main::@1#0] -- register_copy 
    jmp __b1
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [6] if((byte*) main::sc#2<=(const byte*) main::screen+(word) $3e7) goto main::@2 [ main::sc#2 ] ( main:2 [ main::sc#2 ] ) always clobbers reg byte a 
Statement [8] if((byte*) main::cc#2>(const byte*) main::cols-(byte) 1) goto main::@4 [ main::cc#2 ] ( main:2 [ main::cc#2 ] ) always clobbers reg byte a 
Statement [10] *((byte*) main::cc#2) ← (byte) 2 [ main::cc#2 ] ( main:2 [ main::cc#2 ] ) always clobbers reg byte a reg byte y 
Statement [11] (byte*) main::cc#1 ← -- (byte*) main::cc#2 [ main::cc#1 ] ( main:2 [ main::cc#1 ] ) always clobbers reg byte a 
Statement [12] *((byte*) main::sc#2) ← (byte) 'a' [ main::sc#2 ] ( main:2 [ main::sc#2 ] ) always clobbers reg byte a reg byte y 
Potential registers zp[2]:2 [ main::sc#2 main::sc#1 ] : zp[2]:2 , 
Potential registers zp[2]:4 [ main::cc#2 main::cc#1 ] : zp[2]:4 , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 36.67: zp[2]:2 [ main::sc#2 main::sc#1 ] 36.67: zp[2]:4 [ main::cc#2 main::cc#1 ] 
Uplift Scope [] 

Uplifting [main] best 1198 combination zp[2]:2 [ main::sc#2 main::sc#1 ] zp[2]:4 [ main::cc#2 main::cc#1 ] 
Uplifting [] best 1198 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Test rewriting of constant comparisons for pointers
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  // @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 screen = $400
    .label cols = $d800
    .label sc = 2
    .label cc = 4
    // [5] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [5] phi (byte*) main::sc#2 = (const byte*) main::screen [phi:main->main::@1#0] -- pbuz1=pbuc1 
    lda #<screen
    sta.z sc
    lda #>screen
    sta.z sc+1
    jmp __b1
    // main::@1
  __b1:
    // [6] if((byte*) main::sc#2<=(const byte*) main::screen+(word) $3e7) goto main::@2 -- pbuz1_le_pbuc1_then_la1 
    lda.z sc+1
    cmp #>screen+$3e7
    bne !+
    lda.z sc
    cmp #<screen+$3e7
  !:
    bcc __b2
    beq __b2
    // [7] phi from main::@1 to main::@3 [phi:main::@1->main::@3]
  __b3_from___b1:
    // [7] phi (byte*) main::cc#2 = (const byte*) main::cols+(word) $3e7 [phi:main::@1->main::@3#0] -- pbuz1=pbuc1 
    lda #<cols+$3e7
    sta.z cc
    lda #>cols+$3e7
    sta.z cc+1
    jmp __b3
    // main::@3
  __b3:
    // [8] if((byte*) main::cc#2>(const byte*) main::cols-(byte) 1) goto main::@4 -- pbuz1_gt_pbuc1_then_la1 
    lda #>cols-1
    cmp.z cc+1
    bcc __b4
    bne !+
    lda #<cols-1
    cmp.z cc
    bcc __b4
  !:
    jmp __breturn
    // main::@return
  __breturn:
    // [9] return 
    rts
    // main::@4
  __b4:
    // [10] *((byte*) main::cc#2) ← (byte) 2 -- _deref_pbuz1=vbuc1 
    lda #2
    ldy #0
    sta (cc),y
    // [11] (byte*) main::cc#1 ← -- (byte*) main::cc#2 -- pbuz1=_dec_pbuz1 
    lda.z cc
    bne !+
    dec.z cc+1
  !:
    dec.z cc
    // [7] phi from main::@4 to main::@3 [phi:main::@4->main::@3]
  __b3_from___b4:
    // [7] phi (byte*) main::cc#2 = (byte*) main::cc#1 [phi:main::@4->main::@3#0] -- register_copy 
    jmp __b3
    // main::@2
  __b2:
    // [12] *((byte*) main::sc#2) ← (byte) 'a' -- _deref_pbuz1=vbuc1 
    lda #'a'
    ldy #0
    sta (sc),y
    // [13] (byte*) main::sc#1 ← ++ (byte*) main::sc#2 -- pbuz1=_inc_pbuz1 
    inc.z sc
    bne !+
    inc.z sc+1
  !:
    // [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
  __b1_from___b2:
    // [5] phi (byte*) main::sc#2 = (byte*) main::sc#1 [phi:main::@2->main::@1#0] -- register_copy 
    jmp __b1
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __b3
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __b1_from_main:
Removing instruction __b3_from___b1:
Removing instruction __breturn:
Removing instruction __b3_from___b4:
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 __b1:
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::cc
(byte*) main::cc#1 cc zp[2]:4 22.0
(byte*) main::cc#2 cc zp[2]:4 14.666666666666666
(const byte*) main::cols = (byte*) 55296
(byte*) main::sc
(byte*) main::sc#1 sc zp[2]:2 22.0
(byte*) main::sc#2 sc zp[2]:2 14.666666666666666
(const byte*) main::screen = (byte*) 1024

zp[2]:2 [ main::sc#2 main::sc#1 ]
zp[2]:4 [ main::cc#2 main::cc#1 ]


FINAL ASSEMBLER
Score: 1096

  // File Comments
// Test rewriting of constant comparisons for pointers
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  // @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 screen = $400
    .label cols = $d800
    .label sc = 2
    .label cc = 4
    // [5] phi from main to main::@1 [phi:main->main::@1]
    // [5] phi (byte*) main::sc#2 = (const byte*) main::screen [phi:main->main::@1#0] -- pbuz1=pbuc1 
    lda #<screen
    sta.z sc
    lda #>screen
    sta.z sc+1
    // main::@1
  __b1:
    // for(byte* sc =screen;sc<=screen+999;sc++)
    // [6] if((byte*) main::sc#2<=(const byte*) main::screen+(word) $3e7) goto main::@2 -- pbuz1_le_pbuc1_then_la1 
    lda.z sc+1
    cmp #>screen+$3e7
    bne !+
    lda.z sc
    cmp #<screen+$3e7
  !:
    bcc __b2
    beq __b2
    // [7] phi from main::@1 to main::@3 [phi:main::@1->main::@3]
    // [7] phi (byte*) main::cc#2 = (const byte*) main::cols+(word) $3e7 [phi:main::@1->main::@3#0] -- pbuz1=pbuc1 
    lda #<cols+$3e7
    sta.z cc
    lda #>cols+$3e7
    sta.z cc+1
    // main::@3
  __b3:
    // for(byte* cc =cols+999;cc>cols-1;cc--)
    // [8] if((byte*) main::cc#2>(const byte*) main::cols-(byte) 1) goto main::@4 -- pbuz1_gt_pbuc1_then_la1 
    lda #>cols-1
    cmp.z cc+1
    bcc __b4
    bne !+
    lda #<cols-1
    cmp.z cc
    bcc __b4
  !:
    // main::@return
    // }
    // [9] return 
    rts
    // main::@4
  __b4:
    // *cc=2
    // [10] *((byte*) main::cc#2) ← (byte) 2 -- _deref_pbuz1=vbuc1 
    lda #2
    ldy #0
    sta (cc),y
    // for(byte* cc =cols+999;cc>cols-1;cc--)
    // [11] (byte*) main::cc#1 ← -- (byte*) main::cc#2 -- pbuz1=_dec_pbuz1 
    lda.z cc
    bne !+
    dec.z cc+1
  !:
    dec.z cc
    // [7] phi from main::@4 to main::@3 [phi:main::@4->main::@3]
    // [7] phi (byte*) main::cc#2 = (byte*) main::cc#1 [phi:main::@4->main::@3#0] -- register_copy 
    jmp __b3
    // main::@2
  __b2:
    // *sc='a'
    // [12] *((byte*) main::sc#2) ← (byte) 'a' -- _deref_pbuz1=vbuc1 
    lda #'a'
    ldy #0
    sta (sc),y
    // for(byte* sc =screen;sc<=screen+999;sc++)
    // [13] (byte*) main::sc#1 ← ++ (byte*) main::sc#2 -- pbuz1=_inc_pbuz1 
    inc.z sc
    bne !+
    inc.z sc+1
  !:
    // [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
    // [5] phi (byte*) main::sc#2 = (byte*) main::sc#1 [phi:main::@2->main::@1#0] -- register_copy 
    jmp __b1
}
  // File Data

