#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*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ stderr;
int strcmp(char *, char const *);
char *strdupcat(char const *, char const *);
int test_strdupcat(const char *a, const char *b, const char *expected) {
  char *str;
  str = strdupcat(a, b);
  do {
    if ((str) == (NULL)) {
      fprintf(stderr, "failed on line %d: %s\n", 195, "str");
      return 1;
    }
  } while (0);
  ;
  do {
    int __my_ret__ = strcmp(str, expected);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 196, "strcmp(str, expected)");
      return __my_ret__;
    }
  } while (0);
  ;
  free(str);
  return 0;
}


x86 assembly (clang, -O0):
<test_strdupcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strdupcat@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119d <test_strdupcat+0x5d>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
mov    $0xc3,%edx
lea    0xe8b(%rip),%rcx
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1202 <test_strdupcat+0xc2>
jmp    11a2 <test_strdupcat+0x62>
jmp    11a7 <test_strdupcat+0x67>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strcmp@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11ed <test_strdupcat+0xad>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
mov    $0xc4,%edx
lea    0xe3e(%rip),%rcx
call   1060 <fprintf@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1202 <test_strdupcat+0xc2>
jmp    11f2 <test_strdupcat+0xb2>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_strdupcat>:
push   %rbp
push   %rbx
push   %rax
mov    %rdx,%rbp
call   1040 <strdupcat@plt>
test   %rax,%rax
je     1187 <test_strdupcat+0x47>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11af <test_strdupcat+0x6f>
mov    %eax,%ebp
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
lea    0xe8c(%rip),%rsi
lea    0xea0(%rip),%rcx
mov    $0xc4,%edx
call   1060 <fprintf@plt>
jmp    11b9 <test_strdupcat+0x79>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
lea    0xe79(%rip),%rcx
mov    $0xc3,%edx
call   1060 <fprintf@plt>
mov    $0x1,%ebp
jmp    11b9 <test_strdupcat+0x79>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"failed on line %d: %s\0A\00"
@.str.1 = [4 x i8] c"str\00"
@.str.2 = [22 x i8] c"strcmp(str, expected)\00"
define i32 @test_strdupcat(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %5
%11 = load i8*, i8** %6
%12 = call i8* @strdupcat(i8* %10, i8* %11)
store i8* %12, i8** %8
br label %13
13: ; preds = %3
%14 = load i8*, i8** %8
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 195, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %4
br label %35
19: ; preds = %13
br label %20
20: ; preds = %19
br label %21
21: ; preds = %20
%22 = load i8*, i8** %8
%23 = load i8*, i8** %7
%24 = call i32 @strcmp(i8* %22, i8* %23)
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 196, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* %9
store i32 %30, i32* %4
br label %35
31: ; preds = %21
br label %32
32: ; preds = %31
%33 = load i8*, i8** %8
%34 = call i32 @free(i8* %33)
store i32 0, i32* %4
br label %35
35: ; preds = %32, %27, %16
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"failed on line %d: %s\0A\00"
@.str.1 = [4 x i8] c"str\00"
@.str.2 = [22 x i8] c"strcmp(str, expected)\00"
define i32 @test_strdupcat(i8* %0, i8* %1, i8* nocapture %2) {
%4 = tail call i8* @strdupcat(i8* %0, i8* %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 195, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %17
9: ; preds = %3
%10 = tail call i32 @strcmp(i8* %4, i8* dereferenceable(1) %2)
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 196, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %17
15: ; preds = %9
%16 = tail call i32 @free(i8* %4)
br label %17
17: ; preds = %12, %15, %6
%18 = phi i32 [ 1, %6 ], [ 0, %15 ], [ %10, %12 ]
ret i32 %18
}