#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 *malloc(size_t);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ panic(char *, ...);
__attribute__((visibility("hidden"))) void *xzmalloc(size_t size) {
  void *ptr;
  if (size == 0)
    panic("xzmalloc: zero size\n");
  ptr = malloc(size);
  if (ptr == NULL)
    panic("xzmalloc: out of memory (allocating %zu bytes)\n", size);
  memset(ptr, 0, size);
  return ptr;
}


x86 assembly (clang, -O0):
<xzmalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1155 <xzmalloc+0x25>
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <panic@plt>
mov    -0x8(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117f <xzmalloc+0x4f>
mov    -0x8(%rbp),%rsi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <panic@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xzmalloc>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
test   %rdi,%rdi
jne    114a <xzmalloc+0x1a>
lea    0xebd(%rip),%rdi
xor    %eax,%eax
call   1030 <panic@plt>
mov    %r14,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    116b <xzmalloc+0x3b>
lea    0xeb4(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <panic@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1040 <memset@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [21 x i8] c"xzmalloc: zero size\0A\00"
@.str.1 = [48 x i8] c"xzmalloc: out of memory (allocating %zu bytes)\0A\00"
define hidden i8* @xzmalloc(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
store i64 %0, i64* %2
%4 = load i64, i64* %2
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 (i8*, ...) @panic(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = load i64, i64* %2
%10 = call i8* @malloc(i64 %9)
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i64, i64* %2
%15 = call i32 (i8*, ...) @panic(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i64 %14)
br label %16
16: ; preds = %13, %8
%17 = load i8*, i8** %3
%18 = load i64, i64* %2
%19 = call i32 @memset(i8* %17, i32 0, i64 %18)
%20 = load i8*, i8** %3
ret i8* %20
}

LLVM IR (-O2):
@.str = [21 x i8] c"xzmalloc: zero size\0A\00"
@.str.1 = [48 x i8] c"xzmalloc: out of memory (allocating %zu bytes)\0A\00"
define hidden i8* @xzmalloc(i64 %0) {
%2 = icmp eq i64 %0, 0
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 (i8*, ...) @panic(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %3, %1
%6 = tail call i8* @malloc(i64 %0)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 (i8*, ...) @panic(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i64 %0)
br label %10
10: ; preds = %8, %5
%11 = tail call i32 @memset(i8* %6, i32 0, i64 %0)
ret i8* %6
}