Fixing pointer array-indexing *((word*) main::wscreen + (byte) main::i)
Identified constant variable (byte*) main::bscreen
Culled Empty Block (label) main::@2

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  to:@1
main: scope:[main]  from @1
  (byte*) main::bscreen#0 ← ((byte*)) (number) $400
  (byte) main::i#0 ← (byte) 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 )
  (word*~) main::$0 ← ((word*)) (byte*) main::bscreen#0
  (word*) main::wscreen#0 ← (word*~) main::$0
  (word~) main::$1 ← ((word)) (byte) main::i#2
  (byte~) main::$3 ← (byte) main::i#2 * (const byte) SIZEOF_WORD
  *((word*) main::wscreen#0 + (byte~) main::$3) ← (word~) main::$1
  (byte) main::i#1 ← (byte) main::i#2 + rangenext(0,2)
  (bool~) main::$2 ← (byte) main::i#1 != rangelast(0,2)
  if((bool~) main::$2) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  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
(word~) main::$1
(bool~) main::$2
(byte~) main::$3
(label) main::@1
(label) main::@return
(byte*) main::bscreen
(byte*) main::bscreen#0
(byte) main::i
(byte) main::i#0
(byte) main::i#1
(byte) main::i#2
(word*) main::wscreen
(word*) main::wscreen#0

Inlining cast (byte*) main::bscreen#0 ← (byte*)(number) $400
Inlining cast (word*~) main::$0 ← (word*)(byte*) main::bscreen#0
Inlining cast (word~) main::$1 ← (word)(byte) main::i#2
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Successful SSA optimization PassNCastSimplification
Alias (word*) main::wscreen#0 = (word*~) main::$0 
Successful SSA optimization Pass2AliasElimination
Simple Condition (bool~) main::$2 [10] if((byte) main::i#1!=rangelast(0,2)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte*) main::bscreen#0 = (byte*) 1024
Constant (const byte) main::i#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Constant value identified (word*)main::bscreen#0 in [3] (word*) main::wscreen#0 ← (word*)(const byte*) main::bscreen#0
Successful SSA optimization Pass2ConstantValues
Resolved ranged next value [8] main::i#1 ← ++ main::i#2 to ++
Resolved ranged comparison value [10] if(main::i#1!=rangelast(0,2)) goto main::@1 to (number) 3
Adding number conversion cast (unumber) 3 in if((byte) main::i#1!=(number) 3) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast 3
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 3
Successful SSA optimization PassNFinalizeNumberTypeConversions
Constant (const word*) main::wscreen#0 = (word*)main::bscreen#0
Successful SSA optimization Pass2ConstantIdentification
Rewriting multiplication to use shift [2] (byte~) main::$3 ← (byte) main::i#2 * (const byte) SIZEOF_WORD
Successful SSA optimization Pass2MultiplyToShiftRewriting
Inlining constant with var siblings (const byte) main::i#0
Constant inlined main::i#0 = (byte) 0
Successful SSA optimization Pass2ConstantInlining
Eliminating unused constant (const byte) SIZEOF_WORD
Successful SSA optimization PassNEliminateUnusedVars
Added new block during phi lifting main::@3(between main::@1 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 @end
Adding NOP phi() at start of main
CALL GRAPH
Calls in [] to main:2 

Created 1 initial phi equivalence classes
Coalesced [13] main::i#3 ← main::i#1
Coalesced down to 1 phi equivalence classes
Culled Empty Block (label) @2
Culled Empty Block (label) main::@3
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()
main: scope:[main]  from @1
  [4] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@1
  [5] (byte) main::i#2 ← phi( main/(byte) 0 main::@1/(byte) main::i#1 )
  [6] (word~) main::$1 ← (word)(byte) main::i#2
  [7] (byte~) main::$3 ← (byte) main::i#2 << (byte) 1
  [8] *((const word*) main::wscreen#0 + (byte~) main::$3) ← (word~) main::$1
  [9] (byte) main::i#1 ← ++ (byte) main::i#2
  [10] if((byte) main::i#1!=(byte) 3) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  [11] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) main()
(word~) main::$1 11.0
(byte~) main::$3 22.0
(byte*) main::bscreen
(byte) main::i
(byte) main::i#1 16.5
(byte) main::i#2 8.25
(word*) main::wscreen

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
Added variable main::$1 to zero page equivalence class [ main::$1 ]
Added variable main::$3 to zero page equivalence class [ main::$3 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ main::$1 ]
[ main::$3 ]
Allocated zp ZP_BYTE:2 [ main::i#2 main::i#1 ]
Allocated zp ZP_WORD:3 [ main::$1 ]
Allocated zp ZP_BYTE:5 [ main::$3 ]

INITIAL ASM
  // File Comments
// Tests casting pointer types to other pointer types does not produce any ASM code
  // Basic 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 bscreen = $400
    .label wscreen = bscreen
    .label _1 = 3
    .label _3 = 5
    .label i = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
  b1_from_main:
    // [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta i
    jmp b1
    // [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  b1_from_b1:
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    jmp b1
    // main::@1
  b1:
    // [6] (word~) main::$1 ← (word)(byte) main::i#2 -- vwuz1=_word_vbuz2 
    lda i
    sta _1
    lda #0
    sta _1+1
    // [7] (byte~) main::$3 ← (byte) main::i#2 << (byte) 1 -- vbuz1=vbuz2_rol_1 
    lda i
    asl
    sta _3
    // [8] *((const word*) main::wscreen#0 + (byte~) main::$3) ← (word~) main::$1 -- pwuc1_derefidx_vbuz1=vwuz2 
    ldy _3
    lda _1
    sta wscreen,y
    lda _1+1
    sta wscreen+1,y
    // [9] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc i
    // [10] if((byte) main::i#1!=(byte) 3) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #3
    cmp i
    bne b1_from_b1
    jmp breturn
    // main::@return
  breturn:
    // [11] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [6] (word~) main::$1 ← (word)(byte) main::i#2 [ main::i#2 main::$1 ] ( main:2 [ main::i#2 main::$1 ] ) 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] (byte~) main::$3 ← (byte) main::i#2 << (byte) 1 [ main::i#2 main::$1 main::$3 ] ( main:2 [ main::i#2 main::$1 main::$3 ] ) always clobbers reg byte a 
Statement [8] *((const word*) main::wscreen#0 + (byte~) main::$3) ← (word~) main::$1 [ main::i#2 ] ( main:2 [ main::i#2 ] ) always clobbers reg byte a 
Statement [6] (word~) main::$1 ← (word)(byte) main::i#2 [ main::i#2 main::$1 ] ( main:2 [ main::i#2 main::$1 ] ) always clobbers reg byte a 
Statement [7] (byte~) main::$3 ← (byte) main::i#2 << (byte) 1 [ main::i#2 main::$1 main::$3 ] ( main:2 [ main::i#2 main::$1 main::$3 ] ) always clobbers reg byte a 
Statement [8] *((const word*) main::wscreen#0 + (byte~) main::$3) ← (word~) main::$1 [ main::i#2 ] ( main:2 [ main::i#2 ] ) always clobbers reg byte a 
Potential registers zp ZP_BYTE:2 [ main::i#2 main::i#1 ] : zp ZP_BYTE:2 , reg byte x , reg byte y , 
Potential registers zp ZP_WORD:3 [ main::$1 ] : zp ZP_WORD:3 , 
Potential registers zp ZP_BYTE:5 [ main::$3 ] : zp ZP_BYTE:5 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 24.75: zp ZP_BYTE:2 [ main::i#2 main::i#1 ] 22: zp ZP_BYTE:5 [ main::$3 ] 11: zp ZP_WORD:3 [ main::$1 ] 
Uplift Scope [] 

Uplifting [main] best 513 combination reg byte x [ main::i#2 main::i#1 ] reg byte a [ main::$3 ] zp ZP_WORD:3 [ main::$1 ] 
Uplifting [] best 513 combination 
Allocated (was zp ZP_WORD:3) zp ZP_WORD:2 [ main::$1 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests casting pointer types to other pointer types does not produce any ASM code
  // Basic 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 bscreen = $400
    .label wscreen = bscreen
    .label _1 = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
  b1_from_main:
    // [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    jmp b1
    // [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  b1_from_b1:
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    jmp b1
    // main::@1
  b1:
    // [6] (word~) main::$1 ← (word)(byte) main::i#2 -- vwuz1=_word_vbuxx 
    txa
    sta _1
    lda #0
    sta _1+1
    // [7] (byte~) main::$3 ← (byte) main::i#2 << (byte) 1 -- vbuaa=vbuxx_rol_1 
    txa
    asl
    // [8] *((const word*) main::wscreen#0 + (byte~) main::$3) ← (word~) main::$1 -- pwuc1_derefidx_vbuaa=vwuz1 
    tay
    lda _1
    sta wscreen,y
    lda _1+1
    sta wscreen+1,y
    // [9] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [10] if((byte) main::i#1!=(byte) 3) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #3
    bne b1_from_b1
    jmp breturn
    // main::@return
  breturn:
    // [11] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label b1_from_b1 with b1
Removing instruction b1_from_bbegin:
Removing instruction b1:
Removing instruction main_from_b1:
Removing instruction bend_from_b1:
Removing instruction b1_from_b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
Removing instruction b1_from_main:
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
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(void()) main()
(word~) main::$1 $1 zp ZP_WORD:2 11.0
(byte~) main::$3 reg byte a 22.0
(label) main::@1
(label) main::@return
(byte*) main::bscreen
(const byte*) main::bscreen#0 bscreen = (byte*) 1024
(byte) main::i
(byte) main::i#1 reg byte x 16.5
(byte) main::i#2 reg byte x 8.25
(word*) main::wscreen
(const word*) main::wscreen#0 wscreen = (word*)(const byte*) main::bscreen#0

reg byte x [ main::i#2 main::i#1 ]
zp ZP_WORD:2 [ main::$1 ]
reg byte a [ main::$3 ]


FINAL ASSEMBLER
Score: 411

  // File Comments
// Tests casting pointer types to other pointer types does not produce any ASM code
  // Basic 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 bscreen = $400
    .label wscreen = bscreen
    .label _1 = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
    // [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    // main::@1
  b1:
    // (word)i
    // [6] (word~) main::$1 ← (word)(byte) main::i#2 -- vwuz1=_word_vbuxx 
    txa
    sta _1
    lda #0
    sta _1+1
    // wscreen[i] = (word)i
    // [7] (byte~) main::$3 ← (byte) main::i#2 << (byte) 1 -- vbuaa=vbuxx_rol_1 
    txa
    asl
    // [8] *((const word*) main::wscreen#0 + (byte~) main::$3) ← (word~) main::$1 -- pwuc1_derefidx_vbuaa=vwuz1 
    tay
    lda _1
    sta wscreen,y
    lda _1+1
    sta wscreen+1,y
    // for(byte i: 0..2)
    // [9] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [10] if((byte) main::i#1!=(byte) 3) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #3
    bne b1
    // main::@return
    // }
    // [11] return 
    rts
}
  // File Data

