Fixing pointer array-indexing *((word*) SCREEN + (byte) main::i)
Fixing pointer array-indexing *((word*) SCREEN + (byte) main::i)
Identified constant variable (word*) SCREEN
Culled Empty Block (label) main::@4
Culled Empty Block (label) main::@3
Culled Empty Block (label) main::@5
Culled Empty Block (label) main::@6

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

(void()) main()
main: scope:[main]  from @1
  (byte) main::i ← (byte) 0
  to:main::@1
main::@1: scope:[main]  from main main::@2
  (bool~) main::$0 ← (byte) main::i < (number) 8
  if((bool~) main::$0) goto main::@2
  to:main::@return
main::@2: scope:[main]  from main::@1
  (byte~) main::$1 ← (byte) main::i * (const byte) SIZEOF_WORD
  *((const word*) SCREEN + (byte~) main::$1) ← (const word) main::ch
  (byte) main::i ← ++ (byte) main::i
  (byte~) main::$2 ← (byte) main::i * (const byte) SIZEOF_WORD
  *((const word*) SCREEN + (byte~) main::$2) ← (const word) main::ch
  (byte) main::i ← ++ (byte) main::i
  to:main::@1
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 word*) SCREEN = (word*)(number) $400
(const byte) SIZEOF_WORD = (byte) 2
(void()) main()
(bool~) main::$0
(byte~) main::$1
(byte~) main::$2
(label) main::@1
(label) main::@2
(label) main::@return
(const word) main::ch = (word) $102
(byte) main::i loadstore !zp[-1]:2

Adding number conversion cast (unumber) 8 in (bool~) main::$0 ← (byte) main::i < (number) 8
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (word*) 1024
Simplifying constant integer cast 8
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 8
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simple Condition (bool~) main::$0 [2] if((byte) main::i<(byte) 8) goto main::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Rewriting multiplication to use shift [2] (byte~) main::$1 ← (byte) main::i * (const byte) SIZEOF_WORD
Rewriting multiplication to use shift [5] (byte~) main::$2 ← (byte) main::i * (const byte) SIZEOF_WORD
Successful SSA optimization Pass2MultiplyToShiftRewriting
Eliminating unused constant (const byte) SIZEOF_WORD
Successful SSA optimization PassNEliminateUnusedVars
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] (byte) main::i ← (byte) 0
  to:main::@1
main::@1: scope:[main]  from main main::@2
  [5] if((byte) main::i<(byte) 8) goto main::@2
  to:main::@return
main::@return: scope:[main]  from main::@1
  [6] return 
  to:@return
main::@2: scope:[main]  from main::@1
  [7] (byte~) main::$1 ← (byte) main::i << (byte) 1
  [8] *((const word*) SCREEN + (byte~) main::$1) ← (const word) main::ch
  [9] (byte) main::i ← ++ (byte) main::i
  [10] (byte~) main::$2 ← (byte) main::i << (byte) 1
  [11] *((const word*) SCREEN + (byte~) main::$2) ← (const word) main::ch
  [12] (byte) main::i ← ++ (byte) main::i
  to:main::@1


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte~) main::$1 22.0
(byte~) main::$2 22.0
(byte) main::i loadstore !zp[-1]:2 9.875

Initial phi equivalence classes
Added variable main::i to live range equivalence class [ main::i ]
Added variable main::$1 to live range equivalence class [ main::$1 ]
Added variable main::$2 to live range equivalence class [ main::$2 ]
Complete equivalence classes
[ main::i ]
[ main::$1 ]
[ main::$2 ]
Allocated zp[1]:3 [ main::$1 ]
Allocated zp[1]:4 [ main::$2 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Test declaring a variable as at a hard-coded address
// Incrementing a load/store variable will result in cause two *SIZEOF's
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  // @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: {
    .const ch = $102
    .label i = 2
    .label __1 = 3
    .label __2 = 4
    // [4] (byte) main::i ← (byte) 0 -- vbuz1=vbuc1 
    lda #0
    sta.z i
    jmp __b1
    // main::@1
  __b1:
    // [5] if((byte) main::i<(byte) 8) goto main::@2 -- vbuz1_lt_vbuc1_then_la1 
    lda.z i
    cmp #8
    bcc __b2
    jmp __breturn
    // main::@return
  __breturn:
    // [6] return 
    rts
    // main::@2
  __b2:
    // [7] (byte~) main::$1 ← (byte) main::i << (byte) 1 -- vbuz1=vbuz2_rol_1 
    lda.z i
    asl
    sta.z __1
    // [8] *((const word*) SCREEN + (byte~) main::$1) ← (const word) main::ch -- pwuc1_derefidx_vbuz1=vwuc2 
    ldy.z __1
    lda #<ch
    sta SCREEN,y
    lda #>ch
    sta SCREEN+1,y
    // [9] (byte) main::i ← ++ (byte) main::i -- vbuz1=_inc_vbuz1 
    inc.z i
    // [10] (byte~) main::$2 ← (byte) main::i << (byte) 1 -- vbuz1=vbuz2_rol_1 
    lda.z i
    asl
    sta.z __2
    // [11] *((const word*) SCREEN + (byte~) main::$2) ← (const word) main::ch -- pwuc1_derefidx_vbuz1=vwuc2 
    ldy.z __2
    lda #<ch
    sta SCREEN,y
    lda #>ch
    sta SCREEN+1,y
    // [12] (byte) main::i ← ++ (byte) main::i -- vbuz1=_inc_vbuz1 
    inc.z i
    jmp __b1
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] (byte) main::i ← (byte) 0 [ main::i ] ( main:2 [ main::i ] ) always clobbers reg byte a 
Statement [5] if((byte) main::i<(byte) 8) goto main::@2 [ main::i ] ( main:2 [ main::i ] ) always clobbers reg byte a 
Statement [7] (byte~) main::$1 ← (byte) main::i << (byte) 1 [ main::i main::$1 ] ( main:2 [ main::i main::$1 ] ) always clobbers reg byte a 
Statement [8] *((const word*) SCREEN + (byte~) main::$1) ← (const word) main::ch [ main::i ] ( main:2 [ main::i ] ) always clobbers reg byte a 
Statement [10] (byte~) main::$2 ← (byte) main::i << (byte) 1 [ main::i main::$2 ] ( main:2 [ main::i main::$2 ] ) always clobbers reg byte a 
Statement [11] *((const word*) SCREEN + (byte~) main::$2) ← (const word) main::ch [ main::i ] ( main:2 [ main::i ] ) always clobbers reg byte a 
Potential registers zp[1]:2 [ main::i ] : zp[1]:2 , 
Potential registers zp[1]:3 [ main::$1 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:4 [ main::$2 ] : zp[1]:4 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 22: zp[1]:3 [ main::$1 ] 22: zp[1]:4 [ main::$2 ] 9.88: zp[1]:2 [ main::i ] 
Uplift Scope [] 

Uplifting [main] best 681 combination reg byte a [ main::$1 ] reg byte a [ main::$2 ] zp[1]:2 [ main::i ] 
Uplifting [] best 681 combination 
Attempting to uplift remaining variables inzp[1]:2 [ main::i ]
Uplifting [main] best 681 combination zp[1]:2 [ main::i ] 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Test declaring a variable as at a hard-coded address
// Incrementing a load/store variable will result in cause two *SIZEOF's
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  // @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: {
    .const ch = $102
    .label i = 2
    // [4] (byte) main::i ← (byte) 0 -- vbuz1=vbuc1 
    lda #0
    sta.z i
    jmp __b1
    // main::@1
  __b1:
    // [5] if((byte) main::i<(byte) 8) goto main::@2 -- vbuz1_lt_vbuc1_then_la1 
    lda.z i
    cmp #8
    bcc __b2
    jmp __breturn
    // main::@return
  __breturn:
    // [6] return 
    rts
    // main::@2
  __b2:
    // [7] (byte~) main::$1 ← (byte) main::i << (byte) 1 -- vbuaa=vbuz1_rol_1 
    lda.z i
    asl
    // [8] *((const word*) SCREEN + (byte~) main::$1) ← (const word) main::ch -- pwuc1_derefidx_vbuaa=vwuc2 
    tay
    lda #<ch
    sta SCREEN,y
    lda #>ch
    sta SCREEN+1,y
    // [9] (byte) main::i ← ++ (byte) main::i -- vbuz1=_inc_vbuz1 
    inc.z i
    // [10] (byte~) main::$2 ← (byte) main::i << (byte) 1 -- vbuaa=vbuz1_rol_1 
    lda.z i
    asl
    // [11] *((const word*) SCREEN + (byte~) main::$2) ← (const word) main::ch -- pwuc1_derefidx_vbuaa=vwuc2 
    tay
    lda #<ch
    sta SCREEN,y
    lda #>ch
    sta SCREEN+1,y
    // [12] (byte) main::i ← ++ (byte) main::i -- vbuz1=_inc_vbuz1 
    inc.z i
    jmp __b1
}
  // 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 __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 word*) SCREEN = (word*) 1024
(void()) main()
(byte~) main::$1 reg byte a 22.0
(byte~) main::$2 reg byte a 22.0
(label) main::@1
(label) main::@2
(label) main::@return
(const word) main::ch = (word) $102
(byte) main::i loadstore !zp[-1]:2 zp[1]:2 9.875

zp[1]:2 [ main::i ]
reg byte a [ main::$1 ]
reg byte a [ main::$2 ]


FINAL ASSEMBLER
Score: 636

  // File Comments
// Test declaring a variable as at a hard-coded address
// Incrementing a load/store variable will result in cause two *SIZEOF's
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  // @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: {
    .const ch = $102
    .label i = 2
    // i=0
    // [4] (byte) main::i ← (byte) 0 -- vbuz1=vbuc1 
    lda #0
    sta.z i
    // main::@1
  __b1:
    // while(i<8)
    // [5] if((byte) main::i<(byte) 8) goto main::@2 -- vbuz1_lt_vbuc1_then_la1 
    lda.z i
    cmp #8
    bcc __b2
    // main::@return
    // }
    // [6] return 
    rts
    // main::@2
  __b2:
    // SCREEN[i++] = ch
    // [7] (byte~) main::$1 ← (byte) main::i << (byte) 1 -- vbuaa=vbuz1_rol_1 
    lda.z i
    asl
    // [8] *((const word*) SCREEN + (byte~) main::$1) ← (const word) main::ch -- pwuc1_derefidx_vbuaa=vwuc2 
    tay
    lda #<ch
    sta SCREEN,y
    lda #>ch
    sta SCREEN+1,y
    // SCREEN[i++] = ch;
    // [9] (byte) main::i ← ++ (byte) main::i -- vbuz1=_inc_vbuz1 
    inc.z i
    // SCREEN[i++] = ch
    // [10] (byte~) main::$2 ← (byte) main::i << (byte) 1 -- vbuaa=vbuz1_rol_1 
    lda.z i
    asl
    // [11] *((const word*) SCREEN + (byte~) main::$2) ← (const word) main::ch -- pwuc1_derefidx_vbuaa=vwuc2 
    tay
    lda #<ch
    sta SCREEN,y
    lda #>ch
    sta SCREEN+1,y
    // SCREEN[i++] = ch;
    // [12] (byte) main::i ← ++ (byte) main::i -- vbuz1=_inc_vbuz1 
    inc.z i
    jmp __b1
}
  // File Data

