
CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start
  main::$4 = 1 * SIZEOF_UNSIGNED_INT
  main::w1#0 = main::words[main::$4]
  main::$0 = byte0  main::w1#0
  main::SCREEN[0] = main::$0
  main::$1 = byte1  main::w1#0
  main::SCREEN[1] = main::$1
  main::$5 = 2 * SIZEOF_UNSIGNED_INT
  main::w2#0 = main::words[main::$5]
  main::$2 = byte0  main::w2#0
  main::SCREEN[2] = main::$2
  main::$3 = byte1  main::w2#0
  main::SCREEN[3] = main::$3
  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 SIZEOF_UNSIGNED_INT = 2
void __start()
void main()
char main::$0
char main::$1
char main::$2
char main::$3
number main::$4
number main::$5
__constant char * const main::SCREEN = (char *)$400+6*$28
unsigned int main::w1
unsigned int main::w1#0
unsigned int main::w2
unsigned int main::w2#0
__constant unsigned int main::words[3] = (unsigned int *)$400

Adding number conversion cast (unumber) 6*$28 in 
Adding number conversion cast (unumber) 1 in main::$4 = 1 * SIZEOF_UNSIGNED_INT
Adding number conversion cast (unumber) main::$4 in main::$4 = (unumber)1 * SIZEOF_UNSIGNED_INT
Adding number conversion cast (unumber) 0 in main::SCREEN[0] = main::$0
Adding number conversion cast (unumber) 1 in main::SCREEN[1] = main::$1
Adding number conversion cast (unumber) 2 in main::$5 = 2 * SIZEOF_UNSIGNED_INT
Adding number conversion cast (unumber) main::$5 in main::$5 = (unumber)2 * SIZEOF_UNSIGNED_INT
Adding number conversion cast (unumber) 2 in main::SCREEN[2] = main::$2
Adding number conversion cast (unumber) 3 in main::SCREEN[3] = main::$3
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (char *) 1024
Simplifying constant pointer cast (unsigned int *) 1024
Simplifying constant integer cast 1
Simplifying constant integer cast 0
Simplifying constant integer cast 1
Simplifying constant integer cast 2
Simplifying constant integer cast 2
Simplifying constant integer cast 3
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) 0
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) 2
Finalized unsigned number type (char) 2
Finalized unsigned number type (char) 3
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to char in main::$4 = 1 * SIZEOF_UNSIGNED_INT
Inferred type updated to char in main::$5 = 2 * SIZEOF_UNSIGNED_INT
Constant right-side identified [0] main::$4 = 1 * SIZEOF_UNSIGNED_INT
Constant right-side identified [6] main::$5 = 2 * SIZEOF_UNSIGNED_INT
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant main::$4 = 1*SIZEOF_UNSIGNED_INT
Constant main::$5 = 2*SIZEOF_UNSIGNED_INT
Successful SSA optimization Pass2ConstantIdentification
Simplifying expression containing zero main::SCREEN in [3] main::SCREEN[0] = main::$0
Successful SSA optimization PassNSimplifyExpressionWithZero
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 main::$5 = 2*SIZEOF_UNSIGNED_INT
Constant inlined main::$4 = 1*SIZEOF_UNSIGNED_INT
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(main::words+1*SIZEOF_UNSIGNED_INT)
Consolidated array index constant in *(main::SCREEN+1)
Consolidated array index constant in *(main::words+2*SIZEOF_UNSIGNED_INT)
Consolidated array index constant in *(main::SCREEN+2)
Consolidated array index constant in *(main::SCREEN+3)
Successful SSA optimization Pass2ConstantAdditionElimination
Finalized unsigned number type (char) 6
Finalized unsigned number type (char) $28
Finalized unsigned number type (char) 3
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simplifying constant integer cast 6*$28
Successful SSA optimization PassNCastSimplification
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::w1#0 = *(main::words+1*SIZEOF_UNSIGNED_INT)
  [1] main::$0 = byte0  main::w1#0
  [2] *main::SCREEN = main::$0
  [3] main::$1 = byte1  main::w1#0
  [4] *(main::SCREEN+1) = main::$1
  [5] main::w2#0 = *(main::words+2*SIZEOF_UNSIGNED_INT)
  [6] main::$2 = byte0  main::w2#0
  [7] *(main::SCREEN+2) = main::$2
  [8] main::$3 = byte1  main::w2#0
  [9] *(main::SCREEN+3) = main::$3
  to:main::@return
main::@return: scope:[main]  from main
  [10] return 
  to:@return


VARIABLE REGISTER WEIGHTS
void main()
char main::$0 // 4.0
char main::$1 // 4.0
char main::$2 // 4.0
char main::$3 // 4.0
unsigned int main::w1
unsigned int main::w1#0 // 2.0
unsigned int main::w2
unsigned int main::w2#0 // 2.0

Initial phi equivalence classes
Added variable main::w1#0 to live range equivalence class [ main::w1#0 ]
Added variable main::$0 to live range equivalence class [ main::$0 ]
Added variable main::$1 to live range equivalence class [ main::$1 ]
Added variable main::w2#0 to live range equivalence class [ main::w2#0 ]
Added variable main::$2 to live range equivalence class [ main::$2 ]
Added variable main::$3 to live range equivalence class [ main::$3 ]
Complete equivalence classes
[ main::w1#0 ]
[ main::$0 ]
[ main::$1 ]
[ main::w2#0 ]
[ main::$2 ]
[ main::$3 ]
Allocated zp[1]:2 [ main::$0 ]
Allocated zp[1]:3 [ main::$1 ]
Allocated zp[1]:4 [ main::$2 ]
Allocated zp[1]:5 [ main::$3 ]
Allocated zp[2]:6 [ main::w1#0 ]
Allocated zp[2]:8 [ main::w2#0 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [0] main::w1#0 = *(main::words+1*SIZEOF_UNSIGNED_INT) [ main::w1#0 ] (  [ main::w1#0 ] { }  ) always clobbers reg byte a 
Statement [5] main::w2#0 = *(main::words+2*SIZEOF_UNSIGNED_INT) [ main::w2#0 ] (  [ main::w2#0 ] { }  ) always clobbers reg byte a 
Potential registers zp[2]:6 [ main::w1#0 ] : zp[2]:6 , 
Potential registers zp[1]:2 [ main::$0 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:3 [ main::$1 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[2]:8 [ main::w2#0 ] : zp[2]:8 , 
Potential registers zp[1]:4 [ main::$2 ] : zp[1]:4 , reg byte a , reg byte x , reg byte y , 
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] 4: zp[1]:2 [ main::$0 ] 4: zp[1]:3 [ main::$1 ] 4: zp[1]:4 [ main::$2 ] 4: zp[1]:5 [ main::$3 ] 2: zp[2]:6 [ main::w1#0 ] 2: zp[2]:8 [ main::w2#0 ] 
Uplift Scope [] 

Uplifting [main] best 65 combination reg byte a [ main::$0 ] reg byte a [ main::$1 ] reg byte a [ main::$2 ] reg byte a [ main::$3 ] zp[2]:6 [ main::w1#0 ] zp[2]:8 [ main::w2#0 ] 
Limited combination testing to 100 combinations of 256 possible.
Uplifting [] best 65 combination 
Allocated (was zp[2]:6) zp[2]:2 [ main::w1#0 ]
Allocated (was zp[2]:8) zp[2]:4 [ main::w2#0 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests a simple word array
  // Upstart
  // Commodore 64 PRG executable file
.file [name="word-array-0.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_UNSIGNED_INT = 2
.segment Code
  // main
main: {
    .label SCREEN = $400+6*$28
    .label words = $400
    .label w1 = 2
    .label w2 = 4
    // [0] main::w1#0 = *(main::words+1*SIZEOF_UNSIGNED_INT) -- vwuz1=_deref_pwuc1 
    lda words+1*SIZEOF_UNSIGNED_INT
    sta.z w1
    lda words+1*SIZEOF_UNSIGNED_INT+1
    sta.z w1+1
    // [1] main::$0 = byte0  main::w1#0 -- vbuaa=_byte0_vwuz1 
    lda.z w1
    // [2] *main::SCREEN = main::$0 -- _deref_pbuc1=vbuaa 
    sta SCREEN
    // [3] main::$1 = byte1  main::w1#0 -- vbuaa=_byte1_vwuz1 
    lda.z w1+1
    // [4] *(main::SCREEN+1) = main::$1 -- _deref_pbuc1=vbuaa 
    sta SCREEN+1
    // [5] main::w2#0 = *(main::words+2*SIZEOF_UNSIGNED_INT) -- vwuz1=_deref_pwuc1 
    lda words+2*SIZEOF_UNSIGNED_INT
    sta.z w2
    lda words+2*SIZEOF_UNSIGNED_INT+1
    sta.z w2+1
    // [6] main::$2 = byte0  main::w2#0 -- vbuaa=_byte0_vwuz1 
    lda.z w2
    // [7] *(main::SCREEN+2) = main::$2 -- _deref_pbuc1=vbuaa 
    sta SCREEN+2
    // [8] main::$3 = byte1  main::w2#0 -- vbuaa=_byte1_vwuz1 
    lda.z w2+1
    // [9] *(main::SCREEN+3) = main::$3 -- _deref_pbuc1=vbuaa 
    sta SCREEN+3
    jmp __breturn
    // main::@return
  __breturn:
    // [10] return 
    rts
}
  // File Data

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

FINAL SYMBOL TABLE
__constant char SIZEOF_UNSIGNED_INT = 2
void main()
char main::$0 // reg byte a 4.0
char main::$1 // reg byte a 4.0
char main::$2 // reg byte a 4.0
char main::$3 // reg byte a 4.0
__constant char * const main::SCREEN = (char *) 1024+6*$28
unsigned int main::w1
unsigned int main::w1#0 // w1 zp[2]:2 2.0
unsigned int main::w2
unsigned int main::w2#0 // w2 zp[2]:4 2.0
__constant unsigned int main::words[3] = (unsigned int *) 1024

zp[2]:2 [ main::w1#0 ]
reg byte a [ main::$0 ]
reg byte a [ main::$1 ]
zp[2]:4 [ main::w2#0 ]
reg byte a [ main::$2 ]
reg byte a [ main::$3 ]


FINAL ASSEMBLER
Score: 62

  // File Comments
// Tests a simple word array
  // Upstart
  // Commodore 64 PRG executable file
.file [name="word-array-0.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_UNSIGNED_INT = 2
.segment Code
  // main
main: {
    .label SCREEN = $400+6*$28
    .label words = $400
    .label w1 = 2
    .label w2 = 4
    // word w1 = words[1]
    // [0] main::w1#0 = *(main::words+1*SIZEOF_UNSIGNED_INT) -- vwuz1=_deref_pwuc1 
    lda words+1*SIZEOF_UNSIGNED_INT
    sta.z w1
    lda words+1*SIZEOF_UNSIGNED_INT+1
    sta.z w1+1
    // BYTE0(w1)
    // [1] main::$0 = byte0  main::w1#0 -- vbuaa=_byte0_vwuz1 
    lda.z w1
    // SCREEN[0] = BYTE0(w1)
    // [2] *main::SCREEN = main::$0 -- _deref_pbuc1=vbuaa 
    sta SCREEN
    // BYTE1(w1)
    // [3] main::$1 = byte1  main::w1#0 -- vbuaa=_byte1_vwuz1 
    lda.z w1+1
    // SCREEN[1] = BYTE1(w1)
    // [4] *(main::SCREEN+1) = main::$1 -- _deref_pbuc1=vbuaa 
    sta SCREEN+1
    // word w2 = words[2]
    // [5] main::w2#0 = *(main::words+2*SIZEOF_UNSIGNED_INT) -- vwuz1=_deref_pwuc1 
    lda words+2*SIZEOF_UNSIGNED_INT
    sta.z w2
    lda words+2*SIZEOF_UNSIGNED_INT+1
    sta.z w2+1
    // BYTE0(w2)
    // [6] main::$2 = byte0  main::w2#0 -- vbuaa=_byte0_vwuz1 
    lda.z w2
    // SCREEN[2] = BYTE0(w2)
    // [7] *(main::SCREEN+2) = main::$2 -- _deref_pbuc1=vbuaa 
    sta SCREEN+2
    // BYTE1(w2)
    // [8] main::$3 = byte1  main::w2#0 -- vbuaa=_byte1_vwuz1 
    lda.z w2+1
    // SCREEN[3] = BYTE1(w2)
    // [9] *(main::SCREEN+3) = main::$3 -- _deref_pbuc1=vbuaa 
    sta SCREEN+3
    // main::@return
    // }
    // [10] return 
    rts
}
  // File Data

