#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;
int MAP_HUGETLB;
int /*<<< orphan*/ do_mmap(int, int, int);
int open_file(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ system(char *);
int main(void) {
  int hugefd, fd;
  fd = open_file("/dev/shm/hugetlbhog");
  hugefd = open_file("/hugepages/hugetlbhog");
  system("echo 100 > /proc/sys/vm/nr_hugepages");
  do_mmap(-1, MAP_ANONYMOUS, 1);
  do_mmap(fd, 0, 1);
  do_mmap(-1, MAP_ANONYMOUS | MAP_HUGETLB, 1);
  do_mmap(hugefd, 0, 1);
  do_mmap(hugefd, MAP_HUGETLB, 1);
  do_mmap(-1, MAP_ANONYMOUS | MAP_HUGETLB, 0);
  printf("oll korrekt.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
call   1040 <open_file@plt>
mov    %eax,-0xc(%rbp)
lea    0xeaf(%rip),%rdi
call   1040 <open_file@plt>
mov    %eax,-0x8(%rbp)
lea    0xeb6(%rip),%rdi
call   1050 <system@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
mov    $0xffffffff,%edi
mov    $0x1,%edx
call   1030 <do_mmap@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1030 <do_mmap@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
mov    0x2e40(%rip),%rax
or     (%rax),%esi
mov    $0xffffffff,%edi
mov    $0x1,%edx
call   1030 <do_mmap@plt>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1030 <do_mmap@plt>
mov    -0x8(%rbp),%edi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
call   1030 <do_mmap@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
mov    0x2dfa(%rip),%rax
or     (%rax),%esi
mov    $0xffffffff,%edi
xor    %edx,%edx
call   1030 <do_mmap@plt>
lea    0xe44(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xeb5(%rip),%rdi
call   1050 <open_file@plt>
mov    %eax,%ebp
lea    0xebb(%rip),%rdi
call   1050 <open_file@plt>
mov    %eax,%ebx
lea    0xec3(%rip),%rdi
call   1060 <system@plt>
mov    0x2e6d(%rip),%r14
mov    (%r14),%esi
mov    $0xffffffff,%edi
mov    $0x1,%edx
call   1040 <do_mmap@plt>
mov    %ebp,%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1040 <do_mmap@plt>
mov    0x2e56(%rip),%rbp
mov    0x0(%rbp),%esi
or     (%r14),%esi
mov    $0xffffffff,%edi
mov    $0x1,%edx
call   1040 <do_mmap@plt>
mov    %ebx,%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1040 <do_mmap@plt>
mov    0x0(%rbp),%esi
mov    %ebx,%edi
mov    $0x1,%edx
call   1040 <do_mmap@plt>
mov    0x0(%rbp),%esi
or     (%r14),%esi
mov    $0xffffffff,%edi
xor    %edx,%edx
call   1040 <do_mmap@plt>
lea    0xe6a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"/dev/shm/hugetlbhog\00"
@.str.1 = [22 x i8] c"/hugepages/hugetlbhog\00"
@.str.2 = [37 x i8] c"echo 100 > /proc/sys/vm/nr_hugepages\00"
@MAP_ANONYMOUS = global i32 0
@MAP_HUGETLB = global i32 0
@.str.3 = [14 x i8] c"oll korrekt.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @open_file(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 %4, i32* %3
%5 = call i32 @open_file(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 %5, i32* %2
%6 = call i32 @system(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%7 = load i32, i32* @MAP_ANONYMOUS
%8 = call i32 @do_mmap(i32 -1, i32 %7, i32 1)
%9 = load i32, i32* %3
%10 = call i32 @do_mmap(i32 %9, i32 0, i32 1)
%11 = load i32, i32* @MAP_ANONYMOUS
%12 = load i32, i32* @MAP_HUGETLB
%13 = or i32 %11, %12
%14 = call i32 @do_mmap(i32 -1, i32 %13, i32 1)
%15 = load i32, i32* %2
%16 = call i32 @do_mmap(i32 %15, i32 0, i32 1)
%17 = load i32, i32* %2
%18 = load i32, i32* @MAP_HUGETLB
%19 = call i32 @do_mmap(i32 %17, i32 %18, i32 1)
%20 = load i32, i32* @MAP_ANONYMOUS
%21 = load i32, i32* @MAP_HUGETLB
%22 = or i32 %20, %21
%23 = call i32 @do_mmap(i32 -1, i32 %22, i32 0)
%24 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"/dev/shm/hugetlbhog\00"
@.str.1 = [22 x i8] c"/hugepages/hugetlbhog\00"
@.str.2 = [37 x i8] c"echo 100 > /proc/sys/vm/nr_hugepages\00"
@MAP_ANONYMOUS = global i32 0
@MAP_HUGETLB = global i32 0
@str = [13 x i8] c"oll korrekt.\00"
define i32 @main() {
%1 = tail call i32 @open_file(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @open_file(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @system(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%4 = load i32, i32* @MAP_ANONYMOUS
%5 = tail call i32 @do_mmap(i32 -1, i32 %4, i32 1)
%6 = tail call i32 @do_mmap(i32 %1, i32 0, i32 1)
%7 = load i32, i32* @MAP_ANONYMOUS
%8 = load i32, i32* @MAP_HUGETLB
%9 = or i32 %8, %7
%10 = tail call i32 @do_mmap(i32 -1, i32 %9, i32 1)
%11 = tail call i32 @do_mmap(i32 %2, i32 0, i32 1)
%12 = load i32, i32* @MAP_HUGETLB
%13 = tail call i32 @do_mmap(i32 %2, i32 %12, i32 1)
%14 = load i32, i32* @MAP_ANONYMOUS
%15 = load i32, i32* @MAP_HUGETLB
%16 = or i32 %15, %14
%17 = tail call i32 @do_mmap(i32 -1, i32 %16, i32 0)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
ret i32 0
}