#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;
char *MAP_FAILED;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, size_t);
char *mmap(int /*<<< orphan*/ *, size_t, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, size_t);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  char *m;
  size_t s = (8UL * 1024 * 1024);
  m = mmap(NULL, s, PROT_READ | PROT_WRITE,
           MAP_PRIVATE | MAP_ANONYMOUS | 0x40000, -1, 0);
  if (m == MAP_FAILED) {
    perror("map mem");
    m = NULL;
    return 1;
  }
  memset(m, 0, s);
  printf("map_hugetlb ok, press ENTER to quit!\n");
  getchar();
  munmap(m, s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x800000,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
mov    0x2e3e(%rip),%rax
or     (%rax),%edx
mov    0x2e2d(%rip),%rax
mov    (%rax),%ecx
mov    0x2e3c(%rip),%rax
or     (%rax),%ecx
or     $0x40000,%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2df3(%rip),%rcx
cmp    (%rcx),%rax
jne    11f6 <main+0x96>
lea    0xe23(%rip),%rdi
call   1080 <perror@plt>
movq   $0x0,-0x18(%rbp)
movl   $0x1,-0x4(%rbp)
jmp    122c <main+0xcc>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xdfc(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <munmap@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e8d(%rip),%rax
mov    0x2e5e(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e4b(%rip),%rax
mov    (%rax),%ecx
mov    0x2e5a(%rip),%rax
or     (%rax),%ecx
or     $0x40000,%ecx
xor    %r14d,%r14d
mov    $0x800000,%esi
xor    %edi,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbx
mov    0x2e10(%rip),%rax
cmp    (%rax),%rbx
je     11ef <main+0x8f>
mov    $0x800000,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xe3d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    $0x800000,%esi
mov    %rbx,%rdi
call   1070 <munmap@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe0a(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%r14d
jmp    11e4 <main+0x84>

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
@.str = [8 x i8] c"map mem\00"
@.str.1 = [38 x i8] c"map_hugetlb ok, press ENTER to quit!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 8388608, i64* %7
%8 = load i64, i64* %7
%9 = load i32, i32* @PROT_READ
%10 = load i32, i32* @PROT_WRITE
%11 = or i32 %9, %10
%12 = load i32, i32* @MAP_PRIVATE
%13 = load i32, i32* @MAP_ANONYMOUS
%14 = or i32 %12, %13
%15 = or i32 %14, 262144
%16 = call i8* @mmap(i32* null, i64 %8, i32 %11, i32 %15, i32 -1, i32 0)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = load i8*, i8** @MAP_FAILED
%19 = icmp eq i8* %17, %18
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %6
store i32 1, i32* %3
br label %31
22: ; preds = %2
%23 = load i8*, i8** %6
%24 = load i64, i64* %7
%25 = call i32 @memset(i8* %23, i32 0, i64 %24)
%26 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 (...) @getchar()
%28 = load i8*, i8** %6
%29 = load i64, i64* %7
%30 = call i32 @munmap(i8* %28, i64 %29)
store i32 0, i32* %3
br label %31
31: ; preds = %22, %20
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
@.str = [8 x i8] c"map mem\00"
@str = [37 x i8] c"map_hugetlb ok, press ENTER to quit!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @PROT_READ
%4 = load i32, i32* @PROT_WRITE
%5 = or i32 %4, %3
%6 = load i32, i32* @MAP_PRIVATE
%7 = load i32, i32* @MAP_ANONYMOUS
%8 = or i32 %6, %7
%9 = or i32 %8, 262144
%10 = tail call i8* @mmap(i32* null, i64 8388608, i32 %5, i32 %9, i32 -1, i32 0)
%11 = load i8*, i8** @MAP_FAILED
%12 = icmp eq i8* %10, %11
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %20
15: ; preds = %2
%16 = tail call i32 @memset(i8* %10, i32 0, i64 8388608)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%18 = tail call i32 (...) @getchar()
%19 = tail call i32 @munmap(i8* %10, i64 8388608)
br label %20
20: ; preds = %15, %13
%21 = phi i32 [ 1, %13 ], [ 0, %15 ]
ret i32 %21
}