#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;
void *MAP_FAILED;
int MAP_PRIVATE;
int /*<<< orphan*/ _SC_PAGESIZE;
int /*<<< orphan*/ abort();
void *mmap(int /*<<< orphan*/ *, int /*<<< orphan*/, int, int, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ sysconf(int /*<<< orphan*/);
void *alloc_page(int prot) {
  void *ret;
  int flags;
  flags = MAP_PRIVATE | MAP_ANONYMOUS;
  ret = mmap(NULL, sysconf(_SC_PAGESIZE), prot, flags, -1, 0);
  if (ret == MAP_FAILED)
    abort();
  return ret;
}


x86 assembly (clang, -O0):
<alloc_page>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%eax
mov    0x2e95(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
mov    %eax,%esi
mov    -0x4(%rbp),%edx
mov    -0x14(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e41(%rip),%rcx
cmp    (%rcx),%rax
jne    1197 <alloc_page+0x67>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_page>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2e94(%rip),%rax
mov    0x2e9d(%rip),%rcx
mov    (%rcx),%ebp
or     (%rax),%ebp
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
xor    %edi,%edi
mov    %eax,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    0x2e56(%rip),%rcx
cmp    (%rcx),%rax
je     117e <alloc_page+0x4e>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@_SC_PAGESIZE = global i32 0
@MAP_FAILED = global i8* null
define i8* @alloc_page(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* @MAP_PRIVATE
%6 = load i32, i32* @MAP_ANONYMOUS
%7 = or i32 %5, %6
store i32 %7, i32* %4
%8 = load i32, i32* @_SC_PAGESIZE
%9 = call i32 @sysconf(i32 %8)
%10 = load i32, i32* %2
%11 = load i32, i32* %4
%12 = call i8* @mmap(i32* null, i32 %9, i32 %10, i32 %11, i32 -1, i32 0)
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = load i8*, i8** @MAP_FAILED
%15 = icmp eq i8* %13, %14
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = call i32 (...) @abort()
unreachable
18: ; preds = %1
%19 = load i8*, i8** %3
ret i8* %19
}

LLVM IR (-O2):
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@_SC_PAGESIZE = global i32 0
@MAP_FAILED = global i8* null
define i8* @alloc_page(i32 %0) {
%2 = load i32, i32* @MAP_PRIVATE
%3 = load i32, i32* @MAP_ANONYMOUS
%4 = or i32 %3, %2
%5 = load i32, i32* @_SC_PAGESIZE
%6 = tail call i32 @sysconf(i32 %5)
%7 = tail call i8* @mmap(i32* null, i32 %6, i32 %0, i32 %4, i32 -1, i32 0)
%8 = load i8*, i8** @MAP_FAILED
%9 = icmp eq i8* %7, %8
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = tail call i32 (...) @abort()
unreachable
12: ; preds = %1
ret i8* %7
}