
CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start
  main::j#0 = 0
  to:main::@1
main::@1: scope:[main]  from main main::@1
  main::j#2 = phi( main/main::j#0, main::@1/main::j#1 )
  main::$0 = $28 * main::j#2
  main::$1 = screen + main::$0
  main::$2 = main::$1 + $27
  *main::$2 = 0
  main::$3 = $28 * main::j#2
  main::$4 = main::$3 + $25
  screen[main::$4] = 0
  main::j#1 = main::j#2 + rangenext(0,1)
  main::$5 = main::j#1 != rangelast(0,1)
  unroll if(main::$5) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  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
void __start()
void main()
number main::$0
char *main::$1
char *main::$2
number main::$3
number main::$4
bool main::$5
char main::j
char main::j#0
char main::j#1
char main::j#2
__constant char * const screen = (char *)$400

Adding number conversion cast (unumber) $28 in main::$0 = $28 * main::j#2
Adding number conversion cast (unumber) main::$0 in main::$0 = (unumber)$28 * main::j#2
Adding number conversion cast (unumber) $27 in main::$2 = main::$1 + $27
Adding number conversion cast (unumber) 0 in *main::$2 = 0
Adding number conversion cast (unumber) $28 in main::$3 = $28 * main::j#2
Adding number conversion cast (unumber) main::$3 in main::$3 = (unumber)$28 * main::j#2
Adding number conversion cast (unumber) $25 in main::$4 = main::$3 + $25
Adding number conversion cast (unumber) main::$4 in main::$4 = main::$3 + (unumber)$25
Adding number conversion cast (unumber) 0 in screen[main::$4] = 0
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast *main::$2 = (unumber)0
Inlining cast screen[main::$4] = (unumber)0
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast $28
Simplifying constant integer cast $27
Simplifying constant integer cast 0
Simplifying constant integer cast $28
Simplifying constant integer cast $25
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) $28
Finalized unsigned number type (char) $27
Finalized unsigned number type (char) 0
Finalized unsigned number type (char) $28
Finalized unsigned number type (char) $25
Finalized unsigned number type (char) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to char in main::$0 = $28 * main::j#2
Inferred type updated to char in main::$3 = $28 * main::j#2
Inferred type updated to char in main::$4 = main::$3 + $25
Identified duplicate assignment right side [6] main::$3 = $28 * main::j#2
Successful SSA optimization Pass2DuplicateRValueIdentification
Simple Condition main::$5 [11] unroll if(main::j#1!=rangelast(0,1)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant main::j#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [9] main::j#1 = ++ main::j#2 to ++
Resolved ranged comparison value [11] unroll if(main::j#1!=rangelast(0,1)) goto main::@1 to 2
Converting *(pointer+n) to pointer[n] [5] *main::$2 = 0  -- main::$1[$27]
Successful SSA optimization Pass2InlineDerefIdx
Eliminating unused variable main::$2 and assignment [3] main::$2 = main::$1 + $27
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
Adding number conversion cast (unumber) 2 in [8] unroll if(main::j#1!=2) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast 2
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 2
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias main::$3 = main::$0 
Successful SSA optimization Pass2AliasElimination
Unrolling loop Loop head: main::@1 tails: main::@1 blocks: main::@1 
Successful SSA optimization Pass2LoopUnroll
Identical Phi Values main::j#2 main::j#0
Successful SSA optimization Pass2IdenticalPhiElimination
Negating conditional jump and destination [7] if(main::j#1==2) goto main::@return
Successful SSA optimization Pass2ConditionalJumpSequenceImprovement
Constant right-side identified [1] main::$3 = $28 * main::j#0
Constant right-side identified [6] main::j#1 = ++ main::j#0
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant main::$3 = $28*main::j#0
Constant main::j#1 = ++main::j#0
Successful SSA optimization Pass2ConstantIdentification
if() condition always false - eliminating [7] if(main::j#1==2) goto main::@return
Successful SSA optimization Pass2ConstantIfs
Simplifying constant evaluating to zero $28*main::j#0 in 
Successful SSA optimization PassNSimplifyConstantZero
Simplifying expression containing zero screen in [2] main::$1 = screen + main::$3
Simplifying expression containing zero $25 in [4] main::$4 = main::$3 + $25
Successful SSA optimization PassNSimplifyExpressionWithZero
Eliminating unused constant main::$3
Successful SSA optimization PassNEliminateUnusedVars
Constant main::$1 = screen
Constant main::$4 = $25
Successful SSA optimization Pass2ConstantIdentification
Unrolling loop Loop head: main::@1_1 tails: main::@1_1 blocks: main::@1_1 
Successful SSA optimization Pass2LoopUnroll
Identical Phi Values main::j#3 main::j#1
Successful SSA optimization Pass2IdenticalPhiElimination
Negating conditional jump and destination [9] if(main::j#4==2) goto main::@return
Successful SSA optimization Pass2ConditionalJumpSequenceImprovement
Constant right-side identified [3] main::$6 = $28 * main::j#1
Constant right-side identified [8] main::j#4 = ++ main::j#1
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant main::$6 = $28*main::j#1
Constant main::j#4 = ++main::j#1
Successful SSA optimization Pass2ConstantIdentification
Removing PHI-reference to removed block (main::@1_1) in block main::@1_2
if() condition always true - replacing block destination [9] if(main::j#4==2) goto main::@return
Successful SSA optimization Pass2ConstantIfs
Eliminating variable main::j#5 from unused block main::@1_2
Eliminating variable main::$9 from unused block main::@1_2
Eliminating variable main::$10 from unused block main::@1_2
Eliminating variable main::$11 from unused block main::@1_2
Eliminating variable main::j#6 from unused block main::@1_2
Removing unused block main::@1_2
Successful SSA optimization Pass2EliminateUnusedBlocks
Eliminating unused constant main::j#4
Successful SSA optimization PassNEliminateUnusedVars
Constant right-side identified [2] main::$7 = screen + main::$6
Constant right-side identified [4] main::$8 = main::$6 + $25
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant main::$7 = screen+main::$6
Constant main::$8 = main::$6+$25
Successful SSA optimization Pass2ConstantIdentification
Inlining constant with different constant siblings main::j#0
Inlining constant with different constant siblings main::j#1
Constant inlined main::$1 = screen
Constant inlined main::$6 = $28*++0
Constant inlined main::j#1 = ++0
Constant inlined main::$4 = $25
Constant inlined main::j#0 = 0
Constant inlined main::$7 = screen+$28*++0
Constant inlined main::$8 = $28*++0+$25
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(screen+$27)
Consolidated array index constant in *(screen+$25)
Consolidated array index constant in *(screen+$28*++0+$27)
Consolidated array index constant in *(screen+$28*++0+$25)
Successful SSA optimization Pass2ConstantAdditionElimination
Simplifying constant integer increment ++0
Successful SSA optimization Pass2ConstantSimplification
Adding NOP phi() at start of main
CALL GRAPH

Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
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
  [1] *(screen+$27) = 0
  [2] *(screen+$25) = 0
  to:main::@1_1
main::@1_1: scope:[main]  from main::@1
  [3] *(screen+$28*1+$27) = 0
  [4] *(screen+$28*1+$25) = 0
  to:main::@return
main::@return: scope:[main]  from main::@1_1
  [5] return 
  to:@return


VARIABLE REGISTER WEIGHTS
void main()
char main::j

Initial phi equivalence classes
Complete equivalence classes
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [1] *(screen+$27) = 0 [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [2] *(screen+$25) = 0 [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [3] *(screen+$28*1+$27) = 0 [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [4] *(screen+$28*1+$25) = 0 [ ] (  [ ] { }  ) always clobbers reg byte a 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 
Uplift Scope [] 

Uplifting [main] best 66 combination 
Uplifting [] best 66 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
  // Upstart
  // Commodore 64 PRG executable file
.file [name="consolidate-constant-problem.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: {
    jmp __b1
    // main::@1
  __b1:
    // [1] *(screen+$27) = 0 -- _deref_pbuc1=vbuc2 
    lda #0
    sta screen+$27
    // [2] *(screen+$25) = 0 -- _deref_pbuc1=vbuc2 
    lda #0
    sta screen+$25
    jmp __b1_1
    // main::@1_1
  __b1_1:
    // [3] *(screen+$28*1+$27) = 0 -- _deref_pbuc1=vbuc2 
    lda #0
    sta screen+$28*1+$27
    // [4] *(screen+$28*1+$25) = 0 -- _deref_pbuc1=vbuc2 
    lda #0
    sta screen+$28*1+$25
    jmp __breturn
    // main::@return
  __breturn:
    // [5] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __b1_1
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction lda #0
Removing instruction lda #0
Succesful ASM optimization Pass5UnnecesaryLoadElimination
Removing instruction __b1:
Removing instruction __b1_1:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Removing instruction lda #0
Succesful ASM optimization Pass5UnnecesaryLoadElimination

FINAL SYMBOL TABLE
void main()
char main::j
__constant char * const screen = (char *) 1024



FINAL ASSEMBLER
Score: 24

  // File Comments
  // Upstart
  // Commodore 64 PRG executable file
.file [name="consolidate-constant-problem.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: {
    // main::@1
    // *(screen+40*j+39) = 0
    // [1] *(screen+$27) = 0 -- _deref_pbuc1=vbuc2 
    lda #0
    sta screen+$27
    // screen[40*j+37] = 0
    // [2] *(screen+$25) = 0 -- _deref_pbuc1=vbuc2 
    sta screen+$25
    // main::@1_1
    // *(screen+40*j+39) = 0
    // [3] *(screen+$28*1+$27) = 0 -- _deref_pbuc1=vbuc2 
    sta screen+$28*1+$27
    // screen[40*j+37] = 0
    // [4] *(screen+$28*1+$25) = 0 -- _deref_pbuc1=vbuc2 
    sta screen+$28*1+$25
    // main::@return
    // }
    // [5] return 
    rts
}
  // File Data

