#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*/ MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ getpagesize();
void *mmap(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/,
           int /*<<< orphan*/, int, int /*<<< orphan*/);
int munmap(void *, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  void *p;
  int fd = open("/dev/zero", O_RDONLY);
  if (fd < 0) {
    perror("open failed ");
    exit(-1);
  }
  p = mmap(NULL, getpagesize(), PROT_READ, MAP_PRIVATE, fd, 0);
  if (p < 0) {
    perror("map failed ");
    exit(-2);
  }
  for (int i = 0; i < 16; i++) {
    printf("%x ", *(unsigned int *)((unsigned int *)p + i));
  }
  printf("\n");
  int ret = munmap(p, getpagesize());
  if (ret < 0)
    perror("umap fail ");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
lea    0xe71(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11b7 <main+0x47>
lea    0xe62(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   1080 <getpagesize@plt>
mov    %eax,%esi
mov    0x2e31(%rip),%rax
mov    (%rax),%edx
mov    0x2e00(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jae    1207 <main+0x97>
lea    0xe1f(%rip),%rdi
call   1070 <perror@plt>
mov    $0xfffffffe,%edi
call   1090 <exit@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x10,-0x18(%rbp)
jge    123f <main+0xcf>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    120e <main+0x9e>
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1080 <getpagesize@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
call   1050 <munmap@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1280 <main+0x110>
lea    0xdae(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
lea    0xe6c(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     12db <main+0x15b>
mov    %eax,%ebx
xor    %eax,%eax
call   1090 <getpagesize@plt>
mov    0x2e47(%rip),%rcx
mov    (%rcx),%edx
mov    0x2e16(%rip),%rcx
mov    (%rcx),%ecx
xor    %edi,%edi
mov    %eax,%esi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbx
mov    (%rax),%esi
lea    0xe40(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x14(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x1c(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x20(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x24(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x28(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2c(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x30(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x34(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x38(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x3c(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1090 <getpagesize@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <munmap@plt>
test   %eax,%eax
js     12cd <main+0x14d>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd47(%rip),%rdi
call   1080 <perror@plt>
jmp    12c3 <main+0x143>
lea    0xd28(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/zero\00"
@O_RDONLY = global i32 0
@.str.1 = [13 x i8] c"open failed \00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@.str.2 = [12 x i8] c"map failed \00"
@.str.3 = [4 x i8] c"%x \00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [11 x i8] c"umap fail \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %0
%14 = call i32 (...) @getpagesize()
%15 = load i32, i32* @PROT_READ
%16 = load i32, i32* @MAP_PRIVATE
%17 = load i32, i32* %3
%18 = call i8* @mmap(i32* null, i32 %14, i32 %15, i32 %16, i32 %17, i32 0)
store i8* %18, i8** %2
%19 = load i8*, i8** %2
%20 = icmp ult i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %13
%22 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @exit(i32 -2)
unreachable
24: ; preds = %13
store i32 0, i32* %4
br label %25
25: ; preds = %36, %24
%26 = load i32, i32* %4
%27 = icmp slt i32 %26, 16
br i1 %27, label %28, label %39
28: ; preds = %25
%29 = load i8*, i8** %2
%30 = bitcast i8* %29 to i32*
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %28
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %25
39: ; preds = %25
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%41 = load i8*, i8** %2
%42 = call i32 (...) @getpagesize()
%43 = call i32 @munmap(i8* %41, i32 %42)
store i32 %43, i32* %5
%44 = load i32, i32* %5
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %39
%47 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %48
48: ; preds = %46, %39
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/zero\00"
@O_RDONLY = global i32 0
@.str.1 = [13 x i8] c"open failed \00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@.str.3 = [4 x i8] c"%x \00"
@.str.5 = [11 x i8] c"umap fail \00"
define i32 @main() {
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @exit(i32 -1)
unreachable
7: ; preds = %0
%8 = tail call i32 (...) @getpagesize()
%9 = load i32, i32* @PROT_READ
%10 = load i32, i32* @MAP_PRIVATE
%11 = tail call i8* @mmap(i32* null, i32 %8, i32 %9, i32 %10, i32 %2, i32 0)
%12 = bitcast i8* %11 to i32*
%13 = load i32, i32* %12
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds i8, i8* %11, i64 4
%16 = bitcast i8* %15 to i32*
%17 = load i32, i32* %16
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds i8, i8* %11, i64 8
%20 = bitcast i8* %19 to i32*
%21 = load i32, i32* %20
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds i8, i8* %11, i64 12
%24 = bitcast i8* %23 to i32*
%25 = load i32, i32* %24
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = getelementptr inbounds i8, i8* %11, i64 16
%28 = bitcast i8* %27 to i32*
%29 = load i32, i32* %28
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds i8, i8* %11, i64 20
%32 = bitcast i8* %31 to i32*
%33 = load i32, i32* %32
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %33)
%35 = getelementptr inbounds i8, i8* %11, i64 24
%36 = bitcast i8* %35 to i32*
%37 = load i32, i32* %36
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%39 = getelementptr inbounds i8, i8* %11, i64 28
%40 = bitcast i8* %39 to i32*
%41 = load i32, i32* %40
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %41)
%43 = getelementptr inbounds i8, i8* %11, i64 32
%44 = bitcast i8* %43 to i32*
%45 = load i32, i32* %44
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %45)
%47 = getelementptr inbounds i8, i8* %11, i64 36
%48 = bitcast i8* %47 to i32*
%49 = load i32, i32* %48
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %49)
%51 = getelementptr inbounds i8, i8* %11, i64 40
%52 = bitcast i8* %51 to i32*
%53 = load i32, i32* %52
%54 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %53)
%55 = getelementptr inbounds i8, i8* %11, i64 44
%56 = bitcast i8* %55 to i32*
%57 = load i32, i32* %56
%58 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %57)
%59 = getelementptr inbounds i8, i8* %11, i64 48
%60 = bitcast i8* %59 to i32*
%61 = load i32, i32* %60
%62 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %61)
%63 = getelementptr inbounds i8, i8* %11, i64 52
%64 = bitcast i8* %63 to i32*
%65 = load i32, i32* %64
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %65)
%67 = getelementptr inbounds i8, i8* %11, i64 56
%68 = bitcast i8* %67 to i32*
%69 = load i32, i32* %68
%70 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %69)
%71 = getelementptr inbounds i8, i8* %11, i64 60
%72 = bitcast i8* %71 to i32*
%73 = load i32, i32* %72
%74 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %73)
%75 = tail call i32 @putchar(i32 10)
%76 = tail call i32 (...) @getpagesize()
%77 = tail call i32 @munmap(i8* %11, i32 %76)
%78 = icmp slt i32 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %7
%80 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %81
81: ; preds = %79, %7
ret i32 0
}