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


x86 assembly (clang, -O0):
<malloc_or_quit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1188 <malloc_or_quit+0x58>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%r8
lea    0xe8b(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<malloc_or_quit>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %rdi,%rbx
call   1040 <malloc@plt>
test   %rax,%rax
je     114c <malloc_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 = [50 x i8] c"file: '%s' at line: %d failed to malloc %zu bytes\00"
@EXIT_FAILURE = global i32 0
define i8* @malloc_or_quit(i64 %0, i8* %1, i32 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i64 %0, i64* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i64, i64* %4
%9 = call i8* @malloc(i64 %8)
store i8* %9, i8** %7
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %19
11: ; preds = %3
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %5
%14 = load i32, i32* %6
%15 = load i64, i64* %4
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %13, i32 %14, i64 %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %3
%20 = load i8*, i8** %7
ret i8* %20
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [50 x i8] c"file: '%s' at line: %d failed to malloc %zu bytes\00"
@EXIT_FAILURE = global i32 0
define noalias i8* @malloc_or_quit(i64 %0, i8* %1, i32 %2) {
%4 = tail call i8* @malloc(i64 %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %11
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %2, i64 %0)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %3
ret i8* %4
}