Eliminating unused variable with no statement memcpy::$0

CONTROL FLOW GRAPH SSA

void * memcpy(void *destination , void *source , unsigned int num)
memcpy: scope:[memcpy]  from main
  memcpy::num#1 = phi( main/memcpy::num#0 )
  memcpy::destination#1 = phi( main/memcpy::destination#0 )
  memcpy::source#1 = phi( main/memcpy::source#0 )
  memcpy::src#0 = ((char *)) memcpy::source#1
  memcpy::dst#0 = ((char *)) memcpy::destination#1
  memcpy::$2 = (char *)memcpy::source#1
  memcpy::src_end#0 = memcpy::$2 + memcpy::num#1
  to:memcpy::@1
memcpy::@1: scope:[memcpy]  from memcpy memcpy::@2
  memcpy::destination#3 = phi( memcpy/memcpy::destination#1, memcpy::@2/memcpy::destination#4 )
  memcpy::dst#3 = phi( memcpy/memcpy::dst#0, memcpy::@2/memcpy::dst#1 )
  memcpy::src_end#1 = phi( memcpy/memcpy::src_end#0, memcpy::@2/memcpy::src_end#2 )
  memcpy::src#2 = phi( memcpy/memcpy::src#0, memcpy::@2/memcpy::src#1 )
  memcpy::$1 = memcpy::src#2 != memcpy::src_end#1
  if(memcpy::$1) goto memcpy::@2
  to:memcpy::@3
memcpy::@2: scope:[memcpy]  from memcpy::@1
  memcpy::destination#4 = phi( memcpy::@1/memcpy::destination#3 )
  memcpy::src_end#2 = phi( memcpy::@1/memcpy::src_end#1 )
  memcpy::dst#2 = phi( memcpy::@1/memcpy::dst#3 )
  memcpy::src#3 = phi( memcpy::@1/memcpy::src#2 )
  *memcpy::dst#2 = *memcpy::src#3
  memcpy::dst#1 = ++ memcpy::dst#2
  memcpy::src#1 = ++ memcpy::src#3
  to:memcpy::@1
memcpy::@3: scope:[memcpy]  from memcpy::@1
  memcpy::destination#2 = phi( memcpy::@1/memcpy::destination#3 )
  memcpy::return#0 = memcpy::destination#2
  to:memcpy::@return
memcpy::@return: scope:[memcpy]  from memcpy::@3
  memcpy::return#3 = phi( memcpy::@3/memcpy::return#0 )
  memcpy::return#1 = memcpy::return#3
  return 
  to:@return

void main()
main: scope:[main]  from __start
  main::$0 = sizeof  STRING
  memcpy::destination#0 = (void *)SCREEN
  memcpy::source#0 = (void *)STRING
  memcpy::num#0 = main::$0
  call memcpy
  memcpy::return#2 = memcpy::return#1
  to:main::@1
main::@1: scope:[main]  from main
  to:main::@return
main::@return: scope:[main]  from main::@1
  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
__constant char * const SCREEN = (char *)$400
__constant char STRING[] = "hello world"
void __start()
void main()
unsigned int main::$0
void * memcpy(void *destination , void *source , unsigned int num)
bool memcpy::$1
char *memcpy::$2
void *memcpy::destination
void *memcpy::destination#0
void *memcpy::destination#1
void *memcpy::destination#2
void *memcpy::destination#3
void *memcpy::destination#4
char *memcpy::dst
char *memcpy::dst#0
char *memcpy::dst#1
char *memcpy::dst#2
char *memcpy::dst#3
unsigned int memcpy::num
unsigned int memcpy::num#0
unsigned int memcpy::num#1
void *memcpy::return
void *memcpy::return#0
void *memcpy::return#1
void *memcpy::return#2
void *memcpy::return#3
void *memcpy::source
void *memcpy::source#0
void *memcpy::source#1
char *memcpy::src
char *memcpy::src#0
char *memcpy::src#1
char *memcpy::src#2
char *memcpy::src#3
char *memcpy::src_end
char *memcpy::src_end#0
char *memcpy::src_end#1
char *memcpy::src_end#2

Inlining cast memcpy::src#0 = (char *)memcpy::source#1
Inlining cast memcpy::dst#0 = (char *)memcpy::destination#1
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (char *) 1024
Successful SSA optimization PassNCastSimplification
Alias memcpy::src#2 = memcpy::src#3 
Alias memcpy::dst#2 = memcpy::dst#3 
Alias memcpy::src_end#1 = memcpy::src_end#2 
Alias memcpy::destination#2 = memcpy::destination#4 memcpy::destination#3 memcpy::return#0 memcpy::return#3 memcpy::return#1 
Alias memcpy::num#0 = main::$0 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values memcpy::source#1 memcpy::source#0
Identical Phi Values memcpy::destination#1 memcpy::destination#0
Identical Phi Values memcpy::num#1 memcpy::num#0
Identical Phi Values memcpy::src_end#1 memcpy::src_end#0
Identical Phi Values memcpy::destination#2 memcpy::destination#1
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition memcpy::$1 [7] if(memcpy::src#2!=memcpy::src_end#0) goto memcpy::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant right-side identified [12] memcpy::num#0 = sizeof  STRING
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant memcpy::num#0 = sizeof STRING
Constant memcpy::destination#0 = (void *)SCREEN
Constant memcpy::source#0 = (void *)STRING
Successful SSA optimization Pass2ConstantIdentification
Constant memcpy::src#0 = (char *)memcpy::source#0
Constant memcpy::dst#0 = (char *)memcpy::destination#0
Constant memcpy::$2 = (char *)memcpy::source#0
Constant memcpy::return#2 = memcpy::destination#0
Successful SSA optimization Pass2ConstantIdentification
Eliminating unused constant memcpy::return#2
Successful SSA optimization PassNEliminateUnusedVars
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
Resolving string sizeof() sizeof STRING
Successful SSA optimization PassNSizeOfSimplification
Constant right-side identified [0] memcpy::src_end#0 = memcpy::$2 + memcpy::num#0
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant memcpy::src_end#0 = memcpy::$2+memcpy::num#0
Successful SSA optimization Pass2ConstantIdentification
Adding number conversion cast (unumber) $c in 
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast $c
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) $c
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining constant with var siblings memcpy::src#0
Inlining constant with var siblings memcpy::dst#0
Constant inlined memcpy::$2 = (char *)memcpy::source#0
Constant inlined memcpy::dst#0 = (char *)memcpy::destination#0
Constant inlined memcpy::src#0 = (char *)memcpy::source#0
Successful SSA optimization Pass2ConstantInlining
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@1
Adding NOP phi() at start of memcpy
Adding NOP phi() at start of memcpy::@3
CALL GRAPH
Calls in [main] to memcpy:1 

Created 2 initial phi equivalence classes
Coalesced [12] memcpy::src#4 = memcpy::src#1
Coalesced [13] memcpy::dst#4 = memcpy::dst#1
Coalesced down to 2 phi equivalence classes
Culled Empty Block label main::@1
Culled Empty Block label memcpy::@3
Adding NOP phi() at start of main
Adding NOP phi() at start of memcpy

FINAL CONTROL FLOW GRAPH

void main()
main: scope:[main]  from
  [0] phi()
  [1] call memcpy
  to:main::@return
main::@return: scope:[main]  from main
  [2] return 
  to:@return

void * memcpy(void *destination , void *source , unsigned int num)
memcpy: scope:[memcpy]  from main
  [3] phi()
  to:memcpy::@1
memcpy::@1: scope:[memcpy]  from memcpy memcpy::@2
  [4] memcpy::dst#2 = phi( memcpy/(char *)memcpy::destination#0, memcpy::@2/memcpy::dst#1 )
  [4] memcpy::src#2 = phi( memcpy/(char *)memcpy::source#0, memcpy::@2/memcpy::src#1 )
  [5] if(memcpy::src#2!=memcpy::src_end#0) goto memcpy::@2
  to:memcpy::@return
memcpy::@return: scope:[memcpy]  from memcpy::@1
  [6] return 
  to:@return
memcpy::@2: scope:[memcpy]  from memcpy::@1
  [7] *memcpy::dst#2 = *memcpy::src#2
  [8] memcpy::dst#1 = ++ memcpy::dst#2
  [9] memcpy::src#1 = ++ memcpy::src#2
  to:memcpy::@1


VARIABLE REGISTER WEIGHTS
void main()
void * memcpy(void *destination , void *source , unsigned int num)
void *memcpy::destination
char *memcpy::dst
char *memcpy::dst#1 // 101.0
char *memcpy::dst#2 // 101.0
unsigned int memcpy::num
void *memcpy::return
void *memcpy::source
char *memcpy::src
char *memcpy::src#1 // 202.0
char *memcpy::src#2 // 101.0
char *memcpy::src_end

Initial phi equivalence classes
[ memcpy::src#2 memcpy::src#1 ]
[ memcpy::dst#2 memcpy::dst#1 ]
Complete equivalence classes
[ memcpy::src#2 memcpy::src#1 ]
[ memcpy::dst#2 memcpy::dst#1 ]
Allocated zp[2]:2 [ memcpy::src#2 memcpy::src#1 ]
Allocated zp[2]:4 [ memcpy::dst#2 memcpy::dst#1 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [5] if(memcpy::src#2!=memcpy::src_end#0) goto memcpy::@2 [ memcpy::src#2 memcpy::dst#2 ] ( memcpy:1 [ memcpy::src#2 memcpy::dst#2 ] { }  ) always clobbers reg byte a 
Statement [7] *memcpy::dst#2 = *memcpy::src#2 [ memcpy::src#2 memcpy::dst#2 ] ( memcpy:1 [ memcpy::src#2 memcpy::dst#2 ] { }  ) always clobbers reg byte a reg byte y 
Potential registers zp[2]:2 [ memcpy::src#2 memcpy::src#1 ] : zp[2]:2 , 
Potential registers zp[2]:4 [ memcpy::dst#2 memcpy::dst#1 ] : zp[2]:4 , 

REGISTER UPLIFT SCOPES
Uplift Scope [memcpy] 303: zp[2]:2 [ memcpy::src#2 memcpy::src#1 ] 202: zp[2]:4 [ memcpy::dst#2 memcpy::dst#1 ] 
Uplift Scope [main] 
Uplift Scope [] 

Uplifting [memcpy] best 866 combination zp[2]:2 [ memcpy::src#2 memcpy::src#1 ] zp[2]:4 [ memcpy::dst#2 memcpy::dst#1 ] 
Uplifting [main] best 866 combination 
Uplifting [] best 866 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Complex procedure declaration and definition.
  // Upstart
  // Commodore 64 PRG executable file
.file [name="procedure-declare-10.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 SIZEOF_CHAR = 1
  .label SCREEN = $400
.segment Code
  // main
main: {
    // [1] call memcpy
    // [3] phi from main to memcpy [phi:main->memcpy]
  memcpy_from_main:
    jsr memcpy
    jmp __breturn
    // main::@return
  __breturn:
    // [2] return 
    rts
}
  // memcpy
// Copy block of memory (forwards)
// Copies the values of num bytes from the location pointed to by source directly to the memory block pointed to by destination.
// void * memcpy(void *destination, void *source, unsigned int num)
memcpy: {
    .const num = $c*SIZEOF_CHAR
    .label destination = SCREEN
    .label source = STRING
    .label src_end = source+num
    .label dst = 4
    .label src = 2
    // [4] phi from memcpy to memcpy::@1 [phi:memcpy->memcpy::@1]
  __b1_from_memcpy:
    // [4] phi memcpy::dst#2 = (char *)memcpy::destination#0 [phi:memcpy->memcpy::@1#0] -- pbuz1=pbuc1 
    lda #<destination
    sta.z dst
    lda #>destination
    sta.z dst+1
    // [4] phi memcpy::src#2 = (char *)memcpy::source#0 [phi:memcpy->memcpy::@1#1] -- pbuz1=pbuc1 
    lda #<source
    sta.z src
    lda #>source
    sta.z src+1
    jmp __b1
    // memcpy::@1
  __b1:
    // [5] if(memcpy::src#2!=memcpy::src_end#0) goto memcpy::@2 -- pbuz1_neq_pbuc1_then_la1 
    lda.z src+1
    cmp #>src_end
    bne __b2
    lda.z src
    cmp #<src_end
    bne __b2
    jmp __breturn
    // memcpy::@return
  __breturn:
    // [6] return 
    rts
    // memcpy::@2
  __b2:
    // [7] *memcpy::dst#2 = *memcpy::src#2 -- _deref_pbuz1=_deref_pbuz2 
    ldy #0
    lda (src),y
    ldy #0
    sta (dst),y
    // [8] memcpy::dst#1 = ++ memcpy::dst#2 -- pbuz1=_inc_pbuz1 
    inc.z dst
    bne !+
    inc.z dst+1
  !:
    // [9] memcpy::src#1 = ++ memcpy::src#2 -- pbuz1=_inc_pbuz1 
    inc.z src
    bne !+
    inc.z src+1
  !:
    // [4] phi from memcpy::@2 to memcpy::@1 [phi:memcpy::@2->memcpy::@1]
  __b1_from___b2:
    // [4] phi memcpy::dst#2 = memcpy::dst#1 [phi:memcpy::@2->memcpy::@1#0] -- register_copy 
    // [4] phi memcpy::src#2 = memcpy::src#1 [phi:memcpy::@2->memcpy::@1#1] -- register_copy 
    jmp __b1
}
  // File Data
.segment Data
  STRING: .text "hello world"
  .byte 0

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __breturn
Removing instruction jmp __b1
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction ldy #0
Succesful ASM optimization Pass5UnnecesaryLoadElimination
Removing instruction memcpy_from_main:
Removing instruction __breturn:
Removing instruction __b1_from_memcpy:
Removing instruction __breturn:
Removing instruction __b1_from___b2:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
__constant char * const SCREEN = (char *) 1024
__constant char SIZEOF_CHAR = 1
__constant char STRING[] = "hello world"
void main()
void * memcpy(void *destination , void *source , unsigned int num)
void *memcpy::destination
__constant void *memcpy::destination#0 = (void *)SCREEN // destination
char *memcpy::dst
char *memcpy::dst#1 // dst zp[2]:4 101.0
char *memcpy::dst#2 // dst zp[2]:4 101.0
unsigned int memcpy::num
__constant unsigned int memcpy::num#0 = $c*SIZEOF_CHAR // num
void *memcpy::return
void *memcpy::source
__constant void *memcpy::source#0 = (void *)STRING // source
char *memcpy::src
char *memcpy::src#1 // src zp[2]:2 202.0
char *memcpy::src#2 // src zp[2]:2 101.0
char *memcpy::src_end
__constant char *memcpy::src_end#0 = (char *)memcpy::source#0+memcpy::num#0 // src_end

zp[2]:2 [ memcpy::src#2 memcpy::src#1 ]
zp[2]:4 [ memcpy::dst#2 memcpy::dst#1 ]


FINAL ASSEMBLER
Score: 783

  // File Comments
// Complex procedure declaration and definition.
  // Upstart
  // Commodore 64 PRG executable file
.file [name="procedure-declare-10.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 SIZEOF_CHAR = 1
  .label SCREEN = $400
.segment Code
  // main
main: {
    // memcpy(SCREEN, STRING, sizeof(STRING))
    // [1] call memcpy
    // [3] phi from main to memcpy [phi:main->memcpy]
    jsr memcpy
    // main::@return
    // }
    // [2] return 
    rts
}
  // memcpy
// Copy block of memory (forwards)
// Copies the values of num bytes from the location pointed to by source directly to the memory block pointed to by destination.
// void * memcpy(void *destination, void *source, unsigned int num)
memcpy: {
    .const num = $c*SIZEOF_CHAR
    .label destination = SCREEN
    .label source = STRING
    .label src_end = source+num
    .label dst = 4
    .label src = 2
    // [4] phi from memcpy to memcpy::@1 [phi:memcpy->memcpy::@1]
    // [4] phi memcpy::dst#2 = (char *)memcpy::destination#0 [phi:memcpy->memcpy::@1#0] -- pbuz1=pbuc1 
    lda #<destination
    sta.z dst
    lda #>destination
    sta.z dst+1
    // [4] phi memcpy::src#2 = (char *)memcpy::source#0 [phi:memcpy->memcpy::@1#1] -- pbuz1=pbuc1 
    lda #<source
    sta.z src
    lda #>source
    sta.z src+1
    // memcpy::@1
  __b1:
    // while(src!=src_end)
    // [5] if(memcpy::src#2!=memcpy::src_end#0) goto memcpy::@2 -- pbuz1_neq_pbuc1_then_la1 
    lda.z src+1
    cmp #>src_end
    bne __b2
    lda.z src
    cmp #<src_end
    bne __b2
    // memcpy::@return
    // }
    // [6] return 
    rts
    // memcpy::@2
  __b2:
    // *dst++ = *src++
    // [7] *memcpy::dst#2 = *memcpy::src#2 -- _deref_pbuz1=_deref_pbuz2 
    ldy #0
    lda (src),y
    sta (dst),y
    // *dst++ = *src++;
    // [8] memcpy::dst#1 = ++ memcpy::dst#2 -- pbuz1=_inc_pbuz1 
    inc.z dst
    bne !+
    inc.z dst+1
  !:
    // [9] memcpy::src#1 = ++ memcpy::src#2 -- pbuz1=_inc_pbuz1 
    inc.z src
    bne !+
    inc.z src+1
  !:
    // [4] phi from memcpy::@2 to memcpy::@1 [phi:memcpy::@2->memcpy::@1]
    // [4] phi memcpy::dst#2 = memcpy::dst#1 [phi:memcpy::@2->memcpy::@1#0] -- register_copy 
    // [4] phi memcpy::src#2 = memcpy::src#1 [phi:memcpy::@2->memcpy::@1#1] -- register_copy 
    jmp __b1
}
  // File Data
.segment Data
  STRING: .text "hello world"
  .byte 0

