#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;
void *MAP_FAILED;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ exit(int);
void *mmap(int /*<<< orphan*/ *, int, int, int, int /*<<< orphan*/,
           int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, void *);
int main(int argc, char **argv) {
  void *ptr;
  ptr = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0,
             0);
  if (ptr == MAP_FAILED) {
    perror("mmap");
    exit(1);
  }
  printf("mmap returned %p\n", ptr);
  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    0x2e59(%rip),%rax
mov    (%rax),%ecx
mov    0x2e68(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1000,%esi
xor    %r9d,%r9d
mov    %r9d,%r8d
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2e23(%rip),%rcx
cmp    (%rcx),%rax
jne    11bc <main+0x7c>
lea    0xe53(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rsi
lea    0xe3e(%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    0x2e6e(%rip),%rax
mov    0x2e7f(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0x1000,%esi
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    0x2e42(%rip),%rcx
cmp    (%rcx),%rax
jne    1199 <main+0x59>
lea    0xe76(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    0xe65(%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_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
@.str = [5 x i8] c"mmap\00"
@.str.1 = [18 x i8] c"mmap returned %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_ANONYMOUS
%12 = or i32 %10, %11
%13 = call i8* @mmap(i32* null, i32 4096, i32 %9, i32 %12, i32 0, 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 %20
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8*, i8** %6
%22 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = 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_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
@.str = [5 x i8] c"mmap\00"
@.str.1 = [18 x i8] c"mmap returned %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_ANONYMOUS
%8 = or i32 %7, %6
%9 = tail call i8* @mmap(i32* null, i32 4096, i32 %5, i32 %8, i32 0, i32 0)
%10 = load i8*, i8** @MAP_FAILED
%11 = icmp eq i8* %9, %10
br i1 %11, label %12, label %15
12: ; preds = %2
%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 = %2
%16 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%17 = tail call i32 @exit(i32 0)
unreachable
}