#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(int, size_t);
int /*<<< orphan*/ wgmem_error(char *, ...);
extern void *wg_zalloc(size_t size) {
  void *result;
  if (!size) {
    wgmem_error("Error zallocing 0 bytes.\n");
  }
  result = calloc(1, size);
  if (!result) {
    wgmem_error("Error while zallocing %u bytes.\n", size);
  }
  return result;
}


x86 assembly (clang, -O0):
<wg_zalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1145 <wg_zalloc+0x25>
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1040 <wgmem_error@plt>
mov    -0x8(%rbp),%rsi
mov    $0x1,%edi
call   1030 <calloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1174 <wg_zalloc+0x54>
mov    -0x8(%rbp),%rsi
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1040 <wgmem_error@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wg_zalloc>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
test   %rdi,%rdi
jne    113a <wg_zalloc+0x1a>
lea    0xecd(%rip),%rdi
xor    %eax,%eax
call   1040 <wgmem_error@plt>
mov    $0x1,%edi
mov    %r14,%rsi
call   1030 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1160 <wg_zalloc+0x40>
lea    0xec4(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <wgmem_error@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Error zallocing 0 bytes.\0A\00"
@.str.1 = [33 x i8] c"Error while zallocing %u bytes.\0A\00"
define i8* @wg_zalloc(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
store i64 %0, i64* %2
%4 = load i64, i64* %2
%5 = icmp ne i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = call i32 (i8*, ...) @wgmem_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = load i64, i64* %2
%10 = call i8* @calloc(i32 1, i64 %9)
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = icmp ne i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = load i64, i64* %2
%15 = call i32 (i8*, ...) @wgmem_error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i64 %14)
br label %16
16: ; preds = %13, %8
%17 = load i8*, i8** %3
ret i8* %17
}

LLVM IR (-O2):
@.str = [26 x i8] c"Error zallocing 0 bytes.\0A\00"
@.str.1 = [33 x i8] c"Error while zallocing %u bytes.\0A\00"
define i8* @wg_zalloc(i64 %0) {
%2 = icmp eq i64 %0, 0
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 (i8*, ...) @wgmem_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %3, %1
%6 = tail call i8* @calloc(i32 1, i64 %0)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 (i8*, ...) @wgmem_error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i64 %0)
br label %10
10: ; preds = %8, %5
ret i8* %6
}