
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 < 2
  unroll if(main::$0) goto main::@2
  to:main::@return
main::@2: scope:[main]  from main::@1
  main::i#3 = phi( main::@1/main::i#2 )
  main::SCREEN[main::i#3] = 'a'
  main::i#1 = ++ main::i#3
  to:main::@1
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()
bool main::$0
__constant char *main::SCREEN = (char *)$400
char main::i
char main::i#0
char main::i#1
char main::i#2
char main::i#3

Adding number conversion cast (unumber) 2 in main::$0 = main::i#2 < 2
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast 2
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 2
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias main::i#2 = main::i#3 
Successful SSA optimization Pass2AliasElimination
Simple Condition main::$0 [3] unroll if(main::i#2<2) goto main::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant main::i#0 = 0
Successful SSA optimization Pass2ConstantIdentification
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
Unrolling loop Loop head: main::@1 tails: main::@2 blocks: main::@2 main::@1 
Successful SSA optimization Pass2LoopUnroll
Identical Phi Values main::i#2 main::i#0
Successful SSA optimization Pass2IdenticalPhiElimination
Constant right-side identified [3] main::i#1 = ++ main::i#0
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant main::i#1 = ++main::i#0
Successful SSA optimization Pass2ConstantIdentification
if() condition always true - replacing block destination [1] if(main::i#0<2) goto main::@2
Successful SSA optimization Pass2ConstantIfs
Simplifying expression containing zero main::SCREEN in [2] main::SCREEN[main::i#0] = 'a'
Successful SSA optimization PassNSimplifyExpressionWithZero
Unrolling loop Loop head: main::@1_1 tails: main::@2_1 blocks: main::@2_1 main::@1_1 
Successful SSA optimization Pass2LoopUnroll
Identical Phi Values main::i#4 main::i#1
Successful SSA optimization Pass2IdenticalPhiElimination
Constant right-side identified [5] main::i#5 = ++ main::i#1
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant main::i#5 = ++main::i#1
Successful SSA optimization Pass2ConstantIdentification
if() condition always true - replacing block destination [2] if(main::i#1<2) goto main::@2_1
Successful SSA optimization Pass2ConstantIfs
Unrolling loop Loop head: main::@1_2 tails: main::@2_2 blocks: main::@2_2 main::@1_2 
Successful SSA optimization Pass2LoopUnroll
Identical Phi Values main::i#6 main::i#5
Successful SSA optimization Pass2IdenticalPhiElimination
Constant right-side identified [6] main::i#7 = ++ main::i#5
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant main::i#7 = ++main::i#5
Successful SSA optimization Pass2ConstantIdentification
if() condition always false - eliminating [3] if(main::i#5<2) goto main::@2_2
Successful SSA optimization Pass2ConstantIfs
Eliminating variable main::i#8 from unused block main::@1_3
Eliminating variable main::i#9 from unused block main::@2_3
Removing PHI-reference to removed block (main::@2_2) in block main::@1_3
Removing unused block main::@2_2
Removing unused block main::@1_3
Removing unused block main::@2_3
Successful SSA optimization Pass2EliminateUnusedBlocks
Eliminating unused constant main::i#7
Successful SSA optimization PassNEliminateUnusedVars
Eliminating unused constant main::i#5
Successful SSA optimization PassNEliminateUnusedVars
Inlining constant with different constant siblings main::i#0
Inlining constant with different constant siblings main::i#1
Constant inlined main::i#0 = 0
Constant inlined main::i#1 = ++0
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(main::SCREEN+++0)
Successful SSA optimization Pass2ConstantAdditionElimination
Simplifying constant integer increment ++0
Successful SSA optimization Pass2ConstantSimplification
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@1
Adding NOP phi() at start of main::@1_1
Adding NOP phi() at start of main::@1_2
CALL GRAPH

Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block label main::@1
Culled Empty Block label main::@1_1
Culled Empty Block label main::@1_2
Renumbering block main::@2 to main::@1
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] *main::SCREEN = 'a'
  to:main::@2_1
main::@2_1: scope:[main]  from main::@1
  [2] *(main::SCREEN+1) = 'a'
  to:main::@return
main::@return: scope:[main]  from main::@2_1
  [3] return 
  to:@return


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

Initial phi equivalence classes
Complete equivalence classes
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [1] *main::SCREEN = 'a' [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [2] *(main::SCREEN+1) = 'a' [ ] (  [ ] { }  ) always clobbers reg byte a 

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

Uplifting [main] best 54 combination 
Uplifting [] best 54 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Minimal unrolled while() loop
  // Upstart
  // Commodore 64 PRG executable file
.file [name="unroll-while-min.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
.segment Code
  // main
main: {
    .label SCREEN = $400
    jmp __b1
    // main::@1
  __b1:
    // [1] *main::SCREEN = 'a' -- _deref_pbuc1=vbuc2 
    lda #'a'
    sta SCREEN
    jmp __b2_1
    // main::@2_1
  __b2_1:
    // [2] *(main::SCREEN+1) = 'a' -- _deref_pbuc1=vbuc2 
    lda #'a'
    sta SCREEN+1
    jmp __breturn
    // main::@return
  __breturn:
    // [3] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __b2_1
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1:
Removing instruction __b2_1:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Removing instruction lda #'a'
Succesful ASM optimization Pass5UnnecesaryLoadElimination

FINAL SYMBOL TABLE
void main()
__constant char *main::SCREEN = (char *) 1024
char main::i



FINAL ASSEMBLER
Score: 16

  // File Comments
// Minimal unrolled while() loop
  // Upstart
  // Commodore 64 PRG executable file
.file [name="unroll-while-min.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
.segment Code
  // main
main: {
    .label SCREEN = $400
    // main::@1
    // SCREEN[i++] = 'a'
    // [1] *main::SCREEN = 'a' -- _deref_pbuc1=vbuc2 
    lda #'a'
    sta SCREEN
    // main::@2_1
    // [2] *(main::SCREEN+1) = 'a' -- _deref_pbuc1=vbuc2 
    sta SCREEN+1
    // main::@return
    // }
    // [3] return 
    rts
}
  // File Data

