Identified constant variable (byte) c
Identified constant variable (word) d
Identified constant variable (byte) main::col
Identified constant variable (byte*) main::COLS
Identified constant variable (signed byte) main::x
Culled Empty Block (label) main::@2
Culled Empty Block (label) @1
Culled Empty Block (label) s::@1

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (byte) b#0 ← (byte)(number) 2/(number) 2
  to:@2

(void()) main()
main: scope:[main]  from @2
  (byte) b#13 ← phi( @2/(byte) b#14 )
  call s 
  (byte) s::return#0 ← (byte) s::return#2
  to:main::@3
main::@3: scope:[main]  from main
  (byte) b#7 ← phi( main/(byte) b#5 )
  (byte) b#1 ← (byte) b#7
  (byte) b#2 ← ++ (byte) b#1
  (byte) main::i#0 ← (byte) 0
  to:main::@1
main::@1: scope:[main]  from main::@1 main::@3
  (byte) b#8 ← phi( main::@1/(byte) b#8 main::@3/(byte) b#2 )
  (byte) main::i#2 ← phi( main::@1/(byte) main::i#1 main::@3/(byte) main::i#0 )
  *((const byte*) main::COLS + (byte) main::i#2) ← (const byte) main::col
  *((const byte*) SCREEN + (byte) main::i#2) ← (byte) b#8
  (byte) main::i#1 ← (byte) main::i#2 + rangenext(0,$64)
  (bool~) main::$4 ← (byte) main::i#1 != rangelast(0,$64)
  if((bool~) main::$4) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  (byte) b#9 ← phi( main::@1/(byte) b#8 )
  (byte) b#3 ← (byte) b#9
  return 
  to:@return

(byte()) s()
s: scope:[s]  from main
  (byte) b#10 ← phi( main/(byte) b#13 )
  (byte) b#4 ← ++ (byte) b#10
  (byte) s::return#1 ← (number) 2
  to:s::@return
s::@return: scope:[s]  from s
  (byte) b#11 ← phi( s/(byte) b#4 )
  (byte) s::return#3 ← phi( s/(byte) s::return#1 )
  (byte) s::return#2 ← (byte) s::return#3
  (byte) b#5 ← (byte) b#11
  return 
  to:@return
@2: scope:[]  from @begin
  (byte) b#14 ← phi( @begin/(byte) b#0 )
  call main 
  to:@3
@3: scope:[]  from @2
  (byte) b#12 ← phi( @2/(byte) b#3 )
  (byte) b#6 ← (byte) b#12
  to:@end
@end: scope:[]  from @3

SYMBOL TABLE SSA
(label) @2
(label) @3
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*)(number) $400
(byte) b
(byte) b#0
(byte) b#1
(byte) b#10
(byte) b#11
(byte) b#12
(byte) b#13
(byte) b#14
(byte) b#2
(byte) b#3
(byte) b#4
(byte) b#5
(byte) b#6
(byte) b#7
(byte) b#8
(byte) b#9
(void()) main()
(bool~) main::$4
(label) main::@1
(label) main::@3
(label) main::@return
(const byte*) main::COLS = (byte*)(number) $d800
(const byte) main::col = (byte) 2
(byte) main::i
(byte) main::i#0
(byte) main::i#1
(byte) main::i#2
(byte()) s()
(label) s::@return
(byte) s::return
(byte) s::return#0
(byte) s::return#1
(byte) s::return#2
(byte) s::return#3

Adding number conversion cast (unumber) 2 in (byte) s::return#1 ← (number) 2
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte) s::return#1 ← (unumber)(number) 2
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Simplifying constant pointer cast (byte*) 55296
Simplifying constant integer cast 2
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 2
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias (byte) b#1 = (byte) b#7 
Alias (byte) b#3 = (byte) b#9 (byte) b#8 
Alias (byte) s::return#1 = (byte) s::return#3 (byte) s::return#2 
Alias (byte) b#11 = (byte) b#4 (byte) b#5 
Alias (byte) b#0 = (byte) b#14 
Alias (byte) b#12 = (byte) b#6 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte) b#13 (byte) b#0
Identical Phi Values (byte) b#1 (byte) b#11
Identical Phi Values (byte) b#3 (byte) b#2
Identical Phi Values (byte) b#10 (byte) b#13
Identical Phi Values (byte) b#12 (byte) b#3
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition (bool~) main::$4 [12] if((byte) main::i#1!=rangelast(0,$64)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte) b#0 = (byte)2/2
Constant (const byte) main::i#0 = 0
Constant (const byte) s::return#1 = 2
Successful SSA optimization Pass2ConstantIdentification
Constant (const byte) s::return#0 = s::return#1
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [10] main::i#1 ← ++ main::i#2 to ++
Resolved ranged comparison value [12] if(main::i#1!=rangelast(0,$64)) goto main::@1 to (number) $65
Eliminating unused constant (const byte) s::return#0
Successful SSA optimization PassNEliminateUnusedVars
Eliminating unused constant (const byte) s::return#1
Successful SSA optimization PassNEliminateUnusedVars
Adding number conversion cast (unumber) $65 in if((byte) main::i#1!=(number) $65) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast $65
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $65
Successful SSA optimization PassNFinalizeNumberTypeConversions
Constant right-side identified [8] (byte) b#11 ← ++ (const byte) b#0
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const byte) b#11 = ++b#0
Successful SSA optimization Pass2ConstantIdentification
Constant right-side identified [1] (byte) b#2 ← ++ (const byte) b#11
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const byte) b#2 = ++b#11
Successful SSA optimization Pass2ConstantIdentification
Inlining constant with var siblings (const byte) main::i#0
Inlining constant with different constant siblings (const byte) b#0
Inlining constant with different constant siblings (const byte) b#11
Inlining constant with different constant siblings (const byte) b#2
Constant inlined b#2 = ++++(byte)(number) 2/(number) 2
Constant inlined main::i#0 = (byte) 0
Constant inlined b#11 = ++(byte)(number) 2/(number) 2
Constant inlined b#0 = (byte)(number) 2/(number) 2
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@4(between main::@1 and main::@1)
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @2
Adding NOP phi() at start of @3
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@3
Adding NOP phi() at start of s
CALL GRAPH
Calls in [] to main:2 
Calls in [main] to s:6 

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

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()

(void()) main()
main: scope:[main]  from @1
  [4] phi()
  [5] call s 
  to:main::@1
main::@1: scope:[main]  from main main::@1
  [6] (byte) main::i#2 ← phi( main::@1/(byte) main::i#1 main/(byte) 0 )
  [7] *((const byte*) main::COLS + (byte) main::i#2) ← (const byte) main::col
  [8] *((const byte*) SCREEN + (byte) main::i#2) ← ++++(byte)(number) 2/(number) 2
  [9] (byte) main::i#1 ← ++ (byte) main::i#2
  [10] if((byte) main::i#1!=(byte) $65) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  [11] return 
  to:@return

(byte()) s()
s: scope:[s]  from main
  [12] phi()
  to:s::@return
s::@return: scope:[s]  from s
  [13] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(byte) b
(void()) main()
(byte) main::i
(byte) main::i#1 16.5
(byte) main::i#2 14.666666666666666
(byte()) s()
(byte) s::return

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 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// used vars
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  // @begin
__bbegin:
  // [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
  jmp __b1
  // @1
__b1:
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
main_from___b1:
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
  jmp __bend
  // @end
__bend:
  // main
main: {
    // used vars
    .const col = 2
    .label COLS = $d800
    .label i = 2
    // [5] call s 
    // [12] phi from main to s [phi:main->s]
  s_from_main:
    jsr s
    // [6] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [6] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    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*) main::COLS + (byte) main::i#2) ← (const byte) main::col -- pbuc1_derefidx_vbuz1=vbuc2 
    lda #col
    ldy.z i
    sta COLS,y
    // [8] *((const byte*) SCREEN + (byte) main::i#2) ← ++++(byte)(number) 2/(number) 2 -- pbuc1_derefidx_vbuz1=vbuc2 
    lda #2/2+1+1
    ldy.z i
    sta SCREEN,y
    // [9] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [10] if((byte) main::i#1!=(byte) $65) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #$65
    cmp.z i
    bne __b1_from___b1
    jmp __breturn
    // main::@return
  __breturn:
    // [11] return 
    rts
}
  // s
s: {
    jmp __breturn
    // s::@return
  __breturn:
    // [13] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [7] *((const byte*) main::COLS + (byte) main::i#2) ← (const byte) main::col [ main::i#2 ] ( main: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 [8] *((const byte*) SCREEN + (byte) main::i#2) ← ++++(byte)(number) 2/(number) 2 [ main::i#2 ] ( main:2 [ main::i#2 ] ) always clobbers reg byte a 
Statement [7] *((const byte*) main::COLS + (byte) main::i#2) ← (const byte) main::col [ main::i#2 ] ( main:2 [ main::i#2 ] ) always clobbers reg byte a 
Statement [8] *((const byte*) SCREEN + (byte) main::i#2) ← ++++(byte)(number) 2/(number) 2 [ main::i#2 ] ( main: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] 31.17: zp[1]:2 [ main::i#2 main::i#1 ] 
Uplift Scope [s] 
Uplift Scope [] 

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

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// used vars
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  // @begin
__bbegin:
  // [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
  jmp __b1
  // @1
__b1:
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
main_from___b1:
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
  jmp __bend
  // @end
__bend:
  // main
main: {
    // used vars
    .const col = 2
    .label COLS = $d800
    // [5] call s 
    // [12] phi from main to s [phi:main->s]
  s_from_main:
    jsr s
    // [6] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [6] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    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*) main::COLS + (byte) main::i#2) ← (const byte) main::col -- pbuc1_derefidx_vbuxx=vbuc2 
    lda #col
    sta COLS,x
    // [8] *((const byte*) SCREEN + (byte) main::i#2) ← ++++(byte)(number) 2/(number) 2 -- pbuc1_derefidx_vbuxx=vbuc2 
    lda #2/2+1+1
    sta SCREEN,x
    // [9] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [10] if((byte) main::i#1!=(byte) $65) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$65
    bne __b1_from___b1
    jmp __breturn
    // main::@return
  __breturn:
    // [11] return 
    rts
}
  // s
s: {
    jmp __breturn
    // s::@return
  __breturn:
    // [13] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Replacing label __b1_from___b1 with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Removing instruction __b1_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction s_from_main:
Removing instruction __b1_from_main:
Removing instruction __breturn:
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 __b1:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*) 1024
(byte) b
(void()) main()
(label) main::@1
(label) main::@return
(const byte*) main::COLS = (byte*) 55296
(const byte) main::col = (byte) 2
(byte) main::i
(byte) main::i#1 reg byte x 16.5
(byte) main::i#2 reg byte x 14.666666666666666
(byte()) s()
(label) s::@return
(byte) s::return

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


FINAL ASSEMBLER
Score: 243

  // File Comments
// used vars
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  // @begin
  // [1] phi from @begin to @1 [phi:@begin->@1]
  // @1
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
  // [3] phi from @1 to @end [phi:@1->@end]
  // @end
  // main
main: {
    // used vars
    .const col = 2
    .label COLS = $d800
    // s()
    // [5] call s 
    // [12] phi from main to s [phi:main->s]
    jsr s
    // [6] phi from main to main::@1 [phi:main->main::@1]
    // [6] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // [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:
    // COLS[i] = col
    // [7] *((const byte*) main::COLS + (byte) main::i#2) ← (const byte) main::col -- pbuc1_derefidx_vbuxx=vbuc2 
    lda #col
    sta COLS,x
    // SCREEN[i] = b
    // [8] *((const byte*) SCREEN + (byte) main::i#2) ← ++++(byte)(number) 2/(number) 2 -- pbuc1_derefidx_vbuxx=vbuc2 
    lda #2/2+1+1
    sta SCREEN,x
    // for(byte i : 0..100)
    // [9] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [10] if((byte) main::i#1!=(byte) $65) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$65
    bne __b1
    // main::@return
    // }
    // [11] return 
    rts
}
  // s
s: {
    // s::@return
    // [13] return 
    rts
}
  // File Data

