#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 *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *strncat(char *, char *, scalar_t__);
int main() {
  char src[50], dest[50];
  strcpy(src, "This is source");
  strcpy(dest, "This is destination");
  printf("%d\n", (int)strlen(src));
  int old = (int)strlen(dest);
  printf("%d\n", old);
  if (dest[old] == '\0') {
    printf("NULL\n");
  }
  char *str = strncat(dest, src, strlen(src));
  printf("%s\n", dest);
  printf("%s\n", str);
  printf("%d\n", str == dest);
  printf("%d == %d == %d\n", (int)strlen(dest), (int)strlen(str),
         (int)(old + strlen(src)));
  printf("%c\n", str[old]);
  printf("%s\n", &str[old]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xea3(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x80(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%esi
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%esi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movslq -0x84(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
cmp    $0x0,%eax
jne    11d1 <main+0x91>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x80(%rbp),%rax
mov    %rax,-0xb0(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0xa8(%rbp)
lea    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xb0(%rbp),%rdi
mov    -0xa8(%rbp),%rsi
mov    %rax,%rdx
call   1060 <strncat@plt>
mov    %rax,-0x90(%rbp)
lea    -0x80(%rbp),%rsi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x90(%rbp),%rsi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x90(%rbp),%rax
lea    -0x80(%rbp),%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xa0(%rbp)
mov    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x9c(%rbp)
movslq -0x84(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xa0(%rbp),%esi
mov    -0x9c(%rbp),%edx
mov    %rax,%rcx
mov    -0x98(%rbp),%rax
add    %rcx,%rax
mov    %eax,%ecx
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x90(%rbp),%rax
movslq -0x84(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xd6b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x90(%rbp),%rsi
movslq -0x84(%rbp),%rax
add    %rax,%rsi
lea    0xd38(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x78,%rsp
lea    0xe9e(%rip),%rsi
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe99(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0xe9f(%rip),%r15
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %rax,%r12
mov    %r15,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
movslq %r12d,%rax
lea    (%rsp,%rax,1),%r14
cmpb   $0x0,(%rsp,%rax,1)
jne    11cd <main+0x7d>
lea    0xe6f(%rip),%rdi
call   1040 <puts@plt>
lea    0x40(%rsp),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1070 <strncat@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0xe2d(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    (%r12,%rax,1),%ecx
lea    0xdf7(%rip),%rdi
mov    %ebx,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <printf@plt>
movsbl (%r14),%esi
lea    0xdf1(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"This is source\00"
@.str.1 = [20 x i8] c"This is destination\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [6 x i8] c"NULL\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [16 x i8] c"%d == %d == %d\0A\00"
@.str.6 = [4 x i8] c"%c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [50 x i8]
%3 = alloca [50 x i8]
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %1
%6 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%7 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%10 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%11 = call i64 @strlen(i8* %10)
%12 = trunc i64 %11 to i32
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%15 = call i64 @strlen(i8* %14)
%16 = trunc i64 %15 to i32
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %25, %0
%28 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%29 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%30 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%31 = call i64 @strlen(i8* %30)
%32 = call i8* @strncat(i8* %28, i8* %29, i64 %31)
store i8* %32, i8** %5
%33 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %33)
%35 = load i8*, i8** %5
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %35)
%37 = load i8*, i8** %5
%38 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%39 = icmp eq i8* %37, %38
%40 = zext i1 %39 to i32
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %40)
%42 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%43 = call i64 @strlen(i8* %42)
%44 = trunc i64 %43 to i32
%45 = load i8*, i8** %5
%46 = call i64 @strlen(i8* %45)
%47 = trunc i64 %46 to i32
%48 = load i32, i32* %4
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%51 = call i64 @strlen(i8* %50)
%52 = add nsw i64 %49, %51
%53 = trunc i64 %52 to i32
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %44, i32 %47, i32 %53)
%55 = load i8*, i8** %5
%56 = load i32, i32* %4
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %60)
%62 = load i8*, i8** %5
%63 = load i32, i32* %4
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %65)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"This is source\00"
@.str.1 = [20 x i8] c"This is destination\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.5 = [16 x i8] c"%d == %d == %d\0A\00"
@.str.6 = [4 x i8] c"%c\0A\00"
@str = [5 x i8] c"NULL\00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = alloca [50 x i8]
%3 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%5 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%7 = call i64 @strlen(i8* %3)
%8 = trunc i64 %7 to i32
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = call i64 @strlen(i8* %4)
%11 = trunc i64 %10 to i32
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = shl i64 %10, 32
%14 = ashr exact i64 %13, 32
%15 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %0
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
br label %20
20: ; preds = %18, %0
%21 = call i64 @strlen(i8* %3)
%22 = call i8* @strncat(i8* %4, i8* %3, i64 %21)
%23 = call i32 @puts(i8* %4)
%24 = call i32 @puts(i8* %4)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 1)
%26 = call i64 @strlen(i8* %4)
%27 = trunc i64 %26 to i32
%28 = call i64 @strlen(i8* %3)
%29 = add i64 %28, %10
%30 = trunc i64 %29 to i32
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %27, i32 %27, i32 %30)
%32 = load i8, i8* %15
%33 = sext i8 %32 to i32
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %33)
%35 = call i32 @puts(i8* %15)
ret i32 0
}