Fixing pointer array-indexing *((struct Point[]) points + (byte) main::i)
Fixing pointer array-indexing *((struct Point[]) points + (byte) main::i)
Fixing pointer array-indexing *((struct Point[]) points + (byte) main::i)
Rewriting struct pointer member access *((struct Point[]) points + (byte~) main::$3).x
Rewriting struct pointer member access *((struct Point[]) points + (byte~) main::$4).y
Rewriting struct pointer member access *((struct Point[]) points + (byte~) main::$5).y
Culled Empty Block (label) main::@2

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (struct Point[]) points#0 ← { { (number) 1, (number) 2 }, { (number) 3, (number) 4 }, { (number) 5, (number) 6 } }
  to:@1
main: scope:[main]  from @1
  (byte*) main::SCREEN#0 ← ((byte*)) (number) $400
  (byte) main::idx#0 ← (number) 0
  (byte) main::i#0 ← (byte) 0
  to:main::@1
main::@1: scope:[main]  from main main::@1
  (byte) main::idx#4 ← phi( main/(byte) main::idx#0 main::@1/(byte) main::idx#3 )
  (byte) main::i#2 ← phi( main/(byte) main::i#0 main::@1/(byte) main::i#1 )
  (byte~) main::$3 ← (byte) main::i#2 * (const byte) SIZEOF_STRUCT_POINT
  (byte*) main::$6 ← (byte*)(struct Point[]) points#0 + (const byte) OFFSET_STRUCT_POINT_X
  *((byte*) main::SCREEN#0 + (byte) main::idx#4) ← *((byte*) main::$6 + (byte~) main::$3)
  (byte) main::idx#1 ← ++ (byte) main::idx#4
  (byte~) main::$4 ← (byte) main::i#2 * (const byte) SIZEOF_STRUCT_POINT
  (signed word*) main::$7 ← (signed word*)(struct Point[]) points#0 + (const byte) OFFSET_STRUCT_POINT_Y
  (byte~) main::$0 ← < *((signed word*) main::$7 + (byte~) main::$4)
  *((byte*) main::SCREEN#0 + (byte) main::idx#1) ← (byte~) main::$0
  (byte) main::idx#2 ← ++ (byte) main::idx#1
  (byte~) main::$5 ← (byte) main::i#2 * (const byte) SIZEOF_STRUCT_POINT
  (signed word*) main::$8 ← (signed word*)(struct Point[]) points#0 + (const byte) OFFSET_STRUCT_POINT_Y
  (byte~) main::$1 ← > *((signed word*) main::$8 + (byte~) main::$5)
  *((byte*) main::SCREEN#0 + (byte) main::idx#2) ← (byte~) main::$1
  (byte) main::idx#3 ← ++ (byte) main::idx#2
  (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) OFFSET_STRUCT_POINT_X = (byte) 0
(const byte) OFFSET_STRUCT_POINT_Y = (byte) 1
(byte) Point::x
(signed word) Point::y
(const byte) SIZEOF_STRUCT_POINT = (byte) 3
(void()) main()
(byte~) main::$0
(byte~) main::$1
(bool~) main::$2
(byte~) main::$3
(byte~) main::$4
(byte~) main::$5
(byte*) main::$6
(signed word*) main::$7
(signed word*) main::$8
(label) main::@1
(label) main::@return
(byte*) main::SCREEN
(byte*) main::SCREEN#0
(byte) main::i
(byte) main::i#0
(byte) main::i#1
(byte) main::i#2
(byte) main::idx
(byte) main::idx#0
(byte) main::idx#1
(byte) main::idx#2
(byte) main::idx#3
(byte) main::idx#4
(struct Point[]) points
(struct Point[]) points#0

Adding number conversion cast (unumber) 0 in (byte) main::idx#0 ← (number) 0
Successful SSA optimization PassNAddNumberTypeConversions
Added casts to value list in (struct Point[]) points#0 ← (struct Point[]){ (struct Point){ (byte)(number) 1, (signed word)(number) 2 }, (struct Point){ (byte)(number) 3, (signed word)(number) 4 }, (struct Point){ (byte)(number) 5, (signed word)(number) 6 } }
Successful SSA optimization PassNAddInitializerValueListTypeCasts
Inlining cast (byte*) main::SCREEN#0 ← (byte*)(number) $400
Inlining cast (byte) main::idx#0 ← (unumber)(number) 0
Successful SSA optimization Pass2InlineCast
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
Simplifying constant integer cast 6
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Identified duplicate assignment right side [9] (byte~) main::$4 ← (byte) main::i#2 * (const byte) SIZEOF_STRUCT_POINT
Identified duplicate assignment right side [14] (byte~) main::$5 ← (byte) main::i#2 * (const byte) SIZEOF_STRUCT_POINT
Successful SSA optimization Pass2DuplicateRValueIdentification
Simple Condition (bool~) main::$2 [21] if((byte) main::i#1!=rangelast(0,2)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Identified constant from value list (struct Point) { x: (byte) 1, y: (signed word) 2 }
Identified constant from value list (struct Point) { x: (byte) 3, y: (signed word) 4 }
Identified constant from value list (struct Point) { x: (byte) 5, y: (signed word) 6 }
Successful SSA optimization Pass2ConstantInitializerValueLists
Identified constant from value list (struct Point[]) { { x: (byte) 1, y: (signed word) 2 }, { x: (byte) 3, y: (signed word) 4 }, { x: (byte) 5, y: (signed word) 6 } }
Successful SSA optimization Pass2ConstantInitializerValueLists
Constant (const struct Point[]) points#0 = { { x: 1, y: 2 }, { x: 3, y: 4 }, { x: 5, y: 6 } }
Constant (const byte*) main::SCREEN#0 = (byte*) 1024
Constant (const byte) main::idx#0 = 0
Constant (const byte) main::i#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Constant value identified (byte*)points#0 in [6] (byte*) main::$6 ← (byte*)(const struct Point[]) points#0 + (const byte) OFFSET_STRUCT_POINT_X
Constant value identified (signed word*)points#0 in [10] (signed word*) main::$7 ← (signed word*)(const struct Point[]) points#0 + (const byte) OFFSET_STRUCT_POINT_Y
Constant value identified (signed word*)points#0 in [15] (signed word*) main::$8 ← (signed word*)(const struct Point[]) points#0 + (const byte) OFFSET_STRUCT_POINT_Y
Successful SSA optimization Pass2ConstantValues
Resolved ranged next value [19] main::i#1 ← ++ main::i#2 to ++
Resolved ranged comparison value [21] if(main::i#1!=rangelast(0,2)) goto main::@1 to (number) 3
Simplifying expression containing zero (byte*)points#0 in [6] (byte*) main::$6 ← (byte*)(const struct Point[]) points#0 + (const byte) OFFSET_STRUCT_POINT_X
Successful SSA optimization PassNSimplifyExpressionWithZero
Eliminating unused constant (const byte) OFFSET_STRUCT_POINT_X
Successful SSA optimization PassNEliminateUnusedVars
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
Alias (byte~) main::$4 = (byte~) main::$3 (byte~) main::$5 
Successful SSA optimization Pass2AliasElimination
Constant right-side identified [6] (signed word*) main::$7 ← (signed word*)(const struct Point[]) points#0 + (const byte) OFFSET_STRUCT_POINT_Y
Constant right-side identified [11] (signed word*) main::$8 ← (signed word*)(const struct Point[]) points#0 + (const byte) OFFSET_STRUCT_POINT_Y
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const byte*) main::$6 = (byte*)points#0
Constant (const signed word*) main::$7 = (signed word*)points#0+OFFSET_STRUCT_POINT_Y
Constant (const signed word*) main::$8 = (signed word*)points#0+OFFSET_STRUCT_POINT_Y
Successful SSA optimization Pass2ConstantIdentification
Rewriting multiplication to use shift and addition[1] (byte~) main::$4 ← (byte) main::i#2 * (const byte) SIZEOF_STRUCT_POINT
Inlining constant with var siblings (const byte) main::idx#0
Inlining constant with var siblings (const byte) main::i#0
Constant inlined main::i#0 = (byte) 0
Constant inlined main::$6 = (byte*)(const struct Point[]) points#0
Constant inlined main::idx#0 = (byte) 0
Constant inlined main::$7 = (signed word*)(const struct Point[]) points#0+(const byte) OFFSET_STRUCT_POINT_Y
Constant inlined main::$8 = (signed word*)(const struct Point[]) points#0+(const byte) OFFSET_STRUCT_POINT_Y
Successful SSA optimization Pass2ConstantInlining
Alias (byte~) main::$4 = (byte) main::$10 
Successful SSA optimization Pass2AliasElimination
Eliminating unused constant (const byte) SIZEOF_STRUCT_POINT
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 2 initial phi equivalence classes
Coalesced [20] main::i#3 ← main::i#1
Coalesced [21] main::idx#5 ← main::idx#3
Coalesced down to 2 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::idx#4 ← phi( main/(byte) 0 main::@1/(byte) main::idx#3 )
  [5] (byte) main::i#2 ← phi( main/(byte) 0 main::@1/(byte) main::i#1 )
  [6] (byte) main::$9 ← (byte) main::i#2 << (byte) 1
  [7] (byte~) main::$4 ← (byte) main::$9 + (byte) main::i#2
  [8] *((const byte*) main::SCREEN#0 + (byte) main::idx#4) ← *((byte*)(const struct Point[]) points#0 + (byte~) main::$4)
  [9] (byte) main::idx#1 ← ++ (byte) main::idx#4
  [10] (byte~) main::$0 ← < *((signed word*)(const struct Point[]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (byte~) main::$4)
  [11] *((const byte*) main::SCREEN#0 + (byte) main::idx#1) ← (byte~) main::$0
  [12] (byte) main::idx#2 ← ++ (byte) main::idx#1
  [13] (byte~) main::$1 ← > *((signed word*)(const struct Point[]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (byte~) main::$4)
  [14] *((const byte*) main::SCREEN#0 + (byte) main::idx#2) ← (byte~) main::$1
  [15] (byte) main::idx#3 ← ++ (byte) main::idx#2
  [16] (byte) main::i#1 ← ++ (byte) main::i#2
  [17] if((byte) main::i#1!=(byte) 3) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  [18] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(byte) Point::x
(signed word) Point::y
(void()) main()
(byte~) main::$0 22.0
(byte~) main::$1 22.0
(byte~) main::$4 7.333333333333333
(byte) main::$9 22.0
(byte*) main::SCREEN
(byte) main::i
(byte) main::i#1 16.5
(byte) main::i#2 4.0
(byte) main::idx
(byte) main::idx#1 11.0
(byte) main::idx#2 11.0
(byte) main::idx#3 7.333333333333333
(byte) main::idx#4 8.25
(struct Point[]) points

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

INITIAL ASM
Target platform is c64basic
  // File Comments
// Demonstrates initializing an array of structs
// Array of structs containing words
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .const OFFSET_STRUCT_POINT_Y = 1
  // @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 _0 = 7
    .label _1 = 9
    .label _4 = 5
    .label idx = 6
    .label idx_2 = 8
    .label idx_3 = 3
    .label i = 2
    .label idx_4 = 3
    .label _9 = 4
    // [5] phi from main to main::@1 [phi:main->main::@1]
  b1_from_main:
    // [5] phi (byte) main::idx#4 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z idx_4
    // [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#1] -- vbuz1=vbuc1 
    lda #0
    sta.z i
    jmp b1
    // [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  b1_from_b1:
    // [5] phi (byte) main::idx#4 = (byte) main::idx#3 [phi:main::@1->main::@1#0] -- register_copy 
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#1] -- register_copy 
    jmp b1
    // main::@1
  b1:
    // [6] (byte) main::$9 ← (byte) main::i#2 << (byte) 1 -- vbuz1=vbuz2_rol_1 
    lda.z i
    asl
    sta.z _9
    // [7] (byte~) main::$4 ← (byte) main::$9 + (byte) main::i#2 -- vbuz1=vbuz2_plus_vbuz3 
    lda.z _9
    clc
    adc.z i
    sta.z _4
    // [8] *((const byte*) main::SCREEN#0 + (byte) main::idx#4) ← *((byte*)(const struct Point[]) points#0 + (byte~) main::$4) -- pbuc1_derefidx_vbuz1=pbuc2_derefidx_vbuz2 
    ldy.z _4
    lda points,y
    ldy.z idx_4
    sta SCREEN,y
    // [9] (byte) main::idx#1 ← ++ (byte) main::idx#4 -- vbuz1=_inc_vbuz2 
    ldy.z idx_4
    iny
    sty.z idx
    // [10] (byte~) main::$0 ← < *((signed word*)(const struct Point[]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (byte~) main::$4) -- vbuz1=_lo_pwsc1_derefidx_vbuz2 
    ldy.z _4
    lda points+OFFSET_STRUCT_POINT_Y,y
    sta.z _0
    // [11] *((const byte*) main::SCREEN#0 + (byte) main::idx#1) ← (byte~) main::$0 -- pbuc1_derefidx_vbuz1=vbuz2 
    lda.z _0
    ldy.z idx
    sta SCREEN,y
    // [12] (byte) main::idx#2 ← ++ (byte) main::idx#1 -- vbuz1=_inc_vbuz2 
    ldy.z idx
    iny
    sty.z idx_2
    // [13] (byte~) main::$1 ← > *((signed word*)(const struct Point[]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (byte~) main::$4) -- vbuz1=_hi_pwsc1_derefidx_vbuz2 
    ldy.z _4
    lda points+OFFSET_STRUCT_POINT_Y+1,y
    sta.z _1
    // [14] *((const byte*) main::SCREEN#0 + (byte) main::idx#2) ← (byte~) main::$1 -- pbuc1_derefidx_vbuz1=vbuz2 
    lda.z _1
    ldy.z idx_2
    sta SCREEN,y
    // [15] (byte) main::idx#3 ← ++ (byte) main::idx#2 -- vbuz1=_inc_vbuz2 
    ldy.z idx_2
    iny
    sty.z idx_3
    // [16] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [17] if((byte) main::i#1!=(byte) 3) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #3
    cmp.z i
    bne b1_from_b1
    jmp breturn
    // main::@return
  breturn:
    // [18] return 
    rts
}
  // File Data
points:
  .byte 1
  .word 2
  .byte 3
  .word 4
  .byte 5
  .word 6

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [6] (byte) main::$9 ← (byte) main::i#2 << (byte) 1 [ main::i#2 main::idx#4 main::$9 ] ( main:2 [ main::i#2 main::idx#4 main::$9 ] ) 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 ]
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:3 [ main::idx#4 main::idx#3 ]
Statement [7] (byte~) main::$4 ← (byte) main::$9 + (byte) main::i#2 [ main::i#2 main::idx#4 main::$4 ] ( main:2 [ main::i#2 main::idx#4 main::$4 ] ) always clobbers reg byte a 
Statement [8] *((const byte*) main::SCREEN#0 + (byte) main::idx#4) ← *((byte*)(const struct Point[]) points#0 + (byte~) main::$4) [ main::i#2 main::idx#4 main::$4 ] ( main:2 [ main::i#2 main::idx#4 main::$4 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:5 [ main::$4 ]
Statement [10] (byte~) main::$0 ← < *((signed word*)(const struct Point[]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (byte~) main::$4) [ main::i#2 main::$4 main::idx#1 main::$0 ] ( main:2 [ main::i#2 main::$4 main::idx#1 main::$0 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:6 [ main::idx#1 ]
Statement [13] (byte~) main::$1 ← > *((signed word*)(const struct Point[]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (byte~) main::$4) [ main::i#2 main::idx#2 main::$1 ] ( main:2 [ main::i#2 main::idx#2 main::$1 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:8 [ main::idx#2 ]
Statement [6] (byte) main::$9 ← (byte) main::i#2 << (byte) 1 [ main::i#2 main::idx#4 main::$9 ] ( main:2 [ main::i#2 main::idx#4 main::$9 ] ) always clobbers reg byte a 
Statement [7] (byte~) main::$4 ← (byte) main::$9 + (byte) main::i#2 [ main::i#2 main::idx#4 main::$4 ] ( main:2 [ main::i#2 main::idx#4 main::$4 ] ) always clobbers reg byte a 
Statement [8] *((const byte*) main::SCREEN#0 + (byte) main::idx#4) ← *((byte*)(const struct Point[]) points#0 + (byte~) main::$4) [ main::i#2 main::idx#4 main::$4 ] ( main:2 [ main::i#2 main::idx#4 main::$4 ] ) always clobbers reg byte a 
Statement [10] (byte~) main::$0 ← < *((signed word*)(const struct Point[]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (byte~) main::$4) [ main::i#2 main::$4 main::idx#1 main::$0 ] ( main:2 [ main::i#2 main::$4 main::idx#1 main::$0 ] ) always clobbers reg byte a 
Statement [13] (byte~) main::$1 ← > *((signed word*)(const struct Point[]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (byte~) main::$4) [ main::i#2 main::idx#2 main::$1 ] ( main:2 [ main::i#2 main::idx#2 main::$1 ] ) 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_BYTE:3 [ main::idx#4 main::idx#3 ] : zp ZP_BYTE:3 , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:4 [ main::$9 ] : zp ZP_BYTE:4 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:5 [ main::$4 ] : zp ZP_BYTE:5 , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:6 [ main::idx#1 ] : zp ZP_BYTE:6 , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:7 [ main::$0 ] : zp ZP_BYTE:7 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:8 [ main::idx#2 ] : zp ZP_BYTE:8 , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:9 [ main::$1 ] : zp ZP_BYTE:9 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 22: zp ZP_BYTE:4 [ main::$9 ] 22: zp ZP_BYTE:7 [ main::$0 ] 22: zp ZP_BYTE:9 [ main::$1 ] 20.5: zp ZP_BYTE:2 [ main::i#2 main::i#1 ] 15.58: zp ZP_BYTE:3 [ main::idx#4 main::idx#3 ] 11: zp ZP_BYTE:6 [ main::idx#1 ] 11: zp ZP_BYTE:8 [ main::idx#2 ] 7.33: zp ZP_BYTE:5 [ main::$4 ] 
Uplift Scope [Point] 
Uplift Scope [] 

Uplifting [main] best 1098 combination reg byte a [ main::$9 ] reg byte a [ main::$0 ] reg byte a [ main::$1 ] reg byte x [ main::i#2 main::i#1 ] zp ZP_BYTE:3 [ main::idx#4 main::idx#3 ] zp ZP_BYTE:6 [ main::idx#1 ] zp ZP_BYTE:8 [ main::idx#2 ] zp ZP_BYTE:5 [ main::$4 ] 
Limited combination testing to 100 combinations of 15552 possible.
Uplifting [Point] best 1098 combination 
Uplifting [] best 1098 combination 
Attempting to uplift remaining variables inzp ZP_BYTE:3 [ main::idx#4 main::idx#3 ]
Uplifting [main] best 1098 combination zp ZP_BYTE:3 [ main::idx#4 main::idx#3 ] 
Attempting to uplift remaining variables inzp ZP_BYTE:6 [ main::idx#1 ]
Uplifting [main] best 1098 combination zp ZP_BYTE:6 [ main::idx#1 ] 
Attempting to uplift remaining variables inzp ZP_BYTE:8 [ main::idx#2 ]
Uplifting [main] best 1098 combination zp ZP_BYTE:8 [ main::idx#2 ] 
Attempting to uplift remaining variables inzp ZP_BYTE:5 [ main::$4 ]
Uplifting [main] best 1098 combination zp ZP_BYTE:5 [ main::$4 ] 
Coalescing zero page register [ zp ZP_BYTE:3 [ main::idx#4 main::idx#3 ] ] with [ zp ZP_BYTE:6 [ main::idx#1 ] ] - score: 1
Coalescing zero page register [ zp ZP_BYTE:3 [ main::idx#4 main::idx#3 main::idx#1 ] ] with [ zp ZP_BYTE:8 [ main::idx#2 ] ] - score: 1
Allocated (was zp ZP_BYTE:3) zp ZP_BYTE:2 [ main::idx#4 main::idx#3 main::idx#1 main::idx#2 ]
Allocated (was zp ZP_BYTE:5) zp ZP_BYTE:3 [ main::$4 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Demonstrates initializing an array of structs
// Array of structs containing words
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .const OFFSET_STRUCT_POINT_Y = 1
  // @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 _4 = 3
    .label idx = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
  b1_from_main:
    // [5] phi (byte) main::idx#4 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z idx
    // [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#1] -- 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::idx#4 = (byte) main::idx#3 [phi:main::@1->main::@1#0] -- register_copy 
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#1] -- register_copy 
    jmp b1
    // main::@1
  b1:
    // [6] (byte) main::$9 ← (byte) main::i#2 << (byte) 1 -- vbuaa=vbuxx_rol_1 
    txa
    asl
    // [7] (byte~) main::$4 ← (byte) main::$9 + (byte) main::i#2 -- vbuz1=vbuaa_plus_vbuxx 
    stx.z $ff
    clc
    adc.z $ff
    sta.z _4
    // [8] *((const byte*) main::SCREEN#0 + (byte) main::idx#4) ← *((byte*)(const struct Point[]) points#0 + (byte~) main::$4) -- pbuc1_derefidx_vbuz1=pbuc2_derefidx_vbuz2 
    ldy.z _4
    lda points,y
    ldy.z idx
    sta SCREEN,y
    // [9] (byte) main::idx#1 ← ++ (byte) main::idx#4 -- vbuz1=_inc_vbuz1 
    inc.z idx
    // [10] (byte~) main::$0 ← < *((signed word*)(const struct Point[]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (byte~) main::$4) -- vbuaa=_lo_pwsc1_derefidx_vbuz1 
    ldy.z _4
    lda points+OFFSET_STRUCT_POINT_Y,y
    // [11] *((const byte*) main::SCREEN#0 + (byte) main::idx#1) ← (byte~) main::$0 -- pbuc1_derefidx_vbuz1=vbuaa 
    ldy.z idx
    sta SCREEN,y
    // [12] (byte) main::idx#2 ← ++ (byte) main::idx#1 -- vbuz1=_inc_vbuz1 
    inc.z idx
    // [13] (byte~) main::$1 ← > *((signed word*)(const struct Point[]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (byte~) main::$4) -- vbuaa=_hi_pwsc1_derefidx_vbuz1 
    ldy.z _4
    lda points+OFFSET_STRUCT_POINT_Y+1,y
    // [14] *((const byte*) main::SCREEN#0 + (byte) main::idx#2) ← (byte~) main::$1 -- pbuc1_derefidx_vbuz1=vbuaa 
    ldy.z idx
    sta SCREEN,y
    // [15] (byte) main::idx#3 ← ++ (byte) main::idx#2 -- vbuz1=_inc_vbuz1 
    inc.z idx
    // [16] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [17] 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:
    // [18] return 
    rts
}
  // File Data
points:
  .byte 1
  .word 2
  .byte 3
  .word 4
  .byte 5
  .word 6

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing instruction ldx #0 with TAX
Replacing instruction ldy.z _4 with TAY
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
(const byte) OFFSET_STRUCT_POINT_Y OFFSET_STRUCT_POINT_Y = (byte) 1
(byte) Point::x
(signed word) Point::y
(void()) main()
(byte~) main::$0 reg byte a 22.0
(byte~) main::$1 reg byte a 22.0
(byte~) main::$4 $4 zp ZP_BYTE:3 7.333333333333333
(byte) main::$9 reg byte a 22.0
(label) main::@1
(label) main::@return
(byte*) main::SCREEN
(const byte*) main::SCREEN#0 SCREEN = (byte*) 1024
(byte) main::i
(byte) main::i#1 reg byte x 16.5
(byte) main::i#2 reg byte x 4.0
(byte) main::idx
(byte) main::idx#1 idx zp ZP_BYTE:2 11.0
(byte) main::idx#2 idx zp ZP_BYTE:2 11.0
(byte) main::idx#3 idx zp ZP_BYTE:2 7.333333333333333
(byte) main::idx#4 idx zp ZP_BYTE:2 8.25
(struct Point[]) points
(const struct Point[]) points#0 points = { { x: (byte) 1, y: (signed word) 2 }, { x: (byte) 3, y: (signed word) 4 }, { x: (byte) 5, y: (signed word) 6 } }

reg byte x [ main::i#2 main::i#1 ]
zp ZP_BYTE:2 [ main::idx#4 main::idx#3 main::idx#1 main::idx#2 ]
reg byte a [ main::$9 ]
zp ZP_BYTE:3 [ main::$4 ]
reg byte a [ main::$0 ]
reg byte a [ main::$1 ]


FINAL ASSEMBLER
Score: 896

  // File Comments
// Demonstrates initializing an array of structs
// Array of structs containing words
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  .const OFFSET_STRUCT_POINT_Y = 1
  // @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 _4 = 3
    .label idx = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
    // [5] phi (byte) main::idx#4 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z idx
    // [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#1] -- vbuxx=vbuc1 
    tax
    // [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
    // [5] phi (byte) main::idx#4 = (byte) main::idx#3 [phi:main::@1->main::@1#0] -- register_copy 
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#1] -- register_copy 
    // main::@1
  b1:
    // SCREEN[idx++] = points[i].x
    // [6] (byte) main::$9 ← (byte) main::i#2 << (byte) 1 -- vbuaa=vbuxx_rol_1 
    txa
    asl
    // [7] (byte~) main::$4 ← (byte) main::$9 + (byte) main::i#2 -- vbuz1=vbuaa_plus_vbuxx 
    stx.z $ff
    clc
    adc.z $ff
    sta.z _4
    // [8] *((const byte*) main::SCREEN#0 + (byte) main::idx#4) ← *((byte*)(const struct Point[]) points#0 + (byte~) main::$4) -- pbuc1_derefidx_vbuz1=pbuc2_derefidx_vbuz2 
    tay
    lda points,y
    ldy.z idx
    sta SCREEN,y
    // SCREEN[idx++] = points[i].x;
    // [9] (byte) main::idx#1 ← ++ (byte) main::idx#4 -- vbuz1=_inc_vbuz1 
    inc.z idx
    // <points[i].y
    // [10] (byte~) main::$0 ← < *((signed word*)(const struct Point[]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (byte~) main::$4) -- vbuaa=_lo_pwsc1_derefidx_vbuz1 
    ldy.z _4
    lda points+OFFSET_STRUCT_POINT_Y,y
    // SCREEN[idx++] = <points[i].y
    // [11] *((const byte*) main::SCREEN#0 + (byte) main::idx#1) ← (byte~) main::$0 -- pbuc1_derefidx_vbuz1=vbuaa 
    ldy.z idx
    sta SCREEN,y
    // SCREEN[idx++] = <points[i].y;
    // [12] (byte) main::idx#2 ← ++ (byte) main::idx#1 -- vbuz1=_inc_vbuz1 
    inc.z idx
    // >points[i].y
    // [13] (byte~) main::$1 ← > *((signed word*)(const struct Point[]) points#0+(const byte) OFFSET_STRUCT_POINT_Y + (byte~) main::$4) -- vbuaa=_hi_pwsc1_derefidx_vbuz1 
    ldy.z _4
    lda points+OFFSET_STRUCT_POINT_Y+1,y
    // SCREEN[idx++] = >points[i].y
    // [14] *((const byte*) main::SCREEN#0 + (byte) main::idx#2) ← (byte~) main::$1 -- pbuc1_derefidx_vbuz1=vbuaa 
    ldy.z idx
    sta SCREEN,y
    // SCREEN[idx++] = >points[i].y;
    // [15] (byte) main::idx#3 ← ++ (byte) main::idx#2 -- vbuz1=_inc_vbuz1 
    inc.z idx
    // for( char i: 0..2)
    // [16] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [17] if((byte) main::i#1!=(byte) 3) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #3
    bne b1
    // main::@return
    // }
    // [18] return 
    rts
}
  // File Data
points:
  .byte 1
  .word 2
  .byte 3
  .word 4
  .byte 5
  .word 6

