#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*/ perror(char *);
void *xcalloc(size_t nelem, size_t elsize) {
  void *newmem = calloc(nelem ? nelem : 1, elsize ? elsize : 1);
  if (newmem == NULL) {
    perror("xcalloc");
    exit(1);
  }
  return newmem;
}


x86 assembly (clang, -O0):
<xcalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1158 <xcalloc+0x28>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1166 <xcalloc+0x36>
mov    $0x1,%eax
mov    %rax,-0x20(%rbp)
jmp    1166 <xcalloc+0x36>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1186 <xcalloc+0x56>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1194 <xcalloc+0x64>
mov    $0x1,%eax
mov    %rax,-0x30(%rbp)
jmp    1194 <xcalloc+0x64>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c6 <xcalloc+0x96>
lea    0xe49(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xcalloc>:
push   %rax
test   %rdi,%rdi
mov    $0x1,%eax
cmove  %rax,%rdi
test   %rsi,%rsi
cmove  %rax,%rsi
call   1030 <calloc@plt>
test   %rax,%rax
je     1150 <xcalloc+0x20>
pop    %rcx
ret
lea    0xea9(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"xcalloc\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 = icmp ne i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = load i64, i64* %3
br label %11
10: ; preds = %2
br label %11
11: ; preds = %10, %8
%12 = phi i64 [ %9, %8 ], [ 1, %10 ]
%13 = load i64, i64* %4
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = load i64, i64* %4
br label %18
17: ; preds = %11
br label %18
18: ; preds = %17, %15
%19 = phi i64 [ %16, %15 ], [ 1, %17 ]
%20 = call i8* @calloc(i64 %12, i64 %19)
store i8* %20, i8** %5
%21 = load i8*, i8** %5
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %18
%27 = load i8*, i8** %5
ret i8* %27
}

LLVM IR (-O2):
@.str = [8 x i8] c"xcalloc\00"
define noalias i8* @xcalloc(i64 %0, i64 %1) {
%3 = icmp eq i64 %0, 0
%4 = select i1 %3, i64 1, i64 %0
%5 = icmp eq i64 %1, 0
%6 = select i1 %5, i64 1, i64 %1
%7 = tail call i8* @calloc(i64 %4, i64 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
ret i8* %7
}