#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*/ alloc_failed(char const *, int);
int /*<<< orphan*/ assert(int);
void *calloc(long, long);
void *mem_calloc(long count, long nbytes, const char *file, int line) {
  assert(count > 0);
  assert(nbytes > 0);
  void *ptr = calloc(count, nbytes);
  if (ptr == NULL) {
    alloc_failed(file, line);
  }
  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)
cmpq   $0x0,-0x8(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1193 <mem_calloc+0x63>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <alloc_failed@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem_calloc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setg   %dil
call   1040 <assert@plt>
xor    %edi,%edi
test   %rbp,%rbp
setg   %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <calloc@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    117d <mem_calloc+0x4d>
mov    %r15,%rdi
mov    %r14d,%esi
call   1050 <alloc_failed@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
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 sgt i64 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i64, i64* %6
%15 = icmp sgt i64 %14, 0
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i64, i64* %5
%19 = load i64, i64* %6
%20 = call i8* @calloc(i64 %18, i64 %19)
store i8* %20, i8** %9
%21 = load i8*, i8** %9
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %27
23: ; preds = %4
%24 = load i8*, i8** %7
%25 = load i32, i32* %8
%26 = call i32 @alloc_failed(i8* %24, i32 %25)
br label %27
27: ; preds = %23, %4
%28 = load i8*, i8** %9
ret i8* %28
}

LLVM IR (-O2):
define noalias i8* @mem_calloc(i64 %0, i64 %1, i8* %2, i32 %3) {
%5 = icmp sgt i64 %0, 0
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = icmp sgt i64 %1, 0
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i8* @calloc(i64 %0, i64 %1)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %4
%14 = tail call i32 @alloc_failed(i8* %2, i32 %3)
br label %15
15: ; preds = %13, %4
ret i8* %11
}