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


x86 assembly (clang, -O0):
<_safeCalloc>:
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   1030 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    118d <_safeCalloc+0x5d>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe86(%rip),%rsi
call   1040 <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):
<_safeCalloc>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %rdx,%rdi
mov    %rcx,%rsi
call   1030 <calloc@plt>
test   %rax,%rax
je     114f <_safeCalloc+0x1f>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
lea    0xea1(%rip),%rsi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1040 <fprintf@plt>
mov    0x2e68(%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* @_safeCalloc(i8* %0, i32 %1, i64 %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%10 = load i64, i64* %7
%11 = load i64, i64* %8
%12 = call i8* @calloc(i64 %10, i64 %11)
store i8* %12, i8** %9
%13 = load i8*, i8** %9
%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* @_safeCalloc(i8* %0, i32 %1, i64 %2, i64 %3) {
%5 = tail call i8* @calloc(i64 %2, i64 %3)
%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 ([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
}