#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 *_strcat(char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *const);
char *strdup(char *);
void test_strcat(char *const orig_dst, char *const orig_src) {
  char dst[128], src[128];
  strcpy(dst, orig_dst);
  strcpy(src, orig_src);
  char *_dst = strdup(dst);
  char *_src = strdup(src);
  char *_dst_cpy = _dst;
  strcat(dst, src);
  char *_dst_ret = _strcat(_dst, _src);
  if (strcmp(dst, _dst) != 0) {
    do {
      fprintf(stderr, "FAILED (line %d) ", 44);
      fprintf(stderr, "'%s' (strcat) != '%s' (_strcat)", dst, _dst);
      fprintf(stderr, "\n");
      exit(1);
    } while (0);
  }
  if (_dst_ret != _dst_cpy) {
    do {
      fprintf(stderr, "FAILED (line %d) ", 49);
      fprintf(stderr, "incorrect return");
      fprintf(stderr, "\n");
      exit(1);
    } while (0);
  }
}


x86 assembly (clang, -O0):
<test_strcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x90(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x118(%rbp)
lea    -0x110(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x120(%rbp)
mov    -0x118(%rbp),%rax
mov    %rax,-0x128(%rbp)
lea    -0x90(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x118(%rbp),%rdi
mov    -0x120(%rbp),%rsi
call   1060 <_strcat@plt>
mov    %rax,-0x130(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x118(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1288 <test_strcat+0x118>
jmp    1226 <test_strcat+0xb6>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
lea    0xdca(%rip),%rsi
mov    $0x2c,%edx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
lea    -0x90(%rbp),%rdx
mov    -0x118(%rbp),%rcx
lea    0xdb2(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
lea    0xdbb(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x130(%rbp),%rax
cmp    -0x128(%rbp),%rax
je     12f5 <test_strcat+0x185>
jmp    12a1 <test_strcat+0x131>
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
lea    0xd4f(%rip),%rsi
mov    $0x31,%edx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
lea    0xd67(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d05(%rip),%rax
mov    (%rax),%edi
lea    0xd4e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_strcat>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%rbx
mov    %rdi,%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
lea    0x80(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1090 <strdup@plt>
mov    %rax,%r15
mov    %r12,%rdi
call   1090 <strdup@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r12,%rsi
call   1070 <strcat@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <_strcat@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11f5 <test_strcat+0x85>
cmp    %r15,%rbx
jne    1229 <test_strcat+0xb9>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2de4(%rip),%rbx
mov    (%rbx),%edi
lea    0xdfb(%rip),%rsi
mov    $0x2c,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdf8(%rip),%rsi
mov    %rsp,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1255 <test_strcat+0xe5>
mov    0x2db0(%rip),%rbx
mov    (%rbx),%edi
lea    0xdc7(%rip),%rsi
mov    $0x31,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xde6(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdd4(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"FAILED (line %d) \00"
@.str.1 = [32 x i8] c"'%s' (strcat) != '%s' (_strcat)\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [17 x i8] c"incorrect return\00"
define void @test_strcat(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [128 x i8]
%6 = alloca [128 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%12 = load i8*, i8** %3
%13 = call i32 @strcpy(i8* %11, i8* %12)
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%15 = load i8*, i8** %4
%16 = call i32 @strcpy(i8* %14, i8* %15)
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%18 = call i8* @strdup(i8* %17)
store i8* %18, i8** %7
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%20 = call i8* @strdup(i8* %19)
store i8* %20, i8** %8
%21 = load i8*, i8** %7
store i8* %21, i8** %9
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%24 = call i32 @strcat(i8* %22, i8* %23)
%25 = load i8*, i8** %7
%26 = load i8*, i8** %8
%27 = call i8* @_strcat(i8* %25, i8* %26)
store i8* %27, i8** %10
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%29 = load i8*, i8** %7
%30 = call i64 @strcmp(i8* %28, i8* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %44
32: ; preds = %2
br label %33
33: ; preds = %32
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 44)
%36 = load i32, i32* @stderr
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%38 = load i8*, i8** %7
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %37, i8* %38)
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; No predecessors!
br label %44
44: ; preds = %43, %2
%45 = load i8*, i8** %10
%46 = load i8*, i8** %9
%47 = icmp ne i8* %45, %46
br i1 %47, label %48, label %58
48: ; preds = %44
br label %49
49: ; preds = %48
%50 = load i32, i32* @stderr
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 49)
%52 = load i32, i32* @stderr
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; No predecessors!
br label %58
58: ; preds = %57, %44
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"FAILED (line %d) \00"
@.str.1 = [32 x i8] c"'%s' (strcat) != '%s' (_strcat)\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [17 x i8] c"incorrect return\00"
define void @test_strcat(i8* %0, i8* %1) {
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = call i32 @strcpy(i8* %5, i8* %0)
%8 = call i32 @strcpy(i8* %6, i8* %1)
%9 = call i8* @strdup(i8* %5)
%10 = call i8* @strdup(i8* %6)
%11 = call i32 @strcat(i8* %5, i8* %6)
%12 = call i8* @_strcat(i8* %9, i8* %10)
%13 = call i64 @strcmp(i8* %5, i8* %9)
%14 = icmp eq i64 %13, 0
br i1 %14, label %23, label %15
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 44)
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* %9)
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = icmp eq i8* %12, %9
br i1 %24, label %33, label %25
25: ; preds = %23
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 49)
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %23
ret void
}