#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 MAP_ANONYMOUS;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
void *mmap(int /*<<< orphan*/ *, size_t, int, int, int /*<<< orphan*/,
           int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void *page_alloc(size_t size) {
  void *data = mmap(NULL, size, PROT_READ | PROT_WRITE,
                    MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
  if (data == (void *)-1) {
    fprintf(stderr, "Error(MemData::Construction): mmap failed.\n");
    exit(0);
  }
  return data;
}


x86 assembly (clang, -O0):
<page_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
mov    0x2eb1(%rip),%rax
mov    (%rax),%edx
mov    0x2e78(%rip),%rax
or     (%rax),%edx
mov    0x2e67(%rip),%rax
mov    (%rax),%ecx
mov    0x2e7e(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
mov    %r9d,%r8d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x10(%rbp)
jne    11a4 <page_alloc+0x74>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<page_alloc>:
push   %rax
mov    %rdi,%rsi
mov    0x2ebd(%rip),%rax
mov    0x2e86(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e73(%rip),%rax
mov    0x2e8c(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
cmp    $0xffffffffffffffff,%rax
je     116d <page_alloc+0x3d>
pop    %rcx
ret
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@stderr = global i32 0
@.str = [44 x i8] c"Error(MemData::Construction): mmap failed.\0A\00"
define i8* @page_alloc(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
store i64 %0, i64* %2
%4 = load i64, i64* %2
%5 = load i32, i32* @PROT_READ
%6 = load i32, i32* @PROT_WRITE
%7 = or i32 %5, %6
%8 = load i32, i32* @MAP_PRIVATE
%9 = load i32, i32* @MAP_ANONYMOUS
%10 = or i32 %8, %9
%11 = call i8* @mmap(i32* null, i64 %4, i32 %7, i32 %10, i32 0, i32 0)
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = icmp eq i8* %12, inttoptr (i64 -1 to i8*)
br i1 %13, label %14, label %18
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %1
%19 = load i8*, i8** %3
ret i8* %19
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@stderr = global i32 0
@.str = [44 x i8] c"Error(MemData::Construction): mmap failed.\0A\00"
define i8* @page_alloc(i64 %0) {
%2 = load i32, i32* @PROT_READ
%3 = load i32, i32* @PROT_WRITE
%4 = or i32 %3, %2
%5 = load i32, i32* @MAP_PRIVATE
%6 = load i32, i32* @MAP_ANONYMOUS
%7 = or i32 %6, %5
%8 = tail call i8* @mmap(i32* null, i64 %0, i32 %4, i32 %7, i32 0, i32 0)
%9 = icmp eq i8* %8, inttoptr (i64 -1 to i8*)
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %1
ret i8* %8
}