#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 */
typedef int /*<<< orphan*/ u_long;

/* Variables and functions */
void *calloc(size_t, size_t);
int /*<<< orphan*/ fatal(char *, ...);
void *xcalloc(size_t nmemb, size_t size) {
  void *ptr;
  if (size == 0 || nmemb == 0)
    fatal("xcalloc: zero size");
  ptr = calloc(nmemb, size);
  if (ptr == NULL)
    fatal("xcalloc: out of memory (allocating %lu bytes)",
          (u_long)(size * nmemb));
  return ptr;
}


x86 assembly (clang, -O0):
<xcalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1146 <xcalloc+0x26>
cmpq   $0x0,-0x8(%rbp)
jne    1154 <xcalloc+0x34>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <fatal@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1189 <xcalloc+0x69>
mov    -0x10(%rbp),%rax
imul   -0x8(%rbp),%rax
mov    %eax,%esi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <fatal@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,%r14
test   %rdi,%rdi
je     1135 <xcalloc+0x15>
test   %r15,%r15
jne    1143 <xcalloc+0x23>
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1040 <fatal@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    116b <xcalloc+0x4b>
imul   %r14d,%r15d
lea    0xeb2(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <fatal@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [19 x i8] c"xcalloc: zero size\00"
@.str.1 = [46 x i8] c"xcalloc: out of memory (allocating %lu 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* %4
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i64, i64* %3
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8, %2
%12 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %8
%14 = load i64, i64* %3
%15 = load i64, i64* %4
%16 = call i8* @calloc(i64 %14, i64 %15)
store i8* %16, i8** %5
%17 = load i8*, i8** %5
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %25
19: ; preds = %13
%20 = load i64, i64* %4
%21 = load i64, i64* %3
%22 = mul i64 %20, %21
%23 = trunc i64 %22 to i32
%24 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %19, %13
%26 = load i8*, i8** %5
ret i8* %26
}

LLVM IR (-O2):
@.str = [19 x i8] c"xcalloc: zero size\00"
@.str.1 = [46 x i8] c"xcalloc: out of memory (allocating %lu bytes)\00"
define noalias i8* @xcalloc(i64 %0, i64 %1) {
%3 = icmp eq i64 %1, 0
%4 = icmp eq i64 %0, 0
%5 = or i1 %4, %3
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %2, %6
%9 = tail call i8* @calloc(i64 %0, i64 %1)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = mul i64 %1, %0
%13 = trunc i64 %12 to i32
%14 = tail call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %11, %8
ret i8* %9
}