Inlined call call __init
Eliminating unused variable with no statement memset::$2

CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start::@1
  memset::str#0 = (void *)SCREEN
  memset::c#0 = 'c'
  memset::num#0 = $3e8
  call memset
  memset::return#0 = memset::return#2
  to:main::@1
main::@1: scope:[main]  from main
  to:main::@return
main::@return: scope:[main]  from main::@1
  return 
  to:@return

void * memset(void *str , char c , unsigned int num)
memset: scope:[memset]  from main
  memset::c#4 = phi( main/memset::c#0 )
  memset::str#3 = phi( main/memset::str#0 )
  memset::num#1 = phi( main/memset::num#0 )
  memset::$0 = memset::num#1 > 0
  memset::$1 = ! memset::$0
  if(memset::$1) goto memset::@1
  to:memset::@2
memset::@1: scope:[memset]  from memset memset::@3
  memset::str#1 = phi( memset/memset::str#3, memset::@3/memset::str#4 )
  memset::return#1 = memset::str#1
  to:memset::@return
memset::@2: scope:[memset]  from memset
  memset::c#3 = phi( memset/memset::c#4 )
  memset::num#2 = phi( memset/memset::num#1 )
  memset::str#2 = phi( memset/memset::str#3 )
  memset::$4 = (char *)memset::str#2
  memset::end#0 = memset::$4 + memset::num#2
  memset::dst#0 = ((char *)) memset::str#2
  to:memset::@3
memset::@3: scope:[memset]  from memset::@2 memset::@4
  memset::c#2 = phi( memset::@2/memset::c#3, memset::@4/memset::c#1 )
  memset::str#4 = phi( memset::@2/memset::str#2, memset::@4/memset::str#5 )
  memset::end#1 = phi( memset::@2/memset::end#0, memset::@4/memset::end#2 )
  memset::dst#2 = phi( memset::@2/memset::dst#0, memset::@4/memset::dst#1 )
  memset::$3 = memset::dst#2 != memset::end#1
  if(memset::$3) goto memset::@4
  to:memset::@1
memset::@4: scope:[memset]  from memset::@3
  memset::str#5 = phi( memset::@3/memset::str#4 )
  memset::end#2 = phi( memset::@3/memset::end#1 )
  memset::dst#3 = phi( memset::@3/memset::dst#2 )
  memset::c#1 = phi( memset::@3/memset::c#2 )
  *memset::dst#3 = memset::c#1
  memset::dst#1 = ++ memset::dst#3
  to:memset::@3
memset::@return: scope:[memset]  from memset::@1
  memset::return#3 = phi( memset::@1/memset::return#1 )
  memset::return#2 = memset::return#3
  return 
  to:@return

void __start()
__start: scope:[__start]  from
  to:__start::__init1
__start::__init1: scope:[__start]  from __start
  to:__start::@1
__start::@1: scope:[__start]  from __start::__init1
  call main
  to:__start::@2
__start::@2: scope:[__start]  from __start::@1
  to:__start::@return
__start::@return: scope:[__start]  from __start::@2
  return 
  to:@return

SYMBOL TABLE SSA
__constant char *SCREEN = (char *)$400
void __start()
void main()
void * memset(void *str , char c , unsigned int num)
bool memset::$0
bool memset::$1
bool memset::$3
char *memset::$4
char memset::c
char memset::c#0
char memset::c#1
char memset::c#2
char memset::c#3
char memset::c#4
char *memset::dst
char *memset::dst#0
char *memset::dst#1
char *memset::dst#2
char *memset::dst#3
char *memset::end
char *memset::end#0
char *memset::end#1
char *memset::end#2
unsigned int memset::num
unsigned int memset::num#0
unsigned int memset::num#1
unsigned int memset::num#2
void *memset::return
void *memset::return#0
void *memset::return#1
void *memset::return#2
void *memset::return#3
void *memset::str
void *memset::str#0
void *memset::str#1
void *memset::str#2
void *memset::str#3
void *memset::str#4
void *memset::str#5

Adding number conversion cast (unumber) $3e8 in memset::num#0 = $3e8
Adding number conversion cast (unumber) 0 in memset::$0 = memset::num#1 > 0
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast memset::num#0 = (unumber)$3e8
Inlining cast memset::dst#0 = (char *)memset::str#2
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast $3e8
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (unsigned int) $3e8
Finalized unsigned number type (char) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inversing boolean not [8] memset::$1 = memset::num#1 <= 0 from [7] memset::$0 = memset::num#1 > 0
Successful SSA optimization Pass2UnaryNotSimplification
Alias memset::return#1 = memset::str#1 memset::return#3 memset::return#2 
Alias memset::str#2 = memset::str#3 
Alias memset::num#1 = memset::num#2 
Alias memset::c#3 = memset::c#4 
Alias memset::c#1 = memset::c#2 
Alias memset::dst#2 = memset::dst#3 
Alias memset::end#1 = memset::end#2 
Alias memset::str#4 = memset::str#5 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values memset::num#1 memset::num#0
Identical Phi Values memset::str#2 memset::str#0
Identical Phi Values memset::c#3 memset::c#0
Identical Phi Values memset::end#1 memset::end#0
Identical Phi Values memset::str#4 memset::str#2
Identical Phi Values memset::c#1 memset::c#3
Successful SSA optimization Pass2IdenticalPhiElimination
Identical Phi Values memset::return#1 memset::str#0
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition memset::$1 [8] if(memset::num#0<=0) goto memset::@1
Simple Condition memset::$3 [15] if(memset::dst#2!=memset::end#0) goto memset::@4
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant right-side identified [0] memset::str#0 = (void *)SCREEN
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant memset::str#0 = (void *)SCREEN
Constant memset::c#0 = 'c'
Constant memset::num#0 = $3e8
Successful SSA optimization Pass2ConstantIdentification
Constant memset::return#0 = memset::str#0
Constant memset::$4 = (char *)memset::str#0
Constant memset::dst#0 = (char *)memset::str#0
Successful SSA optimization Pass2ConstantIdentification
if() condition always false - eliminating [8] if(memset::num#0<=0) goto memset::@1
Successful SSA optimization Pass2ConstantIfs
Eliminating unused constant memset::return#0
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
Constant right-side identified [2] memset::end#0 = memset::$4 + memset::num#0
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant memset::end#0 = memset::$4+memset::num#0
Successful SSA optimization Pass2ConstantIdentification
Inlining constant with var siblings memset::dst#0
Constant inlined memset::$4 = (char *)memset::str#0
Constant inlined memset::dst#0 = (char *)memset::str#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 memset
Adding NOP phi() at start of memset::@2
Adding NOP phi() at start of memset::@1
CALL GRAPH
Calls in [main] to memset:1 

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

FINAL CONTROL FLOW GRAPH

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

void * memset(void *str , char c , unsigned int num)
memset: scope:[memset]  from main
  [3] phi()
  to:memset::@1
memset::@1: scope:[memset]  from memset memset::@2
  [4] memset::dst#2 = phi( memset/(char *)memset::str#0, memset::@2/memset::dst#1 )
  [5] if(memset::dst#2!=memset::end#0) goto memset::@2
  to:memset::@return
memset::@return: scope:[memset]  from memset::@1
  [6] return 
  to:@return
memset::@2: scope:[memset]  from memset::@1
  [7] *memset::dst#2 = memset::c#0
  [8] memset::dst#1 = ++ memset::dst#2
  to:memset::@1


VARIABLE REGISTER WEIGHTS
void main()
void * memset(void *str , char c , unsigned int num)
char memset::c
char *memset::dst
char *memset::dst#1 // 202.0
char *memset::dst#2 // 134.66666666666666
char *memset::end
unsigned int memset::num
void *memset::return
void *memset::str

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

REGISTER UPLIFT SCOPES
Uplift Scope [memset] 336.67: zp[2]:2 [ memset::dst#2 memset::dst#1 ] 
Uplift Scope [main] 
Uplift Scope [] 

Uplifting [memset] best 586 combination zp[2]:2 [ memset::dst#2 memset::dst#1 ] 
Uplifting [main] best 586 combination 
Uplifting [] best 586 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Minimal classic for() loop - coded using while() to test optimization of loop heads
  // Upstart
  // Commodore 64 PRG executable file
.file [name="loop-memset-min.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: {
    // [1] call memset
    // [3] phi from main to memset [phi:main->memset]
  memset_from_main:
    jsr memset
    jmp __breturn
    // main::@return
  __breturn:
    // [2] return 
    rts
}
  // memset
// Copies the character c (an unsigned char) to the first num characters of the object pointed to by the argument str.
// void * memset(void *str, char c, unsigned int num)
memset: {
    .const c = 'c'
    .const num = $3e8
    .label str = SCREEN
    .label end = str+num
    .label dst = 2
    // [4] phi from memset to memset::@1 [phi:memset->memset::@1]
  __b1_from_memset:
    // [4] phi memset::dst#2 = (char *)memset::str#0 [phi:memset->memset::@1#0] -- pbuz1=pbuc1 
    lda #<str
    sta.z dst
    lda #>str
    sta.z dst+1
    jmp __b1
    // memset::@1
  __b1:
    // [5] if(memset::dst#2!=memset::end#0) goto memset::@2 -- pbuz1_neq_pbuc1_then_la1 
    lda.z dst+1
    cmp #>end
    bne __b2
    lda.z dst
    cmp #<end
    bne __b2
    jmp __breturn
    // memset::@return
  __breturn:
    // [6] return 
    rts
    // memset::@2
  __b2:
    // [7] *memset::dst#2 = memset::c#0 -- _deref_pbuz1=vbuc1 
    lda #c
    ldy #0
    sta (dst),y
    // [8] memset::dst#1 = ++ memset::dst#2 -- pbuz1=_inc_pbuz1 
    inc.z dst
    bne !+
    inc.z dst+1
  !:
    // [4] phi from memset::@2 to memset::@1 [phi:memset::@2->memset::@1]
  __b1_from___b2:
    // [4] phi memset::dst#2 = memset::dst#1 [phi:memset::@2->memset::@1#0] -- register_copy 
    jmp __b1
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __breturn
Removing instruction jmp __b1
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction memset_from_main:
Removing instruction __breturn:
Removing instruction __b1_from_memset:
Removing instruction __breturn:
Removing instruction __b1_from___b2:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
__constant char *SCREEN = (char *) 1024
void main()
void * memset(void *str , char c , unsigned int num)
char memset::c
__constant char memset::c#0 = 'c' // c
char *memset::dst
char *memset::dst#1 // dst zp[2]:2 202.0
char *memset::dst#2 // dst zp[2]:2 134.66666666666666
char *memset::end
__constant char *memset::end#0 = (char *)memset::str#0+memset::num#0 // end
unsigned int memset::num
__constant unsigned int memset::num#0 = $3e8 // num
void *memset::return
void *memset::str
__constant void *memset::str#0 = (void *)SCREEN // str

zp[2]:2 [ memset::dst#2 memset::dst#1 ]


FINAL ASSEMBLER
Score: 523

  // File Comments
// Minimal classic for() loop - coded using while() to test optimization of loop heads
  // Upstart
  // Commodore 64 PRG executable file
.file [name="loop-memset-min.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: {
    // memset(SCREEN, 'c', 1000)
    // [1] call memset
    // [3] phi from main to memset [phi:main->memset]
    jsr memset
    // main::@return
    // }
    // [2] return 
    rts
}
  // memset
// Copies the character c (an unsigned char) to the first num characters of the object pointed to by the argument str.
// void * memset(void *str, char c, unsigned int num)
memset: {
    .const c = 'c'
    .const num = $3e8
    .label str = SCREEN
    .label end = str+num
    .label dst = 2
    // [4] phi from memset to memset::@1 [phi:memset->memset::@1]
    // [4] phi memset::dst#2 = (char *)memset::str#0 [phi:memset->memset::@1#0] -- pbuz1=pbuc1 
    lda #<str
    sta.z dst
    lda #>str
    sta.z dst+1
    // memset::@1
  __b1:
    // while(dst!=end)
    // [5] if(memset::dst#2!=memset::end#0) goto memset::@2 -- pbuz1_neq_pbuc1_then_la1 
    lda.z dst+1
    cmp #>end
    bne __b2
    lda.z dst
    cmp #<end
    bne __b2
    // memset::@return
    // }
    // [6] return 
    rts
    // memset::@2
  __b2:
    // *dst = c
    // [7] *memset::dst#2 = memset::c#0 -- _deref_pbuz1=vbuc1 
    lda #c
    ldy #0
    sta (dst),y
    // dst++;
    // [8] memset::dst#1 = ++ memset::dst#2 -- pbuz1=_inc_pbuz1 
    inc.z dst
    bne !+
    inc.z dst+1
  !:
    // [4] phi from memset::@2 to memset::@1 [phi:memset::@2->memset::@1]
    // [4] phi memset::dst#2 = memset::dst#1 [phi:memset::@2->memset::@1#0] -- register_copy 
    jmp __b1
}
  // File Data

