#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 */
void *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int O_RDONLY;
int O_RDWR;
int O_WRONLY;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int atoi(char *);
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int);
void *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ munmap(void *, int);
int open(char *, int);
int /*<<< orphan*/ printf(char *, void *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ tst_exit();
int main(int argc, char **argv) {
  int rc;
  int fd;
  int openflags;
  int offset;
  int length;
  int passflag;
  int flags;
  void *memmap;
  if (--argc != 5) {
    printf("usage: %s filename openflags offset length passflag\n", argv[0]);
    exit(-1);
  }
  passflag = atoi(argv[5]);
  if ((passflag != 0) && (passflag != 1)) {
    printf("%s error: invalid passflag %s\n", argv[0], argv[5]);
    exit(-1);
  }
  length = atoi(argv[4]);
  if (length < 0) {
    printf("%s error: invalid length %s\n", argv[0], argv[4]);
    exit(-1);
  }
  offset = atoi(argv[3]);
  if (offset < 0) {
    printf("%s error: invalid offset %s\n", argv[0], argv[3]);
    exit(-1);
  }
  if (offset & (4096 - 1)) {
    printf("%s error: unaligned offset %d\n", argv[0], offset);
    exit(-1);
  }
  openflags = atoi(argv[2]);
  if (openflags == O_RDONLY) {
    flags = PROT_READ;
  } else if (openflags == O_WRONLY) {
    flags = PROT_WRITE;
  } else if (openflags == O_RDWR) {
    flags = PROT_READ | PROT_WRITE;
  } else {
    printf("%s error: invalid openflags %s\n", argv[0], argv[2]);
    exit(-1);
  }
  printf("invoking open(%s, %d)\n", argv[1], openflags);
  fd = open(argv[1], openflags);
  if (fd == -1) {
    printf("%s error: open failed with rc = %d (errno = %d)\n", argv[0], rc,
           errno);
    exit(-1);
  }
  printf("invoking memmap(%d, %d, %s, %d)\n", length, flags, argv[1], offset);
  memmap = mmap(NULL, length, flags, MAP_SHARED, fd, offset);
  if (memmap == MAP_FAILED) {
    printf("%s error: mmap failed with errno = %d\n", argv[0], errno);
    if (passflag) {
      close(fd);
      exit(-1);
    }
  }
  sleep(1);
  if (memmap != MAP_FAILED) {
    printf("invoking munmap(%p, %d)\n", memmap, length);
    munmap(memmap, length);
  }
  close(fd);
  _exit(0);
  tst_exit();
}


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    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x5,%eax
je     11d7 <main+0x47>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1222 <main+0x92>
cmpl   $0x1,-0x28(%rbp)
je     1222 <main+0x92>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdx
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1263 <main+0xd3>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    12a4 <main+0x114>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%eax
and    $0xfff,%eax
cmp    $0x0,%eax
je     12d7 <main+0x147>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%edx
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2cdf(%rip),%rcx
cmp    (%rcx),%eax
jne    130a <main+0x17a>
mov    0x2cf8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
jmp    138a <main+0x1fa>
mov    -0x1c(%rbp),%eax
mov    0x2c8c(%rip),%rcx
cmp    (%rcx),%eax
jne    132d <main+0x19d>
mov    0x2c95(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
jmp    1385 <main+0x1f5>
mov    -0x1c(%rbp),%eax
mov    0x2ca1(%rip),%rcx
cmp    (%rcx),%eax
jne    1359 <main+0x1c9>
mov    0x2cb2(%rip),%rax
mov    (%rax),%eax
mov    0x2c69(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x2c(%rbp)
jmp    1380 <main+0x1f0>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xd3e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
jmp    1385 <main+0x1f5>
jmp    138a <main+0x1fa>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x1c(%rbp),%edx
lea    0xd31(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    13eb <main+0x25b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x14(%rbp),%edx
mov    0x2bef(%rip),%rax
mov    (%rax),%ecx
lea    0xd0a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
movslq -0x24(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x20(%rbp),%r8d
lea    0xd10(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    0x2bcf(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x20(%rbp),%r9d
xor    %eax,%eax
mov    %eax,%edi
call   1040 <mmap@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    0x2b75(%rip),%rcx
cmp    (%rcx),%rax
jne    1483 <main+0x2f3>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    0x2b6e(%rip),%rax
mov    (%rax),%edx
lea    0xcdb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x28(%rbp)
je     147e <main+0x2ee>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
jmp    1483 <main+0x2f3>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    -0x38(%rbp),%rax
mov    0x2b18(%rip),%rcx
cmp    (%rcx),%rax
je     14c2 <main+0x332>
mov    -0x38(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    0xcae(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1070 <munmap@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x6,%edi
jne    11d3 <main+0x43>
mov    0x28(%rbx),%rbp
mov    %rbp,%rdi
call   1090 <atoi@plt>
cmp    $0x2,%eax
jae    11ee <main+0x5e>
mov    %eax,%r13d
mov    0x20(%rbx),%rbp
mov    %rbp,%rdi
call   1090 <atoi@plt>
test   %eax,%eax
jns    120c <main+0x7c>
mov    (%rbx),%rsi
lea    0xe83(%rip),%rdi
jmp    11f8 <main+0x68>
mov    (%rbx),%rsi
lea    0xe23(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    (%rbx),%rsi
lea    0xe3d(%rip),%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    %eax,%r14d
mov    0x18(%rbx),%rbp
mov    %rbp,%rdi
call   1090 <atoi@plt>
test   %eax,%eax
jns    122b <main+0x9b>
mov    (%rbx),%rsi
lea    0xe48(%rip),%rdi
jmp    11f8 <main+0x68>
mov    %eax,%r15d
test   $0xfff,%eax
jne    125b <main+0xcb>
mov    0x10(%rbx),%rbp
mov    %rbp,%rdi
call   1090 <atoi@plt>
mov    %eax,%r12d
mov    0x2d85(%rip),%rax
cmp    (%rax),%r12d
jne    1279 <main+0xe9>
mov    0x2da1(%rip),%rax
mov    (%rax),%ebp
jmp    12b2 <main+0x122>
mov    (%rbx),%rsi
lea    0xe29(%rip),%rdi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    0x2d20(%rip),%rax
cmp    (%rax),%r12d
jne    1290 <main+0x100>
mov    0x2d2c(%rip),%rax
mov    (%rax),%ebp
jmp    12b2 <main+0x122>
mov    0x2d41(%rip),%rax
cmp    (%rax),%r12d
jne    13a1 <main+0x211>
mov    0x2d51(%rip),%rax
mov    0x2d0a(%rip),%rcx
mov    (%rcx),%ebp
or     (%rax),%ebp
mov    0x8(%rbx),%rsi
lea    0xe10(%rip),%rdi
mov    %r12d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%rdi
mov    %r12d,%esi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
jne    12fc <main+0x16c>
mov    (%rbx),%rsi
mov    0x2cde(%rip),%rax
mov    (%rax),%ecx
lea    0xdf9(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    %eax,%r12d
mov    %r14d,%esi
mov    0x8(%rbx),%rcx
lea    0xe08(%rip),%rdi
mov    %ebp,%edx
mov    %r15d,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2cc8(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %r12d,%r8d
mov    %r15d,%r9d
call   1040 <mmap@plt>
mov    %rax,%r15
mov    0x2c72(%rip),%rbp
cmp    0x0(%rbp),%rax
jne    1363 <main+0x1d3>
mov    (%rbx),%rsi
mov    0x2c72(%rip),%rax
mov    (%rax),%edx
lea    0xddf(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r13d,%r13d
jne    13b0 <main+0x220>
mov    $0x1,%edi
call   10b0 <sleep@plt>
cmp    0x0(%rbp),%r15
je     1392 <main+0x202>
lea    0xde3(%rip),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r14d,%esi
call   1070 <munmap@plt>
mov    %r12d,%edi
call   1060 <close@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
mov    (%rbx),%rsi
lea    0xd02(%rip),%rdi
jmp    11f8 <main+0x68>
mov    %r12d,%edi
call   1060 <close@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [53 x i8] c"usage: %s filename openflags offset length passflag\0A\00"
@.str.1 = [31 x i8] c"%s error: invalid passflag %s\0A\00"
@.str.2 = [29 x i8] c"%s error: invalid length %s\0A\00"
@.str.3 = [29 x i8] c"%s error: invalid offset %s\0A\00"
@.str.4 = [31 x i8] c"%s error: unaligned offset %d\0A\00"
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@O_WRONLY = global i32 0
@PROT_WRITE = global i32 0
@O_RDWR = global i32 0
@.str.5 = [32 x i8] c"%s error: invalid openflags %s\0A\00"
@.str.6 = [23 x i8] c"invoking open(%s, %d)\0A\00"
@.str.7 = [49 x i8] c"%s error: open failed with rc = %d (errno = %d)\0A\00"
@errno = global i32 0
@.str.8 = [33 x i8] c"invoking memmap(%d, %d, %s, %d)\0A\00"
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.9 = [39 x i8] c"%s error: mmap failed with errno = %d\0A\00"
@.str.10 = [25 x i8] c"invoking munmap(%p, %d)\0A\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
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = add nsw i32 %14, -1
store i32 %15, i32* %4
%16 = icmp ne i32 %15, 5
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 5
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %11
%28 = load i32, i32* %11
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %42
30: ; preds = %23
%31 = load i32, i32* %11
%32 = icmp ne i32 %31, 1
br i1 %32, label %33, label %42
33: ; preds = %30
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 0
%36 = load i8*, i8** %35
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 5
%39 = load i8*, i8** %38
%40 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %36, i8* %39)
%41 = call i32 @exit(i32 -1)
unreachable
42: ; preds = %30, %23
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 4
%45 = load i8*, i8** %44
%46 = call i32 @atoi(i8* %45)
store i32 %46, i32* %10
%47 = load i32, i32* %10
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %58
49: ; preds = %42
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 0
%52 = load i8*, i8** %51
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 4
%55 = load i8*, i8** %54
%56 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %52, i8* %55)
%57 = call i32 @exit(i32 -1)
unreachable
58: ; preds = %42
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 3
%61 = load i8*, i8** %60
%62 = call i32 @atoi(i8* %61)
store i32 %62, i32* %9
%63 = load i32, i32* %9
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %74
65: ; preds = %58
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 0
%68 = load i8*, i8** %67
%69 = load i8**, i8*** %5
%70 = getelementptr inbounds i8*, i8** %69, i64 3
%71 = load i8*, i8** %70
%72 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %68, i8* %71)
%73 = call i32 @exit(i32 -1)
unreachable
74: ; preds = %58
%75 = load i32, i32* %9
%76 = and i32 %75, 4095
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %85
78: ; preds = %74
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 0
%81 = load i8*, i8** %80
%82 = load i32, i32* %9
%83 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %81, i32 %82)
%84 = call i32 @exit(i32 -1)
unreachable
85: ; preds = %74
%86 = load i8**, i8*** %5
%87 = getelementptr inbounds i8*, i8** %86, i64 2
%88 = load i8*, i8** %87
%89 = call i32 @atoi(i8* %88)
store i32 %89, i32* %8
%90 = load i32, i32* %8
%91 = load i32, i32* @O_RDONLY
%92 = icmp eq i32 %90, %91
br i1 %92, label %93, label %95
93: ; preds = %85
%94 = load i32, i32* @PROT_READ
store i32 %94, i32* %12
br label %120
95: ; preds = %85
%96 = load i32, i32* %8
%97 = load i32, i32* @O_WRONLY
%98 = icmp eq i32 %96, %97
br i1 %98, label %99, label %101
99: ; preds = %95
%100 = load i32, i32* @PROT_WRITE
store i32 %100, i32* %12
br label %119
101: ; preds = %95
%102 = load i32, i32* %8
%103 = load i32, i32* @O_RDWR
%104 = icmp eq i32 %102, %103
br i1 %104, label %105, label %109
105: ; preds = %101
%106 = load i32, i32* @PROT_READ
%107 = load i32, i32* @PROT_WRITE
%108 = or i32 %106, %107
store i32 %108, i32* %12
br label %118
109: ; preds = %101
%110 = load i8**, i8*** %5
%111 = getelementptr inbounds i8*, i8** %110, i64 0
%112 = load i8*, i8** %111
%113 = load i8**, i8*** %5
%114 = getelementptr inbounds i8*, i8** %113, i64 2
%115 = load i8*, i8** %114
%116 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %112, i8* %115)
%117 = call i32 @exit(i32 -1)
unreachable
118: ; preds = %105
br label %119
119: ; preds = %118, %99
br label %120
120: ; preds = %119, %93
%121 = load i8**, i8*** %5
%122 = getelementptr inbounds i8*, i8** %121, i64 1
%123 = load i8*, i8** %122
%124 = load i32, i32* %8
%125 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %123, i32 %124)
%126 = load i8**, i8*** %5
%127 = getelementptr inbounds i8*, i8** %126, i64 1
%128 = load i8*, i8** %127
%129 = load i32, i32* %8
%130 = call i32 @open(i8* %128, i32 %129)
store i32 %130, i32* %7
%131 = load i32, i32* %7
%132 = icmp eq i32 %131, -1
br i1 %132, label %133, label %141
133: ; preds = %120
%134 = load i8**, i8*** %5
%135 = getelementptr inbounds i8*, i8** %134, i64 0
%136 = load i8*, i8** %135
%137 = load i32, i32* %6
%138 = load i32, i32* @errno
%139 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0), i8* %136, i32 %137, i32 %138)
%140 = call i32 @exit(i32 -1)
unreachable
141: ; preds = %120
%142 = load i32, i32* %10
%143 = sext i32 %142 to i64
%144 = inttoptr i64 %143 to i8*
%145 = load i32, i32* %12
%146 = load i8**, i8*** %5
%147 = getelementptr inbounds i8*, i8** %146, i64 1
%148 = load i8*, i8** %147
%149 = load i32, i32* %9
%150 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i8* %144, i32 %145, i8* %148, i32 %149)
%151 = load i32, i32* %10
%152 = load i32, i32* %12
%153 = load i32, i32* @MAP_SHARED
%154 = load i32, i32* %7
%155 = load i32, i32* %9
%156 = call i8* @mmap(i32* null, i32 %151, i32 %152, i32 %153, i32 %154, i32 %155)
store i8* %156, i8** %13
%157 = load i8*, i8** %13
%158 = load i8*, i8** @MAP_FAILED
%159 = icmp eq i8* %157, %158
br i1 %159, label %160, label %173
160: ; preds = %141
%161 = load i8**, i8*** %5
%162 = getelementptr inbounds i8*, i8** %161, i64 0
%163 = load i8*, i8** %162
%164 = load i32, i32* @errno
%165 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.9, i64 0, i64 0), i8* %163, i32 %164)
%166 = load i32, i32* %11
%167 = icmp ne i32 %166, 0
br i1 %167, label %168, label %172
168: ; preds = %160
%169 = load i32, i32* %7
%170 = call i32 @close(i32 %169)
%171 = call i32 @exit(i32 -1)
unreachable
172: ; preds = %160
br label %173
173: ; preds = %172, %141
%174 = call i32 @sleep(i32 1)
%175 = load i8*, i8** %13
%176 = load i8*, i8** @MAP_FAILED
%177 = icmp ne i8* %175, %176
br i1 %177, label %178, label %185
178: ; preds = %173
%179 = load i8*, i8** %13
%180 = load i32, i32* %10
%181 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i64 0, i64 0), i8* %179, i32 %180)
%182 = load i8*, i8** %13
%183 = load i32, i32* %10
%184 = call i32 @munmap(i8* %182, i32 %183)
br label %185
185: ; preds = %178, %173
%186 = load i32, i32* %7
%187 = call i32 @close(i32 %186)
%188 = call i32 @_exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [53 x i8] c"usage: %s filename openflags offset length passflag\0A\00"
@.str.1 = [31 x i8] c"%s error: invalid passflag %s\0A\00"
@.str.2 = [29 x i8] c"%s error: invalid length %s\0A\00"
@.str.3 = [29 x i8] c"%s error: invalid offset %s\0A\00"
@.str.4 = [31 x i8] c"%s error: unaligned offset %d\0A\00"
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@O_WRONLY = global i32 0
@PROT_WRITE = global i32 0
@O_RDWR = global i32 0
@.str.5 = [32 x i8] c"%s error: invalid openflags %s\0A\00"
@.str.6 = [23 x i8] c"invoking open(%s, %d)\0A\00"
@.str.7 = [49 x i8] c"%s error: open failed with rc = %d (errno = %d)\0A\00"
@errno = global i32 0
@.str.8 = [33 x i8] c"invoking memmap(%d, %d, %s, %d)\0A\00"
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.9 = [39 x i8] c"%s error: mmap failed with errno = %d\0A\00"
@.str.10 = [25 x i8] c"invoking munmap(%p, %d)\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 6
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 5
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = icmp eq i32 %11, 0
%13 = icmp ult i32 %11, 2
br i1 %13, label %18, label %14
14: ; preds = %8
%15 = load i8*, i8** %1
%16 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %10)
%17 = tail call i32 @exit(i32 -1)
unreachable
18: ; preds = %8
%19 = getelementptr inbounds i8*, i8** %1, i64 4
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i8*, i8** %1
%25 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %24, i8* %20)
%26 = tail call i32 @exit(i32 -1)
unreachable
27: ; preds = %18
%28 = getelementptr inbounds i8*, i8** %1, i64 3
%29 = load i8*, i8** %28
%30 = tail call i32 @atoi(i8* %29)
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = load i8*, i8** %1
%34 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %33, i8* %29)
%35 = tail call i32 @exit(i32 -1)
unreachable
36: ; preds = %27
%37 = and i32 %30, 4095
%38 = icmp eq i32 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %36
%40 = load i8*, i8** %1
%41 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %40, i32 %30)
%42 = tail call i32 @exit(i32 -1)
unreachable
43: ; preds = %36
%44 = getelementptr inbounds i8*, i8** %1, i64 2
%45 = load i8*, i8** %44
%46 = tail call i32 @atoi(i8* %45)
%47 = load i32, i32* @O_RDONLY
%48 = icmp eq i32 %46, %47
br i1 %48, label %49, label %51
49: ; preds = %43
%50 = load i32, i32* @PROT_READ
br label %67
51: ; preds = %43
%52 = load i32, i32* @O_WRONLY
%53 = icmp eq i32 %46, %52
br i1 %53, label %54, label %56
54: ; preds = %51
%55 = load i32, i32* @PROT_WRITE
br label %67
56: ; preds = %51
%57 = load i32, i32* @O_RDWR
%58 = icmp eq i32 %46, %57
br i1 %58, label %59, label %63
59: ; preds = %56
%60 = load i32, i32* @PROT_READ
%61 = load i32, i32* @PROT_WRITE
%62 = or i32 %61, %60
br label %67
63: ; preds = %56
%64 = load i8*, i8** %1
%65 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %64, i8* %45)
%66 = tail call i32 @exit(i32 -1)
unreachable
67: ; preds = %54, %59, %49
%68 = phi i32 [ %50, %49 ], [ %55, %54 ], [ %62, %59 ]
%69 = getelementptr inbounds i8*, i8** %1, i64 1
%70 = load i8*, i8** %69
%71 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %70, i32 %46)
%72 = load i8*, i8** %69
%73 = tail call i32 @open(i8* %72, i32 %46)
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %80
75: ; preds = %67
%76 = load i8*, i8** %1
%77 = load i32, i32* @errno
%78 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0), i8* %76, i32 undef, i32 %77)
%79 = tail call i32 @exit(i32 -1)
unreachable
80: ; preds = %67
%81 = zext i32 %21 to i64
%82 = inttoptr i64 %81 to i8*
%83 = load i8*, i8** %69
%84 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i8* %82, i32 %68, i8* %83, i32 %30)
%85 = load i32, i32* @MAP_SHARED
%86 = tail call i8* @mmap(i32* null, i32 %21, i32 %68, i32 %85, i32 %73, i32 %30)
%87 = load i8*, i8** @MAP_FAILED
%88 = icmp eq i8* %86, %87
br i1 %88, label %89, label %96
89: ; preds = %80
%90 = load i8*, i8** %1
%91 = load i32, i32* @errno
%92 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.9, i64 0, i64 0), i8* %90, i32 %91)
br i1 %12, label %96, label %93
93: ; preds = %89
%94 = tail call i32 @close(i32 %73)
%95 = tail call i32 @exit(i32 -1)
unreachable
96: ; preds = %89, %80
%97 = tail call i32 @sleep(i32 1)
%98 = load i8*, i8** @MAP_FAILED
%99 = icmp eq i8* %86, %98
br i1 %99, label %103, label %100
100: ; preds = %96
%101 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i64 0, i64 0), i8* %86, i32 %21)
%102 = tail call i32 @munmap(i8* %86, i32 %21)
br label %103
103: ; preds = %100, %96
%104 = tail call i32 @close(i32 %73)
%105 = tail call i32 @_exit(i32 0)
unreachable
}