#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*/ abort();
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
char *strdup(char const *);
char *utils_strdup(const char *str) {
  char *ptr = NULL;
  assert(str != NULL);
  if (str) {
    ptr = strdup(str);
    if (!ptr) {
      fprintf(stderr, "strdup() failed.\n");
      abort();
    }
  }
  return ptr;
}


x86 assembly (clang, -O0):
<utils_strdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x8(%rbp)
je     11aa <utils_strdup+0x6a>
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a5 <utils_strdup+0x65>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    11aa <utils_strdup+0x6a>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utils_strdup>:
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1040 <assert@plt>
test   %rbx,%rbx
je     1166 <utils_strdup+0x26>
mov    %rbx,%rdi
call   1060 <strdup@plt>
test   %rax,%rax
je     116a <utils_strdup+0x2a>
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
lea    0xe86(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"strdup() failed.\0A\00"
define i8* @utils_strdup(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %3
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = load i8*, i8** %2
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %20
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i8* @strdup(i8* %11)
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = icmp ne i8* %13, null
br i1 %14, label %19, label %15
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%18 = call i32 (...) @abort()
unreachable
19: ; preds = %10
br label %20
20: ; preds = %19, %1
%21 = load i8*, i8** %3
ret i8* %21
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"strdup() failed.\0A\00"
define noalias i8* @utils_strdup(i8* %0) {
%2 = icmp ne i8* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
br i1 %2, label %5, label %12
5: ; preds = %1
%6 = tail call i8* @strdup(i8* %0)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 (...) @abort()
unreachable
12: ; preds = %5, %1
%13 = phi i8* [ %6, %5 ], [ null, %1 ]
ret i8* %13
}