int main(void) {
  char str1[6] = "hello";
  char str2[6] = "world";
  char str3[12] = "hello ";
  _strncpy(str1, str2, 4);
  printf("strncpy() result = \'%s\', \'%s\'\n", str1, str2);
  printf("strncmp() positive result = %d\n", _strncmp("12354", "12345", 3));
  printf("strncmp() non-positive result = %d\n", _strncmp("12354", "12345", 4));
  _strncat(str3, str2, 4);
  printf("strncat() result = \'%s\'\n", str3);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeab(%rip),%eax
mov    %eax,-0xa(%rbp)
mov    0xea5(%rip),%ax
mov    %ax,-0x6(%rbp)
mov    0xe9d(%rip),%eax
mov    %eax,-0x10(%rbp)
mov    0xe97(%rip),%ax
mov    %ax,-0xc(%rbp)
mov    0xf16(%rip),%rax
mov    %rax,-0x1c(%rbp)
mov    0xf14(%rip),%eax
mov    %eax,-0x14(%rbp)
lea    -0xa(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1060 <_strncpy@plt>
lea    -0xa(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe8f(%rip),%rdi
lea    0xe8e(%rip),%rsi
mov    $0x3,%edx
mov    $0x0,%al
call   1030 <_strncmp@plt>
mov    %eax,%esi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe65(%rip),%rdi
lea    0xe64(%rip),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <_strncmp@plt>
mov    %eax,%esi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1c(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1050 <_strncat@plt>
lea    -0x1c(%rbp),%rsi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
movw   $0x6f,0xc(%rsp)
movl   $0x6c6c6568,0x8(%rsp)
6c
movw   $0x64,0x4(%rsp)
movl   $0x6c726f77,(%rsp)
movabs $0x206f6c6c6568,%rax
mov    %rax,0x10(%rsp)
movl   $0x0,0x18(%rsp)
lea    0x8(%rsp),%rbx
mov    %rsp,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1060 <_strncpy@plt>
lea    0xe6e(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe99(%rip),%rbx
lea    0xe98(%rip),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
xor    %eax,%eax
call   1030 <_strncmp@plt>
lea    0xe59(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1030 <_strncmp@plt>
lea    0xe63(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1050 <_strncat@plt>
lea    0xe60(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.str1 = [6 x i8] c"hello\00"
@__const.main.str2 = [6 x i8] c"world\00"
@__const.main.str3 = [12 x i8] c"hello \00\00\00\00\00\00"
@.str = [31 x i8] c"strncpy() result = '%s', '%s'\0A\00"
@.str.1 = [32 x i8] c"strncmp() positive result = %d\0A\00"
@.str.2 = [6 x i8] c"12354\00"
@.str.3 = [6 x i8] c"12345\00"
@.str.4 = [36 x i8] c"strncmp() non-positive result = %d\0A\00"
@.str.5 = [25 x i8] c"strncat() result = '%s'\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [6 x i8]
%3 = alloca [6 x i8]
%4 = alloca [12 x i8]
store i32 0, i32* %1
%5 = bitcast [6 x i8]* %2 to i8*
%6 = bitcast [6 x i8]* %3 to i8*
%7 = bitcast [12 x i8]* %4 to i8*
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%10 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @_strncpy to i32 (i8*, i8*, i32, ...)*)(i8* %8, i8* %9, i32 4)
%11 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%12 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %12)
%14 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @_strncmp to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 3)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @_strncmp to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 4)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 0
%19 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%20 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @_strncat to i32 (i8*, i8*, i32, ...)*)(i8* %18, i8* %19, i32 4)
%21 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %21)
ret i32 0
}

LLVM IR (-O2):
@__const.main.str1 = [6 x i8] c"hello\00"
@__const.main.str2 = [6 x i8] c"world\00"
@__const.main.str3 = [12 x i8] c"hello \00\00\00\00\00\00"
@.str = [31 x i8] c"strncpy() result = '%s', '%s'\0A\00"
@.str.1 = [32 x i8] c"strncmp() positive result = %d\0A\00"
@.str.2 = [6 x i8] c"12354\00"
@.str.3 = [6 x i8] c"12345\00"
@.str.4 = [36 x i8] c"strncmp() non-positive result = %d\0A\00"
@.str.5 = [25 x i8] c"strncat() result = '%s'\0A\00"
define i32 @main() {
%1 = alloca [6 x i8]
%2 = alloca [6 x i8]
%3 = alloca [12 x i8]
%4 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%7 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @_strncpy to i32 (i8*, i8*, i32, ...)*)(i8* %4, i8* %5, i32 4)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %4, i8* %5)
%9 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @_strncmp to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 3)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @_strncmp to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 4)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 %11)
%13 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @_strncat to i32 (i8*, i8*, i32, ...)*)(i8* %6, i8* %5, i32 4)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %6)
ret i32 0
}