#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 */
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ mmap(int /*<<< orphan*/, int, int /*<<< orphan*/, int /*<<< orphan*/,
                int, int /*<<< orphan*/);
int munmap(int *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char *argv[]) {
  int i;
  int fd;
  uint32_t *map;
  fd = open(argv[1], O_RDONLY);
  if (fd == -1) {
    perror("Error opening file for reading");
    exit(EXIT_FAILURE);
  }
  map = (uint32_t *)mmap(0, 32, PROT_READ, MAP_SHARED, fd, 0);
  if (map == MAP_FAILED) {
    close(fd);
    perror("Error mmapping the file");
    exit(EXIT_FAILURE);
  }
  for (i = 0; i <= 8; ++i) {
    printf("0x%x\n", map[i]);
  }
  if (munmap(map, 32) == -1) {
    perror("Error un-mmapping the file");
  }
  close(fd);
  return 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    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11c3 <main+0x53>
lea    0xe50(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edx
mov    0x2e15(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%r8d
xor    %r9d,%r9d
mov    $0x20,%esi
mov    %r9d,%edi
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2dc8(%rip),%rcx
cmp    (%rcx),%rax
jne    1223 <main+0xb3>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
lea    0xe0f(%rip),%rdi
call   1080 <perror@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jg     1259 <main+0xe9>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdf1(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    122a <main+0xba>
mov    -0x20(%rbp),%rdi
mov    $0x20,%esi
call   1060 <munmap@plt>
cmp    $0xffffffff,%eax
jne    127c <main+0x10c>
lea    0xdc6(%rip),%rdi
call   1080 <perror@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x8(%rsi),%rdi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1261 <main+0xf1>
mov    %eax,%r14d
mov    0x2e5f(%rip),%rax
mov    (%rax),%edx
mov    0x2e46(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x20,%esi
mov    %r14d,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
mov    0x2e00(%rip),%rax
cmp    %rbx,(%rax)
je     126a <main+0xfa>
mov    (%rbx),%esi
lea    0xe65(%rip),%rbp
mov    %rbp,%rdi
call   1040 <printf@plt>
mov    0x4(%rbx),%esi
mov    %rbp,%rdi
call   1040 <printf@plt>
mov    0x8(%rbx),%esi
mov    %rbp,%rdi
call   1040 <printf@plt>
mov    0xc(%rbx),%esi
mov    %rbp,%rdi
call   1040 <printf@plt>
mov    0x10(%rbx),%esi
mov    %rbp,%rdi
call   1040 <printf@plt>
mov    0x14(%rbx),%esi
mov    %rbp,%rdi
call   1040 <printf@plt>
mov    0x18(%rbx),%esi
mov    %rbp,%rdi
call   1040 <printf@plt>
mov    0x1c(%rbx),%esi
mov    %rbp,%rdi
call   1040 <printf@plt>
mov    0x20(%rbx),%esi
mov    %rbp,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x20,%esi
call   1060 <munmap@plt>
cmp    $0xffffffff,%eax
je     1253 <main+0xe3>
mov    %r14d,%edi
call   1050 <close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xde3(%rip),%rdi
call   1080 <perror@plt>
jmp    1244 <main+0xd4>
lea    0xd98(%rip),%rdi
jmp    1279 <main+0x109>
mov    %r14d,%edi
call   1050 <close@plt>
lea    0xda6(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [31 x i8] c"Error opening file for reading\00"
@EXIT_FAILURE = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i32* null
@.str.1 = [24 x i8] c"Error mmapping the file\00"
@.str.2 = [6 x i8] c"0x%x\0A\00"
@.str.3 = [27 x i8] c"Error un-mmapping the file\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* %11, i32 %12)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = load i32, i32* @PROT_READ
%22 = load i32, i32* @MAP_SHARED
%23 = load i32, i32* %7
%24 = call i64 @mmap(i32 0, i32 32, i32 %21, i32 %22, i32 %23, i32 0)
%25 = inttoptr i64 %24 to i32*
store i32* %25, i32** %8
%26 = load i32*, i32** %8
%27 = load i32*, i32** @MAP_FAILED
%28 = icmp eq i32* %26, %27
br i1 %28, label %29, label %35
29: ; preds = %20
%30 = load i32, i32* %7
%31 = call i32 @close(i32 %30)
%32 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %20
store i32 0, i32* %6
br label %36
36: ; preds = %46, %35
%37 = load i32, i32* %6
%38 = icmp sle i32 %37, 8
br i1 %38, label %39, label %49
39: ; preds = %36
%40 = load i32*, i32** %8
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
%44 = load i32, i32* %43
%45 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %39
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %36
49: ; preds = %36
%50 = load i32*, i32** %8
%51 = call i32 @munmap(i32* %50, i32 32)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %55
55: ; preds = %53, %49
%56 = load i32, i32* %7
%57 = call i32 @close(i32 %56)
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [31 x i8] c"Error opening file for reading\00"
@EXIT_FAILURE = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i32* null
@.str.1 = [24 x i8] c"Error mmapping the file\00"
@.str.2 = [6 x i8] c"0x%x\0A\00"
@.str.3 = [27 x i8] c"Error un-mmapping the file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* %4, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = load i32, i32* @PROT_READ
%14 = load i32, i32* @MAP_SHARED
%15 = tail call i64 @mmap(i32 0, i32 32, i32 %13, i32 %14, i32 %6, i32 0)
%16 = inttoptr i64 %15 to i32*
%17 = load i32*, i32** @MAP_FAILED
%18 = icmp eq i32* %17, %16
br i1 %18, label %48, label %19
19: ; preds = %12
%20 = load i32, i32* %16
%21 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds i32, i32* %16, i64 1
%23 = load i32, i32* %22
%24 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds i32, i32* %16, i64 2
%26 = load i32, i32* %25
%27 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds i32, i32* %16, i64 3
%29 = load i32, i32* %28
%30 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds i32, i32* %16, i64 4
%32 = load i32, i32* %31
%33 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds i32, i32* %16, i64 5
%35 = load i32, i32* %34
%36 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = getelementptr inbounds i32, i32* %16, i64 6
%38 = load i32, i32* %37
%39 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = getelementptr inbounds i32, i32* %16, i64 7
%41 = load i32, i32* %40
%42 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %41)
%43 = getelementptr inbounds i32, i32* %16, i64 8
%44 = load i32, i32* %43
%45 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %44)
%46 = tail call i32 @munmap(i32* %16, i32 32)
%47 = icmp eq i32 %46, -1
br i1 %47, label %53, label %55
48: ; preds = %12
%49 = tail call i32 @close(i32 %6)
%50 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%51 = load i32, i32* @EXIT_FAILURE
%52 = tail call i32 @exit(i32 %51)
unreachable
53: ; preds = %19
%54 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %55
55: ; preds = %53, %19
%56 = tail call i32 @close(i32 %6)
ret i32 0
}