#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*/ strcat(char *, char const *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int test_strcat(void) {
  const char *str1 = "hello ";
  const char *str2 = "world!";
  char buffer[20];
  printf("\tstrcat");
  strcpy(buffer, str1);
  strcat(buffer, str2);
  if (strcmp(buffer, "hello world!"))
    return 1;
  printf("\tpassed.\n");
  return 0;
}


x86 assembly (clang, -O0):
<test_strcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xeb1(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xebb(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xea2(%rip),%rdi
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcat@plt>
lea    -0x30(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11aa <test_strcat+0x6a>
movl   $0x1,-0x4(%rbp)
jmp    11bd <test_strcat+0x7d>
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_strcat>:
push   %rbx
sub    $0x20,%rsp
lea    0xeab(%rip),%rdi
call   1050 <printf@plt>
lea    0xe98(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe9b(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
lea    0xe86(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    11ac <test_strcat+0x5c>
lea    0xe77(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"hello \00"
@.str.1 = [7 x i8] c"world!\00"
@.str.2 = [8 x i8] c"\09strcat\00"
@.str.3 = [13 x i8] c"hello world!\00"
@.str.4 = [10 x i8] c"\09passed.\0A\00"
define i32 @test_strcat() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [20 x i8]
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %3
%5 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%7 = load i8*, i8** %2
%8 = call i32 @strcpy(i8* %6, i8* %7)
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%10 = load i8*, i8** %3
%11 = call i32 @strcat(i8* %9, i8* %10)
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%13 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %0
store i32 1, i32* %1
br label %18
16: ; preds = %0
%17 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %18
18: ; preds = %16, %15
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@.str = [7 x i8] c"hello \00"
@.str.1 = [7 x i8] c"world!\00"
@.str.2 = [8 x i8] c"\09strcat\00"
@.str.3 = [13 x i8] c"hello world!\00"
@str = [9 x i8] c"\09passed.\00"
define i32 @test_strcat() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%4 = call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @strcat(i8* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%6 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %10
10: ; preds = %0, %8
%11 = phi i32 [ 0, %8 ], [ 1, %0 ]
ret i32 %11
}