#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 */
void *malloc(size_t);
int /*<<< orphan*/ nomem_rescue();
int /*<<< orphan*/ panic_nomem(char const *, int, char const *);
void *malloc_or_die(const char *file, int line, const char *func, size_t n) {
  void *ret = malloc(n);
  if (ret)
    return ret;
  if (!nomem_rescue() && (ret = malloc(n)))
    return ret;
  panic_nomem(file, line, func);
  return 0;
}


x86 assembly (clang, -O0):
<malloc_or_die>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     116c <malloc_or_die+0x3c>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b8 <malloc_or_die+0x88>
mov    $0x0,%al
call   1030 <nomem_rescue@plt>
cmp    $0x0,%eax
jne    11a0 <malloc_or_die+0x70>
mov    -0x28(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11a0 <malloc_or_die+0x70>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b8 <malloc_or_die+0x88>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1050 <panic_nomem@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<malloc_or_die>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbp
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbx
mov    %rcx,%rdi
call   1040 <malloc@plt>
test   %rax,%rax
jne    1178 <malloc_or_die+0x48>
xor    %eax,%eax
call   1030 <nomem_rescue@plt>
test   %eax,%eax
jne    1168 <malloc_or_die+0x38>
mov    %rbp,%rdi
call   1040 <malloc@plt>
test   %rax,%rax
jne    1178 <malloc_or_die+0x48>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14,%rdx
call   1050 <panic_nomem@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @malloc_or_die(i8* %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%11 = load i64, i64* %9
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %10
%13 = load i8*, i8** %10
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = load i8*, i8** %10
store i8* %16, i8** %5
br label %31
17: ; preds = %4
%18 = call i32 (...) @nomem_rescue()
%19 = icmp ne i32 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %17
%21 = load i64, i64* %9
%22 = call i8* @malloc(i64 %21)
store i8* %22, i8** %10
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = load i8*, i8** %10
store i8* %25, i8** %5
br label %31
26: ; preds = %20, %17
%27 = load i8*, i8** %6
%28 = load i32, i32* %7
%29 = load i8*, i8** %8
%30 = call i32 @panic_nomem(i8* %27, i32 %28, i8* %29)
store i8* null, i8** %5
br label %31
31: ; preds = %26, %24, %15
%32 = load i8*, i8** %5
ret i8* %32
}

LLVM IR (-O2):
define noalias i8* @malloc_or_die(i8* %0, i32 %1, i8* %2, i64 %3) {
%5 = tail call i8* @malloc(i64 %3)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %15
7: ; preds = %4
%8 = tail call i32 (...) @nomem_rescue()
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = tail call i8* @malloc(i64 %3)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10, %7
%14 = tail call i32 @panic_nomem(i8* %0, i32 %1, i8* %2)
br label %15
15: ; preds = %10, %4, %13
%16 = phi i8* [ null, %13 ], [ %5, %4 ], [ %11, %10 ]
ret i8* %16
}