int main() {
  char foo[50] = "Meepineeeeeessssss";
  char *bar = "Merpy";
  printf("strn_cpy: %s\n", strn_cpy(foo, bar, 9));
  if (foo[8] == '\0' && foo[14] != '\0') {
    printf("strn_cpy works as expected.\n");
  }
  bar = " hai";
  printf("strn_cat: %s\n", strn_cat(foo, bar, 9));
  printf("strn_cmp: %d\n", strn_cmp(bar, "hai lits", 10));
  printf("strn_cmp: %d\n", strn_cmp(bar, "no", 10));
  printf("strn_cmp: %d\n", strn_cmp(bar, "derp", 10));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe96(%rip),%rsi
mov    $0x32,%edx
call   1060 <memcpy@plt>
lea    0xeb7(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    $0x9,%edx
mov    $0x0,%al
call   1050 <strn_cpy@plt>
mov    %eax,%esi
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsbl -0x38(%rbp),%eax
cmp    $0x0,%eax
jne    11cb <main+0x7b>
movsbl -0x32(%rbp),%eax
cmp    $0x0,%eax
je     11cb <main+0x7b>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe91(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    $0x9,%edx
mov    $0x0,%al
call   1070 <strn_cat@plt>
mov    %eax,%esi
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x48(%rbp),%rdi
lea    0xe7f(%rip),%rsi
mov    $0xa,%edx
mov    $0x0,%al
call   1030 <strn_cmp@plt>
mov    %eax,%esi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x48(%rbp),%rdi
lea    0xe61(%rip),%rsi
mov    $0xa,%edx
mov    $0x0,%al
call   1030 <strn_cmp@plt>
mov    %eax,%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x48(%rbp),%rdi
lea    0xe3d(%rip),%rsi
mov    $0xa,%edx
mov    $0x0,%al
call   1030 <strn_cmp@plt>
mov    %eax,%esi
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
movaps 0xec2(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xea6(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe8a(%rip),%xmm0
movaps %xmm0,(%rsp)
movw   $0x0,0x30(%rsp)
lea    0xeaa(%rip),%rsi
mov    %rsp,%rdi
mov    $0x9,%edx
xor    %eax,%eax
call   1060 <strn_cpy@plt>
lea    0xe9a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmpb   $0x0,0x8(%rsp)
jne    11c1 <main+0x71>
cmpb   $0x0,0xe(%rsp)
je     11c1 <main+0x71>
lea    0xebc(%rip),%rdi
call   1040 <puts@plt>
lea    0xe7e(%rip),%r14
mov    %rsp,%rdi
mov    %r14,%rsi
mov    $0x9,%edx
xor    %eax,%eax
call   1070 <strn_cat@plt>
lea    0xe6a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe76(%rip),%rsi
mov    %r14,%rdi
mov    $0xa,%edx
xor    %eax,%eax
call   1030 <strn_cmp@plt>
lea    0xe52(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe56(%rip),%rsi
mov    %r14,%rdi
mov    $0xa,%edx
xor    %eax,%eax
call   1030 <strn_cmp@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe37(%rip),%rsi
mov    %r14,%rdi
mov    $0xa,%edx
xor    %eax,%eax
call   1030 <strn_cmp@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.foo = [50 x i8] c"Meepineeeeeessssss\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [6 x i8] c"Merpy\00"
@.str.1 = [14 x i8] c"strn_cpy: %s\0A\00"
@.str.2 = [29 x i8] c"strn_cpy works as expected.\0A\00"
@.str.3 = [5 x i8] c" hai\00"
@.str.4 = [14 x i8] c"strn_cat: %s\0A\00"
@.str.5 = [14 x i8] c"strn_cmp: %d\0A\00"
@.str.6 = [9 x i8] c"hai lits\00"
@.str.7 = [3 x i8] c"no\00"
@.str.8 = [5 x i8] c"derp\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [50 x i8]
%3 = alloca i8*
store i32 0, i32* %1
%4 = bitcast [50 x i8]* %2 to i8*
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %3
%5 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%6 = load i8*, i8** %3
%7 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @strn_cpy to i32 (i8*, i8*, i32, ...)*)(i8* %5, i8* %6, i32 9)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 8
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %0
%14 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 14
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %13, %0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %3
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%22 = load i8*, i8** %3
%23 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @strn_cat to i32 (i8*, i8*, i32, ...)*)(i8* %21, i8* %22, i32 9)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %23)
%25 = load i8*, i8** %3
%26 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @strn_cmp to i32 (i8*, i8*, i32, ...)*)(i8* %25, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 10)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %26)
%28 = load i8*, i8** %3
%29 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @strn_cmp to i32 (i8*, i8*, i32, ...)*)(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 10)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %29)
%31 = load i8*, i8** %3
%32 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @strn_cmp to i32 (i8*, i8*, i32, ...)*)(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 10)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %32)
ret i32 0
}

LLVM IR (-O2):
@__const.main.foo = [50 x i8] c"Meepineeeeeessssss\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [6 x i8] c"Merpy\00"
@.str.1 = [14 x i8] c"strn_cpy: %s\0A\00"
@.str.3 = [5 x i8] c" hai\00"
@.str.4 = [14 x i8] c"strn_cat: %s\0A\00"
@.str.5 = [14 x i8] c"strn_cmp: %d\0A\00"
@.str.6 = [9 x i8] c"hai lits\00"
@.str.7 = [3 x i8] c"no\00"
@.str.8 = [5 x i8] c"derp\00"
@str = [28 x i8] c"strn_cpy works as expected.\00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%3 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @strn_cpy to i32 (i8*, i8*, i32, ...)*)(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 9)
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 8
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 14
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
%11 = select i1 %7, i1 %10, i1 false
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %14
14: ; preds = %12, %0
%15 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @strn_cat to i32 (i8*, i8*, i32, ...)*)(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 9)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %15)
%17 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @strn_cmp to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 10)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %17)
%19 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @strn_cmp to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 10)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %19)
%21 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @strn_cmp to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 10)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %21)
ret i32 0
}