int main(void) {
  char s1[1024], s2[1024];
  int n;
  scanf("%s %s %d", s1, s2, &n);
  strncat(s1, s2, n);
  printf("strncat: %s\n", s1);
  printf("strncmp: %d\n", strncmp(s1, s2, n));
  strncpy(s1, s2, n);
  printf("strncpy: %s\n", s1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x410(%rbp),%rsi
lea    -0x810(%rbp),%rdx
lea    0xe89(%rip),%rdi
lea    -0x814(%rbp),%rcx
mov    $0x0,%al
call   1070 <scanf@plt>
lea    -0x410(%rbp),%rdi
lea    -0x810(%rbp),%rsi
movslq -0x814(%rbp),%rdx
call   1060 <strncat@plt>
lea    -0x410(%rbp),%rsi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x410(%rbp),%rdi
lea    -0x810(%rbp),%rsi
movslq -0x814(%rbp),%rdx
call   1040 <strncmp@plt>
mov    %eax,%esi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x410(%rbp),%rdi
lea    -0x810(%rbp),%rsi
movslq -0x814(%rbp),%rdx
call   1030 <strncpy@plt>
lea    -0x410(%rbp),%rsi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x818,%rsp
lea    0xe9f(%rip),%rdi
lea    0x410(%rsp),%rbx
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%rcx
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <scanf@plt>
movslq 0xc(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strncat@plt>
lea    0xe72(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
movslq 0xc(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strncmp@plt>
lea    0xe5e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movslq 0xc(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strncpy@plt>
lea    0xe4b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%s %s %d\00"
@.str.1 = [13 x i8] c"strncat: %s\0A\00"
@.str.2 = [13 x i8] c"strncmp: %d\0A\00"
@.str.3 = [13 x i8] c"strncpy: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %6, i32* %4)
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = call i8* @strncat(i8* %8, i8* %9, i64 %11)
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = call i32 @strncmp(i8* %15, i8* %16, i64 %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = call i8* @strncpy(i8* %21, i8* %22, i64 %24)
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %26)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"%s %s %d\00"
@.str.1 = [13 x i8] c"strncat: %s\0A\00"
@.str.2 = [13 x i8] c"strncmp: %d\0A\00"
@.str.3 = [13 x i8] c"strncpy: %s\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca [1024 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%6 = bitcast i32* %3 to i8*
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %4, i8* %5, i32* %3)
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = call i8* @strncat(i8* %4, i8* %5, i64 %9)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = call i32 @strncmp(i8* %4, i8* %5, i64 %13)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = call i8* @strncpy(i8* %4, i8* %5, i64 %17)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %4)
ret i32 0
}