#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int, char *);
int /*<<< orphan*/ stdout;
void *calloc_or_die(char *name, size_t nitems, size_t size) {
  void *ret = calloc(nitems, size);
  if (ret == NULL) {
    fprintf(stdout,
            "failed to allocate memory for %d items of %d bytes for %s!\n",
            (int)nitems, (int)size, name);
    exit(2);
  }
  return ret;
}


x86 assembly (clang, -O0):
<calloc_or_die>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118f <calloc_or_die+0x5f>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    %eax,%ecx
mov    -0x8(%rbp),%r8
lea    0xe80(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calloc_or_die>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1030 <calloc@plt>
test   %rax,%rax
je     1154 <calloc_or_die+0x24>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
lea    0xe9c(%rip),%rsi
mov    %ebx,%edx
mov    %r15d,%ecx
mov    %r14,%r8
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [60 x i8] c"failed to allocate memory for %d items of %d bytes for %s!\0A\00"
define i8* @calloc_or_die(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%8 = load i64, i64* %5
%9 = load i64, i64* %6
%10 = call i8* @calloc(i64 %8, i64 %9)
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %22
13: ; preds = %3
%14 = load i32, i32* @stdout
%15 = load i64, i64* %5
%16 = trunc i64 %15 to i32
%17 = load i64, i64* %6
%18 = trunc i64 %17 to i32
%19 = load i8*, i8** %4
%20 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %18, i8* %19)
%21 = call i32 @exit(i32 2)
unreachable
22: ; preds = %3
%23 = load i8*, i8** %7
ret i8* %23
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [60 x i8] c"failed to allocate memory for %d items of %d bytes for %s!\0A\00"
define noalias i8* @calloc_or_die(i8* %0, i64 %1, i64 %2) {
%4 = tail call i8* @calloc(i64 %1, i64 %2)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = load i32, i32* @stdout
%8 = trunc i64 %1 to i32
%9 = trunc i64 %2 to i32
%10 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %9, i8* %0)
%11 = tail call i32 @exit(i32 2)
unreachable
12: ; preds = %3
ret i8* %4
}