#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 *, ...);
int /*<<< orphan*/ strcat2(char *, char *);
int main() {
  char s[1000] = {'s', 't', 'a', 'r', 't', '\0'};
  char *t = " end";
  printf("strcat2(%s, %s) results in", s, t);
  strcat2(s, t);
  printf(" '%s'\n", s);
  s[0] = '\0';
  t = "hi";
  printf("strcat2(%s, %s) results in", s, t);
  strcat2(s, t);
  printf(" '%s'\n", s);
  s[0] = 'h';
  s[1] = 'i';
  s[2] = '\0';
  t = "";
  printf("strcat2(%s, %s) results in", s, t);
  strcat2(s, t);
  printf(" '%s'\n", s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x3f0(%rbp),%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1050 <memset@plt>
movb   $0x73,-0x3f0(%rbp)
movb   $0x74,-0x3ef(%rbp)
movb   $0x61,-0x3ee(%rbp)
movb   $0x72,-0x3ed(%rbp)
movb   $0x74,-0x3ec(%rbp)
lea    0xe81(%rip),%rax
mov    %rax,-0x3f8(%rbp)
lea    -0x3f0(%rbp),%rsi
mov    -0x3f8(%rbp),%rdx
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x3f0(%rbp),%rdi
mov    -0x3f8(%rbp),%rsi
call   1030 <strcat2@plt>
lea    -0x3f0(%rbp),%rsi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movb   $0x0,-0x3f0(%rbp)
lea    0xe4f(%rip),%rax
mov    %rax,-0x3f8(%rbp)
lea    -0x3f0(%rbp),%rsi
mov    -0x3f8(%rbp),%rdx
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x3f0(%rbp),%rdi
mov    -0x3f8(%rbp),%rsi
call   1030 <strcat2@plt>
lea    -0x3f0(%rbp),%rsi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movb   $0x68,-0x3f0(%rbp)
movb   $0x69,-0x3ef(%rbp)
movb   $0x0,-0x3ee(%rbp)
lea    0xde7(%rip),%rax
mov    %rax,-0x3f8(%rbp)
lea    -0x3f0(%rbp),%rsi
mov    -0x3f8(%rbp),%rdx
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x3f0(%rbp),%rdi
mov    -0x3f8(%rbp),%rsi
call   1030 <strcat2@plt>
lea    -0x3f0(%rbp),%rsi
lea    0xd9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x3e8,%rsp
mov    %rsp,%rbx
mov    $0x3e8,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
movl   $0x72617473,(%rsp)
movb   $0x74,0x4(%rsp)
lea    0xea2(%rip),%r14
lea    0xe96(%rip),%r15
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcat2@plt>
lea    0xe94(%rip),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movb   $0x0,(%rsp)
lea    0xe83(%rip),%r12
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <strcat2@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movw   $0x6968,(%rsp)
movb   $0x0,0x2(%rsp)
lea    0xe48(%rip),%r12
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <strcat2@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c" end\00"
@.str.1 = [27 x i8] c"strcat2(%s, %s) results in\00"
@.str.2 = [7 x i8] c" '%s'\0A\00"
@.str.3 = [3 x i8] c"hi\00"
@.str.4 = [1 x i8] zeroinitializer
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x i8]
%3 = alloca i8*
store i32 0, i32* %1
%4 = bitcast [1000 x i8]* %2 to i8*
%5 = bitcast i8* %4 to <{ i8, i8, i8, i8, i8, [995 x i8] }>*
%6 = getelementptr inbounds <{ i8, i8, i8, i8, i8, [995 x i8] }>, <{ i8, i8, i8, i8, i8, [995 x i8] }>* %5, i32 0, i32 0
store i8 115, i8* %6
%7 = getelementptr inbounds <{ i8, i8, i8, i8, i8, [995 x i8] }>, <{ i8, i8, i8, i8, i8, [995 x i8] }>* %5, i32 0, i32 1
store i8 116, i8* %7
%8 = getelementptr inbounds <{ i8, i8, i8, i8, i8, [995 x i8] }>, <{ i8, i8, i8, i8, i8, [995 x i8] }>* %5, i32 0, i32 2
store i8 97, i8* %8
%9 = getelementptr inbounds <{ i8, i8, i8, i8, i8, [995 x i8] }>, <{ i8, i8, i8, i8, i8, [995 x i8] }>* %5, i32 0, i32 3
store i8 114, i8* %9
%10 = getelementptr inbounds <{ i8, i8, i8, i8, i8, [995 x i8] }>, <{ i8, i8, i8, i8, i8, [995 x i8] }>* %5, i32 0, i32 4
store i8 116, i8* %10
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %3
%11 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%12 = load i8*, i8** %3
%13 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %11, i8* %12)
%14 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%15 = load i8*, i8** %3
%16 = call i32 @strcat2(i8* %14, i8* %15)
%17 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%18 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
store i8 0, i8* %19
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %3
%20 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%21 = load i8*, i8** %3
%22 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %21)
%23 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%24 = load i8*, i8** %3
%25 = call i32 @strcat2(i8* %23, i8* %24)
%26 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%27 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
store i8 104, i8* %28
%29 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 1
store i8 105, i8* %29
%30 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 2
store i8 0, i8* %30
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i8** %3
%31 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%32 = load i8*, i8** %3
%33 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %31, i8* %32)
%34 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%35 = load i8*, i8** %3
%36 = call i32 @strcat2(i8* %34, i8* %35)
%37 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%38 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c" end\00"
@.str.1 = [27 x i8] c"strcat2(%s, %s) results in\00"
@.str.2 = [7 x i8] c" '%s'\0A\00"
@.str.3 = [3 x i8] c"hi\00"
@.str.4 = [1 x i8] zeroinitializer
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
store i8 115, i8* %2
%3 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 1
store i8 116, i8* %3
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 2
store i8 97, i8* %4
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 3
store i8 114, i8* %5
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 4
store i8 116, i8* %6
%7 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @strcat2(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %2)
store i8 0, i8* %2
%10 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 @strcat2(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %2)
store i8 104, i8* %2
store i8 105, i8* %3
store i8 0, i8* %4
%13 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 @strcat2(i8* %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%15 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %2)
ret i32 0
}