Identified constant variable (byte*) VIC
Identified constant variable (byte) RED
Culled Empty Block (label) main::@2

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (byte*) SCREEN#0 ← ((byte*)) (number) $400
  (byte) STAR#0 ← (number) $51
  (byte*) VIC#0 ← ((byte*)) (number) $d000
  (byte*~) $0 ← (byte*) VIC#0 + (number) $10*(number) 2
  (byte*~) $1 ← (byte*~) $0 + (number) 1
  (byte*) BGCOL#0 ← (byte*~) $1
  (byte) RED#0 ← (number) 2
  to:@1
main: scope:[main]  from @1
  (byte*) BGCOL#1 ← phi( @1/(byte*) BGCOL#2 )
  *((byte*) SCREEN#0) ← (byte) STAR#0
  *((byte*) BGCOL#1) ← (byte) RED#0
  (byte) main::i#0 ← (byte) $28
  to:main::@1
main::@1: scope:[main]  from main main::@1
  (byte) main::i#2 ← phi( main/(byte) main::i#0 main::@1/(byte) main::i#1 )
  (number~) main::$0 ← (byte) STAR#0 + (number) 1
  *((byte*) SCREEN#0 + (byte) main::i#2) ← (number~) main::$0
  (byte) main::i#1 ← (byte) main::i#2 + rangenext($28,$4f)
  (bool~) main::$1 ← (byte) main::i#1 != rangelast($28,$4f)
  if((bool~) main::$1) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  return 
  to:@return
@1: scope:[]  from @begin
  (byte*) BGCOL#2 ← phi( @begin/(byte*) BGCOL#0 )
  call main 
  to:@2
@2: scope:[]  from @1
  to:@end
@end: scope:[]  from @2

SYMBOL TABLE SSA
(byte*~) $0
(byte*~) $1
(label) @1
(label) @2
(label) @begin
(label) @end
(byte*) BGCOL
(byte*) BGCOL#0
(byte*) BGCOL#1
(byte*) BGCOL#2
(byte) RED
(byte) RED#0
(byte*) SCREEN
(byte*) SCREEN#0
(byte) STAR
(byte) STAR#0
(byte*) VIC
(byte*) VIC#0
(void()) main()
(number~) main::$0
(bool~) main::$1
(label) main::@1
(label) main::@return
(byte) main::i
(byte) main::i#0
(byte) main::i#1
(byte) main::i#2

Adding number conversion cast (unumber) $51 in (byte) STAR#0 ← (number) $51
Adding number conversion cast (unumber) $10*2 in (byte*~) $0 ← (byte*) VIC#0 + (number) $10*(number) 2
Adding number conversion cast (unumber) 1 in (byte*~) $1 ← (byte*~) $0 + (number) 1
Adding number conversion cast (unumber) 2 in (byte) RED#0 ← (number) 2
Adding number conversion cast (unumber) 1 in (number~) main::$0 ← (byte) STAR#0 + (number) 1
Adding number conversion cast (unumber) main::$0 in (number~) main::$0 ← (byte) STAR#0 + (unumber)(number) 1
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte*) SCREEN#0 ← (byte*)(number) $400
Inlining cast (byte) STAR#0 ← (unumber)(number) $51
Inlining cast (byte*) VIC#0 ← (byte*)(number) $d000
Inlining cast (byte) RED#0 ← (unumber)(number) 2
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast $51
Simplifying constant pointer cast (byte*) 53248
Simplifying constant integer cast 1
Simplifying constant integer cast 2
Simplifying constant integer cast 1
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $51
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) 2
Finalized unsigned number type (byte) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to byte in (unumber~) main::$0 ← (byte) STAR#0 + (byte) 1
Alias (byte*) BGCOL#0 = (byte*~) $1 (byte*) BGCOL#2 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte*) BGCOL#1 (byte*) BGCOL#0
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition (bool~) main::$1 [16] if((byte) main::i#1!=rangelast($28,$4f)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte*) SCREEN#0 = (byte*) 1024
Constant (const byte) STAR#0 = $51
Constant (const byte*) VIC#0 = (byte*) 53248
Constant (const byte) RED#0 = 2
Constant (const byte) main::i#0 = $28
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [14] main::i#1 ← ++ main::i#2 to ++
Resolved ranged comparison value [16] if(main::i#1!=rangelast($28,$4f)) goto main::@1 to (number) $50
Converting *(pointer+n) to pointer[n] [9] *((byte*) BGCOL#0) ← (const byte) RED#0  -- *($0 + 1)
Successful SSA optimization Pass2InlineDerefIdx
Eliminating unused variable (byte*) BGCOL#0 and assignment [1] (byte*) BGCOL#0 ← (byte*~) $0 + (byte) 1
Successful SSA optimization PassNEliminateUnusedVars
Adding number conversion cast (unumber) $50 in if((byte) main::i#1!=(number) $50) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast $50
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $50
Successful SSA optimization PassNFinalizeNumberTypeConversions
Constant right-side identified [0] (byte*~) $0 ← (const byte*) VIC#0 + (byte)(number) $10*(number) 2
Constant right-side identified [4] (byte~) main::$0 ← (const byte) STAR#0 + (byte) 1
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const byte*) $0 = VIC#0+(byte)$10*2
Constant (const byte) main::$0 = STAR#0+1
Successful SSA optimization Pass2ConstantIdentification
Inlining constant with var siblings (const byte) main::i#0
Constant inlined $0 = (const byte*) VIC#0+(byte)(number) $10*(number) 2
Constant inlined main::i#0 = (byte) $28
Constant inlined main::$0 = (const byte) STAR#0+(byte) 1
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(VIC#0+(byte)$10*2+1)
Successful SSA optimization Pass2ConstantAdditionElimination
Added new block during phi lifting main::@3(between main::@1 and main::@1)
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @2
Adding NOP phi() at start of @end
CALL GRAPH
Calls in [] to main:2 

Created 1 initial phi equivalence classes
Coalesced [12] main::i#3 ← main::i#1
Coalesced down to 1 phi equivalence classes
Culled Empty Block (label) @2
Culled Empty Block (label) main::@3
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end

FINAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  [0] phi()
  to:@1
@1: scope:[]  from @begin
  [1] phi()
  [2] call main 
  to:@end
@end: scope:[]  from @1
  [3] phi()
main: scope:[main]  from @1
  [4] *((const byte*) SCREEN#0) ← (const byte) STAR#0
  [5] *((const byte*) VIC#0+(byte)(number) $10*(number) 2+(byte) 1) ← (const byte) RED#0
  to:main::@1
main::@1: scope:[main]  from main main::@1
  [6] (byte) main::i#2 ← phi( main/(byte) $28 main::@1/(byte) main::i#1 )
  [7] *((const byte*) SCREEN#0 + (byte) main::i#2) ← (const byte) STAR#0+(byte) 1
  [8] (byte) main::i#1 ← ++ (byte) main::i#2
  [9] if((byte) main::i#1!=(byte) $50) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  [10] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(byte*) BGCOL
(byte) RED
(byte*) SCREEN
(byte) STAR
(byte*) VIC
(void()) main()
(byte) main::i
(byte) main::i#1 16.5
(byte) 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 ZP_BYTE:2 [ main::i#2 main::i#1 ]

INITIAL ASM
Target platform is c64basic
  // File Comments
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .const STAR = $51
  .label VIC = $d000
  .const RED = 2
  // @begin
bbegin:
  // [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
  jmp b1
  // @1
b1:
  // [2] call main 
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
  jmp bend
  // @end
bend:
  // main
main: {
    .label i = 2
    // [4] *((const byte*) SCREEN#0) ← (const byte) STAR#0 -- _deref_pbuc1=vbuc2 
    lda #STAR
    sta SCREEN
    // [5] *((const byte*) VIC#0+(byte)(number) $10*(number) 2+(byte) 1) ← (const byte) RED#0 -- _deref_pbuc1=vbuc2 
    lda #RED
    sta VIC+$10*2+1
    // [6] phi from main to main::@1 [phi:main->main::@1]
  b1_from_main:
    // [6] phi (byte) main::i#2 = (byte) $28 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #$28
    sta.z i
    jmp b1
    // [6] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  b1_from_b1:
    // [6] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    jmp b1
    // main::@1
  b1:
    // [7] *((const byte*) SCREEN#0 + (byte) main::i#2) ← (const byte) STAR#0+(byte) 1 -- pbuc1_derefidx_vbuz1=vbuc2 
    lda #STAR+1
    ldy.z i
    sta SCREEN,y
    // [8] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [9] if((byte) main::i#1!=(byte) $50) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #$50
    cmp.z i
    bne b1_from_b1
    jmp breturn
    // main::@return
  breturn:
    // [10] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] *((const byte*) SCREEN#0) ← (const byte) STAR#0 [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [5] *((const byte*) VIC#0+(byte)(number) $10*(number) 2+(byte) 1) ← (const byte) RED#0 [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [7] *((const byte*) SCREEN#0 + (byte) main::i#2) ← (const byte) STAR#0+(byte) 1 [ main::i#2 ] ( main:2 [ main::i#2 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:2 [ main::i#2 main::i#1 ]
Statement [4] *((const byte*) SCREEN#0) ← (const byte) STAR#0 [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [5] *((const byte*) VIC#0+(byte)(number) $10*(number) 2+(byte) 1) ← (const byte) RED#0 [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [7] *((const byte*) SCREEN#0 + (byte) main::i#2) ← (const byte) STAR#0+(byte) 1 [ main::i#2 ] ( main:2 [ main::i#2 ] ) always clobbers reg byte a 
Potential registers zp ZP_BYTE:2 [ main::i#2 main::i#1 ] : zp ZP_BYTE:2 , reg byte x , reg byte y , 

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

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

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .const STAR = $51
  .label VIC = $d000
  .const RED = 2
  // @begin
bbegin:
  // [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
  jmp b1
  // @1
b1:
  // [2] call main 
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
  jmp bend
  // @end
bend:
  // main
main: {
    // [4] *((const byte*) SCREEN#0) ← (const byte) STAR#0 -- _deref_pbuc1=vbuc2 
    lda #STAR
    sta SCREEN
    // [5] *((const byte*) VIC#0+(byte)(number) $10*(number) 2+(byte) 1) ← (const byte) RED#0 -- _deref_pbuc1=vbuc2 
    lda #RED
    sta VIC+$10*2+1
    // [6] phi from main to main::@1 [phi:main->main::@1]
  b1_from_main:
    // [6] phi (byte) main::i#2 = (byte) $28 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #$28
    jmp b1
    // [6] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  b1_from_b1:
    // [6] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    jmp b1
    // main::@1
  b1:
    // [7] *((const byte*) SCREEN#0 + (byte) main::i#2) ← (const byte) STAR#0+(byte) 1 -- pbuc1_derefidx_vbuxx=vbuc2 
    lda #STAR+1
    sta SCREEN,x
    // [8] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [9] if((byte) main::i#1!=(byte) $50) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$50
    bne b1_from_b1
    jmp breturn
    // main::@return
  breturn:
    // [10] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label b1_from_b1 with b1
Removing instruction b1_from_bbegin:
Removing instruction b1:
Removing instruction bend_from_b1:
Removing instruction b1_from_b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
Removing instruction b1_from_main:
Removing instruction breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction jmp b1
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(byte*) BGCOL
(byte) RED
(const byte) RED#0 RED = (byte) 2
(byte*) SCREEN
(const byte*) SCREEN#0 SCREEN = (byte*) 1024
(byte) STAR
(const byte) STAR#0 STAR = (byte) $51
(byte*) VIC
(const byte*) VIC#0 VIC = (byte*) 53248
(void()) main()
(label) main::@1
(label) main::@return
(byte) main::i
(byte) main::i#1 reg byte x 16.5
(byte) main::i#2 reg byte x 16.5

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


FINAL ASSEMBLER
Score: 173

  // File Comments
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .const STAR = $51
  .label VIC = $d000
  .const RED = 2
  // @begin
  // [1] phi from @begin to @1 [phi:@begin->@1]
  // @1
  // [2] call main 
  // [3] phi from @1 to @end [phi:@1->@end]
  // @end
  // main
main: {
    // *SCREEN = STAR
    // [4] *((const byte*) SCREEN#0) ← (const byte) STAR#0 -- _deref_pbuc1=vbuc2 
    lda #STAR
    sta SCREEN
    // *BGCOL = RED
    // [5] *((const byte*) VIC#0+(byte)(number) $10*(number) 2+(byte) 1) ← (const byte) RED#0 -- _deref_pbuc1=vbuc2 
    lda #RED
    sta VIC+$10*2+1
    // [6] phi from main to main::@1 [phi:main->main::@1]
    // [6] phi (byte) main::i#2 = (byte) $28 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #$28
    // [6] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
    // [6] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    // main::@1
  b1:
    // SCREEN[i] = (STAR+1)
    // [7] *((const byte*) SCREEN#0 + (byte) main::i#2) ← (const byte) STAR#0+(byte) 1 -- pbuc1_derefidx_vbuxx=vbuc2 
    lda #STAR+1
    sta SCREEN,x
    // for(byte i: 40..79)
    // [8] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [9] if((byte) main::i#1!=(byte) $50) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$50
    bne b1
    // main::@return
    // }
    // [10] return 
    rts
}
  // File Data

