Fixing pointer addition (word*~) main::$0 ← (word*) main::words + (number) 1
Fixing pointer addition (word*~) main::$3 ← (word*) main::words + (number) 2
Identified constant variable (word*) main::words

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

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

Adding number conversion cast (unumber) 1 in (number~) main::$6 ← (number) 1 * (const byte) SIZEOF_WORD
Adding number conversion cast (unumber) main::$6 in (number~) main::$6 ← (unumber)(number) 1 * (const byte) SIZEOF_WORD
Adding number conversion cast (unumber) 0 in *((const byte*) main::SCREEN + (number) 0) ← (byte~) main::$1
Adding number conversion cast (unumber) 1 in *((const byte*) main::SCREEN + (number) 1) ← (byte~) main::$2
Adding number conversion cast (unumber) 2 in (number~) main::$7 ← (number) 2 * (const byte) SIZEOF_WORD
Adding number conversion cast (unumber) main::$7 in (number~) main::$7 ← (unumber)(number) 2 * (const byte) SIZEOF_WORD
Adding number conversion cast (unumber) 2 in *((const byte*) main::SCREEN + (number) 2) ← (byte~) main::$4
Adding number conversion cast (unumber) 3 in *((const byte*) main::SCREEN + (number) 3) ← (byte~) main::$5
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (word*) 1024
Simplifying constant integer cast 1
Simplifying constant integer cast 0
Simplifying constant integer cast 1
Simplifying constant integer cast 2
Simplifying constant integer cast 2
Simplifying constant integer cast 3
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) 2
Finalized unsigned number type (byte) 2
Finalized unsigned number type (byte) 3
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to byte in (unumber~) main::$6 ← (byte) 1 * (const byte) SIZEOF_WORD
Inferred type updated to byte in (unumber~) main::$7 ← (byte) 2 * (const byte) SIZEOF_WORD
Constant right-side identified [0] (byte~) main::$6 ← (byte) 1 * (const byte) SIZEOF_WORD
Constant right-side identified [7] (byte~) main::$7 ← (byte) 2 * (const byte) SIZEOF_WORD
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const byte) main::$6 = 1*SIZEOF_WORD
Constant (const byte) main::$7 = 2*SIZEOF_WORD
Successful SSA optimization Pass2ConstantIdentification
Converting *(pointer+n) to pointer[n] [2] (word) main::w1#0 ← *((word*~) main::$0)  -- *(main::words + main::$6)
Converting *(pointer+n) to pointer[n] [9] (word) main::w2#0 ← *((word*~) main::$3)  -- *(main::words + main::$7)
Successful SSA optimization Pass2InlineDerefIdx
Simplifying expression containing zero main::SCREEN in [4] *((const byte*) main::SCREEN + (byte) 0) ← (byte~) main::$1
Successful SSA optimization PassNSimplifyExpressionWithZero
Eliminating unused variable (word*~) main::$0 and assignment [0] (word*~) main::$0 ← (const word*) main::words + (const byte) main::$6
Eliminating unused variable (word*~) main::$3 and assignment [6] (word*~) main::$3 ← (const word*) main::words + (const byte) main::$7
Successful SSA optimization PassNEliminateUnusedVars
Constant inlined main::$6 = (byte) 1*(const byte) SIZEOF_WORD
Constant inlined main::$7 = (byte) 2*(const byte) SIZEOF_WORD
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(main::words+1*SIZEOF_WORD)
Consolidated array index constant in *(main::SCREEN+1)
Consolidated array index constant in *(main::words+2*SIZEOF_WORD)
Consolidated array index constant in *(main::SCREEN+2)
Consolidated array index constant in *(main::SCREEN+3)
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()

(void()) main()
main: scope:[main]  from @1
  [4] (word) main::w1#0 ← *((const word*) main::words+(byte) 1*(const byte) SIZEOF_WORD)
  [5] (byte~) main::$1 ← < (word) main::w1#0
  [6] *((const byte*) main::SCREEN) ← (byte~) main::$1
  [7] (byte~) main::$2 ← > (word) main::w1#0
  [8] *((const byte*) main::SCREEN+(byte) 1) ← (byte~) main::$2
  [9] (word) main::w2#0 ← *((const word*) main::words+(byte) 2*(const byte) SIZEOF_WORD)
  [10] (byte~) main::$4 ← < (word) main::w2#0
  [11] *((const byte*) main::SCREEN+(byte) 2) ← (byte~) main::$4
  [12] (byte~) main::$5 ← > (word) main::w2#0
  [13] *((const byte*) main::SCREEN+(byte) 3) ← (byte~) main::$5
  to:main::@return
main::@return: scope:[main]  from main
  [14] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte~) main::$1 4.0
(byte~) main::$2 4.0
(byte~) main::$4 4.0
(byte~) main::$5 4.0
(word) main::w1
(word) main::w1#0 2.0
(word) main::w2
(word) main::w2#0 2.0

Initial phi equivalence classes
Added variable main::w1#0 to live range equivalence class [ main::w1#0 ]
Added variable main::$1 to live range equivalence class [ main::$1 ]
Added variable main::$2 to live range equivalence class [ main::$2 ]
Added variable main::w2#0 to live range equivalence class [ main::w2#0 ]
Added variable main::$4 to live range equivalence class [ main::$4 ]
Added variable main::$5 to live range equivalence class [ main::$5 ]
Complete equivalence classes
[ main::w1#0 ]
[ main::$1 ]
[ main::$2 ]
[ main::w2#0 ]
[ main::$4 ]
[ main::$5 ]
Allocated zp[2]:2 [ main::w1#0 ]
Allocated zp[1]:4 [ main::$1 ]
Allocated zp[1]:5 [ main::$2 ]
Allocated zp[2]:6 [ main::w2#0 ]
Allocated zp[1]:8 [ main::$4 ]
Allocated zp[1]:9 [ main::$5 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Tests simple word pointer math
  // 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+6*$28
    .label words = $400
    .label __1 = 4
    .label __2 = 5
    .label __4 = 8
    .label __5 = 9
    .label w1 = 2
    .label w2 = 6
    // [4] (word) main::w1#0 ← *((const word*) main::words+(byte) 1*(const byte) SIZEOF_WORD) -- vwuz1=_deref_pwuc1 
    lda words+1*SIZEOF_WORD
    sta.z w1
    lda words+1*SIZEOF_WORD+1
    sta.z w1+1
    // [5] (byte~) main::$1 ← < (word) main::w1#0 -- vbuz1=_lo_vwuz2 
    lda.z w1
    sta.z __1
    // [6] *((const byte*) main::SCREEN) ← (byte~) main::$1 -- _deref_pbuc1=vbuz1 
    lda.z __1
    sta SCREEN
    // [7] (byte~) main::$2 ← > (word) main::w1#0 -- vbuz1=_hi_vwuz2 
    lda.z w1+1
    sta.z __2
    // [8] *((const byte*) main::SCREEN+(byte) 1) ← (byte~) main::$2 -- _deref_pbuc1=vbuz1 
    lda.z __2
    sta SCREEN+1
    // [9] (word) main::w2#0 ← *((const word*) main::words+(byte) 2*(const byte) SIZEOF_WORD) -- vwuz1=_deref_pwuc1 
    lda words+2*SIZEOF_WORD
    sta.z w2
    lda words+2*SIZEOF_WORD+1
    sta.z w2+1
    // [10] (byte~) main::$4 ← < (word) main::w2#0 -- vbuz1=_lo_vwuz2 
    lda.z w2
    sta.z __4
    // [11] *((const byte*) main::SCREEN+(byte) 2) ← (byte~) main::$4 -- _deref_pbuc1=vbuz1 
    lda.z __4
    sta SCREEN+2
    // [12] (byte~) main::$5 ← > (word) main::w2#0 -- vbuz1=_hi_vwuz2 
    lda.z w2+1
    sta.z __5
    // [13] *((const byte*) main::SCREEN+(byte) 3) ← (byte~) main::$5 -- _deref_pbuc1=vbuz1 
    lda.z __5
    sta SCREEN+3
    jmp __breturn
    // main::@return
  __breturn:
    // [14] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] (word) main::w1#0 ← *((const word*) main::words+(byte) 1*(const byte) SIZEOF_WORD) [ main::w1#0 ] ( main:2 [ main::w1#0 ] ) always clobbers reg byte a 
Statement [5] (byte~) main::$1 ← < (word) main::w1#0 [ main::w1#0 main::$1 ] ( main:2 [ main::w1#0 main::$1 ] ) always clobbers reg byte a 
Statement [7] (byte~) main::$2 ← > (word) main::w1#0 [ main::$2 ] ( main:2 [ main::$2 ] ) always clobbers reg byte a 
Statement [9] (word) main::w2#0 ← *((const word*) main::words+(byte) 2*(const byte) SIZEOF_WORD) [ main::w2#0 ] ( main:2 [ main::w2#0 ] ) always clobbers reg byte a 
Statement [10] (byte~) main::$4 ← < (word) main::w2#0 [ main::w2#0 main::$4 ] ( main:2 [ main::w2#0 main::$4 ] ) always clobbers reg byte a 
Statement [12] (byte~) main::$5 ← > (word) main::w2#0 [ main::$5 ] ( main:2 [ main::$5 ] ) always clobbers reg byte a 
Potential registers zp[2]:2 [ main::w1#0 ] : zp[2]:2 , 
Potential registers zp[1]:4 [ main::$1 ] : zp[1]:4 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:5 [ main::$2 ] : zp[1]:5 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[2]:6 [ main::w2#0 ] : zp[2]:6 , 
Potential registers zp[1]:8 [ main::$4 ] : zp[1]:8 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:9 [ main::$5 ] : zp[1]:9 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 4: zp[1]:4 [ main::$1 ] 4: zp[1]:5 [ main::$2 ] 4: zp[1]:8 [ main::$4 ] 4: zp[1]:9 [ main::$5 ] 2: zp[2]:2 [ main::w1#0 ] 2: zp[2]:6 [ main::w2#0 ] 
Uplift Scope [] 

Uplifting [main] best 77 combination reg byte a [ main::$1 ] reg byte a [ main::$2 ] reg byte a [ main::$4 ] reg byte a [ main::$5 ] zp[2]:2 [ main::w1#0 ] zp[2]:6 [ main::w2#0 ] 
Limited combination testing to 100 combinations of 256 possible.
Uplifting [] best 77 combination 
Allocated (was zp[2]:6) zp[2]:4 [ main::w2#0 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests simple word pointer math
  // 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+6*$28
    .label words = $400
    .label w1 = 2
    .label w2 = 4
    // [4] (word) main::w1#0 ← *((const word*) main::words+(byte) 1*(const byte) SIZEOF_WORD) -- vwuz1=_deref_pwuc1 
    lda words+1*SIZEOF_WORD
    sta.z w1
    lda words+1*SIZEOF_WORD+1
    sta.z w1+1
    // [5] (byte~) main::$1 ← < (word) main::w1#0 -- vbuaa=_lo_vwuz1 
    lda.z w1
    // [6] *((const byte*) main::SCREEN) ← (byte~) main::$1 -- _deref_pbuc1=vbuaa 
    sta SCREEN
    // [7] (byte~) main::$2 ← > (word) main::w1#0 -- vbuaa=_hi_vwuz1 
    lda.z w1+1
    // [8] *((const byte*) main::SCREEN+(byte) 1) ← (byte~) main::$2 -- _deref_pbuc1=vbuaa 
    sta SCREEN+1
    // [9] (word) main::w2#0 ← *((const word*) main::words+(byte) 2*(const byte) SIZEOF_WORD) -- vwuz1=_deref_pwuc1 
    lda words+2*SIZEOF_WORD
    sta.z w2
    lda words+2*SIZEOF_WORD+1
    sta.z w2+1
    // [10] (byte~) main::$4 ← < (word) main::w2#0 -- vbuaa=_lo_vwuz1 
    lda.z w2
    // [11] *((const byte*) main::SCREEN+(byte) 2) ← (byte~) main::$4 -- _deref_pbuc1=vbuaa 
    sta SCREEN+2
    // [12] (byte~) main::$5 ← > (word) main::w2#0 -- vbuaa=_hi_vwuz1 
    lda.z w2+1
    // [13] *((const byte*) main::SCREEN+(byte) 3) ← (byte~) main::$5 -- _deref_pbuc1=vbuaa 
    sta SCREEN+3
    jmp __breturn
    // main::@return
  __breturn:
    // [14] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
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 __b1:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const byte) SIZEOF_WORD = (byte) 2
(void()) main()
(byte~) main::$1 reg byte a 4.0
(byte~) main::$2 reg byte a 4.0
(byte~) main::$4 reg byte a 4.0
(byte~) main::$5 reg byte a 4.0
(label) main::@return
(const byte*) main::SCREEN = (byte*)(number) $400+(number) 6*(number) $28
(word) main::w1
(word) main::w1#0 w1 zp[2]:2 2.0
(word) main::w2
(word) main::w2#0 w2 zp[2]:4 2.0
(const word*) main::words = (word*) 1024

zp[2]:2 [ main::w1#0 ]
reg byte a [ main::$1 ]
reg byte a [ main::$2 ]
zp[2]:4 [ main::w2#0 ]
reg byte a [ main::$4 ]
reg byte a [ main::$5 ]


FINAL ASSEMBLER
Score: 62

  // File Comments
// Tests simple word pointer math
  // 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+6*$28
    .label words = $400
    .label w1 = 2
    .label w2 = 4
    // w1 = *(words+1)
    // [4] (word) main::w1#0 ← *((const word*) main::words+(byte) 1*(const byte) SIZEOF_WORD) -- vwuz1=_deref_pwuc1 
    lda words+1*SIZEOF_WORD
    sta.z w1
    lda words+1*SIZEOF_WORD+1
    sta.z w1+1
    // <w1
    // [5] (byte~) main::$1 ← < (word) main::w1#0 -- vbuaa=_lo_vwuz1 
    lda.z w1
    // SCREEN[0] = <w1
    // [6] *((const byte*) main::SCREEN) ← (byte~) main::$1 -- _deref_pbuc1=vbuaa 
    sta SCREEN
    // >w1
    // [7] (byte~) main::$2 ← > (word) main::w1#0 -- vbuaa=_hi_vwuz1 
    lda.z w1+1
    // SCREEN[1] = >w1
    // [8] *((const byte*) main::SCREEN+(byte) 1) ← (byte~) main::$2 -- _deref_pbuc1=vbuaa 
    sta SCREEN+1
    // w2 = *(words+2)
    // [9] (word) main::w2#0 ← *((const word*) main::words+(byte) 2*(const byte) SIZEOF_WORD) -- vwuz1=_deref_pwuc1 
    lda words+2*SIZEOF_WORD
    sta.z w2
    lda words+2*SIZEOF_WORD+1
    sta.z w2+1
    // <w2
    // [10] (byte~) main::$4 ← < (word) main::w2#0 -- vbuaa=_lo_vwuz1 
    lda.z w2
    // SCREEN[2] = <w2
    // [11] *((const byte*) main::SCREEN+(byte) 2) ← (byte~) main::$4 -- _deref_pbuc1=vbuaa 
    sta SCREEN+2
    // >w2
    // [12] (byte~) main::$5 ← > (word) main::w2#0 -- vbuaa=_hi_vwuz1 
    lda.z w2+1
    // SCREEN[3] = >w2
    // [13] *((const byte*) main::SCREEN+(byte) 3) ← (byte~) main::$5 -- _deref_pbuc1=vbuaa 
    sta SCREEN+3
    // main::@return
    // }
    // [14] return 
    rts
}
  // File Data

