Inlined call call __init
Eliminating unused variable with no statement main::$1
Eliminating unused variable with no statement main::$3

CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start::@1
  b#15 = phi( __start::@1/b#16 )
  call s
  s::return#0 = s::return#2
  to:main::@2
main::@2: scope:[main]  from main
  b#8 = phi( main/b#4 )
  b#0 = b#8
  b#1 = ++ b#0
  main::i#0 = 0
  to:main::@1
main::@1: scope:[main]  from main::@1 main::@2
  b#9 = phi( main::@1/b#9, main::@2/b#1 )
  main::i#2 = phi( main::@1/main::i#1, main::@2/main::i#0 )
  main::COLS[main::i#2] = main::col
  SCREEN[main::i#2] = b#9
  main::i#1 = main::i#2 + rangenext(0,$64)
  main::$4 = main::i#1 != rangelast(0,$64)
  if(main::$4) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  b#10 = phi( main::@1/b#9 )
  b#2 = b#10
  return 
  to:@return

char s()
s: scope:[s]  from main
  b#11 = phi( main/b#15 )
  b#3 = ++ b#11
  s::return#1 = 2
  to:s::@return
s::@return: scope:[s]  from s
  b#12 = phi( s/b#3 )
  s::return#3 = phi( s/s::return#1 )
  s::return#2 = s::return#3
  b#4 = b#12
  return 
  to:@return

void __start()
__start: scope:[__start]  from
  to:__start::__init1
__start::__init1: scope:[__start]  from __start
  b#5 = (char)2/2
  to:__start::@1
__start::@1: scope:[__start]  from __start::__init1
  b#16 = phi( __start::__init1/b#5 )
  call main
  to:__start::@2
__start::@2: scope:[__start]  from __start::@1
  b#13 = phi( __start::@1/b#2 )
  b#6 = b#13
  to:__start::@return
__start::@return: scope:[__start]  from __start::@2
  b#14 = phi( __start::@2/b#6 )
  b#7 = b#14
  return 
  to:@return

SYMBOL TABLE SSA
__constant char * const SCREEN = (char *)$400
void __start()
char b
char b#0
char b#1
char b#10
char b#11
char b#12
char b#13
char b#14
char b#15
char b#16
char b#2
char b#3
char b#4
char b#5
char b#6
char b#7
char b#8
char b#9
void main()
bool main::$4
__constant char *main::COLS = (char *)$d800
__constant char main::col = 2
char main::i
char main::i#0
char main::i#1
char main::i#2
char s()
char s::return
char s::return#0
char s::return#1
char s::return#2
char s::return#3

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

Created 1 initial phi equivalence classes
Coalesced [8] main::i#3 = main::i#1
Coalesced down to 1 phi equivalence classes
Culled Empty Block label main::@2
Culled Empty Block label main::@3
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 main::@1
  [1] main::i#2 = phi( main::@1/main::i#1, main/0 )
  [2] main::COLS[main::i#2] = main::col
  [3] SCREEN[main::i#2] = ++++2/2
  [4] main::i#1 = ++ main::i#2
  [5] if(main::i#1!=$65) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  [6] return 
  to:@return


VARIABLE REGISTER WEIGHTS
char b
void main()
char main::i
char main::i#1 // 16.5
char main::i#2 // 14.666666666666666

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 [2] main::COLS[main::i#2] = main::col [ 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 [3] SCREEN[main::i#2] = ++++2/2 [ main::i#2 ] (  [ main::i#2 ] { }  ) always clobbers reg byte a 
Statement [2] main::COLS[main::i#2] = main::col [ main::i#2 ] (  [ main::i#2 ] { }  ) always clobbers reg byte a 
Statement [3] SCREEN[main::i#2] = ++++2/2 [ 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] 31.17: zp[1]:2 [ main::i#2 main::i#1 ] 
Uplift Scope [] 

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

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// used vars
  // Upstart
  // Commodore 64 PRG executable file
.file [name="unused-vars.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: {
    // used vars
    .const col = 2
    .label COLS = $d800
    // [1] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [1] phi main::i#2 = 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    jmp __b1
    // [1] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  __b1_from___b1:
    // [1] phi main::i#2 = main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [2] main::COLS[main::i#2] = main::col -- pbuc1_derefidx_vbuxx=vbuc2 
    lda #col
    sta COLS,x
    // [3] SCREEN[main::i#2] = ++++2/2 -- pbuc1_derefidx_vbuxx=vbuc2 
    lda #2/2+1+1
    sta SCREEN,x
    // [4] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [5] if(main::i#1!=$65) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$65
    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
__constant char * const SCREEN = (char *) 1024
char b
void main()
__constant char *main::COLS = (char *) 55296
__constant char main::col = 2
char main::i
char main::i#1 // reg byte x 16.5
char main::i#2 // reg byte x 14.666666666666666

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


FINAL ASSEMBLER
Score: 231

  // File Comments
// used vars
  // Upstart
  // Commodore 64 PRG executable file
.file [name="unused-vars.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: {
    // used vars
    .const col = 2
    .label COLS = $d800
    // [1] phi from main to main::@1 [phi:main->main::@1]
    // [1] phi main::i#2 = 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // [1] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
    // [1] phi main::i#2 = main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    // main::@1
  __b1:
    // COLS[i] = col
    // [2] main::COLS[main::i#2] = main::col -- pbuc1_derefidx_vbuxx=vbuc2 
    lda #col
    sta COLS,x
    // SCREEN[i] = b
    // [3] SCREEN[main::i#2] = ++++2/2 -- pbuc1_derefidx_vbuxx=vbuc2 
    lda #2/2+1+1
    sta SCREEN,x
    // for(byte i : 0..100)
    // [4] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [5] if(main::i#1!=$65) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$65
    bne __b1
    // main::@return
    // }
    // [6] return 
    rts
}
  // File Data

