#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 */
int /*<<< orphan*/ EX_OSERR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, size_t,
                           int /*<<< orphan*/);
void *malloc(size_t);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void *xalloc(size_t size) {
  void *buf = malloc(size);
  if (!buf) {
    fprintf(stderr, "Could not allocate %zd bytes with malloc(): %s\n", size,
            strerror(errno));
    exit(EX_OSERR);
  }
  memset(buf, 0, size);
  return buf;
}


x86 assembly (clang, -O0):
<xalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b9 <xalloc+0x69>
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
mov    %eax,%ecx
lea    0xe5a(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xalloc>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <malloc@plt>
test   %rax,%rax
je     117c <xalloc+0x2c>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1030 <memset@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e5d(%rip),%rax
mov    (%rax),%ebx
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe66(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %eax,%ecx
call   1040 <fprintf@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [48 x i8] c"Could not allocate %zd bytes with malloc(): %s\0A\00"
@errno = global i32 0
@EX_OSERR = global i32 0
define i8* @xalloc(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
store i64 %0, i64* %2
%4 = load i64, i64* %2
%5 = call i8* @malloc(i64 %4)
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %16, label %8
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i64, i64* %2
%11 = load i32, i32* @errno
%12 = call i32 @strerror(i32 %11)
%13 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i64 %10, i32 %12)
%14 = load i32, i32* @EX_OSERR
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %1
%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):
@stderr = global i32 0
@.str = [48 x i8] c"Could not allocate %zd bytes with malloc(): %s\0A\00"
@errno = global i32 0
@EX_OSERR = global i32 0
define i8* @xalloc(i64 %0) {
%2 = tail call i8* @malloc(i64 %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %11
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = load i32, i32* @errno
%7 = tail call i32 @strerror(i32 %6)
%8 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i64 %0, i32 %7)
%9 = load i32, i32* @EX_OSERR
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %1
%12 = tail call i32 @memset(i8* %2, i32 0, i64 %0)
ret i8* %2
}