#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 *calloc(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ start_debugger();
int /*<<< orphan*/ stderr;
void *rfx_calloc(int size) {
  void *ptr;
  if (size == 0) {
    return 0;
  }
  ptr = calloc(1, size);
  if (!ptr) {
    fprintf(stderr, "FATAL: Out of memory (while trying to claim %d bytes)\n",
            size);
    start_debugger();
    exit(1);
  }
  return ptr;
}


x86 assembly (clang, -O0):
<rfx_calloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1162 <rfx_calloc+0x22>
movq   $0x0,-0x8(%rbp)
jmp    11af <rfx_calloc+0x6f>
mov    -0xc(%rbp),%esi
mov    $0x1,%edi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a7 <rfx_calloc+0x67>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe6f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1040 <start_debugger@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rfx_calloc>:
push   %rbx
test   %edi,%edi
je     115a <rfx_calloc+0x1a>
mov    %edi,%ebx
mov    $0x1,%edi
mov    %ebx,%esi
call   1030 <calloc@plt>
test   %rax,%rax
je     115e <rfx_calloc+0x1e>
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
lea    0xe92(%rip),%rsi
mov    %ebx,%edx
call   1050 <fprintf@plt>
xor    %eax,%eax
call   1040 <start_debugger@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [55 x i8] c"FATAL: Out of memory (while trying to claim %d bytes)\0A\00"
define i8* @rfx_calloc(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i8* null, i8** %2
br label %21
8: ; preds = %1
%9 = load i32, i32* %3
%10 = call i8* @calloc(i32 1, i32 %9)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %19, label %13
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i32, i32* %3
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = call i32 (...) @start_debugger()
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %8
%20 = load i8*, i8** %4
store i8* %20, i8** %2
br label %21
21: ; preds = %19, %7
%22 = load i8*, i8** %2
ret i8* %22
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [55 x i8] c"FATAL: Out of memory (while trying to claim %d bytes)\0A\00"
define noalias i8* @rfx_calloc(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %11, label %3
3: ; preds = %1
%4 = tail call i8* @calloc(i32 1, i32 %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 ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %0)
%9 = tail call i32 (...) @start_debugger()
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %3, %1
%12 = phi i8* [ null, %1 ], [ %4, %3 ]
ret i8* %12
}