
CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start
  strncat::destination#0 = build
  strncat::source#0 = hello
  strncat::num#0 = 5
  call strncat
  strncat::return#0 = strncat::return#4
  to:main::@3
main::@3: scope:[main]  from main
  strncat::destination#1 = build
  strncat::source#1 = space
  strncat::num#1 = 5
  call strncat
  strncat::return#1 = strncat::return#4
  to:main::@4
main::@4: scope:[main]  from main::@3
  strncat::destination#2 = build
  strncat::source#2 = world
  strncat::num#2 = 5
  call strncat
  strncat::return#2 = strncat::return#4
  to:main::@5
main::@5: scope:[main]  from main::@4
  main::i#0 = 0
  to:main::@1
main::@1: scope:[main]  from main::@2 main::@5
  main::i#2 = phi( main::@2/main::i#1, main::@5/main::i#0 )
  main::$3 = 0 != build[main::i#2]
  if(main::$3) goto main::@2
  to:main::@return
main::@2: scope:[main]  from main::@1
  main::i#3 = phi( main::@1/main::i#2 )
  SCREEN[main::i#3] = build[main::i#3]
  main::i#1 = ++ main::i#3
  to:main::@1
main::@return: scope:[main]  from main::@1
  return 
  to:@return

char * strncat(char *destination , const char *source , unsigned int num)
strncat: scope:[strncat]  from main main::@3 main::@4
  strncat::num#7 = phi( main/strncat::num#0, main::@3/strncat::num#1, main::@4/strncat::num#2 )
  strncat::source#7 = phi( main/strncat::source#0, main::@3/strncat::source#1, main::@4/strncat::source#2 )
  strncat::destination#3 = phi( main/strncat::destination#0, main::@3/strncat::destination#1, main::@4/strncat::destination#2 )
  strncat::dst#0 = strncat::destination#3
  to:strncat::@1
strncat::@1: scope:[strncat]  from strncat strncat::@2
  strncat::destination#6 = phi( strncat/strncat::destination#3, strncat::@2/strncat::destination#8 )
  strncat::num#6 = phi( strncat/strncat::num#7, strncat::@2/strncat::num#8 )
  strncat::source#5 = phi( strncat/strncat::source#7, strncat::@2/strncat::source#8 )
  strncat::dst#3 = phi( strncat/strncat::dst#0, strncat::@2/strncat::dst#1 )
  strncat::$1 = 0 != *strncat::dst#3
  if(strncat::$1) goto strncat::@2
  to:strncat::@3
strncat::@2: scope:[strncat]  from strncat::@1
  strncat::destination#8 = phi( strncat::@1/strncat::destination#6 )
  strncat::num#8 = phi( strncat::@1/strncat::num#6 )
  strncat::source#8 = phi( strncat::@1/strncat::source#5 )
  strncat::dst#4 = phi( strncat::@1/strncat::dst#3 )
  strncat::dst#1 = ++ strncat::dst#4
  to:strncat::@1
strncat::@3: scope:[strncat]  from strncat::@1 strncat::@4
  strncat::destination#5 = phi( strncat::@1/strncat::destination#6, strncat::@4/strncat::destination#7 )
  strncat::num#4 = phi( strncat::@1/strncat::num#6, strncat::@4/strncat::num#3 )
  strncat::dst#5 = phi( strncat::@1/strncat::dst#3, strncat::@4/strncat::dst#2 )
  strncat::source#4 = phi( strncat::@1/strncat::source#5, strncat::@4/strncat::source#6 )
  *strncat::dst#5 = *strncat::source#4
  strncat::$0 = strncat::num#4 && *strncat::dst#5
  strncat::source#3 = ++ strncat::source#4
  if(strncat::$0) goto strncat::@4
  to:strncat::@5
strncat::@4: scope:[strncat]  from strncat::@3
  strncat::destination#7 = phi( strncat::@3/strncat::destination#5 )
  strncat::source#6 = phi( strncat::@3/strncat::source#3 )
  strncat::dst#6 = phi( strncat::@3/strncat::dst#5 )
  strncat::num#5 = phi( strncat::@3/strncat::num#4 )
  strncat::num#3 = -- strncat::num#5
  strncat::dst#2 = ++ strncat::dst#6
  to:strncat::@3
strncat::@5: scope:[strncat]  from strncat::@3
  strncat::destination#4 = phi( strncat::@3/strncat::destination#5 )
  strncat::dst#7 = phi( strncat::@3/strncat::dst#5 )
  *strncat::dst#7 = 0
  strncat::return#3 = strncat::destination#4
  to:strncat::@return
strncat::@return: scope:[strncat]  from strncat::@5
  strncat::return#5 = phi( strncat::@5/strncat::return#3 )
  strncat::return#4 = strncat::return#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
__constant char * const SCREEN = (char *)$400
void __start()
__constant char build[$28] = { fill( $28, 0) }
__constant char hello[] = "hello"
void main()
bool main::$3
char main::i
char main::i#0
char main::i#1
char main::i#2
char main::i#3
__constant char space[] = " "
char * strncat(char *destination , const char *source , unsigned int num)
bool strncat::$0
bool strncat::$1
char *strncat::destination
char *strncat::destination#0
char *strncat::destination#1
char *strncat::destination#2
char *strncat::destination#3
char *strncat::destination#4
char *strncat::destination#5
char *strncat::destination#6
char *strncat::destination#7
char *strncat::destination#8
char *strncat::dst
char *strncat::dst#0
char *strncat::dst#1
char *strncat::dst#2
char *strncat::dst#3
char *strncat::dst#4
char *strncat::dst#5
char *strncat::dst#6
char *strncat::dst#7
unsigned int strncat::num
unsigned int strncat::num#0
unsigned int strncat::num#1
unsigned int strncat::num#2
unsigned int strncat::num#3
unsigned int strncat::num#4
unsigned int strncat::num#5
unsigned int strncat::num#6
unsigned int strncat::num#7
unsigned int strncat::num#8
char *strncat::return
char *strncat::return#0
char *strncat::return#1
char *strncat::return#2
char *strncat::return#3
char *strncat::return#4
char *strncat::return#5
const char *strncat::source
const char *strncat::source#0
const char *strncat::source#1
const char *strncat::source#2
const char *strncat::source#3
const char *strncat::source#4
const char *strncat::source#5
const char *strncat::source#6
const char *strncat::source#7
const char *strncat::source#8
__constant char world[] = "world war 3"

Adding number conversion cast (unumber) 5 in strncat::num#0 = 5
Adding number conversion cast (unumber) 5 in strncat::num#1 = 5
Adding number conversion cast (unumber) 5 in strncat::num#2 = 5
Adding number conversion cast (unumber) 0 in main::$3 = 0 != build[main::i#2]
Adding number conversion cast (unumber) 0 in strncat::$1 = 0 != *strncat::dst#3
Adding number conversion cast (unumber) 0 in *strncat::dst#7 = 0
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast strncat::num#0 = (unumber)5
Inlining cast strncat::num#1 = (unumber)5
Inlining cast strncat::num#2 = (unumber)5
Inlining cast *strncat::dst#7 = (unumber)0
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast 5
Simplifying constant integer cast 5
Simplifying constant integer cast 5
Simplifying constant integer cast 0
Simplifying constant integer cast 0
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 5
Finalized unsigned number type (char) 5
Finalized unsigned number type (char) 5
Finalized unsigned number type (char) 0
Finalized unsigned number type (char) 0
Finalized unsigned number type (char) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias main::i#2 = main::i#3 
Alias strncat::dst#0 = strncat::destination#3 
Alias strncat::dst#3 = strncat::dst#4 
Alias strncat::source#5 = strncat::source#8 
Alias strncat::num#6 = strncat::num#8 
Alias strncat::destination#6 = strncat::destination#8 
Alias strncat::num#4 = strncat::num#5 
Alias strncat::dst#5 = strncat::dst#6 strncat::dst#7 
Alias strncat::source#3 = strncat::source#6 
Alias strncat::destination#4 = strncat::destination#7 strncat::destination#5 strncat::return#3 strncat::return#5 strncat::return#4 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values strncat::source#5 strncat::source#7
Identical Phi Values strncat::num#6 strncat::num#7
Identical Phi Values strncat::destination#6 strncat::dst#0
Identical Phi Values strncat::destination#4 strncat::destination#6
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition main::$3 [18] if(0!=build[main::i#2]) goto main::@2
Simple Condition strncat::$1 [25] if(0!=*strncat::dst#3) goto strncat::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Rewriting && if()-condition to two if()s [29] strncat::$0 = strncat::num#4 && *strncat::dst#5
Successful SSA optimization Pass2ConditionalAndOrRewriting
Warning! Adding boolean cast to non-boolean condition strncat::num#4
Warning! Adding boolean cast to non-boolean condition *strncat::dst#5
Constant strncat::destination#0 = build
Constant strncat::source#0 = hello
Constant strncat::num#0 = 5
Constant strncat::destination#1 = build
Constant strncat::source#1 = space
Constant strncat::num#1 = 5
Constant strncat::destination#2 = build
Constant strncat::source#2 = world
Constant strncat::num#2 = 5
Constant main::i#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Eliminating unused variable strncat::return#0 and assignment [1] strncat::return#0 = strncat::dst#0
Eliminating unused variable strncat::return#1 and assignment [3] strncat::return#1 = strncat::dst#0
Eliminating unused variable strncat::return#2 and assignment [5] strncat::return#2 = strncat::dst#0
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
Adding number conversion cast (unumber) 0 in [15] strncat::$2 = 0 != strncat::num#4
Adding number conversion cast (unumber) 0 in [23] strncat::$3 = 0 != *strncat::dst#5
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast 0
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 0
Finalized unsigned number type (char) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simple Condition strncat::$2 [16] if(0!=strncat::num#4) goto strncat::@6
Simple Condition strncat::$3 [22] if(0!=*strncat::dst#5) goto strncat::@4
Successful SSA optimization Pass2ConditionalJumpSimplification
Negating conditional jump and destination [16] if(0==strncat::num#4) goto strncat::@5
Successful SSA optimization Pass2ConditionalJumpSequenceImprovement
Inlining constant with var siblings main::i#0
Inlining constant with var siblings strncat::source#0
Inlining constant with var siblings strncat::num#0
Inlining constant with var siblings strncat::source#1
Inlining constant with var siblings strncat::num#1
Inlining constant with var siblings strncat::source#2
Inlining constant with var siblings strncat::num#2
Constant inlined strncat::destination#2 = build
Constant inlined strncat::source#0 = hello
Constant inlined strncat::source#1 = space
Constant inlined strncat::source#2 = world
Constant inlined strncat::destination#0 = build
Constant inlined strncat::destination#1 = build
Constant inlined main::i#0 = 0
Constant inlined strncat::num#2 = 5
Constant inlined strncat::num#1 = 5
Constant inlined strncat::num#0 = 5
Successful SSA optimization Pass2ConstantInlining
Identical Phi Values strncat::dst#0 build
Identical Phi Values strncat::num#7 5
Successful SSA optimization Pass2IdenticalPhiElimination
Finalized unsigned number type (char) $28
Finalized unsigned number type (char) $28
Successful SSA optimization PassNFinalizeNumberTypeConversions
Added new block during phi lifting strncat::@7(between strncat::@1 and strncat::@3)
Fixing phi predecessor for strncat::num#4 to new block ( strncat::@1 -> strncat::@7 ) during phi lifting.
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@3
Adding NOP phi() at start of main::@4
Adding NOP phi() at start of main::@5
CALL GRAPH
Calls in [main] to strncat:1 strncat:3 strncat:5 

Created 6 initial phi equivalence classes
Coalesced [12] main::i#4 = main::i#1
Coalesced [16] strncat::source#9 = strncat::source#7
Coalesced [17] strncat::dst#9 = strncat::dst#3
Coalesced [27] strncat::source#10 = strncat::source#3
Coalesced [28] strncat::dst#10 = strncat::dst#2
Coalesced [29] strncat::num#9 = strncat::num#3
Coalesced [31] strncat::dst#8 = strncat::dst#1
Coalesced down to 4 phi equivalence classes
Culled Empty Block label main::@5
Culled Empty Block label strncat::@7
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@3
Adding NOP phi() at start of main::@4

FINAL CONTROL FLOW GRAPH

void main()
main: scope:[main]  from
  [0] phi()
  [1] call strncat
  to:main::@3
main::@3: scope:[main]  from main
  [2] phi()
  [3] call strncat
  to:main::@4
main::@4: scope:[main]  from main::@3
  [4] phi()
  [5] call strncat
  to:main::@1
main::@1: scope:[main]  from main::@2 main::@4
  [6] main::i#2 = phi( main::@2/main::i#1, main::@4/0 )
  [7] if(0!=build[main::i#2]) goto main::@2
  to:main::@return
main::@return: scope:[main]  from main::@1
  [8] return 
  to:@return
main::@2: scope:[main]  from main::@1
  [9] SCREEN[main::i#2] = build[main::i#2]
  [10] main::i#1 = ++ main::i#2
  to:main::@1

char * strncat(char *destination , const char *source , unsigned int num)
strncat: scope:[strncat]  from main main::@3 main::@4
  [11] strncat::source#7 = phi( main/hello, main::@3/space, main::@4/world )
  to:strncat::@1
strncat::@1: scope:[strncat]  from strncat strncat::@2
  [12] strncat::dst#3 = phi( strncat/build, strncat::@2/strncat::dst#1 )
  [13] if(0!=*strncat::dst#3) goto strncat::@2
  to:strncat::@3
strncat::@3: scope:[strncat]  from strncat::@1 strncat::@4
  [14] strncat::num#4 = phi( strncat::@1/5, strncat::@4/strncat::num#3 )
  [14] strncat::dst#5 = phi( strncat::@1/strncat::dst#3, strncat::@4/strncat::dst#2 )
  [14] strncat::source#4 = phi( strncat::@1/strncat::source#7, strncat::@4/strncat::source#3 )
  [15] *strncat::dst#5 = *strncat::source#4
  [16] strncat::source#3 = ++ strncat::source#4
  [17] if(0==strncat::num#4) goto strncat::@5
  to:strncat::@6
strncat::@6: scope:[strncat]  from strncat::@3
  [18] if(0!=*strncat::dst#5) goto strncat::@4
  to:strncat::@5
strncat::@5: scope:[strncat]  from strncat::@3 strncat::@6
  [19] *strncat::dst#5 = 0
  to:strncat::@return
strncat::@return: scope:[strncat]  from strncat::@5
  [20] return 
  to:@return
strncat::@4: scope:[strncat]  from strncat::@6
  [21] strncat::num#3 = -- strncat::num#4
  [22] strncat::dst#2 = ++ strncat::dst#5
  to:strncat::@3
strncat::@2: scope:[strncat]  from strncat::@1
  [23] strncat::dst#1 = ++ strncat::dst#3
  to:strncat::@1


VARIABLE REGISTER WEIGHTS
void main()
char main::i
char main::i#1 // 22.0
char main::i#2 // 18.333333333333332
char * strncat(char *destination , const char *source , unsigned int num)
char *strncat::destination
char *strncat::dst
char *strncat::dst#1 // 202.0
char *strncat::dst#2 // 202.0
char *strncat::dst#3 // 202.0
char *strncat::dst#5 // 85.99999999999999
unsigned int strncat::num
unsigned int strncat::num#3 // 101.0
unsigned int strncat::num#4 // 60.599999999999994
char *strncat::return
const char *strncat::source
const char *strncat::source#3 // 40.4
const char *strncat::source#4 // 202.0
const char *strncat::source#7 // 25.25

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
[ strncat::source#4 strncat::source#7 strncat::source#3 ]
[ strncat::dst#5 strncat::dst#3 strncat::dst#1 strncat::dst#2 ]
[ strncat::num#4 strncat::num#3 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ strncat::source#4 strncat::source#7 strncat::source#3 ]
[ strncat::dst#5 strncat::dst#3 strncat::dst#1 strncat::dst#2 ]
[ strncat::num#4 strncat::num#3 ]
Allocated zp[2]:2 [ strncat::dst#5 strncat::dst#3 strncat::dst#1 strncat::dst#2 ]
Allocated zp[2]:4 [ strncat::source#4 strncat::source#7 strncat::source#3 ]
Allocated zp[2]:6 [ strncat::num#4 strncat::num#3 ]
Allocated zp[1]:8 [ main::i#2 main::i#1 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [7] if(0!=build[main::i#2]) goto main::@2 [ main::i#2 ] (  [ main::i#2 ] { }  ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:8 [ main::i#2 main::i#1 ]
Statement [9] SCREEN[main::i#2] = build[main::i#2] [ main::i#2 ] (  [ main::i#2 ] { }  ) always clobbers reg byte a 
Statement [13] if(0!=*strncat::dst#3) goto strncat::@2 [ strncat::source#7 strncat::dst#3 ] ( strncat:1 [ strncat::source#7 strncat::dst#3 ] { }  strncat:3 [ strncat::source#7 strncat::dst#3 ] { }  strncat:5 [ strncat::source#7 strncat::dst#3 ] { }  ) always clobbers reg byte a reg byte y 
Statement [15] *strncat::dst#5 = *strncat::source#4 [ strncat::source#4 strncat::dst#5 strncat::num#4 ] ( strncat:1 [ strncat::source#4 strncat::dst#5 strncat::num#4 ] { }  strncat:3 [ strncat::source#4 strncat::dst#5 strncat::num#4 ] { }  strncat:5 [ strncat::source#4 strncat::dst#5 strncat::num#4 ] { }  ) always clobbers reg byte a reg byte y 
Statement [17] if(0==strncat::num#4) goto strncat::@5 [ strncat::dst#5 strncat::num#4 strncat::source#3 ] ( strncat:1 [ strncat::dst#5 strncat::num#4 strncat::source#3 ] { }  strncat:3 [ strncat::dst#5 strncat::num#4 strncat::source#3 ] { }  strncat:5 [ strncat::dst#5 strncat::num#4 strncat::source#3 ] { }  ) always clobbers reg byte a 
Statement [18] if(0!=*strncat::dst#5) goto strncat::@4 [ strncat::dst#5 strncat::num#4 strncat::source#3 ] ( strncat:1 [ strncat::dst#5 strncat::num#4 strncat::source#3 ] { }  strncat:3 [ strncat::dst#5 strncat::num#4 strncat::source#3 ] { }  strncat:5 [ strncat::dst#5 strncat::num#4 strncat::source#3 ] { }  ) always clobbers reg byte a reg byte y 
Statement [19] *strncat::dst#5 = 0 [ ] ( strncat:1 [ ] { }  strncat:3 [ ] { }  strncat:5 [ ] { }  ) always clobbers reg byte a reg byte y 
Statement [21] strncat::num#3 = -- strncat::num#4 [ strncat::dst#5 strncat::source#3 strncat::num#3 ] ( strncat:1 [ strncat::dst#5 strncat::source#3 strncat::num#3 ] { }  strncat:3 [ strncat::dst#5 strncat::source#3 strncat::num#3 ] { }  strncat:5 [ strncat::dst#5 strncat::source#3 strncat::num#3 ] { }  ) always clobbers reg byte a 
Statement [7] if(0!=build[main::i#2]) goto main::@2 [ main::i#2 ] (  [ main::i#2 ] { }  ) always clobbers reg byte a 
Statement [9] SCREEN[main::i#2] = build[main::i#2] [ main::i#2 ] (  [ main::i#2 ] { }  ) always clobbers reg byte a 
Statement [13] if(0!=*strncat::dst#3) goto strncat::@2 [ strncat::source#7 strncat::dst#3 ] ( strncat:1 [ strncat::source#7 strncat::dst#3 ] { }  strncat:3 [ strncat::source#7 strncat::dst#3 ] { }  strncat:5 [ strncat::source#7 strncat::dst#3 ] { }  ) always clobbers reg byte a reg byte y 
Statement [15] *strncat::dst#5 = *strncat::source#4 [ strncat::source#4 strncat::dst#5 strncat::num#4 ] ( strncat:1 [ strncat::source#4 strncat::dst#5 strncat::num#4 ] { }  strncat:3 [ strncat::source#4 strncat::dst#5 strncat::num#4 ] { }  strncat:5 [ strncat::source#4 strncat::dst#5 strncat::num#4 ] { }  ) always clobbers reg byte a reg byte y 
Statement [17] if(0==strncat::num#4) goto strncat::@5 [ strncat::dst#5 strncat::num#4 strncat::source#3 ] ( strncat:1 [ strncat::dst#5 strncat::num#4 strncat::source#3 ] { }  strncat:3 [ strncat::dst#5 strncat::num#4 strncat::source#3 ] { }  strncat:5 [ strncat::dst#5 strncat::num#4 strncat::source#3 ] { }  ) always clobbers reg byte a 
Statement [18] if(0!=*strncat::dst#5) goto strncat::@4 [ strncat::dst#5 strncat::num#4 strncat::source#3 ] ( strncat:1 [ strncat::dst#5 strncat::num#4 strncat::source#3 ] { }  strncat:3 [ strncat::dst#5 strncat::num#4 strncat::source#3 ] { }  strncat:5 [ strncat::dst#5 strncat::num#4 strncat::source#3 ] { }  ) always clobbers reg byte a reg byte y 
Statement [19] *strncat::dst#5 = 0 [ ] ( strncat:1 [ ] { }  strncat:3 [ ] { }  strncat:5 [ ] { }  ) always clobbers reg byte a reg byte y 
Statement [21] strncat::num#3 = -- strncat::num#4 [ strncat::dst#5 strncat::source#3 strncat::num#3 ] ( strncat:1 [ strncat::dst#5 strncat::source#3 strncat::num#3 ] { }  strncat:3 [ strncat::dst#5 strncat::source#3 strncat::num#3 ] { }  strncat:5 [ strncat::dst#5 strncat::source#3 strncat::num#3 ] { }  ) always clobbers reg byte a 
Potential registers zp[1]:8 [ main::i#2 main::i#1 ] : zp[1]:8 , reg byte x , reg byte y , 
Potential registers zp[2]:4 [ strncat::source#4 strncat::source#7 strncat::source#3 ] : zp[2]:4 , 
Potential registers zp[2]:2 [ strncat::dst#5 strncat::dst#3 strncat::dst#1 strncat::dst#2 ] : zp[2]:2 , 
Potential registers zp[2]:6 [ strncat::num#4 strncat::num#3 ] : zp[2]:6 , 

REGISTER UPLIFT SCOPES
Uplift Scope [strncat] 692: zp[2]:2 [ strncat::dst#5 strncat::dst#3 strncat::dst#1 strncat::dst#2 ] 267.65: zp[2]:4 [ strncat::source#4 strncat::source#7 strncat::source#3 ] 161.6: zp[2]:6 [ strncat::num#4 strncat::num#3 ] 
Uplift Scope [main] 40.33: zp[1]:8 [ main::i#2 main::i#1 ] 
Uplift Scope [] 

Uplifting [strncat] best 1904 combination zp[2]:2 [ strncat::dst#5 strncat::dst#3 strncat::dst#1 strncat::dst#2 ] zp[2]:4 [ strncat::source#4 strncat::source#7 strncat::source#3 ] zp[2]:6 [ strncat::num#4 strncat::num#3 ] 
Uplifting [main] best 1784 combination reg byte x [ main::i#2 main::i#1 ] 
Uplifting [] best 1784 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Test strncat() implementation
  // Upstart
  // Commodore 64 PRG executable file
.file [name="strncat-0.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 strncat
    // [11] phi from main to strncat [phi:main->strncat]
  strncat_from_main:
    // [11] phi strncat::source#7 = hello [phi:main->strncat#0] -- pbuz1=pbuc1 
    lda #<hello
    sta.z strncat.source
    lda #>hello
    sta.z strncat.source+1
    jsr strncat
    // [2] phi from main to main::@3 [phi:main->main::@3]
  __b3_from_main:
    jmp __b3
    // main::@3
  __b3:
    // [3] call strncat
    // [11] phi from main::@3 to strncat [phi:main::@3->strncat]
  strncat_from___b3:
    // [11] phi strncat::source#7 = space [phi:main::@3->strncat#0] -- pbuz1=pbuc1 
    lda #<space
    sta.z strncat.source
    lda #>space
    sta.z strncat.source+1
    jsr strncat
    // [4] phi from main::@3 to main::@4 [phi:main::@3->main::@4]
  __b4_from___b3:
    jmp __b4
    // main::@4
  __b4:
    // [5] call strncat
    // [11] phi from main::@4 to strncat [phi:main::@4->strncat]
  strncat_from___b4:
    // [11] phi strncat::source#7 = world [phi:main::@4->strncat#0] -- pbuz1=pbuc1 
    lda #<world
    sta.z strncat.source
    lda #>world
    sta.z strncat.source+1
    jsr strncat
    // [6] phi from main::@4 to main::@1 [phi:main::@4->main::@1]
  __b1_from___b4:
    // [6] phi main::i#2 = 0 [phi:main::@4->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    jmp __b1
    // main::@1
  __b1:
    // [7] if(0!=build[main::i#2]) goto main::@2 -- 0_neq_pbuc1_derefidx_vbuxx_then_la1 
    lda build,x
    cmp #0
    bne __b2
    jmp __breturn
    // main::@return
  __breturn:
    // [8] return 
    rts
    // main::@2
  __b2:
    // [9] SCREEN[main::i#2] = build[main::i#2] -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_vbuxx 
    lda build,x
    sta SCREEN,x
    // [10] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [6] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
  __b1_from___b2:
    // [6] phi main::i#2 = main::i#1 [phi:main::@2->main::@1#0] -- register_copy 
    jmp __b1
}
  // strncat
// Appends the first num characters of source to destination, plus a terminating null-character.
// If the length of the C string in source is less than num, only the content up to the terminating null-character is copied.
// char * strncat(char *destination, __zp(4) const char *source, __zp(6) unsigned int num)
strncat: {
    .label dst = 2
    .label source = 4
    .label num = 6
    // [12] phi from strncat to strncat::@1 [phi:strncat->strncat::@1]
  __b1_from_strncat:
    // [12] phi strncat::dst#3 = build [phi:strncat->strncat::@1#0] -- pbuz1=pbuc1 
    lda #<build
    sta.z dst
    lda #>build
    sta.z dst+1
    jmp __b1
  // Skip the existing string at dest
    // strncat::@1
  __b1:
    // [13] if(0!=*strncat::dst#3) goto strncat::@2 -- 0_neq__deref_pbuz1_then_la1 
    ldy #0
    lda (dst),y
    cmp #0
    bne __b2
    // [14] phi from strncat::@1 to strncat::@3 [phi:strncat::@1->strncat::@3]
  __b3_from___b1:
    // [14] phi strncat::num#4 = 5 [phi:strncat::@1->strncat::@3#0] -- vwuz1=vbuc1 
    lda #<5
    sta.z num
    lda #>5
    sta.z num+1
    // [14] phi strncat::dst#5 = strncat::dst#3 [phi:strncat::@1->strncat::@3#1] -- register_copy 
    // [14] phi strncat::source#4 = strncat::source#7 [phi:strncat::@1->strncat::@3#2] -- register_copy 
    jmp __b3
  // Copy up to num chars from src
    // strncat::@3
  __b3:
    // [15] *strncat::dst#5 = *strncat::source#4 -- _deref_pbuz1=_deref_pbuz2 
    ldy #0
    lda (source),y
    ldy #0
    sta (dst),y
    // [16] strncat::source#3 = ++ strncat::source#4 -- pbuz1=_inc_pbuz1 
    inc.z source
    bne !+
    inc.z source+1
  !:
    // [17] if(0==strncat::num#4) goto strncat::@5 -- 0_eq_vwuz1_then_la1 
    lda.z num
    ora.z num+1
    beq __b5
    jmp __b6
    // strncat::@6
  __b6:
    // [18] if(0!=*strncat::dst#5) goto strncat::@4 -- 0_neq__deref_pbuz1_then_la1 
    ldy #0
    lda (dst),y
    cmp #0
    bne __b4
    jmp __b5
    // strncat::@5
  __b5:
    // [19] *strncat::dst#5 = 0 -- _deref_pbuz1=vbuc1 
    // Add null-character
    lda #0
    ldy #0
    sta (dst),y
    jmp __breturn
    // strncat::@return
  __breturn:
    // [20] return 
    rts
    // strncat::@4
  __b4:
    // [21] strncat::num#3 = -- strncat::num#4 -- vwuz1=_dec_vwuz1 
    lda.z num
    bne !+
    dec.z num+1
  !:
    dec.z num
    // [22] strncat::dst#2 = ++ strncat::dst#5 -- pbuz1=_inc_pbuz1 
    inc.z dst
    bne !+
    inc.z dst+1
  !:
    // [14] phi from strncat::@4 to strncat::@3 [phi:strncat::@4->strncat::@3]
  __b3_from___b4:
    // [14] phi strncat::num#4 = strncat::num#3 [phi:strncat::@4->strncat::@3#0] -- register_copy 
    // [14] phi strncat::dst#5 = strncat::dst#2 [phi:strncat::@4->strncat::@3#1] -- register_copy 
    // [14] phi strncat::source#4 = strncat::source#3 [phi:strncat::@4->strncat::@3#2] -- register_copy 
    jmp __b3
    // strncat::@2
  __b2:
    // [23] strncat::dst#1 = ++ strncat::dst#3 -- pbuz1=_inc_pbuz1 
    inc.z dst
    bne !+
    inc.z dst+1
  !:
    // [12] phi from strncat::@2 to strncat::@1 [phi:strncat::@2->strncat::@1]
  __b1_from___b2:
    // [12] phi strncat::dst#3 = strncat::dst#1 [phi:strncat::@2->strncat::@1#0] -- register_copy 
    jmp __b1
}
  // File Data
.segment Data
  hello: .text "hello"
  .byte 0
  space: .text " "
  .byte 0
  world: .text "world war 3"
  .byte 0
  build: .fill $28, 0

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b3
Removing instruction jmp __b4
Removing instruction jmp __b1
Removing instruction jmp __breturn
Removing instruction jmp __b1
Removing instruction jmp __b3
Removing instruction jmp __b6
Removing instruction jmp __b5
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction ldy #0
Replacing instruction ldy #0 with TAY
Succesful ASM optimization Pass5UnnecesaryLoadElimination
Removing instruction __b3_from_main:
Removing instruction strncat_from___b3:
Removing instruction __b4_from___b3:
Removing instruction strncat_from___b4:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction strncat_from_main:
Removing instruction __b3:
Removing instruction __b4:
Removing instruction __b1_from___b4:
Removing instruction __breturn:
Removing instruction __b1_from___b2:
Removing instruction __b1_from_strncat:
Removing instruction __b3_from___b1:
Removing instruction __b6:
Removing instruction __breturn:
Removing instruction __b3_from___b4:
Removing instruction __b1_from___b2:
Succesful ASM optimization Pass5UnusedLabelElimination
Replacing instruction lda #>5 with TYA

FINAL SYMBOL TABLE
__constant char * const SCREEN = (char *) 1024
__constant char build[$28] = { fill( $28, 0) }
__constant char hello[] = "hello"
void main()
char main::i
char main::i#1 // reg byte x 22.0
char main::i#2 // reg byte x 18.333333333333332
__constant char space[] = " "
char * strncat(char *destination , const char *source , unsigned int num)
char *strncat::destination
char *strncat::dst
char *strncat::dst#1 // dst zp[2]:2 202.0
char *strncat::dst#2 // dst zp[2]:2 202.0
char *strncat::dst#3 // dst zp[2]:2 202.0
char *strncat::dst#5 // dst zp[2]:2 85.99999999999999
unsigned int strncat::num
unsigned int strncat::num#3 // num zp[2]:6 101.0
unsigned int strncat::num#4 // num zp[2]:6 60.599999999999994
char *strncat::return
const char *strncat::source
const char *strncat::source#3 // source zp[2]:4 40.4
const char *strncat::source#4 // source zp[2]:4 202.0
const char *strncat::source#7 // source zp[2]:4 25.25
__constant char world[] = "world war 3"

reg byte x [ main::i#2 main::i#1 ]
zp[2]:4 [ strncat::source#4 strncat::source#7 strncat::source#3 ]
zp[2]:2 [ strncat::dst#5 strncat::dst#3 strncat::dst#1 strncat::dst#2 ]
zp[2]:6 [ strncat::num#4 strncat::num#3 ]


FINAL ASSEMBLER
Score: 1575

  // File Comments
// Test strncat() implementation
  // Upstart
  // Commodore 64 PRG executable file
.file [name="strncat-0.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: {
    // strncat(build, hello, 5)
    // [1] call strncat
    // [11] phi from main to strncat [phi:main->strncat]
    // [11] phi strncat::source#7 = hello [phi:main->strncat#0] -- pbuz1=pbuc1 
    lda #<hello
    sta.z strncat.source
    lda #>hello
    sta.z strncat.source+1
    jsr strncat
    // [2] phi from main to main::@3 [phi:main->main::@3]
    // main::@3
    // strncat(build, space, 5)
    // [3] call strncat
    // [11] phi from main::@3 to strncat [phi:main::@3->strncat]
    // [11] phi strncat::source#7 = space [phi:main::@3->strncat#0] -- pbuz1=pbuc1 
    lda #<space
    sta.z strncat.source
    lda #>space
    sta.z strncat.source+1
    jsr strncat
    // [4] phi from main::@3 to main::@4 [phi:main::@3->main::@4]
    // main::@4
    // strncat(build, world, 5)
    // [5] call strncat
    // [11] phi from main::@4 to strncat [phi:main::@4->strncat]
    // [11] phi strncat::source#7 = world [phi:main::@4->strncat#0] -- pbuz1=pbuc1 
    lda #<world
    sta.z strncat.source
    lda #>world
    sta.z strncat.source+1
    jsr strncat
    // [6] phi from main::@4 to main::@1 [phi:main::@4->main::@1]
    // [6] phi main::i#2 = 0 [phi:main::@4->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // main::@1
  __b1:
    // while(build[i])
    // [7] if(0!=build[main::i#2]) goto main::@2 -- 0_neq_pbuc1_derefidx_vbuxx_then_la1 
    lda build,x
    cmp #0
    bne __b2
    // main::@return
    // }
    // [8] return 
    rts
    // main::@2
  __b2:
    // SCREEN[i] = build[i]
    // [9] SCREEN[main::i#2] = build[main::i#2] -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_vbuxx 
    lda build,x
    sta SCREEN,x
    // i++;
    // [10] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [6] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
    // [6] phi main::i#2 = main::i#1 [phi:main::@2->main::@1#0] -- register_copy 
    jmp __b1
}
  // strncat
// Appends the first num characters of source to destination, plus a terminating null-character.
// If the length of the C string in source is less than num, only the content up to the terminating null-character is copied.
// char * strncat(char *destination, __zp(4) const char *source, __zp(6) unsigned int num)
strncat: {
    .label dst = 2
    .label source = 4
    .label num = 6
    // [12] phi from strncat to strncat::@1 [phi:strncat->strncat::@1]
    // [12] phi strncat::dst#3 = build [phi:strncat->strncat::@1#0] -- pbuz1=pbuc1 
    lda #<build
    sta.z dst
    lda #>build
    sta.z dst+1
  // Skip the existing string at dest
    // strncat::@1
  __b1:
    // while (*dst)
    // [13] if(0!=*strncat::dst#3) goto strncat::@2 -- 0_neq__deref_pbuz1_then_la1 
    ldy #0
    lda (dst),y
    cmp #0
    bne __b2
    // [14] phi from strncat::@1 to strncat::@3 [phi:strncat::@1->strncat::@3]
    // [14] phi strncat::num#4 = 5 [phi:strncat::@1->strncat::@3#0] -- vwuz1=vbuc1 
    lda #<5
    sta.z num
    tya
    sta.z num+1
    // [14] phi strncat::dst#5 = strncat::dst#3 [phi:strncat::@1->strncat::@3#1] -- register_copy 
    // [14] phi strncat::source#4 = strncat::source#7 [phi:strncat::@1->strncat::@3#2] -- register_copy 
  // Copy up to num chars from src
    // strncat::@3
  __b3:
    // *dst = *source++
    // [15] *strncat::dst#5 = *strncat::source#4 -- _deref_pbuz1=_deref_pbuz2 
    ldy #0
    lda (source),y
    sta (dst),y
    // while (num && (*dst = *source++))
    // [16] strncat::source#3 = ++ strncat::source#4 -- pbuz1=_inc_pbuz1 
    inc.z source
    bne !+
    inc.z source+1
  !:
    // [17] if(0==strncat::num#4) goto strncat::@5 -- 0_eq_vwuz1_then_la1 
    lda.z num
    ora.z num+1
    beq __b5
    // strncat::@6
    // [18] if(0!=*strncat::dst#5) goto strncat::@4 -- 0_neq__deref_pbuz1_then_la1 
    ldy #0
    lda (dst),y
    cmp #0
    bne __b4
    // strncat::@5
  __b5:
    // *dst = 0
    // [19] *strncat::dst#5 = 0 -- _deref_pbuz1=vbuc1 
    // Add null-character
    lda #0
    tay
    sta (dst),y
    // strncat::@return
    // }
    // [20] return 
    rts
    // strncat::@4
  __b4:
    // --num;
    // [21] strncat::num#3 = -- strncat::num#4 -- vwuz1=_dec_vwuz1 
    lda.z num
    bne !+
    dec.z num+1
  !:
    dec.z num
    // ++dst;
    // [22] strncat::dst#2 = ++ strncat::dst#5 -- pbuz1=_inc_pbuz1 
    inc.z dst
    bne !+
    inc.z dst+1
  !:
    // [14] phi from strncat::@4 to strncat::@3 [phi:strncat::@4->strncat::@3]
    // [14] phi strncat::num#4 = strncat::num#3 [phi:strncat::@4->strncat::@3#0] -- register_copy 
    // [14] phi strncat::dst#5 = strncat::dst#2 [phi:strncat::@4->strncat::@3#1] -- register_copy 
    // [14] phi strncat::source#4 = strncat::source#3 [phi:strncat::@4->strncat::@3#2] -- register_copy 
    jmp __b3
    // strncat::@2
  __b2:
    // dst++;
    // [23] strncat::dst#1 = ++ strncat::dst#3 -- pbuz1=_inc_pbuz1 
    inc.z dst
    bne !+
    inc.z dst+1
  !:
    // [12] phi from strncat::@2 to strncat::@1 [phi:strncat::@2->strncat::@1]
    // [12] phi strncat::dst#3 = strncat::dst#1 [phi:strncat::@2->strncat::@1#0] -- register_copy 
    jmp __b1
}
  // File Data
.segment Data
  hello: .text "hello"
  .byte 0
  space: .text " "
  .byte 0
  world: .text "world war 3"
  .byte 0
  build: .fill $28, 0

