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

CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start
  *(&main::p) = memcpy(*(&$0), struct Point, SIZEOF_STRUCT_POINT)
  set::ptr#0 = main::q
  call set
  to:main::@1
main::@1: scope:[main]  from main
  main::$3 = (char *)main::q
  main::$1 = main::$3 + OFFSET_STRUCT_POINT_X
  main::SCREEN[0] = *main::$1
  main::$4 = (char *)main::q
  main::$2 = main::$4 + OFFSET_STRUCT_POINT_Y
  main::SCREEN[1] = *main::$2
  to:main::@return
main::@return: scope:[main]  from main::@1
  return 
  to:@return

void set(struct Point *ptr)
set: scope:[set]  from main
  set::ptr#1 = phi( main/set::ptr#0 )
  set::$2 = (char *)set::ptr#1
  set::$0 = set::$2 + OFFSET_STRUCT_POINT_X
  *set::$0 = 4
  set::$3 = (char *)set::ptr#1
  set::$1 = set::$3 + OFFSET_STRUCT_POINT_Y
  *set::$1 = 5
  to:set::@return
set::@return: scope:[set]  from set
  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 Point $0 = { x: 2, y: 3 }
__constant char OFFSET_STRUCT_POINT_X = 0
__constant char OFFSET_STRUCT_POINT_Y = 1
__constant char SIZEOF_STRUCT_POINT = 2
void __start()
void main()
char *main::$1
char *main::$2
char *main::$3
char *main::$4
__constant char * const main::SCREEN = (char *)$400
__loadstore volatile struct Point main::p
__constant struct Point *main::q = &main::p
void set(struct Point *ptr)
char *set::$0
char *set::$1
char *set::$2
char *set::$3
struct Point *set::ptr
struct Point *set::ptr#0
struct Point *set::ptr#1

Adding number conversion cast (unumber) 0 in main::SCREEN[0] = *main::$1
Adding number conversion cast (unumber) 1 in main::SCREEN[1] = *main::$2
Adding number conversion cast (unumber) 4 in *set::$0 = 4
Adding number conversion cast (unumber) 5 in *set::$1 = 5
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast *set::$0 = (unumber)4
Inlining cast *set::$1 = (unumber)5
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast 0
Simplifying constant integer cast 1
Simplifying constant integer cast 4
Simplifying constant integer cast 5
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 0
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) 4
Finalized unsigned number type (char) 5
Successful SSA optimization PassNFinalizeNumberTypeConversions
Identical Phi Values set::ptr#1 set::ptr#0
Successful SSA optimization Pass2IdenticalPhiElimination
Constant right-side identified [3] main::$3 = (char *)main::q
Constant right-side identified [6] main::$4 = (char *)main::q
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant set::ptr#0 = main::q
Constant main::$3 = (char *)main::q
Constant main::$4 = (char *)main::q
Successful SSA optimization Pass2ConstantIdentification
Constant set::$2 = (char *)set::ptr#0
Constant set::$3 = (char *)set::ptr#0
Successful SSA optimization Pass2ConstantIdentification
Converting *(pointer+n) to pointer[n] [5] main::SCREEN[0] = *main::$1  -- main::$3[OFFSET_STRUCT_POINT_X]
Converting *(pointer+n) to pointer[n] [8] main::SCREEN[1] = *main::$2  -- main::$4[OFFSET_STRUCT_POINT_Y]
Converting *(pointer+n) to pointer[n] [13] *set::$0 = 4  -- set::$2[OFFSET_STRUCT_POINT_X]
Converting *(pointer+n) to pointer[n] [16] *set::$1 = 5  -- set::$3[OFFSET_STRUCT_POINT_Y]
Successful SSA optimization Pass2InlineDerefIdx
Simplifying expression containing zero main::$3 in [4] main::$1 = main::$3 + OFFSET_STRUCT_POINT_X
Simplifying expression containing zero main::$3 in [5] main::SCREEN[0] = main::$3[OFFSET_STRUCT_POINT_X]
Simplifying expression containing zero main::SCREEN in [5] main::SCREEN[0] = *main::$3
Simplifying expression containing zero set::$2 in [12] set::$0 = set::$2 + OFFSET_STRUCT_POINT_X
Simplifying expression containing zero set::$2 in [13] set::$2[OFFSET_STRUCT_POINT_X] = 4
Successful SSA optimization PassNSimplifyExpressionWithZero
Eliminating unused variable main::$1 and assignment [2] main::$1 = main::$3
Eliminating unused variable main::$2 and assignment [4] main::$2 = main::$4 + OFFSET_STRUCT_POINT_Y
Eliminating unused variable set::$0 and assignment [7] set::$0 = set::$2
Eliminating unused variable set::$1 and assignment [9] set::$1 = set::$3 + OFFSET_STRUCT_POINT_Y
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
Constant inlined set::ptr#0 = main::q
Constant inlined set::$3 = (char *)main::q
Constant inlined main::$3 = (char *)main::q
Constant inlined set::$2 = (char *)main::q
Constant inlined main::$4 = (char *)main::q
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *((char *)main::q+OFFSET_STRUCT_POINT_Y)
Consolidated array index constant in *(main::SCREEN+1)
Consolidated array index constant in *((char *)main::q+OFFSET_STRUCT_POINT_Y)
Successful SSA optimization Pass2ConstantAdditionElimination
CALL GRAPH
Calls in [main] to set:1 

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::p) = memcpy(*(&$0), struct Point, SIZEOF_STRUCT_POINT)
  [1] call set
  to:main::@1
main::@1: scope:[main]  from main
  [2] *main::SCREEN = *((char *)main::q)
  [3] *(main::SCREEN+1) = *((char *)main::q+OFFSET_STRUCT_POINT_Y)
  to:main::@return
main::@return: scope:[main]  from main::@1
  [4] return 
  to:@return

void set(struct Point *ptr)
set: scope:[set]  from main
  [5] *((char *)main::q) = 4
  [6] *((char *)main::q+OFFSET_STRUCT_POINT_Y) = 5
  to:set::@return
set::@return: scope:[set]  from set
  [7] return 
  to:@return


VARIABLE REGISTER WEIGHTS
void main()
__loadstore volatile struct Point main::p
void set(struct Point *ptr)
struct Point *set::ptr

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

REGISTER UPLIFT SCOPES
Uplift Scope [Point] 
Uplift Scope [main] 0: zp[2]:2 [ main::p ] 
Uplift Scope [set] 
Uplift Scope [] 

Uplifting [Point] best 69 combination 
Uplifting [main] best 69 combination zp[2]:2 [ main::p ] 
Uplifting [set] best 69 combination 
Uplifting [] best 69 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Minimal struct -  using address-of and passing it to a function
  // Upstart
  // Commodore 64 PRG executable file
.file [name="struct-ptr-14.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
    .label q = p
    .label p = 2
    // [0] *(&main::p) = memcpy(*(&$0), struct Point, SIZEOF_STRUCT_POINT) -- _deref_pssc1=_deref_pssc2_memcpy_vbuc3 
    ldy #SIZEOF_STRUCT_POINT
  !:
    lda __0-1,y
    sta p-1,y
    dey
    bne !-
    // [1] call set
    jsr set
    jmp __b1
    // main::@1
  __b1:
    // [2] *main::SCREEN = *((char *)main::q) -- _deref_pbuc1=_deref_pbuc2 
    lda.z q
    sta SCREEN
    // [3] *(main::SCREEN+1) = *((char *)main::q+OFFSET_STRUCT_POINT_Y) -- _deref_pbuc1=_deref_pbuc2 
    lda q+OFFSET_STRUCT_POINT_Y
    sta SCREEN+1
    jmp __breturn
    // main::@return
  __breturn:
    // [4] return 
    rts
}
  // set
// void set(struct Point *ptr)
set: {
    // [5] *((char *)main::q) = 4 -- _deref_pbuc1=vbuc2 
    lda #4
    sta.z main.q
    // [6] *((char *)main::q+OFFSET_STRUCT_POINT_Y) = 5 -- _deref_pbuc1=vbuc2 
    lda #5
    sta main.q+OFFSET_STRUCT_POINT_Y
    jmp __breturn
    // set::@return
  __breturn:
    // [7] return 
    rts
}
  // File Data
.segment Data
  __0: .byte 2, 3

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

FINAL SYMBOL TABLE
__constant struct Point $0 = { x: 2, y: 3 }
__constant char OFFSET_STRUCT_POINT_Y = 1
__constant char SIZEOF_STRUCT_POINT = 2
void main()
__constant char * const main::SCREEN = (char *) 1024
__loadstore volatile struct Point main::p // zp[2]:2
__constant struct Point *main::q = &main::p
void set(struct Point *ptr)
struct Point *set::ptr

zp[2]:2 [ main::p ]


FINAL ASSEMBLER
Score: 60

  // File Comments
// Minimal struct -  using address-of and passing it to a function
  // Upstart
  // Commodore 64 PRG executable file
.file [name="struct-ptr-14.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
    .label q = p
    .label p = 2
    // volatile struct Point p = { 2, 3 }
    // [0] *(&main::p) = memcpy(*(&$0), struct Point, SIZEOF_STRUCT_POINT) -- _deref_pssc1=_deref_pssc2_memcpy_vbuc3 
    ldy #SIZEOF_STRUCT_POINT
  !:
    lda __0-1,y
    sta p-1,y
    dey
    bne !-
    // set(q)
    // [1] call set
    jsr set
    // main::@1
    // SCREEN[0] = q->x
    // [2] *main::SCREEN = *((char *)main::q) -- _deref_pbuc1=_deref_pbuc2 
    lda.z q
    sta SCREEN
    // SCREEN[1] = q->y
    // [3] *(main::SCREEN+1) = *((char *)main::q+OFFSET_STRUCT_POINT_Y) -- _deref_pbuc1=_deref_pbuc2 
    lda q+OFFSET_STRUCT_POINT_Y
    sta SCREEN+1
    // main::@return
    // }
    // [4] return 
    rts
}
  // set
// void set(struct Point *ptr)
set: {
    // ptr->x = 4
    // [5] *((char *)main::q) = 4 -- _deref_pbuc1=vbuc2 
    lda #4
    sta.z main.q
    // ptr->y = 5
    // [6] *((char *)main::q+OFFSET_STRUCT_POINT_Y) = 5 -- _deref_pbuc1=vbuc2 
    lda #5
    sta main.q+OFFSET_STRUCT_POINT_Y
    // set::@return
    // }
    // [7] return 
    rts
}
  // File Data
.segment Data
  __0: .byte 2, 3

