
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::@2
  main::i#2 = phi( main/main::i#0, main::@2/main::i#1 )
  main::$0 = main::i#2 < $a
  if(main::$0) goto main::@2
  to:main::@3
main::@2: scope:[main]  from main::@1
  main::i#3 = phi( main::@1/main::i#2 )
  main::$1 = $1230 + main::i#3
  main::$3 = main::i#3 * SIZEOF_UNION_DATA
  ((unsigned int *)datas+OFFSET_UNION_DATA_W)[main::$3] = main::$1
  main::i#1 = ++ main::i#3
  to:main::@1
main::@3: scope:[main]  from main::@1
  main::i1#0 = 0
  to:main::@4
main::@4: scope:[main]  from main::@3 main::@5
  main::i1#2 = phi( main::@3/main::i1#0, main::@5/main::i1#1 )
  main::$2 = main::i1#2 < $a
  if(main::$2) goto main::@5
  to:main::@return
main::@5: scope:[main]  from main::@4
  main::i1#3 = phi( main::@4/main::i1#2 )
  main::$4 = main::i1#3 * SIZEOF_UNION_DATA
  SCREEN[main::i1#3] = ((char *)datas+OFFSET_UNION_DATA_B)[main::$4]
  main::i1#1 = ++ main::i1#3
  to:main::@4
main::@return: scope:[main]  from main::@4
  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_UNION_DATA_B = 0
__constant char OFFSET_UNION_DATA_W = 0
__constant char * const SCREEN = (char *)$400
__constant char SIZEOF_UNION_DATA = 2
void __start()
__constant union Data datas[$a] = { fill( $a, 0) }
void main()
bool main::$0
number main::$1
bool main::$2
char main::$3
char main::$4
char main::i
char main::i#0
char main::i#1
char main::i#2
char main::i#3
char main::i1
char main::i1#0
char main::i1#1
char main::i1#2
char main::i1#3

Adding number conversion cast (unumber) $a in main::$0 = main::i#2 < $a
Adding number conversion cast (unumber) $1230 in main::$1 = $1230 + main::i#3
Adding number conversion cast (unumber) main::$1 in main::$1 = (unumber)$1230 + main::i#3
Adding number conversion cast (unumber) $a in main::$2 = main::i1#2 < $a
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast $a
Simplifying constant integer cast $1230
Simplifying constant integer cast $a
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) $a
Finalized unsigned number type (unsigned int) $1230
Finalized unsigned number type (char) $a
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to unsigned int in main::$1 = $1230 + main::i#3
Alias main::i#2 = main::i#3 
Alias main::i1#2 = main::i1#3 
Successful SSA optimization Pass2AliasElimination
Simple Condition main::$0 [3] if(main::i#2<$a) goto main::@2
Simple Condition main::$2 [11] if(main::i1#2<$a) goto main::@5
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant main::i#0 = 0
Constant main::i1#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Simplifying expression containing zero (unsigned int *)datas in [6] ((unsigned int *)datas+OFFSET_UNION_DATA_W)[main::$3] = main::$1
Simplifying expression containing zero (char *)datas in [13] SCREEN[main::i1#2] = ((char *)datas+OFFSET_UNION_DATA_B)[main::$4]
Successful SSA optimization PassNSimplifyExpressionWithZero
Eliminating unused constant OFFSET_UNION_DATA_W
Eliminating unused constant OFFSET_UNION_DATA_B
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
Rewriting multiplication to use shift [3] main::$3 = main::i#2 * SIZEOF_UNION_DATA
Rewriting multiplication to use shift [8] main::$4 = main::i1#2 * SIZEOF_UNION_DATA
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_UNION_DATA
Successful SSA optimization PassNEliminateUnusedVars
Finalized unsigned number type (char) $a
Finalized unsigned number type (char) $a
Successful SSA optimization PassNFinalizeNumberTypeConversions
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@3
CALL GRAPH

Created 2 initial phi equivalence classes
Coalesced [10] main::i1#4 = main::i1#1
Coalesced [15] main::i#4 = main::i#1
Coalesced down to 2 phi equivalence classes
Culled Empty Block label main::@3
Renumbering block main::@4 to main::@3
Renumbering block main::@5 to main::@4
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::@2
  [1] main::i#2 = phi( main/0, main::@2/main::i#1 )
  [2] if(main::i#2<$a) goto main::@2
  to:main::@3
main::@3: scope:[main]  from main::@1 main::@4
  [3] main::i1#2 = phi( main::@1/0, main::@4/main::i1#1 )
  [4] if(main::i1#2<$a) goto main::@4
  to:main::@return
main::@return: scope:[main]  from main::@3
  [5] return 
  to:@return
main::@4: scope:[main]  from main::@3
  [6] main::$4 = main::i1#2 << 1
  [7] SCREEN[main::i1#2] = ((char *)datas)[main::$4]
  [8] main::i1#1 = ++ main::i1#2
  to:main::@3
main::@2: scope:[main]  from main::@1
  [9] main::$1 = $1230 + main::i#2
  [10] main::$3 = main::i#2 << 1
  [11] ((unsigned int *)datas)[main::$3] = main::$1
  [12] main::i#1 = ++ main::i#2
  to:main::@1


VARIABLE REGISTER WEIGHTS
void main()
unsigned int main::$1 // 11.0
char main::$3 // 22.0
char main::$4 // 22.0
char main::i
char main::i#1 // 22.0
char main::i#2 // 11.0
char main::i1
char main::i1#1 // 22.0
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::$1 to live range equivalence class [ main::$1 ]
Added variable main::$3 to live range equivalence class [ main::$3 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ main::i1#2 main::i1#1 ]
[ main::$4 ]
[ main::$1 ]
[ main::$3 ]
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::$4 ]
Allocated zp[1]:5 [ main::$3 ]
Allocated zp[2]:6 [ main::$1 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [6] main::$4 = main::i1#2 << 1 [ main::i1#2 main::$4 ] (  [ main::i1#2 main::$4 ] { }  ) 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 [7] SCREEN[main::i1#2] = ((char *)datas)[main::$4] [ main::i1#2 ] (  [ main::i1#2 ] { }  ) always clobbers reg byte a 
Statement [9] main::$1 = $1230 + main::i#2 [ main::i#2 main::$1 ] (  [ main::i#2 main::$1 ] { }  ) 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 [10] main::$3 = main::i#2 << 1 [ main::i#2 main::$1 main::$3 ] (  [ main::i#2 main::$1 main::$3 ] { }  ) always clobbers reg byte a 
Statement [11] ((unsigned int *)datas)[main::$3] = main::$1 [ main::i#2 ] (  [ main::i#2 ] { }  ) always clobbers reg byte a 
Statement [6] main::$4 = main::i1#2 << 1 [ main::i1#2 main::$4 ] (  [ main::i1#2 main::$4 ] { }  ) always clobbers reg byte a 
Statement [7] SCREEN[main::i1#2] = ((char *)datas)[main::$4] [ main::i1#2 ] (  [ main::i1#2 ] { }  ) always clobbers reg byte a 
Statement [9] main::$1 = $1230 + main::i#2 [ main::i#2 main::$1 ] (  [ main::i#2 main::$1 ] { }  ) always clobbers reg byte a 
Statement [10] main::$3 = main::i#2 << 1 [ main::i#2 main::$1 main::$3 ] (  [ main::i#2 main::$1 main::$3 ] { }  ) always clobbers reg byte a 
Statement [11] ((unsigned int *)datas)[main::$3] = main::$1 [ main::i#2 ] (  [ main::i#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]:4 [ main::$4 ] : zp[1]:4 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[2]:6 [ main::$1 ] : zp[2]:6 , 
Potential registers zp[1]:5 [ main::$3 ] : zp[1]:5 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 35.75: zp[1]:2 [ main::i1#2 main::i1#1 ] 33: zp[1]:3 [ main::i#2 main::i#1 ] 22: zp[1]:4 [ main::$4 ] 22: zp[1]:5 [ main::$3 ] 11: zp[2]:6 [ main::$1 ] 
Uplift Scope [Data] 
Uplift Scope [] 

Uplifting [main] best 861 combination reg byte x [ main::i1#2 main::i1#1 ] reg byte x [ main::i#2 main::i#1 ] reg byte a [ main::$4 ] reg byte a [ main::$3 ] zp[2]:6 [ main::$1 ] 
Limited combination testing to 100 combinations of 144 possible.
Uplifting [Data] best 861 combination 
Uplifting [] best 861 combination 
Allocated (was zp[2]:6) zp[2]:2 [ main::$1 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Minimal union with C-Standard behavior - array of union
  // Upstart
  // Commodore 64 PRG executable file
.file [name="union-3.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
  .label SCREEN = $400
.segment Code
  // main
main: {
    .label __1 = 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
    // main::@1
  __b1:
    // [2] if(main::i#2<$a) goto main::@2 -- vbuxx_lt_vbuc1_then_la1 
    cpx #$a
    bcc __b2
    // [3] phi from main::@1 to main::@3 [phi:main::@1->main::@3]
  __b3_from___b1:
    // [3] phi main::i1#2 = 0 [phi:main::@1->main::@3#0] -- vbuxx=vbuc1 
    ldx #0
    jmp __b3
    // main::@3
  __b3:
    // [4] if(main::i1#2<$a) goto main::@4 -- vbuxx_lt_vbuc1_then_la1 
    cpx #$a
    bcc __b4
    jmp __breturn
    // main::@return
  __breturn:
    // [5] return 
    rts
    // main::@4
  __b4:
    // [6] main::$4 = main::i1#2 << 1 -- vbuaa=vbuxx_rol_1 
    txa
    asl
    // [7] SCREEN[main::i1#2] = ((char *)datas)[main::$4] -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_vbuaa 
    tay
    lda datas,y
    sta SCREEN,x
    // [8] main::i1#1 = ++ main::i1#2 -- vbuxx=_inc_vbuxx 
    inx
    // [3] phi from main::@4 to main::@3 [phi:main::@4->main::@3]
  __b3_from___b4:
    // [3] phi main::i1#2 = main::i1#1 [phi:main::@4->main::@3#0] -- register_copy 
    jmp __b3
    // main::@2
  __b2:
    // [9] main::$1 = $1230 + main::i#2 -- vwuz1=vwuc1_plus_vbuxx 
    txa
    clc
    adc #<$1230
    sta.z __1
    lda #>$1230
    adc #0
    sta.z __1+1
    // [10] main::$3 = main::i#2 << 1 -- vbuaa=vbuxx_rol_1 
    txa
    asl
    // [11] ((unsigned int *)datas)[main::$3] = main::$1 -- pwuc1_derefidx_vbuaa=vwuz1 
    tay
    lda.z __1
    sta datas,y
    lda.z __1+1
    sta datas+1,y
    // [12] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
  __b1_from___b2:
    // [1] phi main::i#2 = main::i#1 [phi:main::@2->main::@1#0] -- register_copy 
    jmp __b1
}
  // File Data
.segment Data
  datas: .fill 2*$a, 0

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __b3
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1_from_main:
Removing instruction __b3_from___b1:
Removing instruction __breturn:
Removing instruction __b3_from___b4:
Removing instruction __b1_from___b2:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
__constant char * const SCREEN = (char *) 1024
__constant union Data datas[$a] = { fill( $a, 0) }
void main()
unsigned int main::$1 // zp[2]:2 11.0
char main::$3 // reg byte a 22.0
char main::$4 // reg byte a 22.0
char main::i
char main::i#1 // reg byte x 22.0
char main::i#2 // reg byte x 11.0
char main::i1
char main::i1#1 // reg byte x 22.0
char main::i1#2 // reg byte x 13.75

reg byte x [ main::i#2 main::i#1 ]
reg byte x [ main::i1#2 main::i1#1 ]
reg byte a [ main::$4 ]
zp[2]:2 [ main::$1 ]
reg byte a [ main::$3 ]


FINAL ASSEMBLER
Score: 771

  // File Comments
// Minimal union with C-Standard behavior - array of union
  // Upstart
  // Commodore 64 PRG executable file
.file [name="union-3.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
  .label SCREEN = $400
.segment Code
  // main
main: {
    .label __1 = 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
    // main::@1
  __b1:
    // for(char i=0;i<10;i++)
    // [2] if(main::i#2<$a) goto main::@2 -- vbuxx_lt_vbuc1_then_la1 
    cpx #$a
    bcc __b2
    // [3] phi from main::@1 to main::@3 [phi:main::@1->main::@3]
    // [3] phi main::i1#2 = 0 [phi:main::@1->main::@3#0] -- vbuxx=vbuc1 
    ldx #0
    // main::@3
  __b3:
    // for(char i=0;i<10;i++)
    // [4] if(main::i1#2<$a) goto main::@4 -- vbuxx_lt_vbuc1_then_la1 
    cpx #$a
    bcc __b4
    // main::@return
    // }
    // [5] return 
    rts
    // main::@4
  __b4:
    // SCREEN[i] = datas[i].b
    // [6] main::$4 = main::i1#2 << 1 -- vbuaa=vbuxx_rol_1 
    txa
    asl
    // [7] SCREEN[main::i1#2] = ((char *)datas)[main::$4] -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_vbuaa 
    tay
    lda datas,y
    sta SCREEN,x
    // for(char i=0;i<10;i++)
    // [8] main::i1#1 = ++ main::i1#2 -- vbuxx=_inc_vbuxx 
    inx
    // [3] phi from main::@4 to main::@3 [phi:main::@4->main::@3]
    // [3] phi main::i1#2 = main::i1#1 [phi:main::@4->main::@3#0] -- register_copy 
    jmp __b3
    // main::@2
  __b2:
    // 0x1230+i
    // [9] main::$1 = $1230 + main::i#2 -- vwuz1=vwuc1_plus_vbuxx 
    txa
    clc
    adc #<$1230
    sta.z __1
    lda #>$1230
    adc #0
    sta.z __1+1
    // datas[i].w = 0x1230+i
    // [10] main::$3 = main::i#2 << 1 -- vbuaa=vbuxx_rol_1 
    txa
    asl
    // [11] ((unsigned int *)datas)[main::$3] = main::$1 -- pwuc1_derefidx_vbuaa=vwuz1 
    tay
    lda.z __1
    sta datas,y
    lda.z __1+1
    sta datas+1,y
    // for(char i=0;i<10;i++)
    // [12] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
    // [1] phi main::i#2 = main::i#1 [phi:main::@2->main::@1#0] -- register_copy 
    jmp __b1
}
  // File Data
.segment Data
  datas: .fill 2*$a, 0

