Removing C-classic struct-unwound assignment main::v = struct-unwound {*(&main::v)}

CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start
  *(&main::v) = memcpy(*(&$0), struct Vector, SIZEOF_STRUCT_VECTOR)
  SCREEN[0] = *((char *)(struct Point *)&main::v+OFFSET_STRUCT_VECTOR_P+OFFSET_STRUCT_POINT_X)
  SCREEN[1] = *((char *)(struct Point *)&main::v+OFFSET_STRUCT_VECTOR_P+OFFSET_STRUCT_POINT_Y)
  SCREEN[2] = *((char *)(struct Point *)&main::v+OFFSET_STRUCT_VECTOR_Q+OFFSET_STRUCT_POINT_X)
  SCREEN[3] = *((char *)(struct Point *)&main::v+OFFSET_STRUCT_VECTOR_Q+OFFSET_STRUCT_POINT_Y)
  to:main::@return
main::@return: scope:[main]  from main
  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 struct Vector $0 = { p: { x: 2, y: 3 }, q: { x: 4, y: 5 } }
__constant char OFFSET_STRUCT_POINT_X = 0
__constant char OFFSET_STRUCT_POINT_Y = 1
__constant char OFFSET_STRUCT_VECTOR_P = 0
__constant char OFFSET_STRUCT_VECTOR_Q = 2
__constant char * const SCREEN = (char *)$400
__constant char SIZEOF_STRUCT_VECTOR = 4
void __start()
void main()
__loadstore struct Vector main::v

Adding number conversion cast (unumber) 0 in SCREEN[0] = *((char *)(struct Point *)&main::v+OFFSET_STRUCT_VECTOR_P+OFFSET_STRUCT_POINT_X)
Adding number conversion cast (unumber) 1 in SCREEN[1] = *((char *)(struct Point *)&main::v+OFFSET_STRUCT_VECTOR_P+OFFSET_STRUCT_POINT_Y)
Adding number conversion cast (unumber) 2 in SCREEN[2] = *((char *)(struct Point *)&main::v+OFFSET_STRUCT_VECTOR_Q+OFFSET_STRUCT_POINT_X)
Adding number conversion cast (unumber) 3 in SCREEN[3] = *((char *)(struct Point *)&main::v+OFFSET_STRUCT_VECTOR_Q+OFFSET_STRUCT_POINT_Y)
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast 0
Simplifying constant integer cast 1
Simplifying constant integer cast 2
Simplifying constant integer cast 3
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 0
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) 2
Finalized unsigned number type (char) 3
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simplifying expression containing zero (char *)(struct Point *)&main::v+OFFSET_STRUCT_VECTOR_P in [1] SCREEN[0] = *((char *)(struct Point *)&main::v+OFFSET_STRUCT_VECTOR_P+OFFSET_STRUCT_POINT_X)
Simplifying expression containing zero (struct Point *)&main::v in [1] SCREEN[0] = *((char *)(struct Point *)&main::v+OFFSET_STRUCT_VECTOR_P)
Simplifying expression containing zero SCREEN in [1] SCREEN[0] = *((char *)(struct Point *)&main::v)
Simplifying expression containing zero (struct Point *)&main::v in [2] SCREEN[1] = *((char *)(struct Point *)&main::v+OFFSET_STRUCT_VECTOR_P+OFFSET_STRUCT_POINT_Y)
Simplifying expression containing zero (char *)(struct Point *)&main::v+OFFSET_STRUCT_VECTOR_Q in [3] SCREEN[2] = *((char *)(struct Point *)&main::v+OFFSET_STRUCT_VECTOR_Q+OFFSET_STRUCT_POINT_X)
Successful SSA optimization PassNSimplifyExpressionWithZero
Eliminating unused constant OFFSET_STRUCT_VECTOR_P
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
Consolidated array index constant in *(SCREEN+1)
Consolidated array index constant in *(SCREEN+2)
Consolidated array index constant in *(SCREEN+3)
Successful SSA optimization Pass2ConstantAdditionElimination
CALL GRAPH

Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes

FINAL CONTROL FLOW GRAPH

void main()
main: scope:[main]  from
  [0] *(&main::v) = memcpy(*(&$0), struct Vector, SIZEOF_STRUCT_VECTOR)
  [1] *SCREEN = *((char *)(struct Point *)&main::v)
  [2] *(SCREEN+1) = *((char *)(struct Point *)&main::v+OFFSET_STRUCT_POINT_Y)
  [3] *(SCREEN+2) = *((char *)(struct Point *)&main::v+OFFSET_STRUCT_VECTOR_Q)
  [4] *(SCREEN+3) = *((char *)(struct Point *)&main::v+OFFSET_STRUCT_VECTOR_Q+OFFSET_STRUCT_POINT_Y)
  to:main::@return
main::@return: scope:[main]  from main
  [5] return 
  to:@return


VARIABLE REGISTER WEIGHTS
void main()
__loadstore struct Vector main::v

Initial phi equivalence classes
Added variable main::v to live range equivalence class [ main::v ]
Complete equivalence classes
[ main::v ]
Allocated zp[4]:2 [ main::v ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [0] *(&main::v) = memcpy(*(&$0), struct Vector, SIZEOF_STRUCT_VECTOR) [ main::v ] (  [ main::v ] { }  ) always clobbers reg byte a reg byte y 
Statement [1] *SCREEN = *((char *)(struct Point *)&main::v) [ main::v ] (  [ main::v ] { }  ) always clobbers reg byte a 
Statement [2] *(SCREEN+1) = *((char *)(struct Point *)&main::v+OFFSET_STRUCT_POINT_Y) [ main::v ] (  [ main::v ] { }  ) always clobbers reg byte a 
Statement [3] *(SCREEN+2) = *((char *)(struct Point *)&main::v+OFFSET_STRUCT_VECTOR_Q) [ main::v ] (  [ main::v ] { }  ) always clobbers reg byte a 
Statement [4] *(SCREEN+3) = *((char *)(struct Point *)&main::v+OFFSET_STRUCT_VECTOR_Q+OFFSET_STRUCT_POINT_Y) [ ] (  [ ] { }  ) always clobbers reg byte a 
Potential registers zp[4]:2 [ main::v ] : zp[4]:2 , 

REGISTER UPLIFT SCOPES
Uplift Scope [Point] 
Uplift Scope [Vector] 
Uplift Scope [main] 0: zp[4]:2 [ main::v ] 
Uplift Scope [] 

Uplifting [Point] best 56 combination 
Uplifting [Vector] best 56 combination 
Uplifting [main] best 56 combination zp[4]:2 [ main::v ] 
Uplifting [] best 56 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Minimal struct with C-Standard behavior - struct containing struct with initializer
  // Upstart
  // Commodore 64 PRG executable file
.file [name="struct-18.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 SIZEOF_STRUCT_VECTOR = 4
  .const OFFSET_STRUCT_POINT_Y = 1
  .const OFFSET_STRUCT_VECTOR_Q = 2
  .label SCREEN = $400
.segment Code
  // main
main: {
    .label v = 2
    // [0] *(&main::v) = memcpy(*(&$0), struct Vector, SIZEOF_STRUCT_VECTOR) -- _deref_pssc1=_deref_pssc2_memcpy_vbuc3 
    ldy #SIZEOF_STRUCT_VECTOR
  !:
    lda __0-1,y
    sta v-1,y
    dey
    bne !-
    // [1] *SCREEN = *((char *)(struct Point *)&main::v) -- _deref_pbuc1=_deref_pbuc2 
    lda.z v
    sta SCREEN
    // [2] *(SCREEN+1) = *((char *)(struct Point *)&main::v+OFFSET_STRUCT_POINT_Y) -- _deref_pbuc1=_deref_pbuc2 
    lda v+OFFSET_STRUCT_POINT_Y
    sta SCREEN+1
    // [3] *(SCREEN+2) = *((char *)(struct Point *)&main::v+OFFSET_STRUCT_VECTOR_Q) -- _deref_pbuc1=_deref_pbuc2 
    lda v+OFFSET_STRUCT_VECTOR_Q
    sta SCREEN+2
    // [4] *(SCREEN+3) = *((char *)(struct Point *)&main::v+OFFSET_STRUCT_VECTOR_Q+OFFSET_STRUCT_POINT_Y) -- _deref_pbuc1=_deref_pbuc2 
    lda v+OFFSET_STRUCT_VECTOR_Q+OFFSET_STRUCT_POINT_Y
    sta SCREEN+3
    jmp __breturn
    // main::@return
  __breturn:
    // [5] return 
    rts
}
  // File Data
.segment Data
  __0: .byte 2, 3, 4, 5

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
__constant struct Vector $0 = { p: { x: 2, y: 3 }, q: { x: 4, y: 5 } }
__constant char OFFSET_STRUCT_POINT_Y = 1
__constant char OFFSET_STRUCT_VECTOR_Q = 2
__constant char * const SCREEN = (char *) 1024
__constant char SIZEOF_STRUCT_VECTOR = 4
void main()
__loadstore struct Vector main::v // zp[4]:2

zp[4]:2 [ main::v ]


FINAL ASSEMBLER
Score: 53

  // File Comments
// Minimal struct with C-Standard behavior - struct containing struct with initializer
  // Upstart
  // Commodore 64 PRG executable file
.file [name="struct-18.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 SIZEOF_STRUCT_VECTOR = 4
  .const OFFSET_STRUCT_POINT_Y = 1
  .const OFFSET_STRUCT_VECTOR_Q = 2
  .label SCREEN = $400
.segment Code
  // main
main: {
    .label v = 2
    // __ma struct Vector v = { {2, 3}, {4, 5} }
    // [0] *(&main::v) = memcpy(*(&$0), struct Vector, SIZEOF_STRUCT_VECTOR) -- _deref_pssc1=_deref_pssc2_memcpy_vbuc3 
    ldy #SIZEOF_STRUCT_VECTOR
  !:
    lda __0-1,y
    sta v-1,y
    dey
    bne !-
    // SCREEN[0] = v.p.x
    // [1] *SCREEN = *((char *)(struct Point *)&main::v) -- _deref_pbuc1=_deref_pbuc2 
    lda.z v
    sta SCREEN
    // SCREEN[1] = v.p.y
    // [2] *(SCREEN+1) = *((char *)(struct Point *)&main::v+OFFSET_STRUCT_POINT_Y) -- _deref_pbuc1=_deref_pbuc2 
    lda v+OFFSET_STRUCT_POINT_Y
    sta SCREEN+1
    // SCREEN[2] = v.q.x
    // [3] *(SCREEN+2) = *((char *)(struct Point *)&main::v+OFFSET_STRUCT_VECTOR_Q) -- _deref_pbuc1=_deref_pbuc2 
    lda v+OFFSET_STRUCT_VECTOR_Q
    sta SCREEN+2
    // SCREEN[3] = v.q.y
    // [4] *(SCREEN+3) = *((char *)(struct Point *)&main::v+OFFSET_STRUCT_VECTOR_Q+OFFSET_STRUCT_POINT_Y) -- _deref_pbuc1=_deref_pbuc2 
    lda v+OFFSET_STRUCT_VECTOR_Q+OFFSET_STRUCT_POINT_Y
    sta SCREEN+3
    // main::@return
    // }
    // [5] return 
    rts
}
  // File Data
.segment Data
  __0: .byte 2, 3, 4, 5

