Fixing pointer increment (word*) main::wp ← ++ (word*) main::wp
Fixing pointer increment (word*) main::wp ← ++ (word*) main::wp
Fixing pointer decrement (word*) main::wp ← -- (word*) main::wp

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  to:@1
main: scope:[main]  from @1
  (byte*) main::SCREEN#0 ← ((byte*)) (number) $400+(number) $28*(number) 6
  (word*) main::wp#0 ← ((word*)) (number) $400
  (word*) main::wp#1 ← (word*) main::wp#0 + (const byte) SIZEOF_WORD
  (byte~) main::$0 ← < *((word*) main::wp#1)
  *((byte*) main::SCREEN#0 + (number) 0) ← (byte~) main::$0
  (byte~) main::$1 ← > *((word*) main::wp#1)
  *((byte*) main::SCREEN#0 + (number) 1) ← (byte~) main::$1
  (word*) main::wp#2 ← (word*) main::wp#1 + (const byte) SIZEOF_WORD
  (byte~) main::$2 ← < *((word*) main::wp#2)
  *((byte*) main::SCREEN#0 + (number) 2) ← (byte~) main::$2
  (byte~) main::$3 ← > *((word*) main::wp#2)
  *((byte*) main::SCREEN#0 + (number) 3) ← (byte~) main::$3
  (word*) main::wp#3 ← (word*) main::wp#2 - (const byte) SIZEOF_WORD
  (byte~) main::$4 ← < *((word*) main::wp#3)
  *((byte*) main::SCREEN#0 + (number) 4) ← (byte~) main::$4
  (byte~) main::$5 ← > *((word*) main::wp#3)
  *((byte*) main::SCREEN#0 + (number) 5) ← (byte~) main::$5
  to:main::@return
main::@return: scope:[main]  from main
  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) SIZEOF_WORD = (byte) 2
(void()) main()
(byte~) main::$0
(byte~) main::$1
(byte~) main::$2
(byte~) main::$3
(byte~) main::$4
(byte~) main::$5
(label) main::@return
(byte*) main::SCREEN
(byte*) main::SCREEN#0
(word*) main::wp
(word*) main::wp#0
(word*) main::wp#1
(word*) main::wp#2
(word*) main::wp#3

Adding number conversion cast (unumber) 0 in *((byte*) main::SCREEN#0 + (number) 0) ← (byte~) main::$0
Adding number conversion cast (unumber) 1 in *((byte*) main::SCREEN#0 + (number) 1) ← (byte~) main::$1
Adding number conversion cast (unumber) 2 in *((byte*) main::SCREEN#0 + (number) 2) ← (byte~) main::$2
Adding number conversion cast (unumber) 3 in *((byte*) main::SCREEN#0 + (number) 3) ← (byte~) main::$3
Adding number conversion cast (unumber) 4 in *((byte*) main::SCREEN#0 + (number) 4) ← (byte~) main::$4
Adding number conversion cast (unumber) 5 in *((byte*) main::SCREEN#0 + (number) 5) ← (byte~) main::$5
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte*) main::SCREEN#0 ← (byte*)(number) $400+(number) $28*(number) 6
Inlining cast (word*) main::wp#0 ← (word*)(number) $400
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (word*) 1024
Simplifying constant integer cast 0
Simplifying constant integer cast 1
Simplifying constant integer cast 2
Simplifying constant integer cast 3
Simplifying constant integer cast 4
Simplifying constant integer cast 5
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) 2
Finalized unsigned number type (byte) 3
Finalized unsigned number type (byte) 4
Finalized unsigned number type (byte) 5
Successful SSA optimization PassNFinalizeNumberTypeConversions
Constant right-side identified [0] (byte*) main::SCREEN#0 ← (byte*)(number) $400+(number) $28*(number) 6
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const byte*) main::SCREEN#0 = (byte*)$400+$28*6
Constant (const word*) main::wp#0 = (word*) 1024
Successful SSA optimization Pass2ConstantIdentification
Simplifying expression containing zero main::SCREEN#0 in [4] *((const byte*) main::SCREEN#0 + (byte) 0) ← (byte~) main::$0
Successful SSA optimization PassNSimplifyExpressionWithZero
Constant right-side identified [0] (word*) main::wp#1 ← (const word*) main::wp#0 + (const byte) SIZEOF_WORD
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const word*) main::wp#1 = main::wp#0+SIZEOF_WORD
Successful SSA optimization Pass2ConstantIdentification
Constant right-side identified [4] (word*) main::wp#2 ← (const word*) main::wp#1 + (const byte) SIZEOF_WORD
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const word*) main::wp#2 = main::wp#1+SIZEOF_WORD
Successful SSA optimization Pass2ConstantIdentification
Constant right-side identified [8] (word*) main::wp#3 ← (const word*) main::wp#2 - (const byte) SIZEOF_WORD
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const word*) main::wp#3 = main::wp#2-SIZEOF_WORD
Successful SSA optimization Pass2ConstantIdentification
Inlining constant with different constant siblings (const word*) main::wp#0
Inlining constant with different constant siblings (const word*) main::wp#1
Inlining constant with different constant siblings (const word*) main::wp#2
Inlining constant with different constant siblings (const word*) main::wp#3
Constant inlined main::wp#0 = (word*) 1024
Constant inlined main::wp#3 = (word*) 1024+(const byte) SIZEOF_WORD+(const byte) SIZEOF_WORD-(const byte) SIZEOF_WORD
Constant inlined main::wp#1 = (word*) 1024+(const byte) SIZEOF_WORD
Constant inlined main::wp#2 = (word*) 1024+(const byte) SIZEOF_WORD+(const byte) SIZEOF_WORD
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(main::SCREEN#0+1)
Consolidated array index constant in *(main::SCREEN#0+2)
Consolidated array index constant in *(main::SCREEN#0+3)
Consolidated array index constant in *(main::SCREEN#0+4)
Consolidated array index constant in *(main::SCREEN#0+5)
Successful SSA optimization Pass2ConstantAdditionElimination
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
CALL GRAPH
Calls in [] to main:2 

Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block (label) @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::$0 ← < *((word*) 1024+(const byte) SIZEOF_WORD)
  [5] *((const byte*) main::SCREEN#0) ← (byte~) main::$0
  [6] (byte~) main::$1 ← > *((word*) 1024+(const byte) SIZEOF_WORD)
  [7] *((const byte*) main::SCREEN#0+(byte) 1) ← (byte~) main::$1
  [8] (byte~) main::$2 ← < *((word*) 1024+(const byte) SIZEOF_WORD+(const byte) SIZEOF_WORD)
  [9] *((const byte*) main::SCREEN#0+(byte) 2) ← (byte~) main::$2
  [10] (byte~) main::$3 ← > *((word*) 1024+(const byte) SIZEOF_WORD+(const byte) SIZEOF_WORD)
  [11] *((const byte*) main::SCREEN#0+(byte) 3) ← (byte~) main::$3
  [12] (byte~) main::$4 ← < *((word*) 1024+(const byte) SIZEOF_WORD+(const byte) SIZEOF_WORD-(const byte) SIZEOF_WORD)
  [13] *((const byte*) main::SCREEN#0+(byte) 4) ← (byte~) main::$4
  [14] (byte~) main::$5 ← > *((word*) 1024+(const byte) SIZEOF_WORD+(const byte) SIZEOF_WORD-(const byte) SIZEOF_WORD)
  [15] *((const byte*) main::SCREEN#0+(byte) 5) ← (byte~) main::$5
  to:main::@return
main::@return: scope:[main]  from main
  [16] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte~) main::$0 4.0
(byte~) main::$1 4.0
(byte~) main::$2 4.0
(byte~) main::$3 4.0
(byte~) main::$4 4.0
(byte~) main::$5 4.0
(byte*) main::SCREEN
(word*) main::wp

Initial phi equivalence classes
Added variable main::$0 to zero page equivalence class [ main::$0 ]
Added variable main::$1 to zero page equivalence class [ main::$1 ]
Added variable main::$2 to zero page equivalence class [ main::$2 ]
Added variable main::$3 to zero page equivalence class [ main::$3 ]
Added variable main::$4 to zero page equivalence class [ main::$4 ]
Added variable main::$5 to zero page equivalence class [ main::$5 ]
Complete equivalence classes
[ main::$0 ]
[ main::$1 ]
[ main::$2 ]
[ main::$3 ]
[ main::$4 ]
[ main::$5 ]
Allocated zp ZP_BYTE:2 [ main::$0 ]
Allocated zp ZP_BYTE:3 [ main::$1 ]
Allocated zp ZP_BYTE:4 [ main::$2 ]
Allocated zp ZP_BYTE:5 [ main::$3 ]
Allocated zp ZP_BYTE:6 [ main::$4 ]
Allocated zp ZP_BYTE:7 [ main::$5 ]

INITIAL ASM
Target platform is c64basic
  // File Comments
// Tests simple word pointer iteration
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .const SIZEOF_WORD = 2
  // @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 SCREEN = $400+$28*6
    .label _0 = 2
    .label _1 = 3
    .label _2 = 4
    .label _3 = 5
    .label _4 = 6
    .label _5 = 7
    // [4] (byte~) main::$0 ← < *((word*) 1024+(const byte) SIZEOF_WORD) -- vbuz1=_lo__deref_pwuc1 
    lda $400+SIZEOF_WORD
    sta.z _0
    // [5] *((const byte*) main::SCREEN#0) ← (byte~) main::$0 -- _deref_pbuc1=vbuz1 
    lda.z _0
    sta SCREEN
    // [6] (byte~) main::$1 ← > *((word*) 1024+(const byte) SIZEOF_WORD) -- vbuz1=_hi__deref_pwuc1 
    lda $400+SIZEOF_WORD+1
    sta.z _1
    // [7] *((const byte*) main::SCREEN#0+(byte) 1) ← (byte~) main::$1 -- _deref_pbuc1=vbuz1 
    lda.z _1
    sta SCREEN+1
    // [8] (byte~) main::$2 ← < *((word*) 1024+(const byte) SIZEOF_WORD+(const byte) SIZEOF_WORD) -- vbuz1=_lo__deref_pwuc1 
    lda $400+SIZEOF_WORD+SIZEOF_WORD
    sta.z _2
    // [9] *((const byte*) main::SCREEN#0+(byte) 2) ← (byte~) main::$2 -- _deref_pbuc1=vbuz1 
    lda.z _2
    sta SCREEN+2
    // [10] (byte~) main::$3 ← > *((word*) 1024+(const byte) SIZEOF_WORD+(const byte) SIZEOF_WORD) -- vbuz1=_hi__deref_pwuc1 
    lda $400+SIZEOF_WORD+SIZEOF_WORD+1
    sta.z _3
    // [11] *((const byte*) main::SCREEN#0+(byte) 3) ← (byte~) main::$3 -- _deref_pbuc1=vbuz1 
    lda.z _3
    sta SCREEN+3
    // [12] (byte~) main::$4 ← < *((word*) 1024+(const byte) SIZEOF_WORD+(const byte) SIZEOF_WORD-(const byte) SIZEOF_WORD) -- vbuz1=_lo__deref_pwuc1 
    lda $400+SIZEOF_WORD+SIZEOF_WORD-SIZEOF_WORD
    sta.z _4
    // [13] *((const byte*) main::SCREEN#0+(byte) 4) ← (byte~) main::$4 -- _deref_pbuc1=vbuz1 
    lda.z _4
    sta SCREEN+4
    // [14] (byte~) main::$5 ← > *((word*) 1024+(const byte) SIZEOF_WORD+(const byte) SIZEOF_WORD-(const byte) SIZEOF_WORD) -- vbuz1=_hi__deref_pwuc1 
    lda $400+SIZEOF_WORD+SIZEOF_WORD-SIZEOF_WORD+1
    sta.z _5
    // [15] *((const byte*) main::SCREEN#0+(byte) 5) ← (byte~) main::$5 -- _deref_pbuc1=vbuz1 
    lda.z _5
    sta SCREEN+5
    jmp breturn
    // main::@return
  breturn:
    // [16] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Potential registers zp ZP_BYTE:2 [ main::$0 ] : zp ZP_BYTE:2 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:3 [ main::$1 ] : zp ZP_BYTE:3 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:4 [ main::$2 ] : zp ZP_BYTE:4 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:5 [ main::$3 ] : zp ZP_BYTE:5 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:6 [ main::$4 ] : zp ZP_BYTE:6 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:7 [ main::$5 ] : zp ZP_BYTE:7 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 4: zp ZP_BYTE:2 [ main::$0 ] 4: zp ZP_BYTE:3 [ main::$1 ] 4: zp ZP_BYTE:4 [ main::$2 ] 4: zp ZP_BYTE:5 [ main::$3 ] 4: zp ZP_BYTE:6 [ main::$4 ] 4: zp ZP_BYTE:7 [ main::$5 ] 
Uplift Scope [] 

Uplifting [main] best 81 combination reg byte a [ main::$0 ] reg byte a [ main::$1 ] reg byte a [ main::$2 ] reg byte a [ main::$3 ] zp ZP_BYTE:6 [ main::$4 ] zp ZP_BYTE:7 [ main::$5 ] 
Limited combination testing to 100 combinations of 4096 possible.
Uplifting [] best 81 combination 
Attempting to uplift remaining variables inzp ZP_BYTE:6 [ main::$4 ]
Uplifting [main] best 75 combination reg byte a [ main::$4 ] 
Attempting to uplift remaining variables inzp ZP_BYTE:7 [ main::$5 ]
Uplifting [main] best 69 combination reg byte a [ main::$5 ] 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests simple word pointer iteration
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .const SIZEOF_WORD = 2
  // @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 SCREEN = $400+$28*6
    // [4] (byte~) main::$0 ← < *((word*) 1024+(const byte) SIZEOF_WORD) -- vbuaa=_lo__deref_pwuc1 
    lda $400+SIZEOF_WORD
    // [5] *((const byte*) main::SCREEN#0) ← (byte~) main::$0 -- _deref_pbuc1=vbuaa 
    sta SCREEN
    // [6] (byte~) main::$1 ← > *((word*) 1024+(const byte) SIZEOF_WORD) -- vbuaa=_hi__deref_pwuc1 
    lda $400+SIZEOF_WORD+1
    // [7] *((const byte*) main::SCREEN#0+(byte) 1) ← (byte~) main::$1 -- _deref_pbuc1=vbuaa 
    sta SCREEN+1
    // [8] (byte~) main::$2 ← < *((word*) 1024+(const byte) SIZEOF_WORD+(const byte) SIZEOF_WORD) -- vbuaa=_lo__deref_pwuc1 
    lda $400+SIZEOF_WORD+SIZEOF_WORD
    // [9] *((const byte*) main::SCREEN#0+(byte) 2) ← (byte~) main::$2 -- _deref_pbuc1=vbuaa 
    sta SCREEN+2
    // [10] (byte~) main::$3 ← > *((word*) 1024+(const byte) SIZEOF_WORD+(const byte) SIZEOF_WORD) -- vbuaa=_hi__deref_pwuc1 
    lda $400+SIZEOF_WORD+SIZEOF_WORD+1
    // [11] *((const byte*) main::SCREEN#0+(byte) 3) ← (byte~) main::$3 -- _deref_pbuc1=vbuaa 
    sta SCREEN+3
    // [12] (byte~) main::$4 ← < *((word*) 1024+(const byte) SIZEOF_WORD+(const byte) SIZEOF_WORD-(const byte) SIZEOF_WORD) -- vbuaa=_lo__deref_pwuc1 
    lda $400+SIZEOF_WORD+SIZEOF_WORD-SIZEOF_WORD
    // [13] *((const byte*) main::SCREEN#0+(byte) 4) ← (byte~) main::$4 -- _deref_pbuc1=vbuaa 
    sta SCREEN+4
    // [14] (byte~) main::$5 ← > *((word*) 1024+(const byte) SIZEOF_WORD+(const byte) SIZEOF_WORD-(const byte) SIZEOF_WORD) -- vbuaa=_hi__deref_pwuc1 
    lda $400+SIZEOF_WORD+SIZEOF_WORD-SIZEOF_WORD+1
    // [15] *((const byte*) main::SCREEN#0+(byte) 5) ← (byte~) main::$5 -- _deref_pbuc1=vbuaa 
    sta SCREEN+5
    jmp breturn
    // main::@return
  breturn:
    // [16] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction b1_from_bbegin:
Removing instruction b1:
Removing instruction bend_from_b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
Removing instruction breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const byte) SIZEOF_WORD SIZEOF_WORD = (byte) 2
(void()) main()
(byte~) main::$0 reg byte a 4.0
(byte~) main::$1 reg byte a 4.0
(byte~) main::$2 reg byte a 4.0
(byte~) main::$3 reg byte a 4.0
(byte~) main::$4 reg byte a 4.0
(byte~) main::$5 reg byte a 4.0
(label) main::@return
(byte*) main::SCREEN
(const byte*) main::SCREEN#0 SCREEN = (byte*)(number) $400+(number) $28*(number) 6
(word*) main::wp

reg byte a [ main::$0 ]
reg byte a [ main::$1 ]
reg byte a [ main::$2 ]
reg byte a [ main::$3 ]
reg byte a [ main::$4 ]
reg byte a [ main::$5 ]


FINAL ASSEMBLER
Score: 54

  // File Comments
// Tests simple word pointer iteration
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  .const SIZEOF_WORD = 2
  // @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 SCREEN = $400+$28*6
    // <*wp
    // [4] (byte~) main::$0 ← < *((word*) 1024+(const byte) SIZEOF_WORD) -- vbuaa=_lo__deref_pwuc1 
    lda $400+SIZEOF_WORD
    // SCREEN[0] = <*wp
    // [5] *((const byte*) main::SCREEN#0) ← (byte~) main::$0 -- _deref_pbuc1=vbuaa 
    sta SCREEN
    // >*wp
    // [6] (byte~) main::$1 ← > *((word*) 1024+(const byte) SIZEOF_WORD) -- vbuaa=_hi__deref_pwuc1 
    lda $400+SIZEOF_WORD+1
    // SCREEN[1] = >*wp
    // [7] *((const byte*) main::SCREEN#0+(byte) 1) ← (byte~) main::$1 -- _deref_pbuc1=vbuaa 
    sta SCREEN+1
    // <*wp
    // [8] (byte~) main::$2 ← < *((word*) 1024+(const byte) SIZEOF_WORD+(const byte) SIZEOF_WORD) -- vbuaa=_lo__deref_pwuc1 
    lda $400+SIZEOF_WORD+SIZEOF_WORD
    // SCREEN[2] = <*wp
    // [9] *((const byte*) main::SCREEN#0+(byte) 2) ← (byte~) main::$2 -- _deref_pbuc1=vbuaa 
    sta SCREEN+2
    // >*wp
    // [10] (byte~) main::$3 ← > *((word*) 1024+(const byte) SIZEOF_WORD+(const byte) SIZEOF_WORD) -- vbuaa=_hi__deref_pwuc1 
    lda $400+SIZEOF_WORD+SIZEOF_WORD+1
    // SCREEN[3] = >*wp
    // [11] *((const byte*) main::SCREEN#0+(byte) 3) ← (byte~) main::$3 -- _deref_pbuc1=vbuaa 
    sta SCREEN+3
    // <*wp
    // [12] (byte~) main::$4 ← < *((word*) 1024+(const byte) SIZEOF_WORD+(const byte) SIZEOF_WORD-(const byte) SIZEOF_WORD) -- vbuaa=_lo__deref_pwuc1 
    lda $400+SIZEOF_WORD+SIZEOF_WORD-SIZEOF_WORD
    // SCREEN[4] = <*wp
    // [13] *((const byte*) main::SCREEN#0+(byte) 4) ← (byte~) main::$4 -- _deref_pbuc1=vbuaa 
    sta SCREEN+4
    // >*wp
    // [14] (byte~) main::$5 ← > *((word*) 1024+(const byte) SIZEOF_WORD+(const byte) SIZEOF_WORD-(const byte) SIZEOF_WORD) -- vbuaa=_hi__deref_pwuc1 
    lda $400+SIZEOF_WORD+SIZEOF_WORD-SIZEOF_WORD+1
    // SCREEN[5] = >*wp
    // [15] *((const byte*) main::SCREEN#0+(byte) 5) ← (byte~) main::$5 -- _deref_pbuc1=vbuaa 
    sta SCREEN+5
    // main::@return
    // }
    // [16] return 
    rts
}
  // File Data

