#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,
                           size_t);
void *realloc(void *, size_t);
int /*<<< orphan*/ stderr;
void *realloc_or_quit(void *ptr, size_t num_bytes, const char *src_file,
                      int src_line) {
  void *mem;
  if ((mem = realloc(ptr, num_bytes)) == NULL) {
    fprintf(stderr, "file: '%s' at line: %d failed to realloc %zu bytes",
            src_file, src_line, num_bytes);
    exit(EXIT_FAILURE);
  } else {
    return mem;
  }
}


x86 assembly (clang, -O0):
<realloc_or_quit>:
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)
cmp    $0x0,%rax
jne    1190 <realloc_or_quit+0x60>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%r8
lea    0xe83(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<realloc_or_quit>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%r14d
mov    %rdx,%rbp
mov    %rsi,%rbx
call   1040 <realloc@plt>
test   %rax,%rax
je     114c <realloc_or_quit+0x1c>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
lea    0xea4(%rip),%rsi
mov    %rbp,%rdx
mov    %r14d,%ecx
mov    %rbx,%r8
call   1030 <fprintf@plt>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [51 x i8] c"file: '%s' at line: %d failed to realloc %zu bytes\00"
@EXIT_FAILURE = global i32 0
define i8* @realloc_or_quit(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 = icmp eq i8* %12, null
br i1 %13, label %14, label %22
14: ; preds = %4
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %7
%17 = load i32, i32* %8
%18 = load i64, i64* %6
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %16, i32 %17, i64 %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 = [51 x i8] c"file: '%s' at line: %d failed to realloc %zu bytes\00"
@EXIT_FAILURE = global i32 0
define noalias i8* @realloc_or_quit(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 %12
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %3, i64 %1)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %4
ret i8* %5
}