#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_SHARED;
int PROT_EXEC;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ exit(int);
long getdefaulthugesize();
char *mmap(int /*<<< orphan*/ *, long, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int main(void) {
  char *ptr;
  long length = getdefaulthugesize();
  ptr = mmap(NULL, length, PROT_READ | PROT_WRITE | PROT_EXEC,
             MAP_SHARED | MAP_ANONYMOUS | 0x40000, -1, 0);
  if (ptr == MAP_FAILED) {
    perror("mmap");
    exit(1);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <getdefaulthugesize@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    0x2e93(%rip),%rax
mov    (%rax),%edx
mov    0x2e52(%rip),%rax
or     (%rax),%edx
mov    0x2e59(%rip),%rax
or     (%rax),%edx
mov    0x2e68(%rip),%rax
mov    (%rax),%ecx
mov    0x2e4f(%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,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e06(%rip),%rcx
cmp    (%rcx),%rax
jne    11d1 <main+0x91>
lea    0xe3e(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1040 <getdefaulthugesize@plt>
mov    0x2ea9(%rip),%rcx
mov    0x2e6a(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2e6f(%rip),%rcx
or     (%rcx),%edx
mov    0x2e7e(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2e65(%rip),%rsi
or     (%rsi),%ecx
or     $0x40000,%ecx
xor    %edi,%edi
mov    %rax,%rsi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    0x2e23(%rip),%rcx
cmp    (%rcx),%rax
jne    11b0 <main+0x70>
lea    0xe5f(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@PROT_EXEC = global i32 0
@MAP_SHARED = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
@.str = [5 x i8] c"mmap\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
store i32 0, i32* %1
%4 = call i64 (...) @getdefaulthugesize()
store i64 %4, i64* %3
%5 = load i64, i64* %3
%6 = load i32, i32* @PROT_READ
%7 = load i32, i32* @PROT_WRITE
%8 = or i32 %6, %7
%9 = load i32, i32* @PROT_EXEC
%10 = or i32 %8, %9
%11 = load i32, i32* @MAP_SHARED
%12 = load i32, i32* @MAP_ANONYMOUS
%13 = or i32 %11, %12
%14 = or i32 %13, 262144
%15 = call i8* @mmap(i32* null, i64 %5, i32 %10, i32 %14, i32 -1, i32 0)
store i8* %15, i8** %2
%16 = load i8*, i8** %2
%17 = load i8*, i8** @MAP_FAILED
%18 = icmp eq i8* %16, %17
br i1 %18, label %19, label %22
19: ; preds = %0
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %0
%23 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@PROT_EXEC = global i32 0
@MAP_SHARED = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
@.str = [5 x i8] c"mmap\00"
define i32 @main() {
%1 = tail call i64 (...) @getdefaulthugesize()
%2 = load i32, i32* @PROT_READ
%3 = load i32, i32* @PROT_WRITE
%4 = or i32 %3, %2
%5 = load i32, i32* @PROT_EXEC
%6 = or i32 %4, %5
%7 = load i32, i32* @MAP_SHARED
%8 = load i32, i32* @MAP_ANONYMOUS
%9 = or i32 %7, %8
%10 = or i32 %9, 262144
%11 = tail call i8* @mmap(i32* null, i64 %1, i32 %6, i32 %10, i32 -1, i32 0)
%12 = load i8*, i8** @MAP_FAILED
%13 = icmp eq i8* %11, %12
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = tail call i32 @exit(i32 0)
unreachable
}