#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;
int /*<<< orphan*/ assert(int);
void *calloc(size_t, size_t);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
extern void *mem_calloc(size_t count, size_t nbytes, const char *file,
                        int line) {
  assert(count > 0 && nbytes > 0);
  void *ptr;
  ptr = calloc(count, nbytes);
  if (!ptr) {
    printf("Memory was not allocated. Exiting...\n");
    exit(EXIT_FAILURE);
  }
  return ptr;
}


x86 assembly (clang, -O0):
<mem_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)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x29(%rbp)
jbe    1172 <mem_calloc+0x32>
cmpq   $0x0,-0x10(%rbp)
seta   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b5 <mem_calloc+0x75>
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem_calloc>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
setne  %al
test   %rsi,%rsi
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1050 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <calloc@plt>
test   %rax,%rax
je     1178 <mem_calloc+0x38>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe81(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"Memory was not allocated. Exiting...\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @mem_calloc(i64 %0, i64 %1, i8* %2, i32 %3) {
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i64 %0, i64* %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i64, i64* %5
%11 = icmp ugt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %4
%13 = load i64, i64* %6
%14 = icmp ugt i64 %13, 0
br label %15
15: ; preds = %12, %4
%16 = phi i1 [ false, %4 ], [ %14, %12 ]
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i64, i64* %5
%20 = load i64, i64* %6
%21 = call i8* @calloc(i64 %19, i64 %20)
store i8* %21, i8** %9
%22 = load i8*, i8** %9
%23 = icmp ne i8* %22, null
br i1 %23, label %28, label %24
24: ; preds = %15
%25 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %15
%29 = load i8*, i8** %9
ret i8* %29
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@str = [37 x i8] c"Memory was not allocated. Exiting...\00"
define noalias i8* @mem_calloc(i64 %0, i64 %1, i8* nocapture readnone %2, i32 %3) {
%5 = icmp ne i64 %0, 0
%6 = icmp ne i64 %1, 0
%7 = and i1 %5, %6
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i8* @calloc(i64 %0, i64 %1)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %4
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %4
ret i8* %10
}