#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int const, char const *,
                           size_t);
void *realloc(void *, size_t);
int /*<<< orphan*/ stderr;
void *eipa_realloc(void **ptr, size_t size, const int line, const char *file) {
  void *newPtr = realloc(*ptr, size);
  if (newPtr == NULL) {
    fprintf(stderr, "[%d@%s][ERROR] can't realloc %lu bytes\n", line, file,
            size);
    exit(EXIT_FAILURE);
  }
  return newPtr;
}


x86 assembly (clang, -O0):
<eipa_realloc>:
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),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1194 <eipa_realloc+0x64>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe7f(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eipa_realloc>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %edx,%ebp
mov    %rsi,%rbx
mov    (%rdi),%rdi
call   1040 <realloc@plt>
test   %rax,%rax
je     114e <eipa_realloc+0x1e>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e8b(%rip),%rax
mov    (%rax),%edi
lea    0xea2(%rip),%rsi
mov    %ebp,%edx
mov    %r14,%rcx
mov    %rbx,%r8
call   1030 <fprintf@plt>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"[%d@%s][ERROR] can't realloc %lu bytes\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @eipa_realloc(i8** %0, i64 %1, i32 %2, i8* %3) {
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i8** %0, i8*** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%10 = load i8**, i8*** %5
%11 = load i8*, i8** %10
%12 = load i64, i64* %6
%13 = call i8* @realloc(i8* %11, i64 %12)
store i8* %13, i8** %9
%14 = load i8*, i8** %9
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %24
16: ; preds = %4
%17 = load i32, i32* @stderr
%18 = load i32, i32* %7
%19 = load i8*, i8** %8
%20 = load i64, i64* %6
%21 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %18, i8* %19, i64 %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %4
%25 = load i8*, i8** %9
ret i8* %25
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"[%d@%s][ERROR] can't realloc %lu bytes\0A\00"
@EXIT_FAILURE = global i32 0
define noalias i8* @eipa_realloc(i8** nocapture %0, i64 %1, i32 %2, i8* %3) {
%5 = load i8*, i8** %0
%6 = tail call i8* @realloc(i8* %5, i64 %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %13
8: ; preds = %4
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %2, i8* %3, i64 %1)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %4
ret i8* %6
}