Inlined call call __init
Eliminating unused variable with no statement __start::__init1_$1

CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start::@1
  BG_COLOR#2 = phi( __start::@1/BG_COLOR#4 )
  *SCREEN = STAR
  *BG_COLOR#2 = RED
  main::i#0 = $28
  to:main::@1
main::@1: scope:[main]  from main main::@1
  main::i#2 = phi( main/main::i#0, main::@1/main::i#1 )
  SCREEN[main::i#2] = STAR+1
  main::i#1 = main::i#2 + rangenext($28,$4f)
  main::$0 = main::i#1 != rangelast($28,$4f)
  if(main::$0) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  return 
  to:@return

void __start()
__start: scope:[__start]  from
  to:__start::__init1
__start::__init1: scope:[__start]  from __start
  __start::__init1_$0 = VIC + $10*2
  BG_COLOR#0 = __start::__init1_$0 + 1
  to:__start::@1
__start::@1: scope:[__start]  from __start::__init1
  BG_COLOR#4 = phi( __start::__init1/BG_COLOR#0 )
  call main
  to:__start::@2
__start::@2: scope:[__start]  from __start::@1
  BG_COLOR#5 = phi( __start::@1/BG_COLOR#4 )
  to:__start::@return
__start::@return: scope:[__start]  from __start::@2
  BG_COLOR#3 = phi( __start::@2/BG_COLOR#5 )
  BG_COLOR#1 = BG_COLOR#3
  return 
  to:@return

SYMBOL TABLE SSA
char *BG_COLOR
char *BG_COLOR#0
char *BG_COLOR#1
char *BG_COLOR#2
char *BG_COLOR#3
char *BG_COLOR#4
char *BG_COLOR#5
__constant char RED = 2
__constant char * const SCREEN = (char *)$400
__constant const char STAR = $51
__constant char *VIC = (char *)$d000
void __start()
char *__start::__init1_$0
void main()
bool main::$0
char main::i
char main::i#0
char main::i#1
char main::i#2

Adding number conversion cast (unumber) STAR+1 in SCREEN[main::i#2] = STAR+1
Adding number conversion cast (unumber) 1 in SCREEN[main::i#2] = ((unumber)) STAR+1
Adding number conversion cast (unumber) $10*2 in __start::__init1_$0 = VIC + $10*2
Adding number conversion cast (unumber) 1 in BG_COLOR#0 = __start::__init1_$0 + 1
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast SCREEN[main::i#2] = (unumber)STAR+(unumber)1
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (char *) 1024
Simplifying constant pointer cast (char *) 53248
Simplifying constant integer cast STAR+(unumber)1
Simplifying constant integer cast 1
Simplifying constant integer cast 1
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias BG_COLOR#0 = BG_COLOR#4 BG_COLOR#5 BG_COLOR#3 BG_COLOR#1 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values BG_COLOR#2 BG_COLOR#0
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition main::$0 [8] if(main::i#1!=rangelast($28,$4f)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant right-side identified [10] __start::__init1_$0 = VIC + (char)$10*2
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant main::i#0 = $28
Constant __start::__init1_$0 = VIC+(char)$10*2
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [6] main::i#1 = ++ main::i#2 to ++
Resolved ranged comparison value [8] if(main::i#1!=rangelast($28,$4f)) goto main::@1 to $50
Converting *(pointer+n) to pointer[n] [2] *BG_COLOR#0 = RED  -- __start::__init1_$0[1]
Successful SSA optimization Pass2InlineDerefIdx
Eliminating unused variable BG_COLOR#0 and assignment [7] BG_COLOR#0 = __start::__init1_$0 + 1
Successful SSA optimization PassNEliminateUnusedVars
Adding number conversion cast (unumber) $50 in [5] if(main::i#1!=$50) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast $50
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) $50
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining constant with var siblings main::i#0
Constant inlined __start::__init1_$0 = VIC+(char)$10*2
Constant inlined main::i#0 = $28
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(VIC+(char)$10*2+1)
Successful SSA optimization Pass2ConstantAdditionElimination
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
Finalized unsigned number type (char) $10
Finalized unsigned number type (char) 2
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simplifying constant integer cast $10*2
Successful SSA optimization PassNCastSimplification
Added new block during phi lifting main::@2(between main::@1 and main::@1)
CALL GRAPH

Created 1 initial phi equivalence classes
Coalesced [7] main::i#3 = main::i#1
Coalesced down to 1 phi equivalence classes
Culled Empty Block label main::@2

FINAL CONTROL FLOW GRAPH

void main()
main: scope:[main]  from
  [0] *SCREEN = STAR
  [1] *(VIC+$10*2+1) = RED
  to:main::@1
main::@1: scope:[main]  from main main::@1
  [2] main::i#2 = phi( main/$28, main::@1/main::i#1 )
  [3] SCREEN[main::i#2] = STAR+1
  [4] main::i#1 = ++ main::i#2
  [5] if(main::i#1!=$50) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  [6] return 
  to:@return


VARIABLE REGISTER WEIGHTS
char *BG_COLOR
void main()
char main::i
char main::i#1 // 16.5
char main::i#2 // 16.5

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
Allocated zp[1]:2 [ main::i#2 main::i#1 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [0] *SCREEN = STAR [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [1] *(VIC+$10*2+1) = RED [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [3] SCREEN[main::i#2] = STAR+1 [ main::i#2 ] (  [ main::i#2 ] { }  ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::i#2 main::i#1 ]
Statement [0] *SCREEN = STAR [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [1] *(VIC+$10*2+1) = RED [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [3] SCREEN[main::i#2] = STAR+1 [ main::i#2 ] (  [ main::i#2 ] { }  ) always clobbers reg byte a 
Potential registers zp[1]:2 [ main::i#2 main::i#1 ] : zp[1]:2 , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 33: zp[1]:2 [ main::i#2 main::i#1 ] 
Uplift Scope [] 

Uplifting [main] best 263 combination reg byte x [ main::i#2 main::i#1 ] 
Uplifting [] best 263 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
  // Upstart
  // Commodore 64 PRG executable file
.file [name="constantmin.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 STAR = $51
  .const RED = 2
  .label SCREEN = $400
  .label VIC = $d000
.segment Code
  // main
main: {
    // [0] *SCREEN = STAR -- _deref_pbuc1=vbuc2 
    lda #STAR
    sta SCREEN
    // [1] *(VIC+$10*2+1) = RED -- _deref_pbuc1=vbuc2 
    lda #RED
    sta VIC+$10*2+1
    // [2] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [2] phi main::i#2 = $28 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #$28
    jmp __b1
    // [2] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  __b1_from___b1:
    // [2] phi main::i#2 = main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [3] SCREEN[main::i#2] = STAR+1 -- pbuc1_derefidx_vbuxx=vbuc2 
    lda #STAR+1
    sta SCREEN,x
    // [4] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [5] if(main::i#1!=$50) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$50
    bne __b1_from___b1
    jmp __breturn
    // main::@return
  __breturn:
    // [6] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __b1_from___b1 with __b1
Removing instruction __b1_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __b1_from_main:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Removing instruction jmp __b1
Succesful ASM optimization Pass5NextJumpElimination

FINAL SYMBOL TABLE
char *BG_COLOR
__constant char RED = 2
__constant char * const SCREEN = (char *) 1024
__constant const char STAR = $51
__constant char *VIC = (char *) 53248
void main()
char main::i
char main::i#1 // reg byte x 16.5
char main::i#2 // reg byte x 16.5

reg byte x [ main::i#2 main::i#1 ]


FINAL ASSEMBLER
Score: 173

  // File Comments
  // Upstart
  // Commodore 64 PRG executable file
.file [name="constantmin.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 STAR = $51
  .const RED = 2
  .label SCREEN = $400
  .label VIC = $d000
.segment Code
  // main
main: {
    // *SCREEN = STAR
    // [0] *SCREEN = STAR -- _deref_pbuc1=vbuc2 
    lda #STAR
    sta SCREEN
    // *BG_COLOR = RED
    // [1] *(VIC+$10*2+1) = RED -- _deref_pbuc1=vbuc2 
    lda #RED
    sta VIC+$10*2+1
    // [2] phi from main to main::@1 [phi:main->main::@1]
    // [2] phi main::i#2 = $28 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #$28
    // [2] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
    // [2] phi main::i#2 = main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    // main::@1
  __b1:
    // SCREEN[i] = (STAR+1)
    // [3] SCREEN[main::i#2] = STAR+1 -- pbuc1_derefidx_vbuxx=vbuc2 
    lda #STAR+1
    sta SCREEN,x
    // for(byte i: 40..79)
    // [4] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [5] if(main::i#1!=$50) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$50
    bne __b1
    // main::@return
    // }
    // [6] return 
    rts
}
  // File Data

