#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 */
struct stat {
  size_t st_size;
};

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int MAP_POPULATE;
int MAP_PRIVATE;
int MAP_SHARED;
int MCL_CURRENT;
int MCL_FUTURE;
int O_RDONLY;
int O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ free(void *);
int fstat(int, struct stat *);
int getopt(int, char **, char *);
int mlock(unsigned long *, size_t);
int mlockall(int);
unsigned long *mmap(void *, size_t, int, int, int, int);
int munlock(unsigned long *, size_t);
int munlockall();
int /*<<< orphan*/ munmap(unsigned long *, size_t);
int open(char const *, int);
int optind;
int /*<<< orphan*/ perror(char *);
int posix_memalign(void **, int, size_t);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ test_read(unsigned long *, size_t);
int /*<<< orphan*/ test_write(unsigned long *, size_t);
int main(int argc, char **argv) {
  int fd, i, opt, ret;
  int oflags, mprot, mflags = 0;
  int is_read_only = 0, is_mlock = 0, is_mlockall = 0;
  int mlock_skip = 0, read_test = 0, write_test = 0;
  void *mptr = NULL;
  unsigned long *p;
  struct stat stat;
  size_t size, cpy_size;
  const char *file_name = NULL;
  while ((opt = getopt(argc, argv, "RMSApsrw")) != -1) {
    switch (opt) {
    case 'R':
      printf("> mmap: read-only\n");
      is_read_only = 1;
      break;
    case 'M':
      printf("> mlock\n");
      is_mlock = 1;
      break;
    case 'S':
      printf("> mlock - skip first iteration\n");
      mlock_skip = 1;
      break;
    case 'A':
      printf("> mlockall\n");
      is_mlockall = 1;
      break;
    case 'p':
      printf("> MAP_POPULATE\n");
      mflags |= MAP_POPULATE;
      break;
    case 's':
      printf("> MAP_SHARED\n");
      mflags |= MAP_SHARED;
      break;
    case 'r':
      printf("> read-test\n");
      read_test = 1;
      break;
    case 'w':
      printf("> write-test\n");
      write_test = 1;
      break;
    }
  }
  if (optind == argc) {
    printf("missing file name\n");
    return EXIT_FAILURE;
  }
  file_name = argv[optind];
  if (!(mflags & MAP_SHARED)) {
    printf("> MAP_PRIVATE\n");
    mflags |= MAP_PRIVATE;
  }
  if (is_read_only) {
    oflags = O_RDONLY;
    mprot = PROT_READ;
  } else {
    oflags = O_RDWR;
    mprot = PROT_READ | PROT_WRITE;
  }
  fd = open(file_name, oflags);
  if (fd == -1) {
    perror("open failed");
    return EXIT_FAILURE;
  }
  ret = fstat(fd, &stat);
  if (ret < 0) {
    perror("fstat failed");
    return EXIT_FAILURE;
  }
  size = stat.st_size;
  printf("> open %s size %#zx flags %#x\n", file_name, size, oflags);
  ret = posix_memalign(&mptr, ((2) * 1024UL * 1024UL), size);
  if (ret == 0)
    free(mptr);
  printf("> mmap mprot 0x%x flags 0x%x\n", mprot, mflags);
  p = mmap(mptr, size, mprot, mflags, fd, 0x0);
  if (!p) {
    perror("mmap failed");
    return EXIT_FAILURE;
  }
  if ((long unsigned)p & (((2) * 1024UL * 1024UL) - 1))
    printf("> mmap: NOT 2MiB aligned: 0x%p\n", p);
  else
    printf("> mmap: 2MiB aligned: 0x%p\n", p);
  cpy_size = size;
  for (i = 0; i < 3; i++) {
    if (is_mlock && !mlock_skip) {
      printf("> mlock 0x%p\n", p);
      ret = mlock(p, size);
      if (ret < 0) {
        perror("mlock failed");
        return EXIT_FAILURE;
      }
    } else if (is_mlockall) {
      printf("> mlockall\n");
      ret = mlockall(MCL_CURRENT | MCL_FUTURE);
      if (ret < 0) {
        perror("mlockall failed");
        return EXIT_FAILURE;
      }
    }
    printf("===== %d =====\n", i + 1);
    if (write_test)
      test_write(p, cpy_size);
    if (read_test)
      test_read(p, cpy_size);
    if (is_mlock && !mlock_skip) {
      printf("> munlock 0x%p\n", p);
      ret = munlock(p, size);
      if (ret < 0) {
        perror("munlock failed");
        return EXIT_FAILURE;
      }
    } else if (is_mlockall) {
      printf("> munlockall\n");
      ret = munlockall();
      if (ret < 0) {
        perror("munlockall failed");
        return EXIT_FAILURE;
      }
    }
    mlock_skip = 0;
  }
  printf("> munmap 0x%p\n", p);
  munmap(p, size);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x78(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe84(%rip),%rdx
call   10e0 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     1372 <main+0x182>
mov    -0x1c(%rbp),%eax
add    $0xffffffbf,%eax
mov    %eax,%ecx
mov    %rcx,-0x80(%rbp)
sub    $0x36,%eax
ja     136d <main+0x17d>
mov    -0x80(%rbp),%rax
lea    0xd77(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x30(%rbp)
jmp    136d <main+0x17d>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x34(%rbp)
jmp    136d <main+0x17d>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x3c(%rbp)
jmp    136d <main+0x17d>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x38(%rbp)
jmp    136d <main+0x17d>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2ca9(%rip),%rax
mov    (%rax),%eax
or     -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    136d <main+0x17d>
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2caf(%rip),%rax
mov    (%rax),%eax
or     -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    136d <main+0x17d>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x40(%rbp)
jmp    136d <main+0x17d>
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x44(%rbp)
jmp    124a <main+0x5a>
mov    0x2c47(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jne    13a3 <main+0x1b3>
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2c07(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1794 <main+0x5a4>
mov    -0x10(%rbp),%rax
mov    0x2c12(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x78(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2c1d(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    13eb <main+0x1fb>
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2ba5(%rip),%rax
mov    (%rax),%eax
or     -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     1412 <main+0x222>
mov    0x2bcc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2bf0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    1433 <main+0x243>
mov    0x2bb7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2bd3(%rip),%rax
mov    (%rax),%eax
mov    0x2b6a(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x28(%rbp)
mov    -0x78(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   10c0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1469 <main+0x279>
lea    0xd35(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2b41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1794 <main+0x5a4>
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
call   1110 <fstat@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    149f <main+0x2af>
lea    0xd0b(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2b0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1794 <main+0x5a4>
mov    -0x60(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x78(%rbp),%rsi
mov    -0x68(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    0xce8(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x68(%rbp),%rdx
lea    -0x50(%rbp),%rdi
mov    $0x200000,%esi
call   1100 <posix_memalign@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    14e8 <main+0x2f8>
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
lea    0xccb(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x50(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x28(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x14(%rbp),%r8d
xor    %r9d,%r9d
call   1070 <mmap@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    1542 <main+0x352>
lea    0xcb2(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2a68(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1794 <main+0x5a4>
mov    -0x58(%rbp),%rax
and    $0x1fffff,%rax
cmp    $0x0,%rax
je     156d <main+0x37d>
mov    -0x58(%rbp),%rsi
lea    0xc89(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    157f <main+0x38f>
mov    -0x58(%rbp),%rsi
lea    0xc92(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x68(%rbp),%rax
mov    %rax,-0x70(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    1769 <main+0x579>
cmpl   $0x0,-0x34(%rbp)
je     15fa <main+0x40a>
cmpl   $0x0,-0x3c(%rbp)
jne    15fa <main+0x40a>
mov    -0x58(%rbp),%rsi
lea    0xc6f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x58(%rbp),%rdi
mov    -0x68(%rbp),%rsi
call   1060 <mlock@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    15f5 <main+0x405>
lea    0xc55(%rip),%rdi
call   10d0 <perror@plt>
mov    0x29b5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1794 <main+0x5a4>
jmp    165d <main+0x46d>
cmpl   $0x0,-0x38(%rbp)
je     1658 <main+0x468>
lea    0xb16(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x298f(%rip),%rax
mov    (%rax),%edi
mov    0x29c6(%rip),%rax
or     (%rax),%edi
call   10b0 <mlockall@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1653 <main+0x463>
lea    0xc04(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2957(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1794 <main+0x5a4>
jmp    1658 <main+0x468>
jmp    165d <main+0x46d>
mov    -0x18(%rbp),%esi
add    $0x1,%esi
lea    0xbe7(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
cmpl   $0x0,-0x44(%rbp)
je     1688 <main+0x498>
mov    -0x58(%rbp),%rdi
mov    -0x70(%rbp),%rsi
call   1050 <test_write@plt>
cmpl   $0x0,-0x40(%rbp)
je     169f <main+0x4af>
mov    -0x58(%rbp),%rdi
mov    -0x70(%rbp),%rsi
call   1090 <test_read@plt>
cmpl   $0x0,-0x34(%rbp)
je     1701 <main+0x511>
cmpl   $0x0,-0x3c(%rbp)
jne    1701 <main+0x511>
mov    -0x58(%rbp),%rsi
lea    0xba3(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x58(%rbp),%rdi
mov    -0x68(%rbp),%rsi
call   1030 <munlock@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    16fc <main+0x50c>
lea    0xb8b(%rip),%rdi
call   10d0 <perror@plt>
mov    0x28ae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1794 <main+0x5a4>
jmp    1754 <main+0x564>
cmpl   $0x0,-0x38(%rbp)
je     174f <main+0x55f>
lea    0xb6e(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x0,%al
call   10f0 <munlockall@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    174a <main+0x55a>
lea    0xb5a(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2860(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1794 <main+0x5a4>
jmp    174f <main+0x55f>
jmp    1754 <main+0x564>
movl   $0x0,-0x3c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    158e <main+0x39e>
mov    -0x58(%rbp),%rsi
lea    0xb2c(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x58(%rbp),%rdi
mov    -0x68(%rbp),%rsi
call   10a0 <munmap@plt>
mov    0x2801(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movq   $0x0,0x18(%rsp)
xor    %r15d,%r15d
lea    0xeb6(%rip),%r14
lea    0xdd3(%rip),%r12
xor    %r13d,%r13d
movl   $0x0,0x14(%rsp)
movl   $0x0,0x4(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
jmp    1270 <main+0x70>
lea    0xfca(%rip),%rdi
call   1070 <puts@plt>
movl   $0x1,0x8(%rsp)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   10f0 <getopt@plt>
lea    -0x41(%rax),%ecx
cmp    $0x36,%ecx
ja     1337 <main+0x137>
movslq (%r12,%rcx,4),%rax
add    %r12,%rax
jmp    *%rax
lea    0xfc7(%rip),%rdi
call   1070 <puts@plt>
movl   $0x1,0x4(%rsp)
jmp    1270 <main+0x70>
lea    0xfdb(%rip),%rdi
call   1070 <puts@plt>
movl   $0x1,0x14(%rsp)
jmp    1270 <main+0x70>
lea    0xfcd(%rip),%rdi
call   1070 <puts@plt>
mov    $0x1,%r13d
jmp    1270 <main+0x70>
lea    0xf92(%rip),%rdi
call   1070 <puts@plt>
movl   $0x1,0x10(%rsp)
jmp    1270 <main+0x70>
lea    0xf62(%rip),%rdi
call   1070 <puts@plt>
mov    0x2cbd(%rip),%rax
or     (%rax),%r15d
jmp    1270 <main+0x70>
lea    0xf2e(%rip),%rdi
call   1070 <puts@plt>
movl   $0x1,0xc(%rsp)
jmp    1270 <main+0x70>
lea    0xf21(%rip),%rdi
call   1070 <puts@plt>
mov    0x2cb1(%rip),%rax
or     (%rax),%r15d
jmp    1270 <main+0x70>
cmp    $0xffffffff,%eax
jne    1270 <main+0x70>
mov    0x2c79(%rip),%rax
movslq (%rax),%rax
cmp    %ebp,%eax
jne    135f <main+0x15f>
lea    0xec4(%rip),%rdi
call   1070 <puts@plt>
jmp    1771 <main+0x571>
mov    (%rbx,%rax,8),%r14
mov    0x2c76(%rip),%rax
test   %r15d,(%rax)
jne    1385 <main+0x185>
lea    0xe88(%rip),%rdi
call   1070 <puts@plt>
mov    0x2c06(%rip),%rax
or     (%rax),%r15d
xor    %ebx,%ebx
test   %r13d,%r13d
mov    0x2c07(%rip),%rax
cmove  (%rax),%ebx
mov    0x2c2d(%rip),%rax
cmove  0x2c2d(%rip),%rax
mov    0x2c4e(%rip),%rcx
or     (%rcx),%ebx
mov    (%rax),%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     1741 <main+0x541>
mov    %eax,%r13d
lea    0x20(%rsp),%rsi
mov    %eax,%edi
call   1120 <fstat@plt>
test   %eax,%eax
js     174a <main+0x54a>
mov    0x20(%rsp),%r12
lea    0xd1a(%rip),%rdi
mov    %r14,%rsi
mov    %r12,%rdx
mov    %ebp,%ecx
xor    %eax,%eax
call   1090 <printf@plt>
lea    0x18(%rsp),%rdi
mov    $0x200000,%esi
mov    %r12,%rdx
call   1110 <posix_memalign@plt>
test   %eax,%eax
jne    1413 <main+0x213>
mov    0x18(%rsp),%rdi
call   1040 <free@plt>
lea    0xd03(%rip),%rdi
mov    %ebx,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1090 <printf@plt>
mov    0x18(%rsp),%rdi
mov    %r12,%rsi
mov    %ebx,%edx
mov    %r15d,%ecx
mov    %r13d,%r8d
xor    %r9d,%r9d
call   1080 <mmap@plt>
test   %rax,%rax
je     1753 <main+0x553>
mov    %rax,%rbp
test   $0x1fffff,%ebp
lea    0xd10(%rip),%rax
lea    0xce9(%rip),%rdi
cmove  %rax,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    0x14(%rsp),%r15d
test   %r15d,%r15d
sete   %al
cmpl   $0x0,0x10(%rsp)
setne  %bl
or     %al,%bl
mov    %r12,%r14
je     14c3 <main+0x2c3>
cmpl   $0x0,0x4(%rsp)
mov    0xc(%rsp),%r12d
mov    0x8(%rsp),%r13d
je     14f1 <main+0x2f1>
lea    0xdc2(%rip),%rdi
call   1070 <puts@plt>
mov    0x2afe(%rip),%rax
mov    0x2b37(%rip),%rcx
mov    (%rcx),%edi
or     (%rax),%edi
call   10c0 <mlockall@plt>
test   %eax,%eax
jns    14f1 <main+0x2f1>
jmp    175c <main+0x55c>
lea    0xcb9(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1060 <mlock@plt>
test   %eax,%eax
mov    0xc(%rsp),%r12d
mov    0x8(%rsp),%r13d
js     1641 <main+0x441>
lea    0xcb6(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1090 <printf@plt>
test   %r13d,%r13d
je     1514 <main+0x314>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1050 <test_write@plt>
test   %r12d,%r12d
je     1524 <main+0x324>
mov    %rbp,%rdi
mov    %r14,%rsi
call   10a0 <test_read@plt>
test   %bl,%bl
je     157b <main+0x37b>
cmpl   $0x0,0x4(%rsp)
je     15a0 <main+0x3a0>
lea    0xcd6(%rip),%rdi
call   1070 <puts@plt>
xor    %eax,%eax
call   1100 <munlockall@plt>
test   %eax,%eax
js     1765 <main+0x565>
test   %r15d,%r15d
jne    15a5 <main+0x3a5>
lea    0xd0a(%rip),%rdi
call   1070 <puts@plt>
mov    0x2a46(%rip),%rax
mov    0x2a7f(%rip),%rcx
mov    (%rcx),%edi
or     (%rax),%edi
call   10c0 <mlockall@plt>
test   %eax,%eax
jns    15c5 <main+0x3c5>
jmp    175c <main+0x55c>
lea    0xc3c(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1030 <munlock@plt>
test   %eax,%eax
jns    15a5 <main+0x3a5>
jmp    16f5 <main+0x4f5>
test   %r15d,%r15d
je     15c5 <main+0x3c5>
lea    0xbd7(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1060 <mlock@plt>
test   %eax,%eax
js     1641 <main+0x441>
lea    0xbe2(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1090 <printf@plt>
test   %r13d,%r13d
je     15e8 <main+0x3e8>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1050 <test_write@plt>
test   %r12d,%r12d
je     15f8 <main+0x3f8>
mov    %rbp,%rdi
mov    %r14,%rsi
call   10a0 <test_read@plt>
test   %r15d,%r15d
je     164d <main+0x44d>
lea    0xbba(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1030 <munlock@plt>
test   %eax,%eax
js     16f5 <main+0x4f5>
lea    0xb5b(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1060 <mlock@plt>
test   %eax,%eax
jns    169a <main+0x49a>
lea    0xb49(%rip),%rdi
jmp    176c <main+0x56c>
cmpl   $0x0,0x4(%rsp)
je     169a <main+0x49a>
lea    0xbb1(%rip),%rdi
call   1070 <puts@plt>
xor    %eax,%eax
call   1100 <munlockall@plt>
test   %eax,%eax
js     1765 <main+0x565>
lea    0xbea(%rip),%rdi
call   1070 <puts@plt>
mov    0x2926(%rip),%rax
mov    0x295f(%rip),%rcx
mov    (%rcx),%edi
or     (%rax),%edi
call   10c0 <mlockall@plt>
test   %eax,%eax
js     175c <main+0x55c>
lea    0xb0d(%rip),%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1090 <printf@plt>
test   %r13d,%r13d
je     16bd <main+0x4bd>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1050 <test_write@plt>
test   %r12d,%r12d
mov    %r14,%rbx
je     16d0 <main+0x4d0>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10a0 <test_read@plt>
test   %r15d,%r15d
je     16fe <main+0x4fe>
lea    0xae2(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <munlock@plt>
test   %eax,%eax
jns    171c <main+0x51c>
lea    0xad2(%rip),%rdi
jmp    176c <main+0x56c>
cmpl   $0x0,0x4(%rsp)
je     171c <main+0x51c>
lea    0xb00(%rip),%rdi
call   1070 <puts@plt>
xor    %eax,%eax
call   1100 <munlockall@plt>
test   %eax,%eax
js     1765 <main+0x565>
lea    0xacc(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   10b0 <munmap@plt>
mov    0x2851(%rip),%rax
jmp    1778 <main+0x578>
lea    0x99d(%rip),%rdi
jmp    176c <main+0x56c>
lea    0x9a0(%rip),%rdi
jmp    176c <main+0x56c>
lea    0x9e1(%rip),%rdi
jmp    176c <main+0x56c>
lea    0xa3b(%rip),%rdi
jmp    176c <main+0x56c>
lea    0xa71(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2828(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [9 x i8] c"RMSApsrw\00"
@.str.1 = [19 x i8] c"> mmap: read-only\0A\00"
@.str.2 = [9 x i8] c"> mlock\0A\00"
@.str.3 = [32 x i8] c"> mlock - skip first iteration\0A\00"
@.str.4 = [12 x i8] c"> mlockall\0A\00"
@.str.5 = [16 x i8] c"> MAP_POPULATE\0A\00"
@MAP_POPULATE = global i32 0
@.str.6 = [14 x i8] c"> MAP_SHARED\0A\00"
@MAP_SHARED = global i32 0
@.str.7 = [13 x i8] c"> read-test\0A\00"
@.str.8 = [14 x i8] c"> write-test\0A\00"
@optind = global i32 0
@.str.9 = [19 x i8] c"missing file name\0A\00"
@EXIT_FAILURE = global i32 0
@.str.10 = [15 x i8] c"> MAP_PRIVATE\0A\00"
@MAP_PRIVATE = global i32 0
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@O_RDWR = global i32 0
@PROT_WRITE = global i32 0
@.str.11 = [12 x i8] c"open failed\00"
@.str.12 = [13 x i8] c"fstat failed\00"
@.str.13 = [31 x i8] c"> open %s size %#zx flags %#x\0A\00"
@.str.14 = [30 x i8] c"> mmap mprot 0x%x flags 0x%x\0A\00"
@.str.15 = [12 x i8] c"mmap failed\00"
@.str.16 = [32 x i8] c"> mmap: NOT 2MiB aligned: 0x%p\0A\00"
@.str.17 = [28 x i8] c"> mmap: 2MiB aligned: 0x%p\0A\00"
@.str.18 = [14 x i8] c"> mlock 0x%p\0A\00"
@.str.19 = [13 x i8] c"mlock failed\00"
@MCL_CURRENT = global i32 0
@MCL_FUTURE = global i32 0
@.str.20 = [16 x i8] c"mlockall failed\00"
@.str.21 = [16 x i8] c"===== %d =====\0A\00"
@.str.22 = [16 x i8] c"> munlock 0x%p\0A\00"
@.str.23 = [15 x i8] c"munlock failed\00"
@.str.24 = [14 x i8] c"> munlockall\0A\00"
@.str.25 = [18 x i8] c"munlockall failed\00"
@.str.26 = [15 x i8] c"> munmap 0x%p\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 i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i8*
%20 = alloca i64*
%21 = alloca %struct.stat
%22 = alloca i64
%23 = alloca i64
%24 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
store i32 0, i32* %15
store i32 0, i32* %16
store i32 0, i32* %17
store i32 0, i32* %18
store i8* null, i8** %19
store i8* null, i8** %24
br label %25
25: ; preds = %54, %2
%26 = load i32, i32* %4
%27 = load i8**, i8*** %5
%28 = call i32 @getopt(i32 %26, i8** %27, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32 %28, i32* %8
%29 = icmp ne i32 %28, -1
br i1 %29, label %30, label %55
30: ; preds = %25
%31 = load i32, i32* %8
switch i32 %31, label %54 [
i32 82, label %32
i32 77, label %34
i32 83, label %36
i32 65, label %38
i32 112, label %40
i32 115, label %45
i32 114, label %50
i32 119, label %52
]
32: ; preds = %30
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %13
br label %54
34: ; preds = %30
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %14
br label %54
36: ; preds = %30
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %16
br label %54
38: ; preds = %30
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %15
br label %54
40: ; preds = %30
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%42 = load i32, i32* @MAP_POPULATE
%43 = load i32, i32* %12
%44 = or i32 %43, %42
store i32 %44, i32* %12
br label %54
45: ; preds = %30
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%47 = load i32, i32* @MAP_SHARED
%48 = load i32, i32* %12
%49 = or i32 %48, %47
store i32 %49, i32* %12
br label %54
50: ; preds = %30
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %17
br label %54
52: ; preds = %30
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %18
br label %54
54: ; preds = %30, %52, %50, %45, %40, %38, %36, %34, %32
br label %25
55: ; preds = %25
%56 = load i32, i32* @optind
%57 = load i32, i32* %4
%58 = icmp eq i32 %56, %57
br i1 %58, label %59, label %62
59: ; preds = %55
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
%61 = load i32, i32* @EXIT_FAILURE
store i32 %61, i32* %3
br label %243
62: ; preds = %55
%63 = load i8**, i8*** %5
%64 = load i32, i32* @optind
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8*, i8** %63, i64 %65
%67 = load i8*, i8** %66
store i8* %67, i8** %24
%68 = load i32, i32* %12
%69 = load i32, i32* @MAP_SHARED
%70 = and i32 %68, %69
%71 = icmp ne i32 %70, 0
br i1 %71, label %77, label %72
72: ; preds = %62
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0))
%74 = load i32, i32* @MAP_PRIVATE
%75 = load i32, i32* %12
%76 = or i32 %75, %74
store i32 %76, i32* %12
br label %77
77: ; preds = %72, %62
%78 = load i32, i32* %13
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %83
80: ; preds = %77
%81 = load i32, i32* @O_RDONLY
store i32 %81, i32* %10
%82 = load i32, i32* @PROT_READ
store i32 %82, i32* %11
br label %88
83: ; preds = %77
%84 = load i32, i32* @O_RDWR
store i32 %84, i32* %10
%85 = load i32, i32* @PROT_READ
%86 = load i32, i32* @PROT_WRITE
%87 = or i32 %85, %86
store i32 %87, i32* %11
br label %88
88: ; preds = %83, %80
%89 = load i8*, i8** %24
%90 = load i32, i32* %10
%91 = call i32 @open(i8* %89, i32 %90)
store i32 %91, i32* %6
%92 = load i32, i32* %6
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %97
94: ; preds = %88
%95 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0))
%96 = load i32, i32* @EXIT_FAILURE
store i32 %96, i32* %3
br label %243
97: ; preds = %88
%98 = load i32, i32* %6
%99 = call i32 @fstat(i32 %98, %struct.stat* %21)
store i32 %99, i32* %9
%100 = load i32, i32* %9
%101 = icmp slt i32 %100, 0
br i1 %101, label %102, label %105
102: ; preds = %97
%103 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0))
%104 = load i32, i32* @EXIT_FAILURE
store i32 %104, i32* %3
br label %243
105: ; preds = %97
%106 = getelementptr inbounds %struct.stat, %struct.stat* %21, i32 0, i32 0
%107 = load i64, i64* %106
store i64 %107, i64* %22
%108 = load i8*, i8** %24
%109 = load i64, i64* %22
%110 = load i32, i32* %10
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.13, i64 0, i64 0), i8* %108, i64 %109, i32 %110)
%112 = load i64, i64* %22
%113 = call i32 @posix_memalign(i8** %19, i32 2097152, i64 %112)
store i32 %113, i32* %9
%114 = load i32, i32* %9
%115 = icmp eq i32 %114, 0
br i1 %115, label %116, label %119
116: ; preds = %105
%117 = load i8*, i8** %19
%118 = call i32 @free(i8* %117)
br label %119
119: ; preds = %116, %105
%120 = load i32, i32* %11
%121 = load i32, i32* %12
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.14, i64 0, i64 0), i32 %120, i32 %121)
%123 = load i8*, i8** %19
%124 = load i64, i64* %22
%125 = load i32, i32* %11
%126 = load i32, i32* %12
%127 = load i32, i32* %6
%128 = call i64* @mmap(i8* %123, i64 %124, i32 %125, i32 %126, i32 %127, i32 0)
store i64* %128, i64** %20
%129 = load i64*, i64** %20
%130 = icmp ne i64* %129, null
br i1 %130, label %134, label %131
131: ; preds = %119
%132 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.15, i64 0, i64 0))
%133 = load i32, i32* @EXIT_FAILURE
store i32 %133, i32* %3
br label %243
134: ; preds = %119
%135 = load i64*, i64** %20
%136 = ptrtoint i64* %135 to i64
%137 = and i64 %136, 2097151
%138 = icmp ne i64 %137, 0
br i1 %138, label %139, label %142
139: ; preds = %134
%140 = load i64*, i64** %20
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.16, i64 0, i64 0), i64* %140)
br label %145
142: ; preds = %134
%143 = load i64*, i64** %20
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.17, i64 0, i64 0), i64* %143)
br label %145
145: ; preds = %142, %139
%146 = load i64, i64* %22
store i64 %146, i64* %23
store i32 0, i32* %7
br label %147
147: ; preds = %233, %145
%148 = load i32, i32* %7
%149 = icmp slt i32 %148, 3
br i1 %149, label %150, label %236
150: ; preds = %147
%151 = load i32, i32* %14
%152 = icmp ne i32 %151, 0
br i1 %152, label %153, label %168
153: ; preds = %150
%154 = load i32, i32* %16
%155 = icmp ne i32 %154, 0
br i1 %155, label %168, label %156
156: ; preds = %153
%157 = load i64*, i64** %20
%158 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.18, i64 0, i64 0), i64* %157)
%159 = load i64*, i64** %20
%160 = load i64, i64* %22
%161 = call i32 @mlock(i64* %159, i64 %160)
store i32 %161, i32* %9
%162 = load i32, i32* %9
%163 = icmp slt i32 %162, 0
br i1 %163, label %164, label %167
164: ; preds = %156
%165 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.19, i64 0, i64 0))
%166 = load i32, i32* @EXIT_FAILURE
store i32 %166, i32* %3
br label %243
167: ; preds = %156
br label %184
168: ; preds = %153, %150
%169 = load i32, i32* %15
%170 = icmp ne i32 %169, 0
br i1 %170, label %171, label %183
171: ; preds = %168
%172 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%173 = load i32, i32* @MCL_CURRENT
%174 = load i32, i32* @MCL_FUTURE
%175 = or i32 %173, %174
%176 = call i32 @mlockall(i32 %175)
store i32 %176, i32* %9
%177 = load i32, i32* %9
%178 = icmp slt i32 %177, 0
br i1 %178, label %179, label %182
179: ; preds = %171
%180 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.20, i64 0, i64 0))
%181 = load i32, i32* @EXIT_FAILURE
store i32 %181, i32* %3
br label %243
182: ; preds = %171
br label %183
183: ; preds = %182, %168
br label %184
184: ; preds = %183, %167
%185 = load i32, i32* %7
%186 = add nsw i32 %185, 1
%187 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.21, i64 0, i64 0), i32 %186)
%188 = load i32, i32* %18
%189 = icmp ne i32 %188, 0
br i1 %189, label %190, label %194
190: ; preds = %184
%191 = load i64*, i64** %20
%192 = load i64, i64* %23
%193 = call i32 @test_write(i64* %191, i64 %192)
br label %194
194: ; preds = %190, %184
%195 = load i32, i32* %17
%196 = icmp ne i32 %195, 0
br i1 %196, label %197, label %201
197: ; preds = %194
%198 = load i64*, i64** %20
%199 = load i64, i64* %23
%200 = call i32 @test_read(i64* %198, i64 %199)
br label %201
201: ; preds = %197, %194
%202 = load i32, i32* %14
%203 = icmp ne i32 %202, 0
br i1 %203, label %204, label %219
204: ; preds = %201
%205 = load i32, i32* %16
%206 = icmp ne i32 %205, 0
br i1 %206, label %219, label %207
207: ; preds = %204
%208 = load i64*, i64** %20
%209 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.22, i64 0, i64 0), i64* %208)
%210 = load i64*, i64** %20
%211 = load i64, i64* %22
%212 = call i32 @munlock(i64* %210, i64 %211)
store i32 %212, i32* %9
%213 = load i32, i32* %9
%214 = icmp slt i32 %213, 0
br i1 %214, label %215, label %218
215: ; preds = %207
%216 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.23, i64 0, i64 0))
%217 = load i32, i32* @EXIT_FAILURE
store i32 %217, i32* %3
br label %243
218: ; preds = %207
br label %232
219: ; preds = %204, %201
%220 = load i32, i32* %15
%221 = icmp ne i32 %220, 0
br i1 %221, label %222, label %231
222: ; preds = %219
%223 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.24, i64 0, i64 0))
%224 = call i32 (...) @munlockall()
store i32 %224, i32* %9
%225 = load i32, i32* %9
%226 = icmp slt i32 %225, 0
br i1 %226, label %227, label %230
227: ; preds = %222
%228 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.25, i64 0, i64 0))
%229 = load i32, i32* @EXIT_FAILURE
store i32 %229, i32* %3
br label %243
230: ; preds = %222
br label %231
231: ; preds = %230, %219
br label %232
232: ; preds = %231, %218
store i32 0, i32* %16
br label %233
233: ; preds = %232
%234 = load i32, i32* %7
%235 = add nsw i32 %234, 1
store i32 %235, i32* %7
br label %147
236: ; preds = %147
%237 = load i64*, i64** %20
%238 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.26, i64 0, i64 0), i64* %237)
%239 = load i64*, i64** %20
%240 = load i64, i64* %22
%241 = call i32 @munmap(i64* %239, i64 %240)
%242 = load i32, i32* @EXIT_SUCCESS
store i32 %242, i32* %3
br label %243
243: ; preds = %236, %227, %215, %179, %164, %131, %102, %94, %59
%244 = load i32, i32* %3
ret i32 %244
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [9 x i8] c"RMSApsrw\00"
@MAP_POPULATE = global i32 0
@MAP_SHARED = global i32 0
@optind = global i32 0
@EXIT_FAILURE = global i32 0
@MAP_PRIVATE = global i32 0
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@O_RDWR = global i32 0
@PROT_WRITE = global i32 0
@.str.11 = [12 x i8] c"open failed\00"
@.str.12 = [13 x i8] c"fstat failed\00"
@.str.13 = [31 x i8] c"> open %s size %#zx flags %#x\0A\00"
@.str.14 = [30 x i8] c"> mmap mprot 0x%x flags 0x%x\0A\00"
@.str.15 = [12 x i8] c"mmap failed\00"
@.str.16 = [32 x i8] c"> mmap: NOT 2MiB aligned: 0x%p\0A\00"
@.str.17 = [28 x i8] c"> mmap: 2MiB aligned: 0x%p\0A\00"
@.str.18 = [14 x i8] c"> mlock 0x%p\0A\00"
@.str.19 = [13 x i8] c"mlock failed\00"
@MCL_CURRENT = global i32 0
@MCL_FUTURE = global i32 0
@.str.20 = [16 x i8] c"mlockall failed\00"
@.str.21 = [16 x i8] c"===== %d =====\0A\00"
@.str.22 = [16 x i8] c"> munlock 0x%p\0A\00"
@.str.23 = [15 x i8] c"munlock failed\00"
@.str.25 = [18 x i8] c"munlockall failed\00"
@.str.26 = [15 x i8] c"> munmap 0x%p\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [14 x i8] c"> MAP_PRIVATE\00"
@str.27 = [13 x i8] c"> munlockall\00"
@str.29 = [18 x i8] c"missing file name\00"
@str.30 = [13 x i8] c"> write-test\00"
@str.31 = [12 x i8] c"> read-test\00"
@str.32 = [13 x i8] c"> MAP_SHARED\00"
@str.33 = [15 x i8] c"> MAP_POPULATE\00"
@str.34 = [11 x i8] c"> mlockall\00"
@str.35 = [31 x i8] c"> mlock - skip first iteration\00"
@str.36 = [8 x i8] c"> mlock\00"
@str.37 = [18 x i8] c"> mmap: read-only\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast %struct.stat* %4 to i8*
br label %7
7: ; preds = %16, %2
%8 = phi i32 [ 0, %2 ], [ %17, %16 ]
%9 = phi i32 [ 0, %2 ], [ %18, %16 ]
%10 = phi i32 [ 0, %2 ], [ %19, %16 ]
%11 = phi i32 [ 0, %2 ], [ %20, %16 ]
%12 = phi i32 [ 0, %2 ], [ %21, %16 ]
%13 = phi i32 [ 0, %2 ], [ %22, %16 ]
%14 = phi i32 [ 0, %2 ], [ %23, %16 ]
%15 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
switch i32 %15, label %16 [
i32 -1, label %44
i32 82, label %24
i32 77, label %26
i32 83, label %28
i32 65, label %30
i32 112, label %32
i32 115, label %36
i32 114, label %40
i32 119, label %42
]
16: ; preds = %7, %42, %40, %36, %32, %30, %28, %26, %24
%17 = phi i32 [ %8, %42 ], [ %8, %40 ], [ %39, %36 ], [ %35, %32 ], [ %8, %30 ], [ %8, %28 ], [ %8, %26 ], [ %8, %24 ], [ %8, %7 ]
%18 = phi i32 [ %9, %42 ], [ %9, %40 ], [ %9, %36 ], [ %9, %32 ], [ %9, %30 ], [ %9, %28 ], [ %9, %26 ], [ 1, %24 ], [ %9, %7 ]
%19 = phi i32 [ %10, %42 ], [ %10, %40 ], [ %10, %36 ], [ %10, %32 ], [ %10, %30 ], [ %10, %28 ], [ 1, %26 ], [ %10, %24 ], [ %10, %7 ]
%20 = phi i32 [ %11, %42 ], [ %11, %40 ], [ %11, %36 ], [ %11, %32 ], [ 1, %30 ], [ %11, %28 ], [ %11, %26 ], [ %11, %24 ], [ %11, %7 ]
%21 = phi i32 [ %12, %42 ], [ %12, %40 ], [ %12, %36 ], [ %12, %32 ], [ %12, %30 ], [ 1, %28 ], [ %12, %26 ], [ %12, %24 ], [ %12, %7 ]
%22 = phi i32 [ %13, %42 ], [ 1, %40 ], [ %13, %36 ], [ %13, %32 ], [ %13, %30 ], [ %13, %28 ], [ %13, %26 ], [ %13, %24 ], [ %13, %7 ]
%23 = phi i32 [ 1, %42 ], [ %14, %40 ], [ %14, %36 ], [ %14, %32 ], [ %14, %30 ], [ %14, %28 ], [ %14, %26 ], [ %14, %24 ], [ %14, %7 ]
br label %7
24: ; preds = %7
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.37, i64 0, i64 0))
br label %16
26: ; preds = %7
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.36, i64 0, i64 0))
br label %16
28: ; preds = %7
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.35, i64 0, i64 0))
br label %16
30: ; preds = %7
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.34, i64 0, i64 0))
br label %16
32: ; preds = %7
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.33, i64 0, i64 0))
%34 = load i32, i32* @MAP_POPULATE
%35 = or i32 %34, %8
br label %16
36: ; preds = %7
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.32, i64 0, i64 0))
%38 = load i32, i32* @MAP_SHARED
%39 = or i32 %38, %8
br label %16
40: ; preds = %7
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.31, i64 0, i64 0))
br label %16
42: ; preds = %7
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.30, i64 0, i64 0))
br label %16
44: ; preds = %7
%45 = load i32, i32* @optind
%46 = icmp eq i32 %45, %0
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.29, i64 0, i64 0))
br label %205
49: ; preds = %44
%50 = sext i32 %45 to i64
%51 = getelementptr inbounds i8*, i8** %1, i64 %50
%52 = load i8*, i8** %51
%53 = load i32, i32* @MAP_SHARED
%54 = and i32 %53, %8
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %49
%57 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%58 = load i32, i32* @MAP_PRIVATE
%59 = or i32 %58, %8
br label %60
60: ; preds = %56, %49
%61 = phi i32 [ %8, %49 ], [ %59, %56 ]
%62 = icmp eq i32 %9, 0
%63 = load i32, i32* @PROT_READ
%64 = load i32, i32* @PROT_WRITE
%65 = select i1 %62, i32 %64, i32 0
%66 = or i32 %65, %63
%67 = load i32, i32* @O_RDWR
%68 = load i32, i32* @O_RDONLY
%69 = select i1 %62, i32 %67, i32 %68
%70 = tail call i32 @open(i8* %52, i32 %69)
%71 = icmp eq i32 %70, -1
br i1 %71, label %72, label %74
72: ; preds = %60
%73 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0))
br label %205
74: ; preds = %60
%75 = call i32 @fstat(i32 %70, %struct.stat* %4)
%76 = icmp slt i32 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %74
%78 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0))
br label %205
79: ; preds = %74
%80 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%81 = load i64, i64* %80
%82 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.13, i64 0, i64 0), i8* %52, i64 %81, i32 %69)
%83 = call i32 @posix_memalign(i8** %3, i32 2097152, i64 %81)
%84 = icmp eq i32 %83, 0
br i1 %84, label %85, label %88
85: ; preds = %79
%86 = load i8*, i8** %3
%87 = call i32 @free(i8* %86)
br label %88
88: ; preds = %85, %79
%89 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.14, i64 0, i64 0), i32 %66, i32 %61)
%90 = load i8*, i8** %3
%91 = call i64* @mmap(i8* %90, i64 %81, i32 %66, i32 %61, i32 %70, i32 0)
%92 = icmp eq i64* %91, null
br i1 %92, label %93, label %95
93: ; preds = %88
%94 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.15, i64 0, i64 0))
br label %205
95: ; preds = %88
%96 = ptrtoint i64* %91 to i64
%97 = and i64 %96, 2097151
%98 = icmp eq i64 %97, 0
%99 = select i1 %98, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.17, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.16, i64 0, i64 0)
%100 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %99, i64* %91)
%101 = icmp eq i32 %10, 0
%102 = icmp eq i32 %11, 0
%103 = icmp eq i32 %14, 0
%104 = icmp eq i32 %13, 0
%105 = icmp ne i32 %12, 0
%106 = select i1 %101, i1 true, i1 %105
br i1 %106, label %113, label %107
107: ; preds = %95
%108 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.18, i64 0, i64 0), i64* %91)
%109 = call i32 @mlock(i64* %91, i64 %81)
%110 = icmp slt i32 %109, 0
br i1 %110, label %111, label %123
111: ; preds = %174, %146, %107
%112 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.19, i64 0, i64 0))
br label %205
113: ; preds = %95
br i1 %102, label %123, label %114
114: ; preds = %113
%115 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.34, i64 0, i64 0))
%116 = load i32, i32* @MCL_CURRENT
%117 = load i32, i32* @MCL_FUTURE
%118 = or i32 %117, %116
%119 = call i32 @mlockall(i32 %118)
%120 = icmp slt i32 %119, 0
br i1 %120, label %121, label %123
121: ; preds = %178, %150, %114
%122 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.20, i64 0, i64 0))
br label %205
123: ; preds = %113, %114, %107
%124 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.21, i64 0, i64 0), i32 1)
br i1 %103, label %127, label %125
125: ; preds = %123
%126 = call i32 @test_write(i64* %91, i64 %81)
br label %127
127: ; preds = %125, %123
br i1 %104, label %130, label %128
128: ; preds = %127
%129 = call i32 @test_read(i64* %91, i64 %81)
br label %130
130: ; preds = %128, %127
br i1 %106, label %137, label %131
131: ; preds = %130
%132 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.22, i64 0, i64 0), i64* %91)
%133 = call i32 @munlock(i64* %91, i64 %81)
%134 = icmp slt i32 %133, 0
br i1 %134, label %135, label %146
135: ; preds = %193, %165, %131
%136 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.23, i64 0, i64 0))
br label %205
137: ; preds = %130
br i1 %102, label %144, label %138
138: ; preds = %137
%139 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.27, i64 0, i64 0))
%140 = call i32 (...) @munlockall()
%141 = icmp slt i32 %140, 0
br i1 %141, label %142, label %145
142: ; preds = %198, %170, %138
%143 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.25, i64 0, i64 0))
br label %205
144: ; preds = %137
br i1 %101, label %157, label %146
145: ; preds = %138
br i1 %101, label %150, label %146
146: ; preds = %131, %144, %145
%147 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.18, i64 0, i64 0), i64* %91)
%148 = call i32 @mlock(i64* %91, i64 %81)
%149 = icmp slt i32 %148, 0
br i1 %149, label %111, label %157
150: ; preds = %145
%151 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.34, i64 0, i64 0))
%152 = load i32, i32* @MCL_CURRENT
%153 = load i32, i32* @MCL_FUTURE
%154 = or i32 %153, %152
%155 = call i32 @mlockall(i32 %154)
%156 = icmp slt i32 %155, 0
br i1 %156, label %121, label %157
157: ; preds = %144, %150, %146
%158 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.21, i64 0, i64 0), i32 2)
br i1 %103, label %161, label %159
159: ; preds = %157
%160 = call i32 @test_write(i64* %91, i64 %81)
br label %161
161: ; preds = %159, %157
br i1 %104, label %164, label %162
162: ; preds = %161
%163 = call i32 @test_read(i64* %91, i64 %81)
br label %164
164: ; preds = %162, %161
br i1 %101, label %169, label %165
165: ; preds = %164
%166 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.22, i64 0, i64 0), i64* %91)
%167 = call i32 @munlock(i64* %91, i64 %81)
%168 = icmp slt i32 %167, 0
br i1 %168, label %135, label %174
169: ; preds = %164
br i1 %102, label %185, label %170
170: ; preds = %169
%171 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.27, i64 0, i64 0))
%172 = call i32 (...) @munlockall()
%173 = icmp slt i32 %172, 0
br i1 %173, label %142, label %178
174: ; preds = %165
%175 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.18, i64 0, i64 0), i64* %91)
%176 = call i32 @mlock(i64* %91, i64 %81)
%177 = icmp slt i32 %176, 0
br i1 %177, label %111, label %185
178: ; preds = %170
%179 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.34, i64 0, i64 0))
%180 = load i32, i32* @MCL_CURRENT
%181 = load i32, i32* @MCL_FUTURE
%182 = or i32 %181, %180
%183 = call i32 @mlockall(i32 %182)
%184 = icmp slt i32 %183, 0
br i1 %184, label %121, label %185
185: ; preds = %169, %178, %174
%186 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.21, i64 0, i64 0), i32 3)
br i1 %103, label %189, label %187
187: ; preds = %185
%188 = call i32 @test_write(i64* %91, i64 %81)
br label %189
189: ; preds = %187, %185
br i1 %104, label %192, label %190
190: ; preds = %189
%191 = call i32 @test_read(i64* %91, i64 %81)
br label %192
192: ; preds = %190, %189
br i1 %101, label %197, label %193
193: ; preds = %192
%194 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.22, i64 0, i64 0), i64* %91)
%195 = call i32 @munlock(i64* %91, i64 %81)
%196 = icmp slt i32 %195, 0
br i1 %196, label %135, label %202
197: ; preds = %192
br i1 %102, label %202, label %198
198: ; preds = %197
%199 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.27, i64 0, i64 0))
%200 = call i32 (...) @munlockall()
%201 = icmp slt i32 %200, 0
br i1 %201, label %142, label %202
202: ; preds = %198, %197, %193
%203 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.26, i64 0, i64 0), i64* %91)
%204 = call i32 @munmap(i64* %91, i64 %81)
br label %205
205: ; preds = %202, %142, %135, %121, %111, %93, %77, %72, %47
%206 = phi i32* [ @EXIT_FAILURE, %47 ], [ @EXIT_FAILURE, %72 ], [ @EXIT_FAILURE, %77 ], [ @EXIT_FAILURE, %121 ], [ @EXIT_FAILURE, %142 ], [ @EXIT_FAILURE, %135 ], [ @EXIT_FAILURE, %111 ], [ @EXIT_SUCCESS, %202 ], [ @EXIT_FAILURE, %93 ]
%207 = load i32, i32* %206
ret i32 %207
}