#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 /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ _SC_PAGE_SIZE;
int /*<<< orphan*/ assert(int);
void *mmap(int /*<<< orphan*/, long, int /*<<< orphan*/, int, int,
           int /*<<< orphan*/);
int munmap(void *, long);
long sysconf(int /*<<< orphan*/);
__attribute__((unused)) void *get_unmapped_page(void) {
  void *ptr;
  int r;
  long pagesz = sysconf(_SC_PAGE_SIZE);
  assert(pagesz == 4096 || pagesz == 8192 || pagesz == 16384 ||
         pagesz == 32768 || pagesz == 65536);
  ptr = mmap(0, pagesz, PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
  assert(ptr != (void *)-1);
  r = munmap(ptr, pagesz);
  assert(r == 0);
  return ptr;
}


x86 assembly (clang, -O0):
<get_unmapped_page>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
call   1060 <sysconf@plt>
mov    %rax,-0x18(%rbp)
mov    $0x1,%al
cmpq   $0x1000,-0x18(%rbp)
mov    %al,-0x19(%rbp)
je     11b4 <get_unmapped_page+0x74>
mov    $0x1,%al
cmpq   $0x2000,-0x18(%rbp)
mov    %al,-0x19(%rbp)
je     11b4 <get_unmapped_page+0x74>
mov    $0x1,%al
cmpq   $0x4000,-0x18(%rbp)
mov    %al,-0x19(%rbp)
je     11b4 <get_unmapped_page+0x74>
mov    $0x1,%al
cmpq   $0x8000,-0x18(%rbp)
mov    %al,-0x19(%rbp)
je     11b4 <get_unmapped_page+0x74>
cmpq   $0x10000,-0x18(%rbp)
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rsi
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
mov    0x2e0b(%rip),%rax
mov    (%rax),%ecx
mov    0x2dea(%rip),%rax
or     (%rax),%ecx
xor    %r9d,%r9d
mov    $0xffffffff,%r8d
mov    %r9d,%edi
call   1030 <mmap@plt>
mov    %rax,-0x8(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <munmap@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_unmapped_page>:
push   %r14
push   %rbx
push   %rax
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
call   1060 <sysconf@plt>
mov    %rax,%r14
add    $0xfffffffffffff000,%rax
rol    $0x34,%rax
cmp    $0x8,%rax
jae    1174 <get_unmapped_page+0x34>
mov    $0x1,%edi
mov    $0x8b,%ecx
bt     %eax,%ecx
jb     1181 <get_unmapped_page+0x41>
xor    %edi,%edi
cmp    $0x10000,%r14
sete   %dil
call   1040 <assert@plt>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edx
mov    0x2e4a(%rip),%rax
mov    0x2e2b(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    %r14,%rsi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
xor    %edi,%edi
cmp    $0xffffffffffffffff,%rax
setne  %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <munmap@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@_SC_PAGE_SIZE = global i32 0
@PROT_READ = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_PRIVATE = global i32 0
define i8* @get_unmapped_page() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i64
%4 = load i32, i32* @_SC_PAGE_SIZE
%5 = call i64 @sysconf(i32 %4)
store i64 %5, i64* %3
%6 = load i64, i64* %3
%7 = icmp eq i64 %6, 4096
br i1 %7, label %20, label %8
8: ; preds = %0
%9 = load i64, i64* %3
%10 = icmp eq i64 %9, 8192
br i1 %10, label %20, label %11
11: ; preds = %8
%12 = load i64, i64* %3
%13 = icmp eq i64 %12, 16384
br i1 %13, label %20, label %14
14: ; preds = %11
%15 = load i64, i64* %3
%16 = icmp eq i64 %15, 32768
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load i64, i64* %3
%19 = icmp eq i64 %18, 65536
br label %20
20: ; preds = %17, %14, %11, %8, %0
%21 = phi i1 [ true, %14 ], [ true, %11 ], [ true, %8 ], [ true, %0 ], [ %19, %17 ]
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = load i64, i64* %3
%25 = load i32, i32* @PROT_READ
%26 = load i32, i32* @MAP_ANONYMOUS
%27 = load i32, i32* @MAP_PRIVATE
%28 = or i32 %26, %27
%29 = call i8* @mmap(i32 0, i64 %24, i32 %25, i32 %28, i32 -1, i32 0)
store i8* %29, i8** %1
%30 = load i8*, i8** %1
%31 = icmp ne i8* %30, inttoptr (i64 -1 to i8*)
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = load i8*, i8** %1
%35 = load i64, i64* %3
%36 = call i32 @munmap(i8* %34, i64 %35)
store i32 %36, i32* %2
%37 = load i32, i32* %2
%38 = icmp eq i32 %37, 0
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = load i8*, i8** %1
ret i8* %41
}

LLVM IR (-O2):
@_SC_PAGE_SIZE = global i32 0
@PROT_READ = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_PRIVATE = global i32 0
define i8* @get_unmapped_page() {
%1 = load i32, i32* @_SC_PAGE_SIZE
%2 = tail call i64 @sysconf(i32 %1)
%3 = add i64 %2, -4096
%4 = tail call i64 @llvm.fshl.i64(i64 %3, i64 %3, i64 52)
%5 = icmp ult i64 %4, 8
br i1 %5, label %9, label %6
6: ; preds = %9, %0
%7 = icmp eq i64 %2, 65536
%8 = zext i1 %7 to i32
br label %14
9: ; preds = %0
%10 = trunc i64 %4 to i8
%11 = lshr i8 -117, %10
%12 = and i8 %11, 1
%13 = icmp eq i8 %12, 0
br i1 %13, label %6, label %14
14: ; preds = %9, %6
%15 = phi i32 [ %8, %6 ], [ 1, %9 ]
%16 = tail call i32 @assert(i32 %15)
%17 = load i32, i32* @PROT_READ
%18 = load i32, i32* @MAP_ANONYMOUS
%19 = load i32, i32* @MAP_PRIVATE
%20 = or i32 %19, %18
%21 = tail call i8* @mmap(i32 0, i64 %2, i32 %17, i32 %20, i32 -1, i32 0)
%22 = icmp ne i8* %21, inttoptr (i64 -1 to i8*)
%23 = zext i1 %22 to i32
%24 = tail call i32 @assert(i32 %23)
%25 = tail call i32 @munmap(i8* %21, i64 %2)
%26 = icmp eq i32 %25, 0
%27 = zext i1 %26 to i32
%28 = tail call i32 @assert(i32 %27)
ret i8* %21
}