#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
void *malloc(unsigned int);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, unsigned long);
int /*<<< orphan*/ stderr;
void *xalloc(unsigned int size) {
  void *pt = malloc(size);
  if (!pt) {
    fprintf(stderr, "%s: Out of memory!\n", "xalloc");
    exit(2);
  }
  memset(pt, 0, (unsigned long)size);
  return pt;
}


x86 assembly (clang, -O0):
<xalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1188 <xalloc+0x48>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
lea    0xe8e(%rip),%rsi
lea    0xe9b(%rip),%rdx
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%eax
mov    %eax,%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xalloc>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
call   1050 <malloc@plt>
test   %rax,%rax
je     1168 <xalloc+0x28>
mov    %rax,%rbx
mov    %ebp,%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    0xe88(%rip),%rsi
lea    0xe95(%rip),%rdx
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"%s: Out of memory!\0A\00"
@.str.1 = [7 x i8] c"xalloc\00"
define i8* @xalloc(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i8* @malloc(i32 %4)
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %12, label %8
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 2)
unreachable
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = load i32, i32* %2
%15 = zext i32 %14 to i64
%16 = call i32 @memset(i8* %13, i32 0, i64 %15)
%17 = load i8*, i8** %3
ret i8* %17
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"%s: Out of memory!\0A\00"
@.str.1 = [7 x i8] c"xalloc\00"
define i8* @xalloc(i32 %0) {
%2 = tail call i8* @malloc(i32 %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @exit(i32 2)
unreachable
8: ; preds = %1
%9 = zext i32 %0 to i64
%10 = tail call i32 @memset(i8* %2, i32 0, i64 %9)
ret i8* %2
}