#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 size_t requested_size;
typedef scalar_t__ pagesize;

/* Variables and functions */
int MAP_ANONYMOUS;
char *MAP_FAILED;
int MAP_FIXED;
int MAP_PRIVATE;
int MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ _SC_PAGE_SIZE;
int /*<<< orphan*/ assert(int);
size_t atoi(char *);
scalar_t__ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ ftruncate(int, size_t);
int /*<<< orphan*/ memcmp(char *, char *, int);
char *mmap(char *, size_t, int, int, int, int /*<<< orphan*/);
scalar_t__ munmap(char *, size_t);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
size_t sysconf(int /*<<< orphan*/);
int main(int argc, char **argv) {
  size_t requested_size, size, pagesize, *p;
  char *map, *second_copy, *big_map;
  int fd;
  if (argc < 3) {
    return 1;
  }
  requested_size = atoi(argv[2]);
  if (!requested_size) {
    return 1;
  }
  fd = open(argv[1], O_RDWR);
  if (fd == -1) {
    perror("open");
    return 1;
  }
  pagesize = sysconf(_SC_PAGE_SIZE);
  size = (((requested_size) + (pagesize)-1) & (~(((pagesize)) - 1)));
  if (ftruncate(fd, size)) {
    perror("truncate");
    return 1;
  }
  big_map = mmap(NULL, 2 * size, PROT_READ | PROT_WRITE,
                 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  if (map == MAP_FAILED) {
    perror("mmap");
    return 1;
  }
  map = mmap(big_map, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd,
             0);
  if (map == MAP_FAILED) {
    perror("mmap");
    return 1;
  }
  if (map != big_map) {
    fprintf(stderr, "MAP_FIXED did not replace old map\n");
    return 1;
  }
  second_copy = mmap(big_map + size, size, PROT_READ | PROT_WRITE,
                     MAP_SHARED | MAP_FIXED, fd, 0);
  if (second_copy == MAP_FAILED) {
    perror("mmap");
    return 1;
  }
  if (second_copy != big_map + size) {
    fprintf(stderr, "MAP_FIXED did not replace old map\n");
    return 1;
  }
  if (close(fd)) {
    perror("close");
    return 1;
  }
  p = (size_t *)map;
  *p++ = requested_size;
  p = ((size_t *)(map + size)) + 1;
  *p = ~requested_size;
  assert(!memcmp(map, map + size, 2 * sizeof(size_t)));
  if (munmap(map, size)) {
    perror("munmap");
    return 1;
  }
  if (munmap(map + size, size)) {
    perror("munmap");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11dc <main+0x2c>
movl   $0x1,-0x4(%rbp)
jmp    153d <main+0x38d>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <atoi@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1204 <main+0x54>
movl   $0x1,-0x4(%rbp)
jmp    153d <main+0x38d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0xffffffff,-0x4c(%rbp)
jne    123f <main+0x8f>
lea    0xdd2(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    153d <main+0x38d>
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
call   10c0 <sysconf@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
add    -0x28(%rbp),%rax
sub    $0x1,%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
xor    $0xffffffffffffffff,%rcx
and    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x4c(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1040 <ftruncate@plt>
cmp    $0x0,%rax
je     129e <main+0xee>
lea    0xd78(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    153d <main+0x38d>
mov    -0x20(%rbp),%rsi
shl    $0x1,%rsi
mov    0x2d4b(%rip),%rax
mov    (%rax),%edx
mov    0x2d02(%rip),%rax
or     (%rax),%edx
mov    0x2ce9(%rip),%rax
mov    (%rax),%ecx
mov    0x2d08(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rax
mov    0x2cad(%rip),%rcx
cmp    (%rcx),%rax
jne    130c <main+0x15c>
lea    0xd13(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    153d <main+0x38d>
mov    -0x48(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2cdd(%rip),%rax
mov    (%rax),%edx
mov    0x2c94(%rip),%rax
or     (%rax),%edx
mov    0x2cbb(%rip),%rax
mov    (%rax),%ecx
mov    0x2c6a(%rip),%rax
or     (%rax),%ecx
mov    -0x4c(%rbp),%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    0x2c45(%rip),%rcx
cmp    (%rcx),%rax
jne    1374 <main+0x1c4>
lea    0xcab(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    153d <main+0x38d>
mov    -0x38(%rbp),%rax
cmp    -0x48(%rbp),%rax
je     13a3 <main+0x1f3>
mov    0x2c37(%rip),%rax
mov    (%rax),%edi
lea    0xc81(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    153d <main+0x38d>
mov    -0x48(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2c42(%rip),%rax
mov    (%rax),%edx
mov    0x2bf9(%rip),%rax
or     (%rax),%edx
mov    0x2c20(%rip),%rax
mov    (%rax),%ecx
mov    0x2bcf(%rip),%rax
or     (%rax),%ecx
mov    -0x4c(%rbp),%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    0x2baa(%rip),%rcx
cmp    (%rcx),%rax
jne    140f <main+0x25f>
lea    0xc10(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    153d <main+0x38d>
mov    -0x40(%rbp),%rax
mov    -0x48(%rbp),%rcx
add    -0x20(%rbp),%rcx
cmp    %rcx,%rax
je     1445 <main+0x295>
mov    0x2b95(%rip),%rax
mov    (%rax),%edi
lea    0xbdf(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    153d <main+0x38d>
mov    -0x4c(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%rax
je     146f <main+0x2bf>
lea    0xbd8(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    153d <main+0x38d>
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
add    $0x8,%rdx
mov    %rdx,-0x30(%rbp)
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rax
add    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rcx
xor    $0xffffffffffffffff,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rdi
mov    -0x38(%rbp),%rsi
add    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <munmap@plt>
cmp    $0x0,%rax
je     1503 <main+0x353>
lea    0xb4a(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    153d <main+0x38d>
mov    -0x38(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <munmap@plt>
cmp    $0x0,%rax
je     1536 <main+0x386>
lea    0xb17(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    153d <main+0x38d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%ebx
cmp    $0x3,%edi
jl     1396 <main+0x1e6>
mov    %rsi,%rbp
mov    0x10(%rsi),%rdi
call   10d0 <atoi@plt>
test   %rax,%rax
je     1396 <main+0x1e6>
mov    %rax,%r14
mov    0x8(%rbp),%rdi
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     137c <main+0x1cc>
mov    %eax,%r12d
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
call   10c0 <sysconf@plt>
mov    %rax,%rbx
add    %r14,%rax
add    $0xffffffffffffffff,%rax
neg    %rbx
and    %rax,%rbx
mov    %r12d,%edi
mov    %rbx,%rsi
call   1040 <ftruncate@plt>
test   %rax,%rax
jne    1385 <main+0x1d5>
lea    (%rbx,%rbx,1),%rsi
mov    0x2dbc(%rip),%r13
mov    0x2d75(%rip),%rbp
mov    0x0(%rbp),%edx
or     0x0(%r13),%edx
mov    0x2d57(%rip),%rax
mov    0x2d78(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%r15
mov    0x0(%rbp),%edx
or     0x0(%r13),%edx
mov    0x2d6b(%rip),%rax
mov    0x2d1c(%rip),%rbp
mov    0x0(%rbp),%ecx
or     (%rax),%ecx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12d,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    0x2cf7(%rip),%r13
cmp    0x0(%r13),%rax
je     1373 <main+0x1c3>
cmp    %r15,%rax
jne    12f5 <main+0x145>
mov    0x2d01(%rip),%rax
mov    (%rax),%edx
mov    0x2d38(%rip),%rax
or     (%rax),%edx
lea    (%r15,%rbx,1),%rax
mov    0x0(%rbp),%ecx
mov    %rax,%rbp
mov    0x2d15(%rip),%rax
or     (%rax),%ecx
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r12d,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
cmp    0x0(%r13),%rax
je     1373 <main+0x1c3>
cmp    %rbp,%rax
je     130f <main+0x15f>
mov    0x2cc4(%rip),%rax
mov    (%rax),%edi
lea    0xd0e(%rip),%rsi
call   1080 <fprintf@plt>
jmp    1391 <main+0x1e1>
mov    %r12d,%edi
call   1050 <close@plt>
test   %rax,%rax
jne    13a7 <main+0x1f7>
mov    %r14,(%r15)
not    %r14
mov    %r14,0x8(%r15,%rbx,1)
mov    %r15,%rdi
mov    %rbp,%rsi
mov    $0x10,%edx
call   1060 <memcmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <munmap@plt>
test   %rax,%rax
jne    136a <main+0x1ba>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1090 <munmap@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1396 <main+0x1e6>
lea    0xccb(%rip),%rdi
jmp    138c <main+0x1dc>
lea    0xc94(%rip),%rdi
jmp    138c <main+0x1dc>
lea    0xc7d(%rip),%rdi
jmp    138c <main+0x1dc>
lea    0xc79(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc88(%rip),%rdi
jmp    138c <main+0x1dc>

LLVM IR (-O0):
@O_RDWR = global i32 0
@.str = [5 x i8] c"open\00"
@_SC_PAGE_SIZE = global i32 0
@.str.1 = [9 x i8] c"truncate\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [5 x i8] c"mmap\00"
@MAP_SHARED = global i32 0
@MAP_FIXED = global i32 0
@stderr = global i32 0
@.str.3 = [35 x i8] c"MAP_FIXED did not replace old map\0A\00"
@.str.4 = [6 x i8] c"close\00"
@.str.5 = [7 x i8] c"munmap\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 1, i32* %3
br label %162
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call i64 @atoi(i8* %20)
store i64 %21, i64* %6
%22 = load i64, i64* %6
%23 = icmp ne i64 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %17
store i32 1, i32* %3
br label %162
25: ; preds = %17
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = load i32, i32* @O_RDWR
%30 = call i32 @open(i8* %28, i32 %29)
store i32 %30, i32* %13
%31 = load i32, i32* %13
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %25
%34 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %162
35: ; preds = %25
%36 = load i32, i32* @_SC_PAGE_SIZE
%37 = call i64 @sysconf(i32 %36)
store i64 %37, i64* %8
%38 = load i64, i64* %6
%39 = load i64, i64* %8
%40 = add i64 %38, %39
%41 = sub i64 %40, 1
%42 = load i64, i64* %8
%43 = sub i64 %42, 1
%44 = xor i64 %43, -1
%45 = and i64 %41, %44
store i64 %45, i64* %7
%46 = load i32, i32* %13
%47 = load i64, i64* %7
%48 = call i64 @ftruncate(i32 %46, i64 %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %35
%51 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %162
52: ; preds = %35
%53 = load i64, i64* %7
%54 = mul i64 2, %53
%55 = load i32, i32* @PROT_READ
%56 = load i32, i32* @PROT_WRITE
%57 = or i32 %55, %56
%58 = load i32, i32* @MAP_PRIVATE
%59 = load i32, i32* @MAP_ANONYMOUS
%60 = or i32 %58, %59
%61 = call i8* @mmap(i8* null, i64 %54, i32 %57, i32 %60, i32 -1, i32 0)
store i8* %61, i8** %12
%62 = load i8*, i8** %10
%63 = load i8*, i8** @MAP_FAILED
%64 = icmp eq i8* %62, %63
br i1 %64, label %65, label %67
65: ; preds = %52
%66 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %162
67: ; preds = %52
%68 = load i8*, i8** %12
%69 = load i64, i64* %7
%70 = load i32, i32* @PROT_READ
%71 = load i32, i32* @PROT_WRITE
%72 = or i32 %70, %71
%73 = load i32, i32* @MAP_SHARED
%74 = load i32, i32* @MAP_FIXED
%75 = or i32 %73, %74
%76 = load i32, i32* %13
%77 = call i8* @mmap(i8* %68, i64 %69, i32 %72, i32 %75, i32 %76, i32 0)
store i8* %77, i8** %10
%78 = load i8*, i8** %10
%79 = load i8*, i8** @MAP_FAILED
%80 = icmp eq i8* %78, %79
br i1 %80, label %81, label %83
81: ; preds = %67
%82 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %162
83: ; preds = %67
%84 = load i8*, i8** %10
%85 = load i8*, i8** %12
%86 = icmp ne i8* %84, %85
br i1 %86, label %87, label %90
87: ; preds = %83
%88 = load i32, i32* @stderr
%89 = call i32 @fprintf(i32 %88, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %162
90: ; preds = %83
%91 = load i8*, i8** %12
%92 = load i64, i64* %7
%93 = getelementptr inbounds i8, i8* %91, i64 %92
%94 = load i64, i64* %7
%95 = load i32, i32* @PROT_READ
%96 = load i32, i32* @PROT_WRITE
%97 = or i32 %95, %96
%98 = load i32, i32* @MAP_SHARED
%99 = load i32, i32* @MAP_FIXED
%100 = or i32 %98, %99
%101 = load i32, i32* %13
%102 = call i8* @mmap(i8* %93, i64 %94, i32 %97, i32 %100, i32 %101, i32 0)
store i8* %102, i8** %11
%103 = load i8*, i8** %11
%104 = load i8*, i8** @MAP_FAILED
%105 = icmp eq i8* %103, %104
br i1 %105, label %106, label %108
106: ; preds = %90
%107 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %162
108: ; preds = %90
%109 = load i8*, i8** %11
%110 = load i8*, i8** %12
%111 = load i64, i64* %7
%112 = getelementptr inbounds i8, i8* %110, i64 %111
%113 = icmp ne i8* %109, %112
br i1 %113, label %114, label %117
114: ; preds = %108
%115 = load i32, i32* @stderr
%116 = call i32 @fprintf(i32 %115, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %162
117: ; preds = %108
%118 = load i32, i32* %13
%119 = call i64 @close(i32 %118)
%120 = icmp ne i64 %119, 0
br i1 %120, label %121, label %123
121: ; preds = %117
%122 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %162
123: ; preds = %117
%124 = load i8*, i8** %10
%125 = bitcast i8* %124 to i64*
store i64* %125, i64** %9
%126 = load i64, i64* %6
%127 = load i64*, i64** %9
%128 = getelementptr inbounds i64, i64* %127, i32 1
store i64* %128, i64** %9
store i64 %126, i64* %127
%129 = load i8*, i8** %10
%130 = load i64, i64* %7
%131 = getelementptr inbounds i8, i8* %129, i64 %130
%132 = bitcast i8* %131 to i64*
%133 = getelementptr inbounds i64, i64* %132, i64 1
store i64* %133, i64** %9
%134 = load i64, i64* %6
%135 = xor i64 %134, -1
%136 = load i64*, i64** %9
store i64 %135, i64* %136
%137 = load i8*, i8** %10
%138 = load i8*, i8** %10
%139 = load i64, i64* %7
%140 = getelementptr inbounds i8, i8* %138, i64 %139
%141 = call i32 @memcmp(i8* %137, i8* %140, i32 16)
%142 = icmp ne i32 %141, 0
%143 = xor i1 %142, true
%144 = zext i1 %143 to i32
%145 = call i32 @assert(i32 %144)
%146 = load i8*, i8** %10
%147 = load i64, i64* %7
%148 = call i64 @munmap(i8* %146, i64 %147)
%149 = icmp ne i64 %148, 0
br i1 %149, label %150, label %152
150: ; preds = %123
%151 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %162
152: ; preds = %123
%153 = load i8*, i8** %10
%154 = load i64, i64* %7
%155 = getelementptr inbounds i8, i8* %153, i64 %154
%156 = load i64, i64* %7
%157 = call i64 @munmap(i8* %155, i64 %156)
%158 = icmp ne i64 %157, 0
br i1 %158, label %159, label %161
159: ; preds = %152
%160 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %162
161: ; preds = %152
store i32 0, i32* %3
br label %162
162: ; preds = %161, %159, %150, %121, %114, %106, %87, %81, %65, %50, %33, %24, %16
%163 = load i32, i32* %3
ret i32 %163
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@.str = [5 x i8] c"open\00"
@_SC_PAGE_SIZE = global i32 0
@.str.1 = [9 x i8] c"truncate\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [5 x i8] c"mmap\00"
@MAP_SHARED = global i32 0
@MAP_FIXED = global i32 0
@stderr = global i32 0
@.str.3 = [35 x i8] c"MAP_FIXED did not replace old map\0A\00"
@.str.4 = [6 x i8] c"close\00"
@.str.5 = [7 x i8] c"munmap\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %94, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 2
%6 = load i8*, i8** %5
%7 = tail call i64 @atoi(i8* %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %94, label %9
9: ; preds = %4
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDWR
%13 = tail call i32 @open(i8* %11, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %94
17: ; preds = %9
%18 = load i32, i32* @_SC_PAGE_SIZE
%19 = tail call i64 @sysconf(i32 %18)
%20 = add i64 %7, -1
%21 = add i64 %20, %19
%22 = sub i64 0, %19
%23 = and i64 %21, %22
%24 = tail call i64 @ftruncate(i32 %13, i64 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %17
%27 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %94
28: ; preds = %17
%29 = shl i64 %23, 1
%30 = load i32, i32* @PROT_READ
%31 = load i32, i32* @PROT_WRITE
%32 = or i32 %31, %30
%33 = load i32, i32* @MAP_PRIVATE
%34 = load i32, i32* @MAP_ANONYMOUS
%35 = or i32 %34, %33
%36 = tail call i8* @mmap(i8* null, i64 %29, i32 %32, i32 %35, i32 -1, i32 0)
%37 = load i32, i32* @PROT_READ
%38 = load i32, i32* @PROT_WRITE
%39 = or i32 %38, %37
%40 = load i32, i32* @MAP_SHARED
%41 = load i32, i32* @MAP_FIXED
%42 = or i32 %41, %40
%43 = tail call i8* @mmap(i8* %36, i64 %23, i32 %39, i32 %42, i32 %13, i32 0)
%44 = load i8*, i8** @MAP_FAILED
%45 = icmp eq i8* %43, %44
br i1 %45, label %46, label %48
46: ; preds = %28
%47 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %94
48: ; preds = %28
%49 = icmp eq i8* %43, %36
br i1 %49, label %53, label %50
50: ; preds = %48
%51 = load i32, i32* @stderr
%52 = tail call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
br label %94
53: ; preds = %48
%54 = getelementptr inbounds i8, i8* %36, i64 %23
%55 = load i32, i32* @PROT_READ
%56 = load i32, i32* @PROT_WRITE
%57 = or i32 %56, %55
%58 = load i32, i32* @MAP_SHARED
%59 = load i32, i32* @MAP_FIXED
%60 = or i32 %59, %58
%61 = tail call i8* @mmap(i8* %54, i64 %23, i32 %57, i32 %60, i32 %13, i32 0)
%62 = load i8*, i8** @MAP_FAILED
%63 = icmp eq i8* %61, %62
br i1 %63, label %64, label %66
64: ; preds = %53
%65 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %94
66: ; preds = %53
%67 = icmp eq i8* %61, %54
br i1 %67, label %71, label %68
68: ; preds = %66
%69 = load i32, i32* @stderr
%70 = tail call i32 @fprintf(i32 %69, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
br label %94
71: ; preds = %66
%72 = tail call i64 @close(i32 %13)
%73 = icmp eq i64 %72, 0
br i1 %73, label %76, label %74
74: ; preds = %71
%75 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %94
76: ; preds = %71
%77 = bitcast i8* %36 to i64*
store i64 %7, i64* %77
%78 = getelementptr inbounds i8, i8* %54, i64 8
%79 = bitcast i8* %78 to i64*
%80 = xor i64 %7, -1
store i64 %80, i64* %79
%81 = tail call i32 @memcmp(i8* %36, i8* %54, i32 16)
%82 = icmp eq i32 %81, 0
%83 = zext i1 %82 to i32
%84 = tail call i32 @assert(i32 %83)
%85 = tail call i64 @munmap(i8* %36, i64 %23)
%86 = icmp eq i64 %85, 0
br i1 %86, label %89, label %87
87: ; preds = %76
%88 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %94
89: ; preds = %76
%90 = tail call i64 @munmap(i8* %54, i64 %23)
%91 = icmp eq i64 %90, 0
br i1 %91, label %94, label %92
92: ; preds = %89
%93 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %94
94: ; preds = %89, %4, %2, %92, %87, %74, %68, %64, %50, %46, %26, %15
%95 = phi i32 [ 1, %15 ], [ 1, %26 ], [ 1, %46 ], [ 1, %50 ], [ 1, %64 ], [ 1, %68 ], [ 1, %74 ], [ 1, %87 ], [ 1, %92 ], [ 1, %2 ], [ 1, %4 ], [ 0, %89 ]
ret i32 %95
}