#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;
void *calloc(size_t const, size_t const);
int /*<<< orphan*/ err(int /*<<< orphan*/, char *, size_t const);
__attribute__((alloc_size(1, 2))) void *xcalloc(const size_t nelems,
                                                const size_t size) {
  void *ret = calloc(nelems, size);
  if (!ret && size && nelems)
    err(EXIT_FAILURE, "cannot allocate %zu bytes", size);
  return ret;
}


x86 assembly (clang, -O0):
<xcalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117b <xcalloc+0x5b>
cmpq   $0x0,-0x10(%rbp)
je     117b <xcalloc+0x5b>
cmpq   $0x0,-0x8(%rbp)
je     117b <xcalloc+0x5b>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe8a(%rip),%rsi
call   1040 <err@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xcalloc>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%rbx
call   1030 <calloc@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     115a <xcalloc+0x3a>
test   %r15,%r15
je     115a <xcalloc+0x3a>
test   %r14,%r14
jne    115a <xcalloc+0x3a>
mov    0x2e97(%rip),%rax
mov    (%rax),%edi
lea    0xeae(%rip),%rsi
mov    %r15,%rdx
call   1040 <err@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [26 x i8] c"cannot allocate %zu bytes\00"
define i8* @xcalloc(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
store i64 %0, i64* %3
store i64 %1, i64* %4
%6 = load i64, i64* %3
%7 = load i64, i64* %4
%8 = call i8* @calloc(i64 %6, i64 %7)
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %21, label %11
11: ; preds = %2
%12 = load i64, i64* %4
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = load i64, i64* %3
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* @EXIT_FAILURE
%19 = load i64, i64* %4
%20 = call i32 @err(i32 %18, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i64 %19)
br label %21
21: ; preds = %17, %14, %11, %2
%22 = load i8*, i8** %5
ret i8* %22
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [26 x i8] c"cannot allocate %zu bytes\00"
define noalias i8* @xcalloc(i64 %0, i64 %1) {
%3 = tail call i8* @calloc(i64 %0, i64 %1)
%4 = icmp eq i8* %3, null
%5 = icmp ne i64 %1, 0
%6 = and i1 %5, %4
%7 = icmp ne i64 %0, 0
%8 = and i1 %7, %6
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @err(i32 %10, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i64 %1)
br label %12
12: ; preds = %9, %2
ret i8* %3
}