#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_HUGETLB;
int /*<<< orphan*/ mmap_chunks_higher(int, int);
int /*<<< orphan*/ mmap_chunks_lower(int, int);
int /*<<< orphan*/ printf(char *);
void mixed_position_16G() {
  printf("Allocating 64k pages < 128TB \n");
  mmap_chunks_lower(4000, 0);
  printf("Allocating 16G chunks < 128TB \n");
  mmap_chunks_lower(1, (MAP_HUGETLB | (34 << 26)));
  printf("Allocating 64k pages < 128TB \n");
  mmap_chunks_lower(4000, 0);
  printf("Allocating 16M chunks < 128TB \n");
  mmap_chunks_lower(64, MAP_HUGETLB);
  printf("Allocating 64k pages > 128TB \n");
  mmap_chunks_higher(12192, 0);
  printf("Allocating 16G chunks > 128TB \n");
  mmap_chunks_higher(1, (MAP_HUGETLB | (34 << 26)));
  printf("Allocating 64k pages > 128TB \n");
  mmap_chunks_higher(12192, 0);
  printf("Allocating 16M chunks > 128TB \n");
  mmap_chunks_higher(64, MAP_HUGETLB);
}


x86 assembly (clang, -O0):
<mixed_position_16G>:
push   %rbp
mov    %rsp,%rbp
lea    0xec5(%rip),%rdi
call   1030 <printf@plt>
mov    $0xfa0,%edi
xor    %esi,%esi
call   1050 <mmap_chunks_lower@plt>
lea    0xecc(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
or     $0x88000000,%esi
mov    $0x1,%edi
call   1050 <mmap_chunks_lower@plt>
lea    0xe88(%rip),%rdi
call   1030 <printf@plt>
mov    $0xfa0,%edi
xor    %esi,%esi
call   1050 <mmap_chunks_lower@plt>
lea    0xeaf(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
mov    $0x40,%edi
call   1050 <mmap_chunks_lower@plt>
lea    0xeb0(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2fa0,%edi
xor    %esi,%esi
call   1040 <mmap_chunks_higher@plt>
lea    0xeb7(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
or     $0x88000000,%esi
mov    $0x1,%edi
call   1040 <mmap_chunks_higher@plt>
lea    0xe73(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2fa0,%edi
xor    %esi,%esi
call   1040 <mmap_chunks_higher@plt>
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%esi
mov    $0x40,%edi
call   1040 <mmap_chunks_higher@plt>
pop    %rbp
ret

x86 assembly (clang, -O2):
<mixed_position_16G>:
push   %r15
push   %r14
push   %rbx
lea    0xee3(%rip),%r14
mov    %r14,%rdi
call   1030 <puts@plt>
mov    $0xfa0,%edi
xor    %esi,%esi
call   1050 <mmap_chunks_lower@plt>
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e8d(%rip),%r15
mov    $0x88000000,%ebx
mov    (%r15),%esi
or     %ebx,%esi
mov    $0x1,%edi
call   1050 <mmap_chunks_lower@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    $0xfa0,%edi
xor    %esi,%esi
call   1050 <mmap_chunks_lower@plt>
lea    0xeab(%rip),%rdi
call   1030 <puts@plt>
mov    (%r15),%esi
mov    $0x40,%edi
call   1050 <mmap_chunks_lower@plt>
lea    0xed0(%rip),%r14
mov    %r14,%rdi
call   1030 <puts@plt>
mov    $0x2fa0,%edi
xor    %esi,%esi
call   1040 <mmap_chunks_higher@plt>
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
or     (%r15),%ebx
mov    $0x1,%edi
mov    %ebx,%esi
call   1040 <mmap_chunks_higher@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    $0x2fa0,%edi
xor    %esi,%esi
call   1040 <mmap_chunks_higher@plt>
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
mov    (%r15),%esi
mov    $0x40,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <mmap_chunks_higher@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"Allocating 64k pages < 128TB \0A\00"
@.str.1 = [32 x i8] c"Allocating 16G chunks < 128TB \0A\00"
@MAP_HUGETLB = global i32 0
@.str.2 = [32 x i8] c"Allocating 16M chunks < 128TB \0A\00"
@.str.3 = [31 x i8] c"Allocating 64k pages > 128TB \0A\00"
@.str.4 = [32 x i8] c"Allocating 16G chunks > 128TB \0A\00"
@.str.5 = [32 x i8] c"Allocating 16M chunks > 128TB \0A\00"
define void @mixed_position_16G() {
%1 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%2 = call i32 @mmap_chunks_lower(i32 4000, i32 0)
%3 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%4 = load i32, i32* @MAP_HUGETLB
%5 = or i32 %4, -2013265920
%6 = call i32 @mmap_chunks_lower(i32 1, i32 %5)
%7 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @mmap_chunks_lower(i32 4000, i32 0)
%9 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* @MAP_HUGETLB
%11 = call i32 @mmap_chunks_lower(i32 64, i32 %10)
%12 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @mmap_chunks_higher(i32 12192, i32 0)
%14 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%15 = load i32, i32* @MAP_HUGETLB
%16 = or i32 %15, -2013265920
%17 = call i32 @mmap_chunks_higher(i32 1, i32 %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 @mmap_chunks_higher(i32 12192, i32 0)
%20 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%21 = load i32, i32* @MAP_HUGETLB
%22 = call i32 @mmap_chunks_higher(i32 64, i32 %21)
ret void
}

LLVM IR (-O2):
@MAP_HUGETLB = global i32 0
@str.6 = [31 x i8] c"Allocating 16G chunks < 128TB \00"
@str.7 = [30 x i8] c"Allocating 64k pages < 128TB \00"
@str.8 = [31 x i8] c"Allocating 16M chunks < 128TB \00"
@str.10 = [31 x i8] c"Allocating 16G chunks > 128TB \00"
@str.11 = [30 x i8] c"Allocating 64k pages > 128TB \00"
@str.12 = [31 x i8] c"Allocating 16M chunks > 128TB \00"
define void @mixed_position_16G() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.7, i64 0, i64 0))
%2 = tail call i32 @mmap_chunks_lower(i32 4000, i32 0)
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.6, i64 0, i64 0))
%4 = load i32, i32* @MAP_HUGETLB
%5 = or i32 %4, -2013265920
%6 = tail call i32 @mmap_chunks_lower(i32 1, i32 %5)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.7, i64 0, i64 0))
%8 = tail call i32 @mmap_chunks_lower(i32 4000, i32 0)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.8, i64 0, i64 0))
%10 = load i32, i32* @MAP_HUGETLB
%11 = tail call i32 @mmap_chunks_lower(i32 64, i32 %10)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.11, i64 0, i64 0))
%13 = tail call i32 @mmap_chunks_higher(i32 12192, i32 0)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.10, i64 0, i64 0))
%15 = load i32, i32* @MAP_HUGETLB
%16 = or i32 %15, -2013265920
%17 = tail call i32 @mmap_chunks_higher(i32 1, i32 %16)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.11, i64 0, i64 0))
%19 = tail call i32 @mmap_chunks_higher(i32 12192, i32 0)
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.12, i64 0, i64 0))
%21 = load i32, i32* @MAP_HUGETLB
%22 = tail call i32 @mmap_chunks_higher(i32 64, i32 %21)
ret void
}