#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(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, int);
void *malloc(size_t);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ stderr;
void *Mem_Calloc(size_t n, const char *file, int line) {
  void *ptr = malloc(n);
  if (!ptr) {
    fprintf(stderr, "Out of memory at %s:%d\n", file, line);
    exit(1);
  } else
    memset(ptr, 0, n);
  return ptr;
}


x86 assembly (clang, -O0):
<Mem_Calloc>:
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   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1191 <Mem_Calloc+0x51>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xe7e(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Mem_Calloc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
call   1050 <malloc@plt>
test   %rax,%rax
je     1178 <Mem_Calloc+0x38>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %rbp,%rdx
call   1030 <memset@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"Out of memory at %s:%d\0A\00"
define i8* @Mem_Calloc(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 = load i8*, i8** %7
%11 = icmp ne i8* %10, null
br i1 %11, label %18, label %12
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %5
%15 = load i32, i32* %6
%16 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %14, i32 %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %3
%19 = load i8*, i8** %7
%20 = load i64, i64* %4
%21 = call i32 @memset(i8* %19, i32 0, i64 %20)
br label %22
22: ; preds = %18
%23 = load i8*, i8** %7
ret i8* %23
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"Out of memory at %s:%d\0A\00"
define i8* @Mem_Calloc(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 %10
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %2)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %3
%11 = tail call i32 @memset(i8* %4, i32 0, i64 %0)
ret i8* %4
}