Eliminating unused variable with no statement main::$0

CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start
  main::j#0 = 0
  to:main::@1
main::@1: scope:[main]  from main main::@5
  main::j#6 = phi( main/main::j#0, main::@5/main::j#1 )
  main::i#0 = 0
  to:main::@2
main::@2: scope:[main]  from main::@1 main::@4
  main::j#4 = phi( main::@1/main::j#6, main::@4/main::j#5 )
  main::i#4 = phi( main::@1/main::i#0, main::@4/main::i#1 )
  main::k#0 = 0
  to:main::@3
main::@3: scope:[main]  from main::@2 main::@3
  main::k#2 = phi( main::@2/main::k#0, main::@3/main::k#1 )
  main::j#2 = phi( main::@2/main::j#4, main::@3/main::j#2 )
  main::i#2 = phi( main::@2/main::i#4, main::@3/main::i#2 )
  main::zpptr2#0 = main::zpptr + main::i#2
  main::w#0 = (unsigned int)main::j#2
  main::$1 = main::zpptr2#0 + main::w#0
  main::zpptr2#1 = main::$1
  *main::zpptr2#1 = main::k#2
  main::k#1 = main::k#2 + rangenext(0,$a)
  main::$2 = main::k#1 != rangelast(0,$a)
  if(main::$2) goto main::@3
  to:main::@4
main::@4: scope:[main]  from main::@3
  main::j#5 = phi( main::@3/main::j#2 )
  main::i#3 = phi( main::@3/main::i#2 )
  main::i#1 = main::i#3 + rangenext(0,$a)
  main::$3 = main::i#1 != rangelast(0,$a)
  if(main::$3) goto main::@2
  to:main::@5
main::@5: scope:[main]  from main::@4
  main::j#3 = phi( main::@4/main::j#5 )
  main::j#1 = main::j#3 + rangenext(0,$a)
  main::$4 = main::j#1 != rangelast(0,$a)
  if(main::$4) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@5
  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()
char *main::$1
bool main::$2
bool main::$3
bool main::$4
char main::i
char main::i#0
char main::i#1
char main::i#2
char main::i#3
char main::i#4
char main::j
char main::j#0
char main::j#1
char main::j#2
char main::j#3
char main::j#4
char main::j#5
char main::j#6
char main::k
char main::k#0
char main::k#1
char main::k#2
unsigned int main::w
unsigned int main::w#0
__constant char *main::zpptr = (char *)$1000
char *main::zpptr2
char *main::zpptr2#0
char *main::zpptr2#1

Simplifying constant pointer cast (char *) 4096
Successful SSA optimization PassNCastSimplification
Alias main::zpptr2#1 = main::$1 
Alias main::i#2 = main::i#3 
Alias main::j#2 = main::j#5 main::j#3 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values main::i#2 main::i#4
Identical Phi Values main::j#2 main::j#4
Successful SSA optimization Pass2IdenticalPhiElimination
Identical Phi Values main::j#4 main::j#6
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition main::$2 [12] if(main::k#1!=rangelast(0,$a)) goto main::@3
Simple Condition main::$3 [15] if(main::i#1!=rangelast(0,$a)) goto main::@2
Simple Condition main::$4 [18] if(main::j#1!=rangelast(0,$a)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant main::j#0 = 0
Constant main::i#0 = 0
Constant main::k#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [10] main::k#1 = ++ main::k#2 to ++
Resolved ranged comparison value [12] if(main::k#1!=rangelast(0,$a)) goto main::@3 to $b
Resolved ranged next value [13] main::i#1 = ++ main::i#4 to ++
Resolved ranged comparison value [15] if(main::i#1!=rangelast(0,$a)) goto main::@2 to $b
Resolved ranged next value [16] main::j#1 = ++ main::j#6 to ++
Resolved ranged comparison value [18] if(main::j#1!=rangelast(0,$a)) goto main::@1 to $b
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
Adding number conversion cast (unumber) $b in [8] if(main::k#1!=$b) goto main::@3
Adding number conversion cast (unumber) $b in [10] if(main::i#1!=$b) goto main::@2
Adding number conversion cast (unumber) $b in [12] if(main::j#1!=$b) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast $b
Simplifying constant integer cast $b
Simplifying constant integer cast $b
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) $b
Finalized unsigned number type (char) $b
Finalized unsigned number type (char) $b
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining constant with var siblings main::j#0
Inlining constant with var siblings main::i#0
Inlining constant with var siblings main::k#0
Constant inlined main::i#0 = 0
Constant inlined main::k#0 = 0
Constant inlined main::j#0 = 0
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@6(between main::@5 and main::@1)
Added new block during phi lifting main::@7(between main::@4 and main::@2)
Added new block during phi lifting main::@8(between main::@3 and main::@3)
Adding NOP phi() at start of main
CALL GRAPH

Created 3 initial phi equivalence classes
Coalesced [15] main::j#7 = main::j#1
Coalesced [16] main::i#5 = main::i#1
Coalesced [17] main::k#3 = main::k#1
Coalesced down to 3 phi equivalence classes
Culled Empty Block label main::@6
Culled Empty Block label main::@7
Culled Empty Block label main::@8
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::@5
  [1] main::j#6 = phi( main/0, main::@5/main::j#1 )
  to:main::@2
main::@2: scope:[main]  from main::@1 main::@4
  [2] main::i#4 = phi( main::@1/0, main::@4/main::i#1 )
  to:main::@3
main::@3: scope:[main]  from main::@2 main::@3
  [3] main::k#2 = phi( main::@2/0, main::@3/main::k#1 )
  [4] main::zpptr2#0 = main::zpptr + main::i#4
  [5] main::w#0 = (unsigned int)main::j#6
  [6] main::zpptr2#1 = main::zpptr2#0 + main::w#0
  [7] *main::zpptr2#1 = main::k#2
  [8] main::k#1 = ++ main::k#2
  [9] if(main::k#1!=$b) goto main::@3
  to:main::@4
main::@4: scope:[main]  from main::@3
  [10] main::i#1 = ++ main::i#4
  [11] if(main::i#1!=$b) goto main::@2
  to:main::@5
main::@5: scope:[main]  from main::@4
  [12] main::j#1 = ++ main::j#6
  [13] if(main::j#1!=$b) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@5
  [14] return 
  to:@return


VARIABLE REGISTER WEIGHTS
void main()
char main::i
char main::i#1 // 151.5
char main::i#4 // 150.375
char main::j
char main::j#1 // 16.5
char main::j#6 // 2.0
char main::k
char main::k#1 // 1501.5
char main::k#2 // 600.5999999999999
unsigned int main::w
unsigned int main::w#0 // 2002.0
char *main::zpptr2
char *main::zpptr2#0 // 1001.0
char *main::zpptr2#1 // 2002.0

Initial phi equivalence classes
[ main::j#6 main::j#1 ]
[ main::i#4 main::i#1 ]
[ main::k#2 main::k#1 ]
Added variable main::zpptr2#0 to live range equivalence class [ main::zpptr2#0 ]
Added variable main::w#0 to live range equivalence class [ main::w#0 ]
Added variable main::zpptr2#1 to live range equivalence class [ main::zpptr2#1 ]
Complete equivalence classes
[ main::j#6 main::j#1 ]
[ main::i#4 main::i#1 ]
[ main::k#2 main::k#1 ]
[ main::zpptr2#0 ]
[ main::w#0 ]
[ main::zpptr2#1 ]
Allocated zp[1]:2 [ main::k#2 main::k#1 ]
Allocated zp[2]:3 [ main::w#0 ]
Allocated zp[2]:5 [ main::zpptr2#1 ]
Allocated zp[2]:7 [ main::zpptr2#0 ]
Allocated zp[1]:9 [ main::i#4 main::i#1 ]
Allocated zp[1]:10 [ main::j#6 main::j#1 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] main::zpptr2#0 = main::zpptr + main::i#4 [ main::j#6 main::i#4 main::k#2 main::zpptr2#0 ] (  [ main::j#6 main::i#4 main::k#2 main::zpptr2#0 ] { }  ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:10 [ main::j#6 main::j#1 ]
Removing always clobbered register reg byte a as potential for zp[1]:9 [ main::i#4 main::i#1 ]
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::k#2 main::k#1 ]
Statement [5] main::w#0 = (unsigned int)main::j#6 [ main::j#6 main::i#4 main::k#2 main::zpptr2#0 main::w#0 ] (  [ main::j#6 main::i#4 main::k#2 main::zpptr2#0 main::w#0 ] { }  ) always clobbers reg byte a 
Statement [6] main::zpptr2#1 = main::zpptr2#0 + main::w#0 [ main::j#6 main::i#4 main::k#2 main::zpptr2#1 ] (  [ main::j#6 main::i#4 main::k#2 main::zpptr2#1 ] { }  ) always clobbers reg byte a 
Statement [7] *main::zpptr2#1 = main::k#2 [ main::j#6 main::i#4 main::k#2 ] (  [ main::j#6 main::i#4 main::k#2 ] { }  ) always clobbers reg byte a reg byte y 
Removing always clobbered register reg byte y as potential for zp[1]:10 [ main::j#6 main::j#1 ]
Removing always clobbered register reg byte y as potential for zp[1]:9 [ main::i#4 main::i#1 ]
Removing always clobbered register reg byte y as potential for zp[1]:2 [ main::k#2 main::k#1 ]
Statement [4] main::zpptr2#0 = main::zpptr + main::i#4 [ main::j#6 main::i#4 main::k#2 main::zpptr2#0 ] (  [ main::j#6 main::i#4 main::k#2 main::zpptr2#0 ] { }  ) always clobbers reg byte a 
Statement [5] main::w#0 = (unsigned int)main::j#6 [ main::j#6 main::i#4 main::k#2 main::zpptr2#0 main::w#0 ] (  [ main::j#6 main::i#4 main::k#2 main::zpptr2#0 main::w#0 ] { }  ) always clobbers reg byte a 
Statement [6] main::zpptr2#1 = main::zpptr2#0 + main::w#0 [ main::j#6 main::i#4 main::k#2 main::zpptr2#1 ] (  [ main::j#6 main::i#4 main::k#2 main::zpptr2#1 ] { }  ) always clobbers reg byte a 
Statement [7] *main::zpptr2#1 = main::k#2 [ main::j#6 main::i#4 main::k#2 ] (  [ main::j#6 main::i#4 main::k#2 ] { }  ) always clobbers reg byte a reg byte y 
Potential registers zp[1]:10 [ main::j#6 main::j#1 ] : zp[1]:10 , reg byte x , 
Potential registers zp[1]:9 [ main::i#4 main::i#1 ] : zp[1]:9 , reg byte x , 
Potential registers zp[1]:2 [ main::k#2 main::k#1 ] : zp[1]:2 , reg byte x , 
Potential registers zp[2]:7 [ main::zpptr2#0 ] : zp[2]:7 , 
Potential registers zp[2]:3 [ main::w#0 ] : zp[2]:3 , 
Potential registers zp[2]:5 [ main::zpptr2#1 ] : zp[2]:5 , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 2,102.1: zp[1]:2 [ main::k#2 main::k#1 ] 2,002: zp[2]:3 [ main::w#0 ] 2,002: zp[2]:5 [ main::zpptr2#1 ] 1,001: zp[2]:7 [ main::zpptr2#0 ] 301.88: zp[1]:9 [ main::i#4 main::i#1 ] 18.5: zp[1]:10 [ main::j#6 main::j#1 ] 
Uplift Scope [] 

Uplifting [main] best 78421 combination reg byte x [ main::k#2 main::k#1 ] zp[2]:3 [ main::w#0 ] zp[2]:5 [ main::zpptr2#1 ] zp[2]:7 [ main::zpptr2#0 ] zp[1]:9 [ main::i#4 main::i#1 ] zp[1]:10 [ main::j#6 main::j#1 ] 
Uplifting [] best 78421 combination 
Attempting to uplift remaining variables inzp[1]:9 [ main::i#4 main::i#1 ]
Uplifting [main] best 78421 combination zp[1]:9 [ main::i#4 main::i#1 ] 
Attempting to uplift remaining variables inzp[1]:10 [ main::j#6 main::j#1 ]
Uplifting [main] best 78421 combination zp[1]:10 [ main::j#6 main::j#1 ] 
Coalescing zero page register [ zp[2]:7 [ main::zpptr2#0 ] ] with [ zp[2]:5 [ main::zpptr2#1 ] ] - score: 1
Allocated (was zp[2]:7) zp[2]:2 [ main::zpptr2#0 main::zpptr2#1 ]
Allocated (was zp[2]:3) zp[2]:4 [ main::w#0 ]
Allocated (was zp[1]:9) zp[1]:6 [ main::i#4 main::i#1 ]
Allocated (was zp[1]:10) zp[1]:7 [ main::j#6 main::j#1 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
  // Upstart
  // Commodore 64 PRG executable file
.file [name="zpptr.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 zpptr = $1000
    .label zpptr2 = 2
    .label w = 4
    .label i = 6
    .label j = 7
    // [1] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [1] phi main::j#6 = 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z j
    jmp __b1
    // [1] phi from main::@5 to main::@1 [phi:main::@5->main::@1]
  __b1_from___b5:
    // [1] phi main::j#6 = main::j#1 [phi:main::@5->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [2] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  __b2_from___b1:
    // [2] phi main::i#4 = 0 [phi:main::@1->main::@2#0] -- vbuz1=vbuc1 
    lda #0
    sta.z i
    jmp __b2
    // [2] phi from main::@4 to main::@2 [phi:main::@4->main::@2]
  __b2_from___b4:
    // [2] phi main::i#4 = main::i#1 [phi:main::@4->main::@2#0] -- register_copy 
    jmp __b2
    // main::@2
  __b2:
    // [3] phi from main::@2 to main::@3 [phi:main::@2->main::@3]
  __b3_from___b2:
    // [3] phi main::k#2 = 0 [phi:main::@2->main::@3#0] -- vbuxx=vbuc1 
    ldx #0
    jmp __b3
    // [3] phi from main::@3 to main::@3 [phi:main::@3->main::@3]
  __b3_from___b3:
    // [3] phi main::k#2 = main::k#1 [phi:main::@3->main::@3#0] -- register_copy 
    jmp __b3
    // main::@3
  __b3:
    // [4] main::zpptr2#0 = main::zpptr + main::i#4 -- pbuz1=pbuc1_plus_vbuz2 
    lda.z i
    clc
    adc #<zpptr
    sta.z zpptr2
    lda #>zpptr
    adc #0
    sta.z zpptr2+1
    // [5] main::w#0 = (unsigned int)main::j#6 -- vwuz1=_word_vbuz2 
    lda.z j
    sta.z w
    lda #0
    sta.z w+1
    // [6] main::zpptr2#1 = main::zpptr2#0 + main::w#0 -- pbuz1=pbuz1_plus_vwuz2 
    clc
    lda.z zpptr2
    adc.z w
    sta.z zpptr2
    lda.z zpptr2+1
    adc.z w+1
    sta.z zpptr2+1
    // [7] *main::zpptr2#1 = main::k#2 -- _deref_pbuz1=vbuxx 
    txa
    ldy #0
    sta (zpptr2),y
    // [8] main::k#1 = ++ main::k#2 -- vbuxx=_inc_vbuxx 
    inx
    // [9] if(main::k#1!=$b) goto main::@3 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$b
    bne __b3_from___b3
    jmp __b4
    // main::@4
  __b4:
    // [10] main::i#1 = ++ main::i#4 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [11] if(main::i#1!=$b) goto main::@2 -- vbuz1_neq_vbuc1_then_la1 
    lda #$b
    cmp.z i
    bne __b2_from___b4
    jmp __b5
    // main::@5
  __b5:
    // [12] main::j#1 = ++ main::j#6 -- vbuz1=_inc_vbuz1 
    inc.z j
    // [13] if(main::j#1!=$b) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #$b
    cmp.z j
    bne __b1_from___b5
    jmp __breturn
    // main::@return
  __breturn:
    // [14] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __b2
Removing instruction jmp __b3
Removing instruction jmp __b4
Removing instruction jmp __b5
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __b3_from___b3 with __b3
Replacing label __b2_from___b4 with __b2
Replacing label __b1_from___b5 with __b1
Removing instruction __b1_from___b5:
Removing instruction __b2_from___b1:
Removing instruction __b2_from___b4:
Removing instruction __b3_from___b2:
Removing instruction __b3_from___b3:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __b1_from_main:
Removing instruction __b4:
Removing instruction __b5:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Removing instruction jmp __b1
Removing instruction jmp __b2
Removing instruction jmp __b3
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction lda #$b
Succesful ASM optimization Pass5UnnecesaryLoadElimination

FINAL SYMBOL TABLE
void main()
char main::i
char main::i#1 // i zp[1]:6 151.5
char main::i#4 // i zp[1]:6 150.375
char main::j
char main::j#1 // j zp[1]:7 16.5
char main::j#6 // j zp[1]:7 2.0
char main::k
char main::k#1 // reg byte x 1501.5
char main::k#2 // reg byte x 600.5999999999999
unsigned int main::w
unsigned int main::w#0 // w zp[2]:4 2002.0
__constant char *main::zpptr = (char *) 4096
char *main::zpptr2
char *main::zpptr2#0 // zpptr2 zp[2]:2 1001.0
char *main::zpptr2#1 // zpptr2 zp[2]:2 2002.0

zp[1]:7 [ main::j#6 main::j#1 ]
zp[1]:6 [ main::i#4 main::i#1 ]
reg byte x [ main::k#2 main::k#1 ]
zp[2]:2 [ main::zpptr2#0 main::zpptr2#1 ]
zp[2]:4 [ main::w#0 ]


FINAL ASSEMBLER
Score: 68411

  // File Comments
  // Upstart
  // Commodore 64 PRG executable file
.file [name="zpptr.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 zpptr = $1000
    .label zpptr2 = 2
    .label w = 4
    .label i = 6
    .label j = 7
    // [1] phi from main to main::@1 [phi:main->main::@1]
    // [1] phi main::j#6 = 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z j
    // [1] phi from main::@5 to main::@1 [phi:main::@5->main::@1]
    // [1] phi main::j#6 = main::j#1 [phi:main::@5->main::@1#0] -- register_copy 
    // main::@1
  __b1:
    // [2] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
    // [2] phi main::i#4 = 0 [phi:main::@1->main::@2#0] -- vbuz1=vbuc1 
    lda #0
    sta.z i
    // [2] phi from main::@4 to main::@2 [phi:main::@4->main::@2]
    // [2] phi main::i#4 = main::i#1 [phi:main::@4->main::@2#0] -- register_copy 
    // main::@2
  __b2:
    // [3] phi from main::@2 to main::@3 [phi:main::@2->main::@3]
    // [3] phi main::k#2 = 0 [phi:main::@2->main::@3#0] -- vbuxx=vbuc1 
    ldx #0
    // [3] phi from main::@3 to main::@3 [phi:main::@3->main::@3]
    // [3] phi main::k#2 = main::k#1 [phi:main::@3->main::@3#0] -- register_copy 
    // main::@3
  __b3:
    // byte* zpptr2 = zpptr+i
    // [4] main::zpptr2#0 = main::zpptr + main::i#4 -- pbuz1=pbuc1_plus_vbuz2 
    lda.z i
    clc
    adc #<zpptr
    sta.z zpptr2
    lda #>zpptr
    adc #0
    sta.z zpptr2+1
    // word w = (word)j
    // [5] main::w#0 = (unsigned int)main::j#6 -- vwuz1=_word_vbuz2 
    lda.z j
    sta.z w
    lda #0
    sta.z w+1
    // zpptr2 = zpptr2 + w
    // [6] main::zpptr2#1 = main::zpptr2#0 + main::w#0 -- pbuz1=pbuz1_plus_vwuz2 
    clc
    lda.z zpptr2
    adc.z w
    sta.z zpptr2
    lda.z zpptr2+1
    adc.z w+1
    sta.z zpptr2+1
    // *zpptr2 = k
    // [7] *main::zpptr2#1 = main::k#2 -- _deref_pbuz1=vbuxx 
    txa
    ldy #0
    sta (zpptr2),y
    // for(byte k : 0..10)
    // [8] main::k#1 = ++ main::k#2 -- vbuxx=_inc_vbuxx 
    inx
    // [9] if(main::k#1!=$b) goto main::@3 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$b
    bne __b3
    // main::@4
    // for(byte i : 0..10)
    // [10] main::i#1 = ++ main::i#4 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [11] if(main::i#1!=$b) goto main::@2 -- vbuz1_neq_vbuc1_then_la1 
    lda #$b
    cmp.z i
    bne __b2
    // main::@5
    // for(byte j : 0..10)
    // [12] main::j#1 = ++ main::j#6 -- vbuz1=_inc_vbuz1 
    inc.z j
    // [13] if(main::j#1!=$b) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    cmp.z j
    bne __b1
    // main::@return
    // }
    // [14] return 
    rts
}
  // File Data

