#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 *realloc(void *, size_t);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void *wrap_realloc(void *ptr, size_t size, const char *file, unsigned int line,
                   const char *func) {
  void *p = realloc(ptr, 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_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
jne    11e0 <wrap_realloc+0xa0>
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x40(%rbp),%r8
mov    -0x34(%rbp),%r9d
lea    0xe36(%rip),%rsi
mov    %eax,(%rsp)
call   1030 <fprintf@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x30(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wrap_realloc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8,%rbp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbx
call   1040 <realloc@plt>
test   %rax,%rax
je     116f <wrap_realloc+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_realloc(i8* %0, i64 %1, i8* %2, i32 %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%12 = load i8*, i8** %6
%13 = load i64, i64* %7
%14 = call i8* @realloc(i8* %12, i64 %13)
store i8* %14, i8** %11
%15 = load i8*, i8** %11
%16 = icmp eq i8* null, %15
br i1 %16, label %17, label %28
17: ; preds = %5
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %10
%20 = load i64, i64* %7
%21 = load i8*, i8** %8
%22 = load i32, i32* %9
%23 = load i32, i32* @errno
%24 = call i32 @strerror(i32 %23)
%25 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %19, i64 %20, i8* %21, i32 %22, i32 %24)
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %5
%29 = load i8*, i8** %11
ret i8* %29
}

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