#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
void *MAP_FAILED;
int /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ getpagesize();
void *mmap(int /*<<< orphan*/ *, int /*<<< orphan*/, int, int /*<<< orphan*/,
           int, int /*<<< orphan*/);
int munmap(void *, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, void *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int fd;
  void *ptr;
  int val;
  fd = open("/dev/zero", O_RDWR);
  if (fd != -1) {
    ptr = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
    if (ptr == MAP_FAILED) {
      fprintf(stderr, "Error on mmap: %s\n", strerror(errno));
      exit(EXIT_FAILURE);
    } else {
      printf("Address of ananonymous memory mapping %p\n", ptr);
      val = munmap(ptr, getpagesize());
      if (val == -1) {
        fprintf(stderr, "Error on munmap: %s\n", strerror(errno));
        exit(EXIT_FAILURE);
      }
      close(fd);
    }
  } else {
    fprintf(stderr, "Error on open: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
lea    0xe4a(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     12cc <main+0x13c>
mov    $0x0,%al
call   1090 <getpagesize@plt>
mov    %eax,%esi
mov    0x2e20(%rip),%rax
mov    (%rax),%edx
mov    0x2dd7(%rip),%rax
or     (%rax),%edx
mov    0x2dbe(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2d95(%rip),%rcx
cmp    (%rcx),%rax
jne    124e <main+0xbe>
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
lea    0xdcf(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rsi
lea    0xdc4(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1090 <getpagesize@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1070 <munmap@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    12bf <main+0x12f>
mov    0x2d44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xd9b(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
jmp    1306 <main+0x176>
mov    0x2cfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
lea    0xd69(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2ca3(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
lea    0xe5d(%rip),%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
jne    11d0 <main+0x40>
mov    0x2e1c(%rip),%rax
mov    (%rax),%ebx
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xe91(%rip),%rsi
jmp    1275 <main+0xe5>
mov    %eax,%ebp
xor    %eax,%eax
call   1090 <getpagesize@plt>
mov    0x2e18(%rip),%rcx
mov    0x2dd1(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2db6(%rip),%rcx
mov    (%rcx),%ecx
xor    %edi,%edi
mov    %eax,%esi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
mov    0x2d93(%rip),%rax
cmp    (%rax),%rbx
jne    1232 <main+0xa2>
mov    0x2db7(%rip),%rax
mov    (%rax),%ebx
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xdda(%rip),%rsi
jmp    1275 <main+0xe5>
lea    0xde4(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <getpagesize@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <munmap@plt>
cmp    $0xffffffff,%eax
jne    128d <main+0xfd>
mov    0x2d72(%rip),%rax
mov    (%rax),%ebx
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xdd2(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/zero\00"
@O_RDWR = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@stderr = global i32 0
@.str.1 = [19 x i8] c"Error on mmap: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [42 x i8] c"Address of ananonymous memory mapping %p\0A\00"
@.str.3 = [21 x i8] c"Error on munmap: %s\0A\00"
@.str.4 = [19 x i8] c"Error on open: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @O_RDWR
%10 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %50
13: ; preds = %2
%14 = call i32 (...) @getpagesize()
%15 = load i32, i32* @PROT_READ
%16 = load i32, i32* @PROT_WRITE
%17 = or i32 %15, %16
%18 = load i32, i32* @MAP_PRIVATE
%19 = load i32, i32* %6
%20 = call i8* @mmap(i32* null, i32 %14, i32 %17, i32 %18, i32 %19, i32 0)
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = load i8*, i8** @MAP_FAILED
%23 = icmp eq i8* %21, %22
br i1 %23, label %24, label %31
24: ; preds = %13
%25 = load i32, i32* @stderr
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %13
%32 = load i8*, i8** %7
%33 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = load i8*, i8** %7
%35 = call i32 (...) @getpagesize()
%36 = call i32 @munmap(i8* %34, i32 %35)
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %46
39: ; preds = %31
%40 = load i32, i32* @stderr
%41 = load i32, i32* @errno
%42 = call i8* @strerror(i32 %41)
%43 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %42)
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %31
%47 = load i32, i32* %6
%48 = call i32 @close(i32 %47)
br label %49
49: ; preds = %46
br label %57
50: ; preds = %2
%51 = load i32, i32* @stderr
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %53)
%55 = load i32, i32* @EXIT_FAILURE
%56 = call i32 @exit(i32 %55)
unreachable
57: ; preds = %49
%58 = load i32, i32* @EXIT_SUCCESS
%59 = call i32 @exit(i32 %58)
unreachable
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/zero\00"
@O_RDWR = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@stderr = global i32 0
@.str.1 = [19 x i8] c"Error on mmap: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [42 x i8] c"Address of ananonymous memory mapping %p\0A\00"
@.str.3 = [21 x i8] c"Error on munmap: %s\0A\00"
@.str.4 = [19 x i8] c"Error on open: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %38, label %6
6: ; preds = %2
%7 = tail call i32 (...) @getpagesize()
%8 = load i32, i32* @PROT_READ
%9 = load i32, i32* @PROT_WRITE
%10 = or i32 %9, %8
%11 = load i32, i32* @MAP_PRIVATE
%12 = tail call i8* @mmap(i32* null, i32 %7, i32 %10, i32 %11, i32 %4, i32 0)
%13 = load i8*, i8** @MAP_FAILED
%14 = icmp eq i8* %12, %13
br i1 %14, label %15, label %22
15: ; preds = %6
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %6
%23 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%24 = tail call i32 (...) @getpagesize()
%25 = tail call i32 @munmap(i8* %12, i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %34
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = load i32, i32* @errno
%30 = tail call i8* @strerror(i32 %29)
%31 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = tail call i32 @exit(i32 %32)
unreachable
34: ; preds = %22
%35 = tail call i32 @close(i32 %4)
%36 = load i32, i32* @EXIT_SUCCESS
%37 = tail call i32 @exit(i32 %36)
unreachable
38: ; preds = %2
%39 = load i32, i32* @stderr
%40 = load i32, i32* @errno
%41 = tail call i8* @strerror(i32 %40)
%42 = tail call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %41)
%43 = load i32, i32* @EXIT_FAILURE
%44 = tail call i32 @exit(i32 %43)
unreachable
}