#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_ANON;
char *MAP_FAILED;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *mmap(int /*<<< orphan*/ *, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char *buf;
  buf = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
  if (buf == MAP_FAILED) {
    fprintf(stderr, "mmap() returned NULL\n");
    exit(1);
  }
  printf("%p\n", buf);
  exit(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)
mov    0x2e9b(%rip),%rax
mov    (%rax),%edx
mov    0x2e6a(%rip),%rax
or     (%rax),%edx
mov    0x2e51(%rip),%rax
mov    (%rax),%ecx
mov    0x2e50(%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,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2e18(%rip),%rcx
cmp    (%rcx),%rax
jne    11c8 <main+0x88>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rsi
lea    0xe43(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2eb0(%rip),%rax
mov    0x2e81(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e66(%rip),%rax
mov    0x2e67(%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    0x2e37(%rip),%rcx
cmp    (%rcx),%rax
jne    11a5 <main+0x65>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0xe6a(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    0xe6a(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANON = global i32 0
@MAP_FAILED = global i8* null
@stderr = global i32 0
@.str = [22 x i8] c"mmap() returned NULL\0A\00"
@.str.1 = [4 x i8] c"%p\0A\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_ANON
%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 %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%18 = tail call i32 @exit(i32 0)
unreachable
}