#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 */
typedef int /*<<< orphan*/ src;
typedef int /*<<< orphan*/ dest;

/* Variables and functions */
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char const *, int);
void testStrncat(const char *src) {
  char dest[10];
  strncat(dest, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAA", sizeof(dest) - 1);
  strncat(dest, "AAAAAAAAAAAAAAAAAAAAAAAAAAA", sizeof(dest));
  strncat(dest, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", sizeof(dest) - strlen(dest));
  strncat(dest, src, sizeof(src));
  strncat(dest, "AAAAAAAAAAAAAAAAAAAAAAAAAAA", sizeof(char));
}


x86 assembly (clang, -O0):
<testStrncat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x12(%rbp),%rdi
lea    0xecb(%rip),%rsi
mov    $0x9,%edx
call   1040 <strncat@plt>
lea    -0x12(%rbp),%rdi
lea    0xeb8(%rip),%rsi
mov    $0xa,%edx
call   1040 <strncat@plt>
lea    -0x12(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x12(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rdi
movslq %eax,%rcx
mov    $0xa,%eax
sub    %rcx,%rax
mov    %eax,%edx
lea    0xe81(%rip),%rsi
call   1040 <strncat@plt>
lea    -0x12(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x8,%edx
call   1040 <strncat@plt>
lea    -0x12(%rbp),%rdi
lea    0xe63(%rip),%rsi
mov    $0x1,%edx
call   1040 <strncat@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testStrncat>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
lea    0xece(%rip),%rsi
lea    0xe(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x9,%edx
call   1040 <strncat@plt>
lea    0xeb7(%rip),%r15
mov    $0xa,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0xa,%edx
call   1040 <strncat@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
sub    %eax,%ebp
lea    0xe8d(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <strncat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x8,%edx
call   1040 <strncat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1040 <strncat@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"AAAAAAAAAAAAAAAAAAAAAAAAAAAAA\00"
@.str.1 = [28 x i8] c"AAAAAAAAAAAAAAAAAAAAAAAAAAA\00"
@.str.2 = [32 x i8] c"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\00"
define void @testStrncat(i8* %0) {
%2 = alloca i8*
%3 = alloca [10 x i8]
store i8* %0, i8** %2
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = call i32 @strncat(i8* %4, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 9)
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%7 = call i32 @strncat(i8* %6, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 10)
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%10 = call i32 @strlen(i8* %9)
%11 = sext i32 %10 to i64
%12 = sub i64 10, %11
%13 = trunc i64 %12 to i32
%14 = call i32 @strncat(i8* %8, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%16 = load i8*, i8** %2
%17 = call i32 @strncat(i8* %15, i8* %16, i32 8)
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%19 = call i32 @strncat(i8* %18, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 1)
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"AAAAAAAAAAAAAAAAAAAAAAAAAAAAA\00"
@.str.1 = [28 x i8] c"AAAAAAAAAAAAAAAAAAAAAAAAAAA\00"
@.str.2 = [32 x i8] c"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\00"
define void @testStrncat(i8* %0) {
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%4 = call i32 @strncat(i8* %3, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 9)
%5 = call i32 @strncat(i8* %3, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 10)
%6 = call i32 @strlen(i8* %3)
%7 = sub i32 10, %6
%8 = call i32 @strncat(i8* %3, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = call i32 @strncat(i8* %3, i8* %0, i32 8)
%10 = call i32 @strncat(i8* %3, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 1)
ret void
}