#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 *ft_strncat(char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
char *strdup(char *);
int main(int ac, char **av) {
  printf("-----------------------\n");
  printf("         strncat        \n");
  printf("-----------------------\n");
  char *a = strdup("abc");
  char *b = strdup("DEF");
  printf("s1 = '%s'\n", a);
  printf("s2 = '%s'\n", b);
  printf("   =>  str = ft_strncat(s1, s2, 1)\n");
  printf("       str = '%s'\n", (a = ft_strncat(a, b, 1)));
  printf("       str[5] = %d", a[5]);
  printf("\n\n");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebc(%rip),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x18(%rbp)
lea    0xeb0(%rip),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1040 <ft_strncat@plt>
mov    %rax,%rsi
mov    %rsi,-0x18(%rbp)
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
movsbl 0x5(%rax),%esi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xf12(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xeea(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xe92(%rip),%rdi
call   1060 <strdup@plt>
mov    %rax,%r14
lea    0xe87(%rip),%rdi
call   1060 <strdup@plt>
mov    %rax,%rbx
lea    0xe7c(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe76(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec7(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <ft_strncat@plt>
mov    %rax,%rbx
lea    0xe51(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0x5(%rbx),%esi
lea    0xe4f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe21(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str.2 = [4 x i8] c"abc\00"
@.str.3 = [4 x i8] c"DEF\00"
@.str.4 = [11 x i8] c"s1 = '%s'\0A\00"
@.str.5 = [11 x i8] c"s2 = '%s'\0A\00"
@.str.7 = [19 x i8] c" str = '%s'\0A\00"
@.str.8 = [19 x i8] c" str[5] = %d\00"
@str.10 = [25 x i8] c" strncat \00"
@str.11 = [24 x i8] c"-----------------------\00"
@str.12 = [35 x i8] c" => str = ft_strncat(s1, s2, 1)\00"
@str.13 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.11, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.10, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.11, i64 0, i64 0))
%6 = tail call dereferenceable_or_null(4) i8* @strdup(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call dereferenceable_or_null(4) i8* @strdup(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %7)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.12, i64 0, i64 0))
%11 = tail call i8* @ft_strncat(i8* %6, i8* %7, i32 1)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds i8, i8* %11, i64 5
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i32 %15)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.13, i64 0, i64 0))
ret i32 0
}