#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*/ _expect_string_eq(char const *, char *, char *);
int /*<<< orphan*/ _expect_true(int /*<<< orphan*/, char *);
char *az_strdup(char const *);
int /*<<< orphan*/ free(char *);
void test_strdup(void) {
  _expect_true(az_strdup(NULL) == NULL, "az_strdup(NULL) == NULL");
  const char *str = "Hello, world!";
  char *copy = az_strdup(str);
  _expect_string_eq(str, copy, "copy");
  free(copy);
}


x86 assembly (clang, -O0):
<test_strdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %eax,%eax
mov    %eax,%edi
call   1050 <az_strdup@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
lea    0xe9c(%rip),%rsi
call   1060 <_expect_true@plt>
lea    0xea8(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <az_strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xe96(%rip),%rdx
call   1040 <_expect_string_eq@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_strdup>:
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
call   1050 <az_strdup@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
lea    0xea5(%rip),%rsi
call   1060 <_expect_true@plt>
lea    0xeb1(%rip),%r14
mov    %r14,%rdi
call   1050 <az_strdup@plt>
mov    %rax,%rbx
lea    0xead(%rip),%rdx
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <_expect_string_eq@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"az_strdup(NULL) == NULL\00"
@.str.1 = [14 x i8] c"Hello, world!\00"
@.str.2 = [5 x i8] c"copy\00"
define void @test_strdup() {
%1 = alloca i8*
%2 = alloca i8*
%3 = call i8* @az_strdup(i8* null)
%4 = icmp eq i8* %3, null
%5 = zext i1 %4 to i32
%6 = call i32 @_expect_true(i32 %5, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8** %1
%7 = load i8*, i8** %1
%8 = call i8* @az_strdup(i8* %7)
store i8* %8, i8** %2
%9 = load i8*, i8** %1
%10 = load i8*, i8** %2
%11 = call i32 @_expect_string_eq(i8* %9, i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%12 = load i8*, i8** %2
%13 = call i32 @free(i8* %12)
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"az_strdup(NULL) == NULL\00"
@.str.1 = [14 x i8] c"Hello, world!\00"
@.str.2 = [5 x i8] c"copy\00"
define void @test_strdup() {
%1 = tail call i8* @az_strdup(i8* null)
%2 = icmp eq i8* %1, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @_expect_true(i32 %3, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%5 = tail call i8* @az_strdup(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @_expect_string_eq(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @free(i8* %5)
ret void
}