#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char const *, char const *, size_t, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int /*<<< orphan*/ strlen(char const *);
int /*<<< orphan*/ x_strncat(char *, char const *, size_t);
void strncat_test(const char *dst, const char *src, size_t size) {
  char buffer[strlen(dst) + size + 1];
  strcpy(buffer, dst);
  x_strncat(buffer, src, size);
  printf("strncat (%s %s, %lu) = \"%s\"\n", dst, src, size, buffer);
}


x86 assembly (clang, -O0):
<strncat_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
movslq %eax,%rcx
mov    -0x18(%rbp),%rdx
lea    0x1(%rcx,%rdx,1),%rax
mov    %rsp,%rsi
mov    %rsi,-0x20(%rbp)
lea    0x10(%rcx,%rdx,1),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <x_strncat@plt>
mov    -0x30(%rbp),%r8
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe45(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strncat_test>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
call   1040 <strlen@plt>
cltq
add    %r15,%rax
add    $0x10,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <x_strncat@plt>
lea    0xe71(%rip),%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %rbx,%r8
call   1050 <printf@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"strncat (%s %s, %lu) = \22%s\22\0A\00"
define void @strncat_test(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = sext i32 %10 to i64
%12 = load i64, i64* %6
%13 = add i64 %11, %12
%14 = add i64 %13, 1
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %7
%16 = alloca i8, i64 %14
store i64 %14, i64* %8
%17 = load i8*, i8** %4
%18 = call i32 @strcpy(i8* %16, i8* %17)
%19 = load i8*, i8** %5
%20 = load i64, i64* %6
%21 = call i32 @x_strncat(i8* %16, i8* %19, i64 %20)
%22 = load i8*, i8** %4
%23 = load i8*, i8** %5
%24 = load i64, i64* %6
%25 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %22, i8* %23, i64 %24, i8* %16)
%26 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"strncat (%s %s, %lu) = \22%s\22\0A\00"
define void @strncat_test(i8* %0, i8* %1, i64 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = sext i32 %4 to i64
%6 = add i64 %2, 1
%7 = add i64 %6, %5
%8 = alloca i8, i64 %7
%9 = call i32 @strcpy(i8* %8, i8* %0)
%10 = call i32 @x_strncat(i8* %8, i8* %1, i64 %2)
%11 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i64 %2, i8* %8)
ret void
}