#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 errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int,
                           char const *, int const);
void *realloc(void *, size_t const);
int /*<<< orphan*/ stderr;
char *strerror(int);
void *wrapper_realloc(void *ptr, const size_t size, const char *file,
                      const int line) {
  void *allocation = realloc(ptr, size);
  if (!allocation) {
    fprintf(stderr, "Error: %s (%d) at %s line %d\n", strerror(errno), errno,
            file, line);
    exit(EXIT_FAILURE);
  }
  return allocation;
}


x86 assembly (clang, -O0):
<wrapper_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11be <wrapper_realloc+0x7e>
mov    0x2e66(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
mov    0x2e3e(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%r8
mov    -0x1c(%rbp),%r9d
lea    0xe55(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wrapper_realloc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdx,%rbx
call   1040 <realloc@plt>
test   %rax,%rax
je     1161 <wrapper_realloc+0x21>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e78(%rip),%rax
mov    (%rax),%r14d
mov    0x2e66(%rip),%r15
mov    (%r15),%edi
call   1060 <strerror@plt>
mov    (%r15),%ecx
lea    0xe7c(%rip),%rsi
mov    %r14d,%edi
mov    %rax,%rdx
mov    %rbx,%r8
mov    %ebp,%r9d
call   1030 <fprintf@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"Error: %s (%d) at %s line %d\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i8* @wrapper_realloc(i8* %0, i64 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i8*, i8** %5
%11 = load i64, i64* %6
%12 = call i8* @realloc(i8* %10, i64 %11)
store i8* %12, i8** %9
%13 = load i8*, i8** %9
%14 = icmp ne i8* %13, null
br i1 %14, label %25, label %15
15: ; preds = %4
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = load i32, i32* @errno
%20 = load i8*, i8** %7
%21 = load i32, i32* %8
%22 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %18, i32 %19, i8* %20, 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 = [30 x i8] c"Error: %s (%d) at %s line %d\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define noalias i8* @wrapper_realloc(i8* nocapture %0, i64 %1, i8* %2, i32 %3) {
%5 = tail call i8* @realloc(i8* %0, i64 %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %15
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = load i32, i32* @errno
%12 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %10, i32 %11, i8* %2, i32 %3)
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %4
ret i8* %5
}