#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 *, char const *, int);
void *realloc(void *, size_t);
int /*<<< orphan*/ stderr;
void *_safeRealloc(const char *src, int line, void *ptr, size_t size) {
  void *ptr_temp = realloc(ptr, size);
  if (ptr == NULL) {
    fprintf(stderr, "[%s:%d] OUT OF MEMORY", src, line);
    exit(EXIT_FAILURE);
  }
  return ptr_temp;
}


x86 assembly (clang, -O0):
<_safeRealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118d <_safeRealloc+0x5d>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe86(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_safeRealloc>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbp
mov    %esi,%r14d
mov    %rdi,%rbx
mov    %rdx,%rdi
mov    %rcx,%rsi
call   1040 <realloc@plt>
test   %rbp,%rbp
je     1152 <_safeRealloc+0x22>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
lea    0xe9e(%rip),%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
call   1030 <fprintf@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

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

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