#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;
  else
    printf(".");
  printf(" passed.\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    11c9 <test_strcat+0x89>
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
lea    0xe61(%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    0xe9b(%rip),%rdi
call   1060 <printf@plt>
lea    0xe88(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
lea    0xe76(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    11c6 <test_strcat+0x66>
mov    $0x2e,%edi
call   1030 <putchar@plt>
lea    0xe5d(%rip),%rdi
call   1050 <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 = [2 x i8] c".\00"
@.str.5 = [10 x i8] c" passed.\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 %20
16: ; preds = %0
%17 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %18
18: ; preds = %16
%19 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
br label %20
20: ; preds = %18, %15
%21 = load i32, i32* %1
ret i32 %21
}

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" passed.\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 %11
8: ; preds = %0
%9 = call i32 @putchar(i32 46)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %11
11: ; preds = %0, %8
%12 = phi i32 [ 0, %8 ], [ 1, %0 ]
ret i32 %12
}