#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 *mmap(int /*<<< orphan*/ *, unsigned long, int, unsigned long, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ validate_addr(char *, int /*<<< orphan*/);
scalar_t__ validate_lower_address_hint();
int mmap_chunks_lower(unsigned long no_of_chunks, unsigned long hugetlb_arg) {
  unsigned long i;
  char *ptr;
  for (i = 0; i < no_of_chunks; i++) {
    ptr = mmap(NULL, 17179869184UL, PROT_READ | PROT_WRITE,
               MAP_PRIVATE | MAP_ANONYMOUS | hugetlb_arg, -1, 0);
    if (ptr == MAP_FAILED) {
      printf("Map failed address < 128TB %p \n", ptr);
      if (validate_lower_address_hint()) {
        printf("\n Mmap failed !!! So Problem i = %d\n", i);
        exit(-1);
      }
    }
    if (validate_addr(ptr, 0)) {
      printf("\n Address failed, in > 128Tb !!! So Problem \n");
      exit(-1);
    }
  }
  printf("< 128Tb: \n chunks allocated= %d \n\n", i);
  return 0;
}


x86 assembly (clang, -O0):
<mmap_chunks_lower>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    125b <mmap_chunks_lower+0x10b>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edx
mov    0x2e4a(%rip),%rax
or     (%rax),%edx
mov    0x2e39(%rip),%rax
mov    (%rax),%rcx
mov    0x2e47(%rip),%rax
or     (%rax),%rcx
or     -0x10(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%edi
movabs $0x400000000,%rsi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2df5(%rip),%rcx
cmp    (%rcx),%rax
jne    1218 <mmap_chunks_lower+0xc8>
mov    -0x20(%rbp),%rsi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <validate_lower_address_hint@plt>
cmp    $0x0,%rax
je     1213 <mmap_chunks_lower+0xc3>
mov    -0x18(%rbp),%rsi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
jmp    1218 <mmap_chunks_lower+0xc8>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1070 <validate_addr@plt>
cmp    $0x0,%rax
je     1245 <mmap_chunks_lower+0xf5>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
jmp    124a <mmap_chunks_lower+0xfa>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1168 <mmap_chunks_lower+0x18>
mov    -0x18(%rbp),%rsi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mmap_chunks_lower>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
test   %rdi,%rdi
je     120a <mmap_chunks_lower+0xaa>
mov    %rsi,%r14
movabs $0x400000000,%r12
mov    0x2e35(%rip),%r13
xor    %ebx,%ebx
nopl   (%rax)
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
mov    0x2e58(%rip),%rax
or     (%rax),%edx
mov    0x2e1f(%rip),%rax
mov    (%rax),%rcx
or     %r14,%rcx
mov    0x2e2a(%rip),%rax
or     (%rax),%rcx
xor    %edi,%edi
mov    %r12,%rsi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,%rbp
cmp    0x0(%r13),%rax
jne    11f2 <mmap_chunks_lower+0x92>
lea    0xe24(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1030 <validate_lower_address_hint@plt>
test   %rax,%rax
jne    1242 <mmap_chunks_lower+0xe2>
mov    %rbp,%rdi
xor    %esi,%esi
call   1080 <validate_addr@plt>
test   %rax,%rax
jne    122c <mmap_chunks_lower+0xcc>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1190 <mmap_chunks_lower+0x30>
lea    0xe34(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe35(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
lea    0xdd7(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <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 = [32 x i8] c"Map failed address < 128TB %p \0A\00"
@.str.1 = [37 x i8] c"\0A Mmap failed !!! So Problem i = %d\0A\00"
@.str.2 = [46 x i8] c"\0A Address failed, in > 128Tb !!! So Problem \0A\00"
@.str.3 = [35 x i8] c"< 128Tb: \0A chunks allocated= %d \0A\0A\00"
define i32 @mmap_chunks_lower(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8*
store i64 %0, i64* %3
store i64 %1, i64* %4
store i64 0, i64* %5
br label %7
7: ; preds = %42, %2
%8 = load i64, i64* %5
%9 = load i64, i64* %3
%10 = icmp ult i64 %8, %9
br i1 %10, label %11, label %45
11: ; preds = %7
%12 = load i32, i32* @PROT_READ
%13 = load i32, i32* @PROT_WRITE
%14 = or i32 %12, %13
%15 = load i64, i64* @MAP_PRIVATE
%16 = load i64, i64* @MAP_ANONYMOUS
%17 = or i64 %15, %16
%18 = load i64, i64* %4
%19 = or i64 %17, %18
%20 = call i8* @mmap(i32* null, i64 17179869184, i32 %14, i64 %19, i32 -1, i32 0)
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = load i8*, i8** @MAP_FAILED
%23 = icmp eq i8* %21, %22
br i1 %23, label %24, label %34
24: ; preds = %11
%25 = load i8*, i8** %6
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = call i64 (...) @validate_lower_address_hint()
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %24
%30 = load i64, i64* %5
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i64 %30)
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %24
br label %34
34: ; preds = %33, %11
%35 = load i8*, i8** %6
%36 = call i64 @validate_addr(i8* %35, i32 0)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @exit(i32 -1)
unreachable
41: ; preds = %34
br label %42
42: ; preds = %41
%43 = load i64, i64* %5
%44 = add i64 %43, 1
store i64 %44, i64* %5
br label %7
45: ; preds = %7
%46 = load i64, i64* %5
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i64 %46)
ret i32 0
}

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 = [32 x i8] c"Map failed address < 128TB %p \0A\00"
@.str.1 = [37 x i8] c"\0A Mmap failed !!! So Problem i = %d\0A\00"
@.str.3 = [35 x i8] c"< 128Tb: \0A chunks allocated= %d \0A\0A\00"
@str = [45 x i8] c"\0A Address failed, in > 128Tb !!! So Problem \00"
define i32 @mmap_chunks_lower(i64 %0, i64 %1) {
%3 = icmp eq i64 %0, 0
br i1 %3, label %32, label %4
4: ; preds = %2, %29
%5 = phi i64 [ %30, %29 ], [ 0, %2 ]
%6 = load i32, i32* @PROT_READ
%7 = load i32, i32* @PROT_WRITE
%8 = or i32 %7, %6
%9 = load i64, i64* @MAP_PRIVATE
%10 = load i64, i64* @MAP_ANONYMOUS
%11 = or i64 %9, %1
%12 = or i64 %11, %10
%13 = tail call i8* @mmap(i32* null, i64 17179869184, i32 %8, i64 %12, i32 -1, i32 0)
%14 = load i8*, i8** @MAP_FAILED
%15 = icmp eq i8* %13, %14
br i1 %15, label %16, label %23
16: ; preds = %4
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %13)
%18 = tail call i64 (...) @validate_lower_address_hint()
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %16
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i64 %5)
%22 = tail call i32 @exit(i32 -1)
unreachable
23: ; preds = %16, %4
%24 = tail call i64 @validate_addr(i8* %13, i32 0)
%25 = icmp eq i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%28 = tail call i32 @exit(i32 -1)
unreachable
29: ; preds = %23
%30 = add nuw i64 %5, 1
%31 = icmp eq i64 %30, %0
br i1 %31, label %32, label %4
32: ; preds = %29, %2
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i64 %0)
ret i32 0
}