#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 == 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     117b <get_unmapped_page+0x3b>
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    0x2e65(%rip),%rax
mov    (%rax),%edx
mov    0x2e44(%rip),%rax
mov    (%rax),%ecx
mov    0x2e23(%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
cmp    $0x1000,%rax
sete   %al
cmp    $0x10000,%r14
sete   %cl
or     %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edx
mov    0x2e5e(%rip),%rax
mov    0x2e3f(%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 %11, label %8
8: ; preds = %0
%9 = load i64, i64* %3
%10 = icmp eq i64 %9, 65536
br label %11
11: ; preds = %8, %0
%12 = phi i1 [ true, %0 ], [ %10, %8 ]
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i64, i64* %3
%16 = load i32, i32* @PROT_READ
%17 = load i32, i32* @MAP_ANONYMOUS
%18 = load i32, i32* @MAP_PRIVATE
%19 = or i32 %17, %18
%20 = call i8* @mmap(i32 0, i64 %15, i32 %16, i32 %19, i32 -1, i32 0)
store i8* %20, i8** %1
%21 = load i8*, i8** %1
%22 = icmp ne i8* %21, inttoptr (i64 -1 to i8*)
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load i8*, i8** %1
%26 = load i64, i64* %3
%27 = call i32 @munmap(i8* %25, i64 %26)
store i32 %27, i32* %2
%28 = load i32, i32* %2
%29 = icmp eq i32 %28, 0
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = load i8*, i8** %1
ret i8* %32
}

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 = icmp eq i64 %2, 4096
%4 = icmp eq i64 %2, 65536
%5 = or i1 %3, %4
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = load i32, i32* @PROT_READ
%9 = load i32, i32* @MAP_ANONYMOUS
%10 = load i32, i32* @MAP_PRIVATE
%11 = or i32 %10, %9
%12 = tail call i8* @mmap(i32 0, i64 %2, i32 %8, i32 %11, i32 -1, i32 0)
%13 = icmp ne i8* %12, inttoptr (i64 -1 to i8*)
%14 = zext i1 %13 to i32
%15 = tail call i32 @assert(i32 %14)
%16 = tail call i32 @munmap(i8* %12, i64 %2)
%17 = icmp eq i32 %16, 0
%18 = zext i1 %17 to i32
%19 = tail call i32 @assert(i32 %18)
ret i8* %12
}