#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*/ wgmem_error(char *, ...);
extern void *wg_calloc(size_t nmemb, size_t size) {
  void *result;
  if (!size || !nmemb) {
    wgmem_error("Error callocing 0 bytes.\n");
  }
  result = calloc(nmemb, size);
  if (!result) {
    wgmem_error("Error while callocing %u elements of %u bytes.\n", nmemb,
                size);
  }
  return result;
}


x86 assembly (clang, -O0):
<wg_calloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1146 <wg_calloc+0x26>
cmpq   $0x0,-0x8(%rbp)
jne    1154 <wg_calloc+0x34>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <wgmem_error@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1186 <wg_calloc+0x66>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <wgmem_error@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wg_calloc>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
test   %rdi,%rdi
je     1135 <wg_calloc+0x15>
test   %r14,%r14
jne    1143 <wg_calloc+0x23>
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1040 <wgmem_error@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    116a <wg_calloc+0x4a>
lea    0xebd(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <wgmem_error@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Error callocing 0 bytes.\0A\00"
@.str.1 = [48 x i8] c"Error while callocing %u elements of %u bytes.\0A\00"
define i8* @wg_calloc(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 ne i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i64, i64* %3
%10 = icmp ne i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8, %2
%12 = call i32 (i8*, ...) @wgmem_error(i8* getelementptr inbounds ([26 x i8], [26 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 ne i8* %17, null
br i1 %18, label %23, label %19
19: ; preds = %13
%20 = load i64, i64* %3
%21 = load i64, i64* %4
%22 = call i32 (i8*, ...) @wgmem_error(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i64 %20, i64 %21)
br label %23
23: ; preds = %19, %13
%24 = load i8*, i8** %5
ret i8* %24
}

LLVM IR (-O2):
@.str = [26 x i8] c"Error callocing 0 bytes.\0A\00"
@.str.1 = [48 x i8] c"Error while callocing %u elements of %u bytes.\0A\00"
define noalias i8* @wg_calloc(i64 %0, i64 %1) {
%3 = icmp ne i64 %1, 0
%4 = icmp ne i64 %0, 0
%5 = and i1 %4, %3
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @wgmem_error(i8* getelementptr inbounds ([26 x i8], [26 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 %13
11: ; preds = %8
%12 = tail call i32 (i8*, ...) @wgmem_error(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i64 %0, i64 %1)
br label %13
13: ; preds = %11, %8
ret i8* %9
}