#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 */
unsigned long MAP_ANONYMOUS;
char *MAP_FAILED;
unsigned long MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ exit(int);
char *hind_addr();
char *mmap(char *, unsigned long, int, unsigned long, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ validate_addr(char *, int);
int mmap_chunks_higher(unsigned long no_of_chunks, unsigned long hugetlb_arg) {
  unsigned long i;
  char *hptr;
  char *hint;
  int mmap_args = 0;
  for (i = 0; i < no_of_chunks; i++) {
    hint = hind_addr();
    hptr = mmap(hint, 17179869184UL, PROT_READ | PROT_WRITE,
                MAP_PRIVATE | MAP_ANONYMOUS | hugetlb_arg, -1, 0);
    if (hptr == MAP_FAILED) {
      printf("\n Map failed at address %p < 384TB in iteration = %d \n", hptr,
             i);
      exit(-1);
    }
    if (validate_addr(hptr, 1)) {
      printf("\n Address failed, not in > 128Tb iterator = %d\n", i);
      exit(-1);
    }
  }
  printf("> 128Tb: \n chunks allocated= %d \n", i);
}


x86 assembly (clang, -O0):
<mmap_chunks_higher>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x34(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1250 <mmap_chunks_higher+0x100>
mov    $0x0,%al
call   1050 <hind_addr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2e65(%rip),%rax
mov    (%rax),%edx
mov    0x2e34(%rip),%rax
or     (%rax),%edx
mov    0x2e23(%rip),%rax
mov    (%rax),%rcx
mov    0x2e31(%rip),%rax
or     (%rax),%rcx
or     -0x18(%rbp),%rcx
movabs $0x400000000,%rsi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2de3(%rip),%rcx
cmp    (%rcx),%rax
jne    1206 <mmap_chunks_higher+0xb6>
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    $0x1,%esi
call   1070 <validate_addr@plt>
cmp    $0x0,%rax
je     123a <mmap_chunks_higher+0xea>
mov    -0x20(%rbp),%rsi
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
jmp    123f <mmap_chunks_higher+0xef>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    116f <mmap_chunks_higher+0x1f>
mov    -0x20(%rbp),%rsi
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mmap_chunks_higher>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
test   %rdi,%rdi
je     11df <mmap_chunks_higher+0x8f>
mov    %rsi,%r14
mov    0x2e73(%rip),%rbp
movabs $0x400000000,%r12
mov    0x2e42(%rip),%r13
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <hind_addr@plt>
mov    0x2e42(%rip),%rcx
mov    (%rcx),%edx
mov    0x2e61(%rip),%rcx
or     (%rcx),%edx
mov    0x2e28(%rip),%rcx
mov    (%rcx),%rcx
or     %r14,%rcx
or     0x0(%rbp),%rcx
mov    %rax,%rdi
mov    %r12,%rsi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
cmp    0x0(%r13),%rax
je     11fe <mmap_chunks_higher+0xae>
mov    %rax,%rdi
mov    $0x1,%esi
call   1070 <validate_addr@plt>
test   %rax,%rax
jne    121c <mmap_chunks_higher+0xcc>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1180 <mmap_chunks_higher+0x30>
lea    0xe81(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
lea    0xdfb(%rip),%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
lea    0xe14(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i64 0
@MAP_ANONYMOUS = global i64 0
@MAP_FAILED = global i8* null
@.str = [55 x i8] c"\0A Map failed at address %p < 384TB in iteration = %d \0A\00"
@.str.1 = [48 x i8] c"\0A Address failed, not in > 128Tb iterator = %d\0A\00"
@.str.2 = [34 x i8] c"> 128Tb: \0A chunks allocated= %d \0A\00"
define i32 @mmap_chunks_higher(i64 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i64 %0, i64* %4
store i64 %1, i64* %5
store i32 0, i32* %9
store i64 0, i64* %6
br label %10
10: ; preds = %43, %2
%11 = load i64, i64* %6
%12 = load i64, i64* %4
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %46
14: ; preds = %10
%15 = call i8* (...) @hind_addr()
store i8* %15, i8** %8
%16 = load i8*, i8** %8
%17 = load i32, i32* @PROT_READ
%18 = load i32, i32* @PROT_WRITE
%19 = or i32 %17, %18
%20 = load i64, i64* @MAP_PRIVATE
%21 = load i64, i64* @MAP_ANONYMOUS
%22 = or i64 %20, %21
%23 = load i64, i64* %5
%24 = or i64 %22, %23
%25 = call i8* @mmap(i8* %16, i64 17179869184, i32 %19, i64 %24, i32 -1, i32 0)
store i8* %25, i8** %7
%26 = load i8*, i8** %7
%27 = load i8*, i8** @MAP_FAILED
%28 = icmp eq i8* %26, %27
br i1 %28, label %29, label %34
29: ; preds = %14
%30 = load i8*, i8** %7
%31 = load i64, i64* %6
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i8* %30, i64 %31)
%33 = call i32 @exit(i32 -1)
unreachable
34: ; preds = %14
%35 = load i8*, i8** %7
%36 = call i64 @validate_addr(i8* %35, i32 1)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i64, i64* %6
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i64 %39)
%41 = call i32 @exit(i32 -1)
unreachable
42: ; preds = %34
br label %43
43: ; preds = %42
%44 = load i64, i64* %6
%45 = add i64 %44, 1
store i64 %45, i64* %6
br label %10
46: ; preds = %10
%47 = load i64, i64* %6
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i64 %47)
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i64 0
@MAP_ANONYMOUS = global i64 0
@MAP_FAILED = global i8* null
@.str = [55 x i8] c"\0A Map failed at address %p < 384TB in iteration = %d \0A\00"
@.str.1 = [48 x i8] c"\0A Address failed, not in > 128Tb iterator = %d\0A\00"
@.str.2 = [34 x i8] c"> 128Tb: \0A chunks allocated= %d \0A\00"
define i32 @mmap_chunks_higher(i64 %0, i64 %1) {
%3 = icmp eq i64 %0, 0
br i1 %3, label %29, label %4
4: ; preds = %2, %26
%5 = phi i64 [ %27, %26 ], [ 0, %2 ]
%6 = tail call i8* (...) @hind_addr()
%7 = load i32, i32* @PROT_READ
%8 = load i32, i32* @PROT_WRITE
%9 = or i32 %8, %7
%10 = load i64, i64* @MAP_PRIVATE
%11 = load i64, i64* @MAP_ANONYMOUS
%12 = or i64 %10, %1
%13 = or i64 %12, %11
%14 = tail call i8* @mmap(i8* %6, i64 17179869184, i32 %9, i64 %13, i32 -1, i32 0)
%15 = load i8*, i8** @MAP_FAILED
%16 = icmp eq i8* %14, %15
br i1 %16, label %17, label %20
17: ; preds = %4
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i8* %14, i64 %5)
%19 = tail call i32 @exit(i32 -1)
unreachable
20: ; preds = %4
%21 = tail call i64 @validate_addr(i8* %14, i32 1)
%22 = icmp eq i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i64 %5)
%25 = tail call i32 @exit(i32 -1)
unreachable
26: ; preds = %20
%27 = add nuw i64 %5, 1
%28 = icmp eq i64 %27, %0
br i1 %28, label %29, label %4
29: ; preds = %26, %2
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i64 %0)
ret i32 undef
}