int main() {
  char *current = "helloworld";
  char destination[12];
  printf("strcpy of helloworld %s \n", mystrcpy(current, destination));
  printf("%s \n", mystrncpy(current, destination, 1));
  printf("%s \n", mystrncpy(current, destination, 0));
  printf("length of helloworld = %d", mystrlen("helloworld"));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x0,%al
call   1050 <mystrcpy@plt>
mov    %eax,%esi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1060 <mystrncpy@plt>
mov    %eax,%esi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
mov    $0x0,%al
call   1060 <mystrncpy@plt>
mov    %eax,%esi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <mystrlen@plt>
mov    %eax,%esi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xeb0(%rip),%r14
lea    0x4(%rsp),%r15
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <mystrcpy@plt>
lea    0xea2(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1060 <mystrncpy@plt>
lea    0xe95(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <mystrncpy@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <mystrlen@plt>
lea    0xe62(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"helloworld\00"
@.str.1 = [26 x i8] c"strcpy of helloworld %s \0A\00"
@.str.2 = [5 x i8] c"%s \0A\00"
@.str.3 = [26 x i8] c"length of helloworld = %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [12 x i8]
store i32 0, i32* %1
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %2
%4 = load i8*, i8** %2
%5 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%6 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @mystrcpy to i32 (i8*, i8*, ...)*)(i8* %4, i8* %5)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = load i8*, i8** %2
%9 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%10 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @mystrncpy to i32 (i8*, i8*, i32, ...)*)(i8* %8, i8* %9, i32 1)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = load i8*, i8** %2
%13 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%14 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @mystrncpy to i32 (i8*, i8*, i32, ...)*)(i8* %12, i8* %13, i32 0)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = call i32 (i8*, ...) bitcast (i32 (...)* @mystrlen to i32 (i8*, ...)*)(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %16)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"helloworld\00"
@.str.1 = [26 x i8] c"strcpy of helloworld %s \0A\00"
@.str.2 = [5 x i8] c"%s \0A\00"
@.str.3 = [26 x i8] c"length of helloworld = %d\00"
define i32 @main() {
%1 = alloca [12 x i8]
%2 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%3 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @mystrcpy to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @mystrncpy to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %2, i32 1)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @mystrncpy to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %2, i32 0)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = call i32 (i8*, ...) bitcast (i32 (...)* @mystrlen to i32 (i8*, ...)*)(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %9)
ret i32 0
}