#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 */
char *ho_strncat(char *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strncat(char *, char *, int);
int main() {
  char buf[128] = "0123";
  buf[0] = 0;
  printf("%s\n", ho_strncat(buf, "aaa", 2));
  strcpy(buf, "0123");
  buf[0] = 0;
  printf("%s\n", strncat(buf, "aaa", 2));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
movb   $0x30,-0x90(%rbp)
movb   $0x31,-0x8f(%rbp)
movb   $0x32,-0x8e(%rbp)
movb   $0x33,-0x8d(%rbp)
movb   $0x0,-0x90(%rbp)
lea    -0x90(%rbp),%rdi
lea    0xe5e(%rip),%rsi
mov    $0x2,%edx
call   1070 <ho_strncat@plt>
mov    %rax,%rsi
lea    0xe46(%rip),%rdi
call   1040 <printf@plt>
lea    -0x90(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   1030 <strcpy@plt>
movb   $0x0,-0x90(%rbp)
lea    -0x90(%rbp),%rdi
lea    0xe1d(%rip),%rsi
mov    $0x2,%edx
call   1060 <strncat@plt>
mov    %rax,%rsi
lea    0xe05(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movw   $0x3231,0x1(%rsp)
movb   $0x33,0x3(%rsp)
movb   $0x0,(%rsp)
lea    0xe77(%rip),%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
call   1060 <ho_strncat@plt>
lea    0xe59(%rip),%r15
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
lea    0xe4f(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
movb   $0x0,(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
call   1050 <strncat@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [4 x i8] c"aaa\00"
@.str.2 = [5 x i8] c"0123\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [128 x i8]
store i32 0, i32* %1
%3 = bitcast [128 x i8]* %2 to i8*
%4 = bitcast i8* %3 to [128 x i8]*
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i32 0, i32 0
store i8 48, i8* %5
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i32 0, i32 1
store i8 49, i8* %6
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i32 0, i32 2
store i8 50, i8* %7
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i32 0, i32 3
store i8 51, i8* %8
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
store i8 0, i8* %9
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%11 = call i8* @ho_strncat(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 2)
%12 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%14 = call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
store i8 0, i8* %15
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%17 = call i8* @strncat(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 2)
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %17)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [4 x i8] c"aaa\00"
@.str.2 = [5 x i8] c"0123\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 1
store i8 49, i8* %3
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 2
store i8 50, i8* %4
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 3
store i8 51, i8* %5
store i8 0, i8* %2
%6 = call i8* @ho_strncat(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 2)
%7 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i8 0, i8* %2
%9 = call i8* @strncat(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 2)
%10 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %9)
ret i32 0
}