Inlined call call __init
Eliminating unused variable with no statement main::$0
Eliminating unused variable with no statement main::$1
Removing C-classic struct-unwound assignment sum::d = struct-unwound {*((char *)&sum::d+OFFSET_STRUCT_DATA_C), *((char *)&sum::d+OFFSET_STRUCT_DATA_D)}
Removing C-classic struct-unwound assignment sum::return = struct-unwound {*(&sum::return)}

CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start::@1
  idx#11 = phi( __start::@1/idx#12 )
  sum::a#0 = 1
  sum::b#0 = 2
  call sum
  sum::return = sum::return
  to:main::@1
main::@1: scope:[main]  from main
  idx#6 = phi( main/idx#11 )
  main::x = sum::return
  SCREEN[idx#6] = *((char *)&main::x+OFFSET_STRUCT_DATA_C)
  idx#0 = ++ idx#6
  sum::a#1 = 3
  sum::b#1 = 4
  call sum
  sum::return = sum::return
  to:main::@2
main::@2: scope:[main]  from main::@1
  idx#7 = phi( main::@1/idx#0 )
  main::y = sum::return
  SCREEN[idx#7] = *((char *)&main::y+OFFSET_STRUCT_DATA_D)
  idx#1 = ++ idx#7
  to:main::@return
main::@return: scope:[main]  from main::@2
  idx#8 = phi( main::@2/idx#1 )
  idx#2 = idx#8
  return 
  to:@return

struct Data sum(char a , char b)
sum: scope:[sum]  from main main::@1
  sum::b#2 = phi( main/sum::b#0, main::@1/sum::b#1 )
  sum::a#2 = phi( main/sum::a#0, main::@1/sum::a#1 )
  sum::$0 = sum::a#2 + sum::b#2
  *((char *)&sum::d+OFFSET_STRUCT_DATA_C) = sum::$0
  *((char *)&sum::d+OFFSET_STRUCT_DATA_D) = sum::b#2
  *(&sum::return) = memcpy(*(&sum::d), struct Data, SIZEOF_STRUCT_DATA)
  to:sum::@return
sum::@return: scope:[sum]  from sum
  return 
  to:@return

void __start()
__start: scope:[__start]  from
  to:__start::__init1
__start::__init1: scope:[__start]  from __start
  idx#3 = 0
  to:__start::@1
__start::@1: scope:[__start]  from __start::__init1
  idx#12 = phi( __start::__init1/idx#3 )
  call main
  to:__start::@2
__start::@2: scope:[__start]  from __start::@1
  idx#9 = phi( __start::@1/idx#2 )
  idx#4 = idx#9
  to:__start::@return
__start::@return: scope:[__start]  from __start::@2
  idx#10 = phi( __start::@2/idx#4 )
  idx#5 = idx#10
  return 
  to:@return

SYMBOL TABLE SSA
__constant char OFFSET_STRUCT_DATA_C = 0
__constant char OFFSET_STRUCT_DATA_D = 1
__constant char * const SCREEN = (char *)$400
__constant char SIZEOF_STRUCT_DATA = 2
void __start()
char idx
char idx#0
char idx#1
char idx#10
char idx#11
char idx#12
char idx#2
char idx#3
char idx#4
char idx#5
char idx#6
char idx#7
char idx#8
char idx#9
void main()
__loadstore struct Data main::x
__loadstore struct Data main::y
struct Data sum(char a , char b)
char sum::$0
char sum::a
char sum::a#0
char sum::a#1
char sum::a#2
char sum::b
char sum::b#0
char sum::b#1
char sum::b#2
__loadstore struct Data sum::d
__loadstore struct Data sum::return

Adding number conversion cast (unumber) 1 in sum::a#0 = 1
Adding number conversion cast (unumber) 2 in sum::b#0 = 2
Adding number conversion cast (unumber) 3 in sum::a#1 = 3
Adding number conversion cast (unumber) 4 in sum::b#1 = 4
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast sum::a#0 = (unumber)1
Inlining cast sum::b#0 = (unumber)2
Inlining cast sum::a#1 = (unumber)3
Inlining cast sum::b#1 = (unumber)4
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast 1
Simplifying constant integer cast 2
Simplifying constant integer cast 3
Simplifying constant integer cast 4
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) 2
Finalized unsigned number type (char) 3
Finalized unsigned number type (char) 4
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias idx#11 = idx#6 
Alias idx#0 = idx#7 
Alias idx#1 = idx#8 idx#2 
Alias idx#12 = idx#3 
Alias idx#10 = idx#4 idx#9 idx#5 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values idx#11 idx#12
Identical Phi Values idx#10 idx#1
Successful SSA optimization Pass2IdenticalPhiElimination
Constant sum::a#0 = 1
Constant sum::b#0 = 2
Constant sum::a#1 = 3
Constant sum::b#1 = 4
Constant idx#12 = 0
Successful SSA optimization Pass2ConstantIdentification
Simplifying expression containing zero (char *)&main::x in [6] SCREEN[idx#12] = *((char *)&main::x+OFFSET_STRUCT_DATA_C)
Simplifying expression containing zero SCREEN in [6] SCREEN[idx#12] = *((char *)&main::x)
Simplifying expression containing zero (char *)&sum::d in [18] *((char *)&sum::d+OFFSET_STRUCT_DATA_C) = sum::$0
Successful SSA optimization PassNSimplifyExpressionWithZero
Eliminating unused variable idx#1 and assignment [9] idx#1 = ++ idx#0
Eliminating unused constant OFFSET_STRUCT_DATA_C
Successful SSA optimization PassNEliminateUnusedVars
Removing unused procedure __start
Removing unused procedure block __start
Removing unused procedure block __start::__init1
Removing unused procedure block __start::@1
Removing unused procedure block __start::@2
Removing unused procedure block __start::@return
Successful SSA optimization PassNEliminateEmptyStart
Constant right-side identified [4] idx#0 = ++ idx#12
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant idx#0 = ++idx#12
Successful SSA optimization Pass2ConstantIdentification
Inlining constant with var siblings sum::a#0
Inlining constant with var siblings sum::b#0
Inlining constant with var siblings sum::a#1
Inlining constant with var siblings sum::b#1
Inlining constant with different constant siblings idx#12
Inlining constant with different constant siblings idx#0
Constant inlined idx#12 = 0
Constant inlined sum::b#1 = 4
Constant inlined sum::b#0 = 2
Constant inlined sum::a#1 = 3
Constant inlined idx#0 = ++0
Constant inlined sum::a#0 = 1
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(SCREEN+++0)
Successful SSA optimization Pass2ConstantAdditionElimination
Simplifying constant integer increment ++0
Successful SSA optimization Pass2ConstantSimplification
Removing C-classic struct-unwound assignment sum::return = struct-unwound {}
Removing C-classic struct-unwound assignment main::x = struct-unwound {*(&main::x)}
Removing C-classic struct-unwound assignment sum::return = struct-unwound {}
Removing C-classic struct-unwound assignment main::y = struct-unwound {*(&main::y)}
Adding NOP phi() at start of main
CALL GRAPH
Calls in [main] to sum:1 sum:4 

Created 2 initial phi equivalence classes
Coalesced down to 2 phi equivalence classes
Adding NOP phi() at start of main

FINAL CONTROL FLOW GRAPH

void main()
main: scope:[main]  from
  [0] phi()
  [1] call sum
  to:main::@1
main::@1: scope:[main]  from main
  [2] *(&main::x) = memcpy(*(&sum::return), struct Data, SIZEOF_STRUCT_DATA)
  [3] *SCREEN = *((char *)&main::x)
  [4] call sum
  to:main::@2
main::@2: scope:[main]  from main::@1
  [5] *(&main::y) = memcpy(*(&sum::return), struct Data, SIZEOF_STRUCT_DATA)
  [6] *(SCREEN+1) = *((char *)&main::y+OFFSET_STRUCT_DATA_D)
  to:main::@return
main::@return: scope:[main]  from main::@2
  [7] return 
  to:@return

struct Data sum(char a , char b)
sum: scope:[sum]  from main main::@1
  [8] sum::b#2 = phi( main/2, main::@1/4 )
  [8] sum::a#2 = phi( main/1, main::@1/3 )
  [9] sum::$0 = sum::a#2 + sum::b#2
  [10] *((char *)&sum::d) = sum::$0
  [11] *((char *)&sum::d+OFFSET_STRUCT_DATA_D) = sum::b#2
  [12] *(&sum::return) = memcpy(*(&sum::d), struct Data, SIZEOF_STRUCT_DATA)
  to:sum::@return
sum::@return: scope:[sum]  from sum
  [13] return 
  to:@return


VARIABLE REGISTER WEIGHTS
char idx
void main()
__loadstore struct Data main::x
__loadstore struct Data main::y
struct Data sum(char a , char b)
char sum::$0 // 22.0
char sum::a
char sum::a#2 // 11.0
char sum::b
char sum::b#2 // 7.333333333333333
__loadstore struct Data sum::d
__loadstore struct Data sum::return

Initial phi equivalence classes
[ sum::a#2 ]
[ sum::b#2 ]
Added variable sum::$0 to live range equivalence class [ sum::$0 ]
Added variable main::x to live range equivalence class [ main::x ]
Added variable main::y to live range equivalence class [ main::y ]
Added variable sum::return to live range equivalence class [ sum::return ]
Added variable sum::d to live range equivalence class [ sum::d ]
Complete equivalence classes
[ sum::a#2 ]
[ sum::b#2 ]
[ sum::$0 ]
[ main::x ]
[ main::y ]
[ sum::return ]
[ sum::d ]
Allocated zp[1]:2 [ sum::$0 ]
Allocated zp[1]:3 [ sum::a#2 ]
Allocated zp[1]:4 [ sum::b#2 ]
Allocated zp[2]:5 [ main::x ]
Allocated zp[2]:7 [ main::y ]
Allocated zp[2]:9 [ sum::return ]
Allocated zp[2]:11 [ sum::d ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [2] *(&main::x) = memcpy(*(&sum::return), struct Data, SIZEOF_STRUCT_DATA) [ main::x sum::return main::y sum::d ] (  [ main::x sum::return main::y sum::d ] { }  ) always clobbers reg byte a reg byte y 
Statement [3] *SCREEN = *((char *)&main::x) [ sum::return main::y sum::d ] (  [ sum::return main::y sum::d ] { }  ) always clobbers reg byte a 
Statement [5] *(&main::y) = memcpy(*(&sum::return), struct Data, SIZEOF_STRUCT_DATA) [ main::y ] (  [ main::y ] { }  ) always clobbers reg byte a reg byte y 
Statement [6] *(SCREEN+1) = *((char *)&main::y+OFFSET_STRUCT_DATA_D) [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [9] sum::$0 = sum::a#2 + sum::b#2 [ sum::return sum::b#2 sum::$0 sum::d ] ( sum:1 [ main::x main::y sum::return sum::b#2 sum::$0 sum::d ] { }  sum:4 [ main::y sum::return sum::b#2 sum::$0 sum::d ] { }  ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:4 [ sum::b#2 ]
Statement [12] *(&sum::return) = memcpy(*(&sum::d), struct Data, SIZEOF_STRUCT_DATA) [ sum::return sum::d ] ( sum:1 [ main::x main::y sum::return sum::d ] { }  sum:4 [ main::y sum::return sum::d ] { }  ) always clobbers reg byte a reg byte y 
Statement [2] *(&main::x) = memcpy(*(&sum::return), struct Data, SIZEOF_STRUCT_DATA) [ main::x sum::return main::y sum::d ] (  [ main::x sum::return main::y sum::d ] { }  ) always clobbers reg byte a reg byte y 
Statement [3] *SCREEN = *((char *)&main::x) [ sum::return main::y sum::d ] (  [ sum::return main::y sum::d ] { }  ) always clobbers reg byte a 
Statement [5] *(&main::y) = memcpy(*(&sum::return), struct Data, SIZEOF_STRUCT_DATA) [ main::y ] (  [ main::y ] { }  ) always clobbers reg byte a reg byte y 
Statement [6] *(SCREEN+1) = *((char *)&main::y+OFFSET_STRUCT_DATA_D) [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [9] sum::$0 = sum::a#2 + sum::b#2 [ sum::return sum::b#2 sum::$0 sum::d ] ( sum:1 [ main::x main::y sum::return sum::b#2 sum::$0 sum::d ] { }  sum:4 [ main::y sum::return sum::b#2 sum::$0 sum::d ] { }  ) always clobbers reg byte a 
Statement [12] *(&sum::return) = memcpy(*(&sum::d), struct Data, SIZEOF_STRUCT_DATA) [ sum::return sum::d ] ( sum:1 [ main::x main::y sum::return sum::d ] { }  sum:4 [ main::y sum::return sum::d ] { }  ) always clobbers reg byte a reg byte y 
Potential registers zp[1]:3 [ sum::a#2 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:4 [ sum::b#2 ] : zp[1]:4 , reg byte x , reg byte y , 
Potential registers zp[1]:2 [ sum::$0 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[2]:5 [ main::x ] : zp[2]:5 , 
Potential registers zp[2]:7 [ main::y ] : zp[2]:7 , 
Potential registers zp[2]:9 [ sum::return ] : zp[2]:9 , 
Potential registers zp[2]:11 [ sum::d ] : zp[2]:11 , 

REGISTER UPLIFT SCOPES
Uplift Scope [sum] 22: zp[1]:2 [ sum::$0 ] 11: zp[1]:3 [ sum::a#2 ] 7.33: zp[1]:4 [ sum::b#2 ] 0: zp[2]:9 [ sum::return ] 0: zp[2]:11 [ sum::d ] 
Uplift Scope [Data] 
Uplift Scope [main] 0: zp[2]:5 [ main::x ] 0: zp[2]:7 [ main::y ] 
Uplift Scope [] 

Uplifting [sum] best 122 combination reg byte a [ sum::$0 ] reg byte a [ sum::a#2 ] reg byte x [ sum::b#2 ] zp[2]:9 [ sum::return ] zp[2]:11 [ sum::d ] 
Uplifting [Data] best 122 combination 
Uplifting [main] best 122 combination zp[2]:5 [ main::x ] zp[2]:7 [ main::y ] 
Uplifting [] best 122 combination 
Allocated (was zp[2]:5) zp[2]:2 [ main::x ]
Allocated (was zp[2]:7) zp[2]:4 [ main::y ]
Allocated (was zp[2]:9) zp[2]:6 [ sum::return ]
Allocated (was zp[2]:11) zp[2]:8 [ sum::d ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Test intermediate vars
  // Upstart
  // Commodore 64 PRG executable file
.file [name="intermediates-struct.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_DATA_D = 1
  .const SIZEOF_STRUCT_DATA = 2
  .label SCREEN = $400
.segment Code
  // main
main: {
    .label x = 2
    .label y = 4
    // [1] call sum
    // [8] phi from main to sum [phi:main->sum]
  sum_from_main:
    // [8] phi sum::b#2 = 2 [phi:main->sum#0] -- vbuxx=vbuc1 
    ldx #2
    // [8] phi sum::a#2 = 1 [phi:main->sum#1] -- vbuaa=vbuc1 
    lda #1
    jsr sum
    jmp __b1
    // main::@1
  __b1:
    // [2] *(&main::x) = memcpy(*(&sum::return), struct Data, SIZEOF_STRUCT_DATA) -- _deref_pssc1=_deref_pssc2_memcpy_vbuc3 
    ldy #SIZEOF_STRUCT_DATA
  !:
    lda sum.return-1,y
    sta x-1,y
    dey
    bne !-
    // [3] *SCREEN = *((char *)&main::x) -- _deref_pbuc1=_deref_pbuc2 
    lda.z x
    sta SCREEN
    // [4] call sum
    // [8] phi from main::@1 to sum [phi:main::@1->sum]
  sum_from___b1:
    // [8] phi sum::b#2 = 4 [phi:main::@1->sum#0] -- vbuxx=vbuc1 
    ldx #4
    // [8] phi sum::a#2 = 3 [phi:main::@1->sum#1] -- vbuaa=vbuc1 
    lda #3
    jsr sum
    jmp __b2
    // main::@2
  __b2:
    // [5] *(&main::y) = memcpy(*(&sum::return), struct Data, SIZEOF_STRUCT_DATA) -- _deref_pssc1=_deref_pssc2_memcpy_vbuc3 
    ldy #SIZEOF_STRUCT_DATA
  !:
    lda sum.return-1,y
    sta y-1,y
    dey
    bne !-
    // [6] *(SCREEN+1) = *((char *)&main::y+OFFSET_STRUCT_DATA_D) -- _deref_pbuc1=_deref_pbuc2 
    lda y+OFFSET_STRUCT_DATA_D
    sta SCREEN+1
    jmp __breturn
    // main::@return
  __breturn:
    // [7] return 
    rts
}
  // sum
// __zp(6) struct Data sum(__register(A) char a, __register(X) char b)
sum: {
    .label return = 6
    .label d = 8
    // [9] sum::$0 = sum::a#2 + sum::b#2 -- vbuaa=vbuaa_plus_vbuxx 
    stx.z $ff
    clc
    adc.z $ff
    // [10] *((char *)&sum::d) = sum::$0 -- _deref_pbuc1=vbuaa 
    sta.z d
    // [11] *((char *)&sum::d+OFFSET_STRUCT_DATA_D) = sum::b#2 -- _deref_pbuc1=vbuxx 
    stx d+OFFSET_STRUCT_DATA_D
    // [12] *(&sum::return) = memcpy(*(&sum::d), struct Data, SIZEOF_STRUCT_DATA) -- _deref_pssc1=_deref_pssc2_memcpy_vbuc3 
    ldy #SIZEOF_STRUCT_DATA
  !:
    lda d-1,y
    sta return-1,y
    dey
    bne !-
    jmp __breturn
    // sum::@return
  __breturn:
    // [13] return 
    rts
}
  // File Data

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

FINAL SYMBOL TABLE
__constant char OFFSET_STRUCT_DATA_D = 1
__constant char * const SCREEN = (char *) 1024
__constant char SIZEOF_STRUCT_DATA = 2
char idx
void main()
__loadstore struct Data main::x // zp[2]:2
__loadstore struct Data main::y // zp[2]:4
struct Data sum(char a , char b)
char sum::$0 // reg byte a 22.0
char sum::a
char sum::a#2 // reg byte a 11.0
char sum::b
char sum::b#2 // reg byte x 7.333333333333333
__loadstore struct Data sum::d // zp[2]:8
__loadstore struct Data sum::return // zp[2]:6

reg byte a [ sum::a#2 ]
reg byte x [ sum::b#2 ]
reg byte a [ sum::$0 ]
zp[2]:2 [ main::x ]
zp[2]:4 [ main::y ]
zp[2]:6 [ sum::return ]
zp[2]:8 [ sum::d ]


FINAL ASSEMBLER
Score: 110

  // File Comments
// Test intermediate vars
  // Upstart
  // Commodore 64 PRG executable file
.file [name="intermediates-struct.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_DATA_D = 1
  .const SIZEOF_STRUCT_DATA = 2
  .label SCREEN = $400
.segment Code
  // main
main: {
    .label x = 2
    .label y = 4
    // struct Data x = sum(1,2)
    // [1] call sum
    // [8] phi from main to sum [phi:main->sum]
    // [8] phi sum::b#2 = 2 [phi:main->sum#0] -- vbuxx=vbuc1 
    ldx #2
    // [8] phi sum::a#2 = 1 [phi:main->sum#1] -- vbuaa=vbuc1 
    lda #1
    jsr sum
    // main::@1
    // struct Data x = sum(1,2)
    // [2] *(&main::x) = memcpy(*(&sum::return), struct Data, SIZEOF_STRUCT_DATA) -- _deref_pssc1=_deref_pssc2_memcpy_vbuc3 
    ldy #SIZEOF_STRUCT_DATA
  !:
    lda sum.return-1,y
    sta x-1,y
    dey
    bne !-
    // SCREEN[idx++] = x.c
    // [3] *SCREEN = *((char *)&main::x) -- _deref_pbuc1=_deref_pbuc2 
    lda.z x
    sta SCREEN
    // struct Data y = sum(3, 4)
    // [4] call sum
    // [8] phi from main::@1 to sum [phi:main::@1->sum]
    // [8] phi sum::b#2 = 4 [phi:main::@1->sum#0] -- vbuxx=vbuc1 
    ldx #4
    // [8] phi sum::a#2 = 3 [phi:main::@1->sum#1] -- vbuaa=vbuc1 
    lda #3
    jsr sum
    // main::@2
    // struct Data y = sum(3, 4)
    // [5] *(&main::y) = memcpy(*(&sum::return), struct Data, SIZEOF_STRUCT_DATA) -- _deref_pssc1=_deref_pssc2_memcpy_vbuc3 
    ldy #SIZEOF_STRUCT_DATA
  !:
    lda sum.return-1,y
    sta y-1,y
    dey
    bne !-
    // SCREEN[idx++] = y.d
    // [6] *(SCREEN+1) = *((char *)&main::y+OFFSET_STRUCT_DATA_D) -- _deref_pbuc1=_deref_pbuc2 
    lda y+OFFSET_STRUCT_DATA_D
    sta SCREEN+1
    // main::@return
    // }
    // [7] return 
    rts
}
  // sum
// __zp(6) struct Data sum(__register(A) char a, __register(X) char b)
sum: {
    .label return = 6
    .label d = 8
    // a+b
    // [9] sum::$0 = sum::a#2 + sum::b#2 -- vbuaa=vbuaa_plus_vbuxx 
    stx.z $ff
    clc
    adc.z $ff
    // struct Data d = { a+b, b }
    // [10] *((char *)&sum::d) = sum::$0 -- _deref_pbuc1=vbuaa 
    sta.z d
    // [11] *((char *)&sum::d+OFFSET_STRUCT_DATA_D) = sum::b#2 -- _deref_pbuc1=vbuxx 
    stx d+OFFSET_STRUCT_DATA_D
    // return d;
    // [12] *(&sum::return) = memcpy(*(&sum::d), struct Data, SIZEOF_STRUCT_DATA) -- _deref_pssc1=_deref_pssc2_memcpy_vbuc3 
    ldy #SIZEOF_STRUCT_DATA
  !:
    lda d-1,y
    sta return-1,y
    dey
    bne !-
    // sum::@return
    // }
    // [13] return 
    rts
}
  // File Data

