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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2eb2(%rip),%rax
mov    (%rax),%edx
mov    0x2e71(%rip),%rax
or     (%rax),%edx
mov    0x2e78(%rip),%rax
or     (%rax),%edx
mov    0x2e87(%rip),%rax
mov    (%rax),%ecx
mov    0x2e6e(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e26(%rip),%rcx
cmp    (%rcx),%rax
jne    11b1 <main+0x81>
lea    0xe5e(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2ec0(%rip),%rax
mov    0x2e81(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e86(%rip),%rax
or     (%rax),%edx
mov    0x2e95(%rip),%rax
mov    0x2e7e(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    0x2e3e(%rip),%rcx
cmp    (%rcx),%rax
jne    1195 <main+0x65>
lea    0xe7a(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
xor    %edi,%edi
call   1050 <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*
store i32 0, i32* %1
%3 = load i32, i32* @PROT_READ
%4 = load i32, i32* @PROT_WRITE
%5 = or i32 %3, %4
%6 = load i32, i32* @PROT_EXEC
%7 = or i32 %5, %6
%8 = load i32, i32* @MAP_SHARED
%9 = load i32, i32* @MAP_ANONYMOUS
%10 = or i32 %8, %9
%11 = call i8* @mmap(i32* null, i32 4096, i32 %7, i32 %10, i32 -1, i32 0)
store i8* %11, i8** %2
%12 = load i8*, i8** %2
%13 = load i8*, i8** @MAP_FAILED
%14 = icmp eq i8* %12, %13
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %0
%19 = 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 = load i32, i32* @PROT_READ
%2 = load i32, i32* @PROT_WRITE
%3 = or i32 %2, %1
%4 = load i32, i32* @PROT_EXEC
%5 = or i32 %3, %4
%6 = load i32, i32* @MAP_SHARED
%7 = load i32, i32* @MAP_ANONYMOUS
%8 = or i32 %7, %6
%9 = tail call i8* @mmap(i32* null, i32 4096, i32 %5, i32 %8, i32 -1, i32 0)
%10 = load i8*, i8** @MAP_FAILED
%11 = icmp eq i8* %9, %10
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = tail call i32 @exit(i32 0)
unreachable
}