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


x86 assembly (clang, -O0):
<wrap_malloc>:
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   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    11d8 <wrap_malloc+0x98>
mov    0x2e69(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    -0x2c(%rbp),%r9d
lea    0xe3e(%rip),%rsi
mov    %eax,(%rsp)
call   1030 <fprintf@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x28(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wrap_malloc>:
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   1040 <malloc@plt>
test   %rax,%rax
je     116f <wrap_malloc+0x2f>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e6a(%rip),%rax
mov    (%rax),%r12d
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %eax,(%rsp)
lea    0xe6f(%rip),%rsi
mov    %r12d,%edi
mov    %rbp,%rdx
mov    %rbx,%rcx
mov    %r15,%r8
mov    %r14d,%r9d
call   1030 <fprintf@plt>
mov    0x2e24(%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_malloc(i64 %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i64 %0, i64* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%10 = load i64, i64* %5
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %9
%12 = load i8*, i8** %9
%13 = icmp eq i8* null, %12
br i1 %13, label %14, label %25
14: ; preds = %4
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %8
%17 = load i64, i64* %5
%18 = load i8*, i8** %6
%19 = load i32, i32* %7
%20 = load i32, i32* @errno
%21 = call i32 @strerror(i32 %20)
%22 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %16, i64 %17, i8* %18, i32 %19, i32 %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %4
%26 = load i8*, i8** %9
ret i8* %26
}

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_malloc(i64 %0, i8* %1, i32 %2, i8* %3) {
%5 = tail call i8* @malloc(i64 %0)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %14
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i32 @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %3, i64 %0, i8* %1, i32 %2, i32 %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %4
ret i8* %5
}