#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*/ EXIT_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           int /*<<< orphan*/, char const *, unsigned int,
                           int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strdup(char const *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char const *);
char *wrap_strdup(const char *s, const char *file, unsigned int line,
                  const char *func) {
  char *p = strdup(s);
  if (NULL == p) {
    fprintf(stderr, "[%s] Failed to allocate %zd bytes at %s line %u: %s\n",
            func, strlen(s), file, line, strerror(errno));
    exit(EXIT_FAILURE);
  }
  return p;
}


x86 assembly (clang, -O0):
<wrap_strdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    11eb <wrap_strdup+0x9b>
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    -0x3c(%rbp),%ecx
mov    -0x38(%rbp),%r8
mov    -0x2c(%rbp),%r9d
lea    0xe2b(%rip),%rsi
mov    %eax,(%rsp)
call   1040 <fprintf@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x28(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wrap_strdup>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%rbp
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbx
call   1060 <strdup@plt>
test   %rax,%rax
je     117f <wrap_strdup+0x2f>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e5a(%rip),%rax
mov    (%rax),%r12d
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,(%rsp)
lea    0xe55(%rip),%rsi
mov    %r12d,%edi
mov    %rbp,%rdx
mov    %ebx,%ecx
mov    %r15,%r8
mov    %r14d,%r9d
call   1040 <fprintf@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [53 x i8] c"[%s] Failed to allocate %zd bytes at %s line %u: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i8* @wrap_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 eq i8* null, %12
br i1 %13, label %14, label %26
14: ; preds = %4
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %8
%17 = load i8*, i8** %5
%18 = call i32 @strlen(i8* %17)
%19 = load i8*, i8** %6
%20 = load i32, i32* %7
%21 = load i32, i32* @errno
%22 = call i32 @strerror(i32 %21)
%23 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %16, i32 %18, i8* %19, i32 %20, i32 %22)
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %4
%27 = load i8*, i8** %9
ret i8* %27
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [53 x i8] c"[%s] Failed to allocate %zd bytes at %s line %u: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define noalias i8* @wrap_strdup(i8* %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 %15
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 @strlen(i8* %0)
%10 = load i32, i32* @errno
%11 = tail call i32 @strerror(i32 %10)
%12 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %3, i32 %9, i8* %1, i32 %2, i32 %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %4
ret i8* %5
}