#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 /*<<< orphan*/ MAP_HUGETLB;
int /*<<< orphan*/ mmap_chunks_higher(int, int /*<<< orphan*/);
int /*<<< orphan*/ mmap_chunks_lower(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
void alloc_huge_reverse(int chunks) {
  printf("Allocating hugepage chunks > 128TB \n");
  mmap_chunks_higher(chunks / 2, MAP_HUGETLB);
  printf("Allocating hugepage chunks < 128TB \n");
  mmap_chunks_lower(chunks / 2, MAP_HUGETLB);
}


x86 assembly (clang, -O0):
<alloc_huge_reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0xebe(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
mov    0x2e95(%rip),%rax
mov    (%rax),%esi
call   1040 <mmap_chunks_higher@plt>
lea    0xebc(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
call   1050 <mmap_chunks_lower@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_huge_reverse>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0xec4(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%ebp
shr    $0x1f,%ebp
add    %ebx,%ebp
sar    %ebp
mov    0x2e9f(%rip),%rbx
mov    (%rbx),%esi
mov    %ebp,%edi
call   1040 <mmap_chunks_higher@plt>
lea    0xec3(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%esi
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <mmap_chunks_lower@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"Allocating hugepage chunks > 128TB \0A\00"
@MAP_HUGETLB = global i32 0
@.str.1 = [37 x i8] c"Allocating hugepage chunks < 128TB \0A\00"
define void @alloc_huge_reverse(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* %2
%5 = sdiv i32 %4, 2
%6 = load i32, i32* @MAP_HUGETLB
%7 = call i32 @mmap_chunks_higher(i32 %5, i32 %6)
%8 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* %2
%10 = sdiv i32 %9, 2
%11 = load i32, i32* @MAP_HUGETLB
%12 = call i32 @mmap_chunks_lower(i32 %10, i32 %11)
ret void
}

LLVM IR (-O2):
@MAP_HUGETLB = global i32 0
@str = [36 x i8] c"Allocating hugepage chunks > 128TB \00"
@str.2 = [36 x i8] c"Allocating hugepage chunks < 128TB \00"
define void @alloc_huge_reverse(i32 %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%3 = sdiv i32 %0, 2
%4 = load i32, i32* @MAP_HUGETLB
%5 = tail call i32 @mmap_chunks_higher(i32 %3, i32 %4)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.2, i64 0, i64 0))
%7 = load i32, i32* @MAP_HUGETLB
%8 = tail call i32 @mmap_chunks_lower(i32 %3, i32 %7)
ret void
}