
CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start
  main::i#0 = 0
  to:main::@1
main::@1: scope:[main]  from main main::@1
  main::i#2 = phi( main/main::i#0, main::@1/main::i#1 )
  main::$3 = main::i#2 * SIZEOF_STRUCT_POINT
  ((char *)points+OFFSET_STRUCT_POINT_X)[main::$3] = main::i#2
  main::$0 = main::i#2 + 1
  main::$4 = main::i#2 * SIZEOF_STRUCT_POINT
  ((char *)points+OFFSET_STRUCT_POINT_Y)[main::$4] = main::$0
  main::i#1 = main::i#2 + rangenext(0,4)
  main::$1 = main::i#1 != rangelast(0,4)
  if(main::$1) goto main::@1
  to:main::@2
main::@2: scope:[main]  from main::@1
  main::i1#0 = 0
  to:main::@3
main::@3: scope:[main]  from main::@2 main::@3
  main::i1#2 = phi( main::@2/main::i1#0, main::@3/main::i1#1 )
  main::$5 = main::i1#2 * SIZEOF_STRUCT_POINT
  main::SCREEN[main::i1#2] = ((char *)points+OFFSET_STRUCT_POINT_X)[main::$5]
  main::$6 = main::i1#2 * SIZEOF_STRUCT_POINT
  (main::SCREEN+$28)[main::i1#2] = ((char *)points+OFFSET_STRUCT_POINT_Y)[main::$6]
  main::i1#1 = main::i1#2 + rangenext(0,4)
  main::$2 = main::i1#1 != rangelast(0,4)
  if(main::$2) goto main::@3
  to:main::@return
main::@return: scope:[main]  from main::@3
  return 
  to:@return

void __start()
__start: scope:[__start]  from
  call main
  to:__start::@1
__start::@1: scope:[__start]  from __start
  to:__start::@return
__start::@return: scope:[__start]  from __start::@1
  return 
  to:@return

SYMBOL TABLE SSA
__constant char OFFSET_STRUCT_POINT_X = 0
__constant char OFFSET_STRUCT_POINT_Y = 1
__constant char SIZEOF_STRUCT_POINT = 2
void __start()
void main()
number main::$0
bool main::$1
bool main::$2
char main::$3
char main::$4
char main::$5
char main::$6
__constant char * const main::SCREEN = (char *)$400
char main::i
char main::i#0
char main::i#1
char main::i#2
char main::i1
char main::i1#0
char main::i1#1
char main::i1#2
__constant struct Point points[4] = { fill( 4, 0) }

Adding number conversion cast (unumber) 1 in main::$0 = main::i#2 + 1
Adding number conversion cast (unumber) main::$0 in main::$0 = main::i#2 + (unumber)1
Adding number conversion cast (unumber) $28 in (main::SCREEN+$28)[main::i1#2] = ((char *)points+OFFSET_STRUCT_POINT_Y)[main::$6]
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast 1
Simplifying constant integer cast $28
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) $28
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to char in main::$0 = main::i#2 + 1
Identified duplicate assignment right side [5] main::$4 = main::i#2 * SIZEOF_STRUCT_POINT
Identified duplicate assignment right side [14] main::$6 = main::i1#2 * SIZEOF_STRUCT_POINT
Successful SSA optimization Pass2DuplicateRValueIdentification
Simple Condition main::$1 [9] if(main::i#1!=rangelast(0,4)) goto main::@1
Simple Condition main::$2 [18] if(main::i1#1!=rangelast(0,4)) goto main::@3
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant main::i#0 = 0
Constant main::i1#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [7] main::i#1 = ++ main::i#2 to ++
Resolved ranged comparison value [9] if(main::i#1!=rangelast(0,4)) goto main::@1 to 5
Resolved ranged next value [16] main::i1#1 = ++ main::i1#2 to ++
Resolved ranged comparison value [18] if(main::i1#1!=rangelast(0,4)) goto main::@3 to 5
Simplifying expression containing zero (char *)points in [3] ((char *)points+OFFSET_STRUCT_POINT_X)[main::$3] = main::i#2
Simplifying expression containing zero (char *)points in [13] main::SCREEN[main::i1#2] = ((char *)points+OFFSET_STRUCT_POINT_X)[main::$5]
Successful SSA optimization PassNSimplifyExpressionWithZero
Eliminating unused constant OFFSET_STRUCT_POINT_X
Successful SSA optimization PassNEliminateUnusedVars
Removing unused procedure __start
Removing unused procedure block __start
Removing unused procedure block __start::@1
Removing unused procedure block __start::@return
Successful SSA optimization PassNEliminateEmptyStart
Adding number conversion cast (unumber) 5 in [7] if(main::i#1!=5) goto main::@1
Adding number conversion cast (unumber) 5 in [14] if(main::i1#1!=5) goto main::@3
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast 5
Simplifying constant integer cast 5
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 5
Finalized unsigned number type (char) 5
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias main::$4 = main::$3 
Alias main::$6 = main::$5 
Successful SSA optimization Pass2AliasElimination
Rewriting multiplication to use shift [1] main::$4 = main::i#2 * SIZEOF_STRUCT_POINT
Rewriting multiplication to use shift [8] main::$6 = main::i1#2 * SIZEOF_STRUCT_POINT
Successful SSA optimization Pass2MultiplyToShiftRewriting
Inlining constant with var siblings main::i#0
Inlining constant with var siblings main::i1#0
Constant inlined main::i#0 = 0
Constant inlined main::i1#0 = 0
Successful SSA optimization Pass2ConstantInlining
Eliminating unused constant SIZEOF_STRUCT_POINT
Successful SSA optimization PassNEliminateUnusedVars
Finalized unsigned number type (char) 4
Finalized unsigned number type (char) 4
Successful SSA optimization PassNFinalizeNumberTypeConversions
Added new block during phi lifting main::@4(between main::@1 and main::@1)
Added new block during phi lifting main::@5(between main::@3 and main::@3)
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@2
CALL GRAPH

Created 2 initial phi equivalence classes
Coalesced [16] main::i1#3 = main::i1#1
Coalesced [17] main::i#3 = main::i#1
Coalesced down to 2 phi equivalence classes
Culled Empty Block label main::@2
Culled Empty Block label main::@5
Culled Empty Block label main::@4
Renumbering block main::@3 to main::@2
Adding NOP phi() at start of main

FINAL CONTROL FLOW GRAPH

void main()
main: scope:[main]  from
  [0] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@1
  [1] main::i#2 = phi( main/0, main::@1/main::i#1 )
  [2] main::$4 = main::i#2 << 1
  [3] ((char *)points)[main::$4] = main::i#2
  [4] main::$0 = main::i#2 + 1
  [5] ((char *)points+OFFSET_STRUCT_POINT_Y)[main::$4] = main::$0
  [6] main::i#1 = ++ main::i#2
  [7] if(main::i#1!=5) goto main::@1
  to:main::@2
main::@2: scope:[main]  from main::@1 main::@2
  [8] main::i1#2 = phi( main::@1/0, main::@2/main::i1#1 )
  [9] main::$6 = main::i1#2 << 1
  [10] main::SCREEN[main::i1#2] = ((char *)points)[main::$6]
  [11] (main::SCREEN+$28)[main::i1#2] = ((char *)points+OFFSET_STRUCT_POINT_Y)[main::$6]
  [12] main::i1#1 = ++ main::i1#2
  [13] if(main::i1#1!=5) goto main::@2
  to:main::@return
main::@return: scope:[main]  from main::@2
  [14] return 
  to:@return


VARIABLE REGISTER WEIGHTS
void main()
char main::$0 // 22.0
char main::$4 // 11.0
char main::$6 // 16.5
char main::i
char main::i#1 // 16.5
char main::i#2 // 11.0
char main::i1
char main::i1#1 // 16.5
char main::i1#2 // 13.75

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
[ main::i1#2 main::i1#1 ]
Added variable main::$4 to live range equivalence class [ main::$4 ]
Added variable main::$0 to live range equivalence class [ main::$0 ]
Added variable main::$6 to live range equivalence class [ main::$6 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ main::i1#2 main::i1#1 ]
[ main::$4 ]
[ main::$0 ]
[ main::$6 ]
Allocated zp[1]:2 [ main::i1#2 main::i1#1 ]
Allocated zp[1]:3 [ main::i#2 main::i#1 ]
Allocated zp[1]:4 [ main::$0 ]
Allocated zp[1]:5 [ main::$6 ]
Allocated zp[1]:6 [ main::$4 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [2] main::$4 = main::i#2 << 1 [ main::i#2 main::$4 ] (  [ main::i#2 main::$4 ] { }  ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:3 [ main::i#2 main::i#1 ]
Statement [3] ((char *)points)[main::$4] = main::i#2 [ main::i#2 main::$4 ] (  [ main::i#2 main::$4 ] { }  ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:6 [ main::$4 ]
Statement [9] main::$6 = main::i1#2 << 1 [ main::i1#2 main::$6 ] (  [ main::i1#2 main::$6 ] { }  ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::i1#2 main::i1#1 ]
Statement [10] main::SCREEN[main::i1#2] = ((char *)points)[main::$6] [ main::i1#2 main::$6 ] (  [ main::i1#2 main::$6 ] { }  ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:5 [ main::$6 ]
Statement [11] (main::SCREEN+$28)[main::i1#2] = ((char *)points+OFFSET_STRUCT_POINT_Y)[main::$6] [ main::i1#2 ] (  [ main::i1#2 ] { }  ) always clobbers reg byte a 
Statement [2] main::$4 = main::i#2 << 1 [ main::i#2 main::$4 ] (  [ main::i#2 main::$4 ] { }  ) always clobbers reg byte a 
Statement [3] ((char *)points)[main::$4] = main::i#2 [ main::i#2 main::$4 ] (  [ main::i#2 main::$4 ] { }  ) always clobbers reg byte a 
Statement [9] main::$6 = main::i1#2 << 1 [ main::i1#2 main::$6 ] (  [ main::i1#2 main::$6 ] { }  ) always clobbers reg byte a 
Statement [10] main::SCREEN[main::i1#2] = ((char *)points)[main::$6] [ main::i1#2 main::$6 ] (  [ main::i1#2 main::$6 ] { }  ) always clobbers reg byte a 
Statement [11] (main::SCREEN+$28)[main::i1#2] = ((char *)points+OFFSET_STRUCT_POINT_Y)[main::$6] [ main::i1#2 ] (  [ main::i1#2 ] { }  ) always clobbers reg byte a 
Potential registers zp[1]:3 [ main::i#2 main::i#1 ] : zp[1]:3 , reg byte x , reg byte y , 
Potential registers zp[1]:2 [ main::i1#2 main::i1#1 ] : zp[1]:2 , reg byte x , reg byte y , 
Potential registers zp[1]:6 [ main::$4 ] : zp[1]:6 , reg byte x , reg byte y , 
Potential registers zp[1]:4 [ main::$0 ] : zp[1]:4 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:5 [ main::$6 ] : zp[1]:5 , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 30.25: zp[1]:2 [ main::i1#2 main::i1#1 ] 27.5: zp[1]:3 [ main::i#2 main::i#1 ] 22: zp[1]:4 [ main::$0 ] 16.5: zp[1]:5 [ main::$6 ] 11: zp[1]:6 [ main::$4 ] 
Uplift Scope [Point] 
Uplift Scope [] 

Uplifting [main] best 906 combination reg byte y [ main::i1#2 main::i1#1 ] reg byte x [ main::i#2 main::i#1 ] reg byte y [ main::$0 ] reg byte x [ main::$6 ] zp[1]:6 [ main::$4 ] 
Limited combination testing to 100 combinations of 324 possible.
Uplifting [Point] best 906 combination 
Uplifting [] best 906 combination 
Attempting to uplift remaining variables inzp[1]:6 [ main::$4 ]
Uplifting [main] best 906 combination zp[1]:6 [ main::$4 ] 
Allocated (was zp[1]:6) zp[1]:2 [ main::$4 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Minimal struct - array of struct
  // Upstart
  // Commodore 64 PRG executable file
.file [name="struct-ptr-0.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(main)
  // Global Constants & labels
  .const OFFSET_STRUCT_POINT_Y = 1
.segment Code
  // main
main: {
    .label SCREEN = $400
    .label __4 = 2
    // [1] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [1] phi main::i#2 = 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    jmp __b1
    // [1] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  __b1_from___b1:
    // [1] phi main::i#2 = main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [2] main::$4 = main::i#2 << 1 -- vbuz1=vbuxx_rol_1 
    txa
    asl
    sta.z __4
    // [3] ((char *)points)[main::$4] = main::i#2 -- pbuc1_derefidx_vbuz1=vbuxx 
    ldy.z __4
    txa
    sta points,y
    // [4] main::$0 = main::i#2 + 1 -- vbuyy=vbuxx_plus_1 
    txa
    tay
    iny
    // [5] ((char *)points+OFFSET_STRUCT_POINT_Y)[main::$4] = main::$0 -- pbuc1_derefidx_vbuz1=vbuyy 
    tya
    ldy.z __4
    sta points+OFFSET_STRUCT_POINT_Y,y
    // [6] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [7] if(main::i#1!=5) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #5
    bne __b1_from___b1
    // [8] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  __b2_from___b1:
    // [8] phi main::i1#2 = 0 [phi:main::@1->main::@2#0] -- vbuyy=vbuc1 
    ldy #0
    jmp __b2
    // [8] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
  __b2_from___b2:
    // [8] phi main::i1#2 = main::i1#1 [phi:main::@2->main::@2#0] -- register_copy 
    jmp __b2
    // main::@2
  __b2:
    // [9] main::$6 = main::i1#2 << 1 -- vbuxx=vbuyy_rol_1 
    tya
    asl
    tax
    // [10] main::SCREEN[main::i1#2] = ((char *)points)[main::$6] -- pbuc1_derefidx_vbuyy=pbuc2_derefidx_vbuxx 
    lda points,x
    sta SCREEN,y
    // [11] (main::SCREEN+$28)[main::i1#2] = ((char *)points+OFFSET_STRUCT_POINT_Y)[main::$6] -- pbuc1_derefidx_vbuyy=pbuc2_derefidx_vbuxx 
    lda points+OFFSET_STRUCT_POINT_Y,x
    sta SCREEN+$28,y
    // [12] main::i1#1 = ++ main::i1#2 -- vbuyy=_inc_vbuyy 
    iny
    // [13] if(main::i1#1!=5) goto main::@2 -- vbuyy_neq_vbuc1_then_la1 
    cpy #5
    bne __b2_from___b2
    jmp __breturn
    // main::@return
  __breturn:
    // [14] return 
    rts
}
  // File Data
.segment Data
  points: .fill 2*4, 0

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __b2
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing instruction ldy.z __4 with TAY
Replacing label __b1_from___b1 with __b1
Replacing label __b2_from___b2 with __b2
Removing instruction __b1_from___b1:
Removing instruction __b2_from___b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __b1_from_main:
Removing instruction __b2_from___b1:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Removing instruction jmp __b1
Removing instruction jmp __b2
Succesful ASM optimization Pass5NextJumpElimination

FINAL SYMBOL TABLE
__constant char OFFSET_STRUCT_POINT_Y = 1
void main()
char main::$0 // reg byte y 22.0
char main::$4 // zp[1]:2 11.0
char main::$6 // reg byte x 16.5
__constant char * const main::SCREEN = (char *) 1024
char main::i
char main::i#1 // reg byte x 16.5
char main::i#2 // reg byte x 11.0
char main::i1
char main::i1#1 // reg byte y 16.5
char main::i1#2 // reg byte y 13.75
__constant struct Point points[4] = { fill( 4, 0) }

reg byte x [ main::i#2 main::i#1 ]
reg byte y [ main::i1#2 main::i1#1 ]
zp[1]:2 [ main::$4 ]
reg byte y [ main::$0 ]
reg byte x [ main::$6 ]


FINAL ASSEMBLER
Score: 746

  // File Comments
// Minimal struct - array of struct
  // Upstart
  // Commodore 64 PRG executable file
.file [name="struct-ptr-0.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(main)
  // Global Constants & labels
  .const OFFSET_STRUCT_POINT_Y = 1
.segment Code
  // main
main: {
    .label SCREEN = $400
    .label __4 = 2
    // [1] phi from main to main::@1 [phi:main->main::@1]
    // [1] phi main::i#2 = 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // [1] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
    // [1] phi main::i#2 = main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    // main::@1
  __b1:
    // points[i].x = i
    // [2] main::$4 = main::i#2 << 1 -- vbuz1=vbuxx_rol_1 
    txa
    asl
    sta.z __4
    // [3] ((char *)points)[main::$4] = main::i#2 -- pbuc1_derefidx_vbuz1=vbuxx 
    tay
    txa
    sta points,y
    // i+1
    // [4] main::$0 = main::i#2 + 1 -- vbuyy=vbuxx_plus_1 
    txa
    tay
    iny
    // points[i].y = i+1
    // [5] ((char *)points+OFFSET_STRUCT_POINT_Y)[main::$4] = main::$0 -- pbuc1_derefidx_vbuz1=vbuyy 
    tya
    ldy.z __4
    sta points+OFFSET_STRUCT_POINT_Y,y
    // for( byte i: 0..4)
    // [6] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [7] if(main::i#1!=5) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #5
    bne __b1
    // [8] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
    // [8] phi main::i1#2 = 0 [phi:main::@1->main::@2#0] -- vbuyy=vbuc1 
    ldy #0
    // [8] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
    // [8] phi main::i1#2 = main::i1#1 [phi:main::@2->main::@2#0] -- register_copy 
    // main::@2
  __b2:
    // SCREEN[i] = points[i].x
    // [9] main::$6 = main::i1#2 << 1 -- vbuxx=vbuyy_rol_1 
    tya
    asl
    tax
    // [10] main::SCREEN[main::i1#2] = ((char *)points)[main::$6] -- pbuc1_derefidx_vbuyy=pbuc2_derefidx_vbuxx 
    lda points,x
    sta SCREEN,y
    // (SCREEN+40)[i] = points[i].y
    // [11] (main::SCREEN+$28)[main::i1#2] = ((char *)points+OFFSET_STRUCT_POINT_Y)[main::$6] -- pbuc1_derefidx_vbuyy=pbuc2_derefidx_vbuxx 
    lda points+OFFSET_STRUCT_POINT_Y,x
    sta SCREEN+$28,y
    // for( byte i: 0..4)
    // [12] main::i1#1 = ++ main::i1#2 -- vbuyy=_inc_vbuyy 
    iny
    // [13] if(main::i1#1!=5) goto main::@2 -- vbuyy_neq_vbuc1_then_la1 
    cpy #5
    bne __b2
    // main::@return
    // }
    // [14] return 
    rts
}
  // File Data
.segment Data
  points: .fill 2*4, 0

