Removing C-classic struct-unwound assignment point2 = struct-unwound {*(&point2)}

CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start
  *((char *)&point1+OFFSET_STRUCT_POINT_X) = 2
  *((char *)&point1+OFFSET_STRUCT_POINT_Y) = 3
  *(&point2) = memcpy(*(&point1), struct Point, SIZEOF_STRUCT_POINT)
  *((char *)&point2+OFFSET_STRUCT_POINT_X) = 4
  main::SCREEN[0] = *((char *)&point1+OFFSET_STRUCT_POINT_X)
  main::SCREEN[1] = *((char *)&point1+OFFSET_STRUCT_POINT_Y)
  main::SCREEN[2] = *((char *)&point2+OFFSET_STRUCT_POINT_X)
  main::SCREEN[3] = *((char *)&point2+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 char OFFSET_STRUCT_POINT_X = 0
__constant char OFFSET_STRUCT_POINT_Y = 1
__constant char SIZEOF_STRUCT_POINT = 2
void __start()
void main()
__constant char * const main::SCREEN = (char *)$400
__loadstore struct Point point1 = {}
__loadstore struct Point point2 = {}

Adding number conversion cast (unumber) 2 in *((char *)&point1+OFFSET_STRUCT_POINT_X) = 2
Adding number conversion cast (unumber) 3 in *((char *)&point1+OFFSET_STRUCT_POINT_Y) = 3
Adding number conversion cast (unumber) 4 in *((char *)&point2+OFFSET_STRUCT_POINT_X) = 4
Adding number conversion cast (unumber) 0 in main::SCREEN[0] = *((char *)&point1+OFFSET_STRUCT_POINT_X)
Adding number conversion cast (unumber) 1 in main::SCREEN[1] = *((char *)&point1+OFFSET_STRUCT_POINT_Y)
Adding number conversion cast (unumber) 2 in main::SCREEN[2] = *((char *)&point2+OFFSET_STRUCT_POINT_X)
Adding number conversion cast (unumber) 3 in main::SCREEN[3] = *((char *)&point2+OFFSET_STRUCT_POINT_Y)
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast *((char *)&point1+OFFSET_STRUCT_POINT_X) = (unumber)2
Inlining cast *((char *)&point1+OFFSET_STRUCT_POINT_Y) = (unumber)3
Inlining cast *((char *)&point2+OFFSET_STRUCT_POINT_X) = (unumber)4
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast 2
Simplifying constant integer cast 3
Simplifying constant integer cast 4
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) 2
Finalized unsigned number type (char) 3
Finalized unsigned number type (char) 4
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 *)&point1 in [0] *((char *)&point1+OFFSET_STRUCT_POINT_X) = 2
Simplifying expression containing zero (char *)&point2 in [3] *((char *)&point2+OFFSET_STRUCT_POINT_X) = 4
Simplifying expression containing zero (char *)&point1 in [4] main::SCREEN[0] = *((char *)&point1+OFFSET_STRUCT_POINT_X)
Simplifying expression containing zero main::SCREEN in [4] main::SCREEN[0] = *((char *)&point1)
Simplifying expression containing zero (char *)&point2 in [6] main::SCREEN[2] = *((char *)&point2+OFFSET_STRUCT_POINT_X)
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
Consolidated array index constant in *(main::SCREEN+1)
Consolidated array index constant in *(main::SCREEN+2)
Consolidated array index constant in *(main::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] *((char *)&point1) = 2
  [1] *((char *)&point1+OFFSET_STRUCT_POINT_Y) = 3
  [2] *(&point2) = memcpy(*(&point1), struct Point, SIZEOF_STRUCT_POINT)
  [3] *((char *)&point2) = 4
  [4] *main::SCREEN = *((char *)&point1)
  [5] *(main::SCREEN+1) = *((char *)&point1+OFFSET_STRUCT_POINT_Y)
  [6] *(main::SCREEN+2) = *((char *)&point2)
  [7] *(main::SCREEN+3) = *((char *)&point2+OFFSET_STRUCT_POINT_Y)
  to:main::@return
main::@return: scope:[main]  from main
  [8] return 
  to:@return


VARIABLE REGISTER WEIGHTS
void main()
__loadstore struct Point point1 = {}
__loadstore struct Point point2 = {}

Initial phi equivalence classes
Added variable point1 to live range equivalence class [ point1 ]
Added variable point2 to live range equivalence class [ point2 ]
Complete equivalence classes
[ point1 ]
[ point2 ]
Allocated mem[2] [ point1 ]
Allocated mem[2] [ point2 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [0] *((char *)&point1) = 2 [ point1 point2 ] (  [ point1 point2 ] { }  ) always clobbers reg byte a 
Statement [1] *((char *)&point1+OFFSET_STRUCT_POINT_Y) = 3 [ point1 point2 ] (  [ point1 point2 ] { }  ) always clobbers reg byte a 
Statement [2] *(&point2) = memcpy(*(&point1), struct Point, SIZEOF_STRUCT_POINT) [ point1 point2 ] (  [ point1 point2 ] { }  ) always clobbers reg byte a reg byte y 
Statement [3] *((char *)&point2) = 4 [ point1 point2 ] (  [ point1 point2 ] { }  ) always clobbers reg byte a 
Statement [4] *main::SCREEN = *((char *)&point1) [ point1 point2 ] (  [ point1 point2 ] { }  ) always clobbers reg byte a 
Statement [5] *(main::SCREEN+1) = *((char *)&point1+OFFSET_STRUCT_POINT_Y) [ point2 ] (  [ point2 ] { }  ) always clobbers reg byte a 
Statement [6] *(main::SCREEN+2) = *((char *)&point2) [ point2 ] (  [ point2 ] { }  ) always clobbers reg byte a 
Statement [7] *(main::SCREEN+3) = *((char *)&point2+OFFSET_STRUCT_POINT_Y) [ ] (  [ ] { }  ) always clobbers reg byte a 
Potential registers mem[2] [ point1 ] : mem[2] , 
Potential registers mem[2] [ point2 ] : mem[2] , 

REGISTER UPLIFT SCOPES
Uplift Scope [Point] 
Uplift Scope [main] 
Uplift Scope [] 0: mem[2] [ point1 ] 0: mem[2] [ point2 ] 

Uplifting [Point] best 75 combination 
Uplifting [main] best 75 combination 
Uplifting [] best 75 combination mem[2] [ point1 ] mem[2] [ point2 ] 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Minimal struct - two instances being copied (using assignment)
  // Upstart
  // Commodore 64 PRG executable file
.file [name="struct-2.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_POINT = 2
  .const OFFSET_STRUCT_POINT_Y = 1
.segment Code
  // main
main: {
    .label SCREEN = $400
    // [0] *((char *)&point1) = 2 -- _deref_pbuc1=vbuc2 
    lda #2
    sta point1
    // [1] *((char *)&point1+OFFSET_STRUCT_POINT_Y) = 3 -- _deref_pbuc1=vbuc2 
    lda #3
    sta point1+OFFSET_STRUCT_POINT_Y
    // [2] *(&point2) = memcpy(*(&point1), struct Point, SIZEOF_STRUCT_POINT) -- _deref_pssc1=_deref_pssc2_memcpy_vbuc3 
    ldy #SIZEOF_STRUCT_POINT
  !:
    lda point1-1,y
    sta point2-1,y
    dey
    bne !-
    // [3] *((char *)&point2) = 4 -- _deref_pbuc1=vbuc2 
    lda #4
    sta point2
    // [4] *main::SCREEN = *((char *)&point1) -- _deref_pbuc1=_deref_pbuc2 
    lda point1
    sta SCREEN
    // [5] *(main::SCREEN+1) = *((char *)&point1+OFFSET_STRUCT_POINT_Y) -- _deref_pbuc1=_deref_pbuc2 
    lda point1+OFFSET_STRUCT_POINT_Y
    sta SCREEN+1
    // [6] *(main::SCREEN+2) = *((char *)&point2) -- _deref_pbuc1=_deref_pbuc2 
    lda point2
    sta SCREEN+2
    // [7] *(main::SCREEN+3) = *((char *)&point2+OFFSET_STRUCT_POINT_Y) -- _deref_pbuc1=_deref_pbuc2 
    lda point2+OFFSET_STRUCT_POINT_Y
    sta SCREEN+3
    jmp __breturn
    // main::@return
  __breturn:
    // [8] return 
    rts
}
  // File Data
.segment Data
  point1: .fill SIZEOF_STRUCT_POINT, 0
  point2: .fill SIZEOF_STRUCT_POINT, 0

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

FINAL SYMBOL TABLE
__constant char OFFSET_STRUCT_POINT_Y = 1
__constant char SIZEOF_STRUCT_POINT = 2
void main()
__constant char * const main::SCREEN = (char *) 1024
__loadstore struct Point point1 = {} // mem[2]
__loadstore struct Point point2 = {} // mem[2]

mem[2] [ point1 ]
mem[2] [ point2 ]


FINAL ASSEMBLER
Score: 72

  // File Comments
// Minimal struct - two instances being copied (using assignment)
  // Upstart
  // Commodore 64 PRG executable file
.file [name="struct-2.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_POINT = 2
  .const OFFSET_STRUCT_POINT_Y = 1
.segment Code
  // main
main: {
    .label SCREEN = $400
    // point1.x = 2
    // [0] *((char *)&point1) = 2 -- _deref_pbuc1=vbuc2 
    lda #2
    sta point1
    // point1.y = 3
    // [1] *((char *)&point1+OFFSET_STRUCT_POINT_Y) = 3 -- _deref_pbuc1=vbuc2 
    lda #3
    sta point1+OFFSET_STRUCT_POINT_Y
    // point2 = point1
    // [2] *(&point2) = memcpy(*(&point1), struct Point, SIZEOF_STRUCT_POINT) -- _deref_pssc1=_deref_pssc2_memcpy_vbuc3 
    ldy #SIZEOF_STRUCT_POINT
  !:
    lda point1-1,y
    sta point2-1,y
    dey
    bne !-
    // point2.x = 4
    // [3] *((char *)&point2) = 4 -- _deref_pbuc1=vbuc2 
    lda #4
    sta point2
    // SCREEN[0] = point1.x
    // [4] *main::SCREEN = *((char *)&point1) -- _deref_pbuc1=_deref_pbuc2 
    lda point1
    sta SCREEN
    // SCREEN[1] = point1.y
    // [5] *(main::SCREEN+1) = *((char *)&point1+OFFSET_STRUCT_POINT_Y) -- _deref_pbuc1=_deref_pbuc2 
    lda point1+OFFSET_STRUCT_POINT_Y
    sta SCREEN+1
    // SCREEN[2] = point2.x
    // [6] *(main::SCREEN+2) = *((char *)&point2) -- _deref_pbuc1=_deref_pbuc2 
    lda point2
    sta SCREEN+2
    // SCREEN[3] = point2.y
    // [7] *(main::SCREEN+3) = *((char *)&point2+OFFSET_STRUCT_POINT_Y) -- _deref_pbuc1=_deref_pbuc2 
    lda point2+OFFSET_STRUCT_POINT_Y
    sta SCREEN+3
    // main::@return
    // }
    // [8] return 
    rts
}
  // File Data
.segment Data
  point1: .fill SIZEOF_STRUCT_POINT, 0
  point2: .fill SIZEOF_STRUCT_POINT, 0

