#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*/ alloc_test_free(char *);
int alloc_test_get_allocated();
int /*<<< orphan*/ alloc_test_set_limit(int);
char *alloc_test_strdup(char *);
int /*<<< orphan*/ assert(int);
scalar_t__ strcmp(char *, char *);
void test_strdup(void) {
  char *str;
  assert(alloc_test_get_allocated() == 0);
  str = alloc_test_strdup("hello world");
  assert(str != NULL);
  assert(strcmp(str, "hello world") == 0);
  assert(alloc_test_get_allocated() == 12);
  alloc_test_free(str);
  assert(alloc_test_get_allocated() == 0);
  alloc_test_set_limit(1);
  str = alloc_test_strdup("hello world");
  assert(str != NULL);
  assert(alloc_test_get_allocated() == 12);
  assert(alloc_test_strdup("hello world") == NULL);
  assert(alloc_test_get_allocated() == 12);
  alloc_test_free(str);
}


x86 assembly (clang, -O0):
<test_strdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1050 <alloc_test_get_allocated@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xe7a(%rip),%rdi
call   1080 <alloc_test_strdup@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0x0,%al
call   1050 <alloc_test_get_allocated@plt>
cmp    $0xc,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1040 <alloc_test_free@plt>
mov    $0x0,%al
call   1050 <alloc_test_get_allocated@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0x1,%edi
call   1030 <alloc_test_set_limit@plt>
lea    0xdf6(%rip),%rdi
call   1080 <alloc_test_strdup@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0x0,%al
call   1050 <alloc_test_get_allocated@plt>
cmp    $0xc,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xdbd(%rip),%rdi
call   1080 <alloc_test_strdup@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0x0,%al
call   1050 <alloc_test_get_allocated@plt>
cmp    $0xc,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1040 <alloc_test_free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_strdup>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <alloc_test_get_allocated@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
lea    0xe81(%rip),%r14
mov    %r14,%rdi
call   1080 <alloc_test_strdup@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1070 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
xor    %eax,%eax
call   1050 <alloc_test_get_allocated@plt>
xor    %edi,%edi
cmp    $0xc,%eax
sete   %dil
call   1070 <assert@plt>
mov    %rbx,%rdi
call   1040 <alloc_test_free@plt>
xor    %eax,%eax
call   1050 <alloc_test_get_allocated@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
mov    $0x1,%edi
call   1030 <alloc_test_set_limit@plt>
mov    %r14,%rdi
call   1080 <alloc_test_strdup@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1070 <assert@plt>
xor    %eax,%eax
call   1050 <alloc_test_get_allocated@plt>
xor    %edi,%edi
cmp    $0xc,%eax
sete   %dil
call   1070 <assert@plt>
mov    %r14,%rdi
call   1080 <alloc_test_strdup@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
xor    %eax,%eax
call   1050 <alloc_test_get_allocated@plt>
xor    %edi,%edi
cmp    $0xc,%eax
sete   %dil
call   1070 <assert@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <alloc_test_free@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"hello world\00"
define void @test_strdup() {
%1 = alloca i8*
%2 = call i32 (...) @alloc_test_get_allocated()
%3 = icmp eq i32 %2, 0
%4 = zext i1 %3 to i32
%5 = call i32 @assert(i32 %4)
%6 = call i8* @alloc_test_strdup(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %1
%7 = load i8*, i8** %1
%8 = icmp ne i8* %7, null
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i8*, i8** %1
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = call i32 (...) @alloc_test_get_allocated()
%17 = icmp eq i32 %16, 12
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i8*, i8** %1
%21 = call i32 @alloc_test_free(i8* %20)
%22 = call i32 (...) @alloc_test_get_allocated()
%23 = icmp eq i32 %22, 0
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = call i32 @alloc_test_set_limit(i32 1)
%27 = call i8* @alloc_test_strdup(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %27, i8** %1
%28 = load i8*, i8** %1
%29 = icmp ne i8* %28, null
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = call i32 (...) @alloc_test_get_allocated()
%33 = icmp eq i32 %32, 12
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = call i8* @alloc_test_strdup(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%37 = icmp eq i8* %36, null
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = call i32 (...) @alloc_test_get_allocated()
%41 = icmp eq i32 %40, 12
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = load i8*, i8** %1
%45 = call i32 @alloc_test_free(i8* %44)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"hello world\00"
define void @test_strdup() {
%1 = tail call i32 (...) @alloc_test_get_allocated()
%2 = icmp eq i32 %1, 0
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i8* @alloc_test_strdup(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%6 = icmp ne i8* %5, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = tail call i32 (...) @alloc_test_get_allocated()
%14 = icmp eq i32 %13, 12
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = tail call i32 @alloc_test_free(i8* %5)
%18 = tail call i32 (...) @alloc_test_get_allocated()
%19 = icmp eq i32 %18, 0
%20 = zext i1 %19 to i32
%21 = tail call i32 @assert(i32 %20)
%22 = tail call i32 @alloc_test_set_limit(i32 1)
%23 = tail call i8* @alloc_test_strdup(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%24 = icmp ne i8* %23, null
%25 = zext i1 %24 to i32
%26 = tail call i32 @assert(i32 %25)
%27 = tail call i32 (...) @alloc_test_get_allocated()
%28 = icmp eq i32 %27, 12
%29 = zext i1 %28 to i32
%30 = tail call i32 @assert(i32 %29)
%31 = tail call i8* @alloc_test_strdup(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%32 = icmp eq i8* %31, null
%33 = zext i1 %32 to i32
%34 = tail call i32 @assert(i32 %33)
%35 = tail call i32 (...) @alloc_test_get_allocated()
%36 = icmp eq i32 %35, 12
%37 = zext i1 %36 to i32
%38 = tail call i32 @assert(i32 %37)
%39 = tail call i32 @alloc_test_free(i8* %23)
ret void
}