#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(size_t, size_t);
int /*<<< orphan*/ die(char *, char const *, unsigned int, char const *,
                       unsigned int, unsigned int);
void *checked_calloc(size_t nmemb, size_t size, const char *filename,
                     unsigned int line, const char *func) {
  void *p = calloc(nmemb, size);
  if (!p)
    die("%s:%u: %s: OUT OF MEMORY calloc(%u, %u)\n", filename, line, func,
        (unsigned)nmemb, (unsigned)size);
  return p;
}


x86 assembly (clang, -O0):
<checked_calloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <calloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    117c <checked_calloc+0x5c>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %eax,%r8d
mov    -0x10(%rbp),%rax
mov    %eax,%r9d
lea    0xe89(%rip),%rdi
call   1040 <die@plt>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checked_calloc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %ecx,%r15d
mov    %rdx,%r13
mov    %rsi,%r12
mov    %rdi,%rbp
call   1030 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1162 <checked_calloc+0x42>
lea    0xeb2(%rip),%rdi
mov    %r13,%rsi
mov    %r15d,%edx
mov    %r14,%rcx
mov    %ebp,%r8d
mov    %r12d,%r9d
call   1040 <die@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"%s:%u: %s: OUT OF MEMORY calloc(%u, %u)\0A\00"
define i8* @checked_calloc(i64 %0, i64 %1, i8* %2, i32 %3, i8* %4) {
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i64 %0, i64* %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%12 = load i64, i64* %6
%13 = load i64, i64* %7
%14 = call i8* @calloc(i64 %12, i64 %13)
store i8* %14, i8** %11
%15 = load i8*, i8** %11
%16 = icmp ne i8* %15, null
br i1 %16, label %26, label %17
17: ; preds = %5
%18 = load i8*, i8** %8
%19 = load i32, i32* %9
%20 = load i8*, i8** %10
%21 = load i64, i64* %6
%22 = trunc i64 %21 to i32
%23 = load i64, i64* %7
%24 = trunc i64 %23 to i32
%25 = call i32 @die(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %18, i32 %19, i8* %20, i32 %22, i32 %24)
br label %26
26: ; preds = %17, %5
%27 = load i8*, i8** %11
ret i8* %27
}

LLVM IR (-O2):
@.str = [41 x i8] c"%s:%u: %s: OUT OF MEMORY calloc(%u, %u)\0A\00"
define noalias i8* @checked_calloc(i64 %0, i64 %1, i8* %2, i32 %3, i8* %4) {
%6 = tail call i8* @calloc(i64 %0, i64 %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = trunc i64 %0 to i32
%10 = trunc i64 %1 to i32
%11 = tail call i32 @die(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %3, i8* %4, i32 %9, i32 %10)
br label %12
12: ; preds = %8, %5
ret i8* %6
}