#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*/ fprintf(int /*<<< orphan*/, char *, char *, int,
                           char const *);
int /*<<< orphan*/ stderr;
char *strdup(char const *);
char *helper_strdup(const char *str, char *file, int line, const char *fn) {
  char *result;
  result = strdup(str);
  if (!result) {
    fprintf(stderr, "Out of memory in strdup() at %s:%i [%s]\n", file, line,
            fn);
    abort();
  }
  return result;
}


x86 assembly (clang, -O0):
<helper_strdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1186 <helper_strdup+0x56>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x20(%rbp),%r8
lea    0xe86(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<helper_strdup>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %edx,%ebp
mov    %rsi,%rbx
call   1050 <strdup@plt>
test   %rax,%rax
je     114b <helper_strdup+0x1b>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
lea    0xea5(%rip),%rsi
mov    %rbx,%rdx
mov    %ebp,%ecx
mov    %r14,%r8
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [41 x i8] c"Out of memory in strdup() at %s:%i [%s]\0A\00"
define noalias i8* @helper_strdup(i8* nocapture %0, i8* %1, i32 %2, i8* %3) {
%5 = tail call i8* @strdup(i8* %0)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %2, i8* %3)
%10 = tail call i32 (...) @abort()
unreachable
11: ; preds = %4
ret i8* %5
}