#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;
scalar_t__ MAP_FAILED;
int MAP_HUGETLB;
int MAP_NORESERVE;
int MAP_SHARED;
int /*<<< orphan*/ PROT_NONE;
int /*<<< orphan*/ err(int, char *);
int getpagesize();
scalar_t__ mincore(void *, int, unsigned char *);
scalar_t__ mmap(void *, int, int /*<<< orphan*/, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, unsigned long);
int main(void) {
  unsigned char buf[getpagesize() / sizeof(unsigned char)];
  int right = 1;
  unsigned long addr = 0;
  if (mmap((void *)0x66000000, 0x20000000000, PROT_NONE,
           MAP_SHARED | MAP_ANONYMOUS | MAP_HUGETLB | MAP_NORESERVE, -1,
           0) == MAP_FAILED)
    err(1, "mmap");
  while (right) {
    if (mincore((void *)0x86000000, 0x1000000, buf))
      perror("mincore");
    for (int n = 0; n < getpagesize() / sizeof(unsigned char); n++) {
      addr = *(unsigned long *)(&buf[n]);
      if (addr > 0xffffffff00000000) {
        right = 0;
        goto out;
      }
    }
  }
out:
  printf("%p\n", addr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
call   1080 <getpagesize@plt>
cltq
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%edx
mov    0x2e26(%rip),%rax
mov    (%rax),%ecx
mov    0x2e05(%rip),%rax
or     (%rax),%ecx
mov    0x2e1c(%rip),%rax
or     (%rax),%ecx
mov    0x2dfb(%rip),%rax
or     (%rax),%ecx
mov    $0x66000000,%edi
xor    %r9d,%r9d
mov    $0xffffffff,%r8d
mov    %r9d,%esi
call   1030 <mmap@plt>
mov    0x2dc4(%rip),%rcx
cmp    (%rcx),%rax
jne    120e <main+0xae>
mov    $0x1,%edi
lea    0xdf7(%rip),%rsi
call   1060 <err@plt>
jmp    1213 <main+0xb3>
cmpl   $0x0,-0x1c(%rbp)
je     12ba <main+0x15a>
mov    -0x38(%rbp),%rdx
mov    $0x86000000,%edi
mov    $0x1000000,%esi
call   1050 <mincore@plt>
cmp    $0x0,%rax
je     1246 <main+0xe6>
lea    0xdc4(%rip),%rdi
call   1070 <perror@plt>
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1080 <getpagesize@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
shr    $0x0,%rcx
cmp    %rcx,%rax
jae    12b5 <main+0x155>
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,1),%rax
mov    %rax,-0x28(%rbp)
movabs $0xffffffff00000000,%rax
ff ff ff
cmp    %rax,-0x28(%rbp)
jbe    12a2 <main+0x142>
movl   $0x0,-0x1c(%rbp)
jmp    12bf <main+0x15f>
jmp    12a7 <main+0x147>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    124d <main+0xed>
jmp    1213 <main+0xb3>
jmp    12bf <main+0x15f>
mov    -0x28(%rbp),%rsi
lea    0xd43(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %eax,%eax
call   1080 <getpagesize@plt>
cltq
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    0x2e54(%rip),%rax
mov    0x2e35(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e52(%rip),%rax
mov    0x2e43(%rip),%rdx
or     (%rdx),%ecx
mov    (%rax),%edx
mov    0x2e20(%rip),%rax
or     (%rax),%ecx
mov    $0x66000000,%edi
xor    %esi,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    0x2dea(%rip),%rcx
cmp    (%rcx),%rax
jne    11e4 <main+0x84>
lea    0xe26(%rip),%rsi
mov    $0x1,%edi
call   1060 <err@plt>
movabs $0xffffffff00000001,%r15
ff ff ff
lea    0xe10(%rip),%r14
mov    $0x86000000,%edi
mov    $0x1000000,%esi
mov    %r12,%rdx
call   1050 <mincore@plt>
test   %rax,%rax
jne    123d <main+0xdd>
xor    %eax,%eax
call   1080 <getpagesize@plt>
test   %eax,%eax
je     11f5 <main+0x95>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r12,%rbx,1),%rsi
cmp    %r15,%rsi
jae    1247 <main+0xe7>
add    $0x1,%rbx
xor    %eax,%eax
call   1080 <getpagesize@plt>
cltq
cmp    %rax,%rbx
jb     1220 <main+0xc0>
jmp    11f5 <main+0x95>
mov    %r14,%rdi
call   1070 <perror@plt>
jmp    120c <main+0xac>
lea    0xdbf(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PROT_NONE = global i32 0
@MAP_SHARED = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_HUGETLB = global i32 0
@MAP_NORESERVE = global i32 0
@MAP_FAILED = global i64 0
@.str = [5 x i8] c"mmap\00"
@.str.1 = [8 x i8] c"mincore\00"
@.str.2 = [4 x i8] c"%p\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (...) @getpagesize()
%8 = sext i32 %7 to i64
%9 = udiv i64 %8, 1
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %2
%11 = alloca i8, i64 %9
store i64 %9, i64* %3
store i32 1, i32* %4
store i64 0, i64* %5
%12 = load i32, i32* @PROT_NONE
%13 = load i32, i32* @MAP_SHARED
%14 = load i32, i32* @MAP_ANONYMOUS
%15 = or i32 %13, %14
%16 = load i32, i32* @MAP_HUGETLB
%17 = or i32 %15, %16
%18 = load i32, i32* @MAP_NORESERVE
%19 = or i32 %17, %18
%20 = call i64 @mmap(i8* inttoptr (i64 1711276032 to i8*), i32 0, i32 %12, i32 %19, i32 -1, i32 0)
%21 = load i64, i64* @MAP_FAILED
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %0
%24 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23, %0
br label %26
26: ; preds = %55, %25
%27 = load i32, i32* %4
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %56
29: ; preds = %26
%30 = call i64 @mincore(i8* inttoptr (i64 2248146944 to i8*), i32 16777216, i8* %11)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %29
store i32 0, i32* %6
br label %35
35: ; preds = %52, %34
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = call i32 (...) @getpagesize()
%39 = sext i32 %38 to i64
%40 = udiv i64 %39, 1
%41 = icmp ult i64 %37, %40
br i1 %41, label %42, label %55
42: ; preds = %35
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %11, i64 %44
%46 = bitcast i8* %45 to i64*
%47 = load i64, i64* %46
store i64 %47, i64* %5
%48 = load i64, i64* %5
%49 = icmp ugt i64 %48, -4294967296
br i1 %49, label %50, label %51
50: ; preds = %42
store i32 0, i32* %4
br label %57
51: ; preds = %42
br label %52
52: ; preds = %51
%53 = load i32, i32* %6
%54 = add nsw i32 %53, 1
store i32 %54, i32* %6
br label %35
55: ; preds = %35
br label %26
56: ; preds = %26
br label %57
57: ; preds = %56, %50
%58 = load i64, i64* %5
%59 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 %58)
store i32 0, i32* %1
%60 = load i8*, i8** %2
%61 = load i32, i32* %1
ret i32 %61
}

LLVM IR (-O2):
@PROT_NONE = global i32 0
@MAP_SHARED = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_HUGETLB = global i32 0
@MAP_NORESERVE = global i32 0
@MAP_FAILED = global i64 0
@.str = [5 x i8] c"mmap\00"
@.str.1 = [8 x i8] c"mincore\00"
@.str.2 = [4 x i8] c"%p\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @getpagesize()
%2 = sext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = load i32, i32* @PROT_NONE
%5 = load i32, i32* @MAP_SHARED
%6 = load i32, i32* @MAP_ANONYMOUS
%7 = or i32 %6, %5
%8 = load i32, i32* @MAP_HUGETLB
%9 = or i32 %7, %8
%10 = load i32, i32* @MAP_NORESERVE
%11 = or i32 %9, %10
%12 = tail call i64 @mmap(i8* inttoptr (i64 1711276032 to i8*), i32 0, i32 %4, i32 %11, i32 -1, i32 0)
%13 = load i64, i64* @MAP_FAILED
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %0
br label %18
18: ; preds = %26, %17
%19 = call i64 @mincore(i8* inttoptr (i64 2248146944 to i8*), i32 16777216, i8* %3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = call i32 (...) @getpagesize()
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %27, %23
br label %18
27: ; preds = %31
%28 = call i32 (...) @getpagesize()
%29 = sext i32 %28 to i64
%30 = icmp ult i64 %37, %29
br i1 %30, label %31, label %26
31: ; preds = %23, %27
%32 = phi i64 [ %37, %27 ], [ 0, %23 ]
%33 = getelementptr inbounds i8, i8* %3, i64 %32
%34 = bitcast i8* %33 to i64*
%35 = load i64, i64* %34
%36 = icmp ugt i64 %35, -4294967296
%37 = add nuw i64 %32, 1
br i1 %36, label %38, label %27
38: ; preds = %31
%39 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 %35)
ret i32 0
}