#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*/ free(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ strcmp(char *, char *);
char *strdup(char *);
int test_strdup(void) {
  char *str;
  printf("\tstrdup");
  str = strdup("supercalifragilistic");
  if (!str)
    return 1;
  if (strcmp(str, "supercalifragilistic"))
    return 1;
  free(str);
  printf("\tpassed.\n");
  return 0;
}


x86 assembly (clang, -O0):
<test_strdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1040 <printf@plt>
lea    0xead(%rip),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117b <test_strdup+0x3b>
movl   $0x1,-0x4(%rbp)
jmp    11bd <test_strdup+0x7d>
mov    -0x10(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11a1 <test_strdup+0x61>
movl   $0x1,-0x4(%rbp)
jmp    11bd <test_strdup+0x7d>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
lea    0xe6c(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_strdup>:
push   %rbp
push   %rbx
push   %rax
lea    0xea6(%rip),%rdi
call   1050 <printf@plt>
lea    0xea2(%rip),%rdi
call   1070 <strdup@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     11a2 <test_strdup+0x52>
mov    %rax,%rbx
lea    0xe89(%rip),%rsi
mov    %rax,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11a2 <test_strdup+0x52>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe82(%rip),%rdi
call   1040 <puts@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [8 x i8] c"\09strdup\00"
@.str.1 = [21 x i8] c"supercalifragilistic\00"
@str = [9 x i8] c"\09passed.\00"
define i32 @test_strdup() {
%1 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%2 = tail call dereferenceable_or_null(21) i8* @strdup(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %10, label %4
4: ; preds = %0
%5 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = tail call i32 @free(i8* %2)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %10
10: ; preds = %4, %0, %7
%11 = phi i32 [ 0, %7 ], [ 1, %0 ], [ 1, %4 ]
ret i32 %11
}