#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int MAP_ANONYMOUS;
int MAP_PRIVATE;
int PROT_EXEC;
int PROT_READ;
int PROT_WRITE;
scalar_t__ errno;
void *mmap(int /*<<< orphan*/ *, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ mprotect(void *, int, int);
int /*<<< orphan*/ munmap(void *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, void *);
int main() {
  void *m;
  m = mmap(NULL, 4096, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  printf("anon page, r-- = %p\n", m);
  if (errno) {
    perror("> ");
  }
  mprotect(m, 4096, PROT_READ | PROT_WRITE);
  if (errno) {
    perror("adding write> ");
  }
  mprotect(m, 4096, PROT_READ);
  if (errno) {
    perror("removing write> ");
  }
  mprotect(m, 4096, PROT_READ | PROT_WRITE | PROT_EXEC);
  if (errno) {
    perror("adding write+exec> ");
  }
  munmap(m, 4096);
  if (errno) {
    perror("munmap> ");
  }
  m = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1,
           0);
  printf("anon page, rw- = %p\n", m);
  if (errno) {
    perror("> ");
  }
  mprotect(m, 4096, PROT_READ | PROT_WRITE | PROT_EXEC);
  if (errno) {
    perror("adding exec> ");
  }
  munmap(m, 4096);
  if (errno) {
    perror("munmap> ");
  }
  m = mmap(NULL, 4096, PROT_READ | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1,
           0);
  printf("anon page, r-x = %p\n", m);
  if (errno) {
    perror("> ");
  }
  mprotect(m, 4096, PROT_READ | PROT_WRITE | PROT_EXEC);
  if (errno) {
    perror("adding write> ");
  }
  munmap(m, 4096);
  if (errno) {
    perror("munmap> ");
  }
  m = mmap(NULL, 4096, PROT_READ | PROT_WRITE | PROT_EXEC,
           MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  printf("anon page, rwx = %p\n", m);
  if (errno) {
    perror("> ");
  }
  munmap(m, 4096);
  if (errno) {
    perror("munmap> ");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%edx
mov    0x2e49(%rip),%rax
mov    (%rax),%ecx
mov    0x2e68(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe60(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e1c(%rip),%rax
cmpq   $0x0,(%rax)
je     11c2 <main+0x72>
lea    0xeb5(%rip),%rdi
call   1070 <perror@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e2b(%rip),%rax
mov    (%rax),%edx
mov    0x2dea(%rip),%rax
or     (%rax),%edx
mov    $0x1000,%esi
call   1060 <mprotect@plt>
mov    0x2ddf(%rip),%rax
cmpq   $0x0,(%rax)
je     11ff <main+0xaf>
lea    0xe1b(%rip),%rdi
call   1070 <perror@plt>
mov    -0x10(%rbp),%rdi
mov    0x2dee(%rip),%rax
mov    (%rax),%edx
mov    $0x1000,%esi
call   1060 <mprotect@plt>
mov    0x2dab(%rip),%rax
cmpq   $0x0,(%rax)
je     1233 <main+0xe3>
lea    0xdf6(%rip),%rdi
call   1070 <perror@plt>
mov    -0x10(%rbp),%rdi
mov    0x2dba(%rip),%rax
mov    (%rax),%edx
mov    0x2d79(%rip),%rax
or     (%rax),%edx
mov    0x2d88(%rip),%rax
or     (%rax),%edx
mov    $0x1000,%esi
call   1060 <mprotect@plt>
mov    0x2d65(%rip),%rax
cmpq   $0x0,(%rax)
je     1279 <main+0x129>
lea    0xdc1(%rip),%rdi
call   1070 <perror@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1000,%esi
call   1050 <munmap@plt>
mov    0x2d3a(%rip),%rax
cmpq   $0x0,(%rax)
je     12a4 <main+0x154>
lea    0xdaa(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edx
mov    0x2d0c(%rip),%rax
or     (%rax),%edx
mov    0x2cfb(%rip),%rax
mov    (%rax),%ecx
mov    0x2d1a(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xd64(%rip),%rdi
call   1040 <printf@plt>
mov    0x2cce(%rip),%rax
cmpq   $0x0,(%rax)
je     1310 <main+0x1c0>
lea    0xd67(%rip),%rdi
call   1070 <perror@plt>
mov    -0x10(%rbp),%rdi
mov    0x2cdd(%rip),%rax
mov    (%rax),%edx
mov    0x2c9c(%rip),%rax
or     (%rax),%edx
mov    0x2cab(%rip),%rax
or     (%rax),%edx
mov    $0x1000,%esi
call   1060 <mprotect@plt>
mov    0x2c88(%rip),%rax
cmpq   $0x0,(%rax)
je     1356 <main+0x206>
lea    0xd16(%rip),%rdi
call   1070 <perror@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1000,%esi
call   1050 <munmap@plt>
mov    0x2c5d(%rip),%rax
cmpq   $0x0,(%rax)
je     1381 <main+0x231>
lea    0xccd(%rip),%rdi
call   1070 <perror@plt>
mov    0x2c70(%rip),%rax
mov    (%rax),%edx
mov    0x2c47(%rip),%rax
or     (%rax),%edx
mov    0x2c1e(%rip),%rax
mov    (%rax),%ecx
mov    0x2c3d(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xcaa(%rip),%rdi
call   1040 <printf@plt>
mov    0x2bf1(%rip),%rax
cmpq   $0x0,(%rax)
je     13ed <main+0x29d>
lea    0xc8a(%rip),%rdi
call   1070 <perror@plt>
mov    -0x10(%rbp),%rdi
mov    0x2c00(%rip),%rax
mov    (%rax),%edx
mov    0x2bbf(%rip),%rax
or     (%rax),%edx
mov    0x2bce(%rip),%rax
or     (%rax),%edx
mov    $0x1000,%esi
call   1060 <mprotect@plt>
mov    0x2bab(%rip),%rax
cmpq   $0x0,(%rax)
je     1433 <main+0x2e3>
lea    0xbe7(%rip),%rdi
call   1070 <perror@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1000,%esi
call   1050 <munmap@plt>
mov    0x2b80(%rip),%rax
cmpq   $0x0,(%rax)
je     145e <main+0x30e>
lea    0xbf0(%rip),%rdi
call   1070 <perror@plt>
mov    0x2b93(%rip),%rax
mov    (%rax),%edx
mov    0x2b52(%rip),%rax
or     (%rax),%edx
mov    0x2b61(%rip),%rax
or     (%rax),%edx
mov    0x2b38(%rip),%rax
mov    (%rax),%ecx
mov    0x2b57(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xbd9(%rip),%rdi
call   1040 <printf@plt>
mov    0x2b0b(%rip),%rax
cmpq   $0x0,(%rax)
je     14d3 <main+0x383>
lea    0xba4(%rip),%rdi
call   1070 <perror@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1000,%esi
call   1050 <munmap@plt>
mov    0x2ae0(%rip),%rax
cmpq   $0x0,(%rax)
je     14fe <main+0x3ae>
lea    0xb50(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e96(%rip),%r12
mov    (%r12),%edx
mov    0x2e4b(%rip),%rax
mov    0x2e6c(%rip),%r13
mov    0x0(%r13),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
lea    0xe67(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    0x2e20(%rip),%r14
cmpq   $0x0,(%r14)
jne    139b <main+0x24b>
mov    0x2e07(%rip),%rbp
mov    0x0(%rbp),%edx
or     (%r12),%edx
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1060 <mprotect@plt>
cmpq   $0x0,(%r14)
jne    13ac <main+0x25c>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1060 <mprotect@plt>
cmpq   $0x0,(%r14)
jne    13bd <main+0x26d>
mov    0x0(%rbp),%edx
or     (%r12),%edx
mov    0x2dd8(%rip),%r15
or     (%r15),%edx
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1060 <mprotect@plt>
cmpq   $0x0,(%r14)
jne    13ce <main+0x27e>
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1050 <munmap@plt>
cmpq   $0x0,(%r14)
jne    13df <main+0x28f>
mov    0x0(%rbp),%edx
or     (%r12),%edx
mov    0x0(%r13),%ecx
mov    0x2d75(%rip),%rax
or     (%rax),%ecx
xor    %edi,%edi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
lea    0xdee(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
cmpq   $0x0,(%r14)
jne    13f0 <main+0x2a0>
mov    0x0(%rbp),%edx
or     (%r12),%edx
or     (%r15),%edx
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1060 <mprotect@plt>
cmpq   $0x0,(%r14)
jne    1401 <main+0x2b1>
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1050 <munmap@plt>
cmpq   $0x0,(%r14)
jne    1412 <main+0x2c2>
mov    (%r15),%edx
or     (%r12),%edx
mov    0x0(%r13),%ecx
mov    0x2cf8(%rip),%rax
or     (%rax),%ecx
xor    %edi,%edi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
lea    0xd94(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
cmpq   $0x0,(%r14)
jne    1423 <main+0x2d3>
mov    0x0(%rbp),%edx
or     (%r12),%edx
or     (%r15),%edx
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1060 <mprotect@plt>
cmpq   $0x0,(%r14)
jne    1434 <main+0x2e4>
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1050 <munmap@plt>
cmpq   $0x0,(%r14)
jne    1445 <main+0x2f5>
mov    0x0(%rbp),%edx
or     (%r12),%edx
or     (%r15),%edx
mov    0x0(%r13),%ecx
mov    0x2c78(%rip),%rax
or     (%rax),%ecx
xor    %edi,%edi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
lea    0xd29(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
cmpq   $0x0,(%r14)
jne    1456 <main+0x306>
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1050 <munmap@plt>
cmpq   $0x0,(%r14)
jne    1467 <main+0x317>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcd0(%rip),%rdi
call   1070 <perror@plt>
jmp    11b2 <main+0x62>
lea    0xc62(%rip),%rdi
call   1070 <perror@plt>
jmp    11d7 <main+0x87>
lea    0xc60(%rip),%rdi
call   1070 <perror@plt>
jmp    11f2 <main+0xa2>
lea    0xc60(%rip),%rdi
call   1070 <perror@plt>
jmp    121a <main+0xca>
lea    0xc63(%rip),%rdi
call   1070 <perror@plt>
jmp    1231 <main+0xe1>
lea    0xc7b(%rip),%rdi
call   1070 <perror@plt>
jmp    1276 <main+0x126>
lea    0xc5f(%rip),%rdi
call   1070 <perror@plt>
jmp    1297 <main+0x147>
lea    0xc30(%rip),%rdi
call   1070 <perror@plt>
jmp    12ae <main+0x15e>
lea    0xc48(%rip),%rdi
call   1070 <perror@plt>
jmp    12f3 <main+0x1a3>
lea    0xbda(%rip),%rdi
call   1070 <perror@plt>
jmp    1314 <main+0x1c4>
lea    0xbfd(%rip),%rdi
call   1070 <perror@plt>
jmp    132b <main+0x1db>
lea    0xc15(%rip),%rdi
call   1070 <perror@plt>
jmp    1373 <main+0x223>
lea    0xbdb(%rip),%rdi
call   1070 <perror@plt>
jmp    138a <main+0x23a>

LLVM IR (-O0):
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@.str = [21 x i8] c"anon page, r-- = %p\0A\00"
@errno = global i64 0
@.str.1 = [3 x i8] c"> \00"
@PROT_WRITE = global i32 0
@.str.2 = [15 x i8] c"adding write> \00"
@.str.3 = [17 x i8] c"removing write> \00"
@PROT_EXEC = global i32 0
@.str.4 = [20 x i8] c"adding write+exec> \00"
@.str.5 = [9 x i8] c"munmap> \00"
@.str.6 = [21 x i8] c"anon page, rw- = %p\0A\00"
@.str.7 = [14 x i8] c"adding exec> \00"
@.str.8 = [21 x i8] c"anon page, r-x = %p\0A\00"
@.str.9 = [21 x i8] c"anon page, rwx = %p\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
%3 = load i32, i32* @PROT_READ
%4 = load i32, i32* @MAP_PRIVATE
%5 = load i32, i32* @MAP_ANONYMOUS
%6 = or i32 %4, %5
%7 = call i8* @mmap(i32* null, i32 4096, i32 %3, i32 %6, i32 -1, i32 0)
store i8* %7, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i64, i64* @errno
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %0
%15 = load i8*, i8** %2
%16 = load i32, i32* @PROT_READ
%17 = load i32, i32* @PROT_WRITE
%18 = or i32 %16, %17
%19 = call i32 @mprotect(i8* %15, i32 4096, i32 %18)
%20 = load i64, i64* @errno
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %14
%25 = load i8*, i8** %2
%26 = load i32, i32* @PROT_READ
%27 = call i32 @mprotect(i8* %25, i32 4096, i32 %26)
%28 = load i64, i64* @errno
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %30, %24
%33 = load i8*, i8** %2
%34 = load i32, i32* @PROT_READ
%35 = load i32, i32* @PROT_WRITE
%36 = or i32 %34, %35
%37 = load i32, i32* @PROT_EXEC
%38 = or i32 %36, %37
%39 = call i32 @mprotect(i8* %33, i32 4096, i32 %38)
%40 = load i64, i64* @errno
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %32
%43 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %44
44: ; preds = %42, %32
%45 = load i8*, i8** %2
%46 = call i32 @munmap(i8* %45, i32 4096)
%47 = load i64, i64* @errno
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %44
%50 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %51
51: ; preds = %49, %44
%52 = load i32, i32* @PROT_READ
%53 = load i32, i32* @PROT_WRITE
%54 = or i32 %52, %53
%55 = load i32, i32* @MAP_PRIVATE
%56 = load i32, i32* @MAP_ANONYMOUS
%57 = or i32 %55, %56
%58 = call i8* @mmap(i32* null, i32 4096, i32 %54, i32 %57, i32 -1, i32 0)
store i8* %58, i8** %2
%59 = load i8*, i8** %2
%60 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %59)
%61 = load i64, i64* @errno
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %51
%64 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %65
65: ; preds = %63, %51
%66 = load i8*, i8** %2
%67 = load i32, i32* @PROT_READ
%68 = load i32, i32* @PROT_WRITE
%69 = or i32 %67, %68
%70 = load i32, i32* @PROT_EXEC
%71 = or i32 %69, %70
%72 = call i32 @mprotect(i8* %66, i32 4096, i32 %71)
%73 = load i64, i64* @errno
%74 = icmp ne i64 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %65
%76 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
br label %77
77: ; preds = %75, %65
%78 = load i8*, i8** %2
%79 = call i32 @munmap(i8* %78, i32 4096)
%80 = load i64, i64* @errno
%81 = icmp ne i64 %80, 0
br i1 %81, label %82, label %84
82: ; preds = %77
%83 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %84
84: ; preds = %82, %77
%85 = load i32, i32* @PROT_READ
%86 = load i32, i32* @PROT_EXEC
%87 = or i32 %85, %86
%88 = load i32, i32* @MAP_PRIVATE
%89 = load i32, i32* @MAP_ANONYMOUS
%90 = or i32 %88, %89
%91 = call i8* @mmap(i32* null, i32 4096, i32 %87, i32 %90, i32 -1, i32 0)
store i8* %91, i8** %2
%92 = load i8*, i8** %2
%93 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* %92)
%94 = load i64, i64* @errno
%95 = icmp ne i64 %94, 0
br i1 %95, label %96, label %98
96: ; preds = %84
%97 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %98
98: ; preds = %96, %84
%99 = load i8*, i8** %2
%100 = load i32, i32* @PROT_READ
%101 = load i32, i32* @PROT_WRITE
%102 = or i32 %100, %101
%103 = load i32, i32* @PROT_EXEC
%104 = or i32 %102, %103
%105 = call i32 @mprotect(i8* %99, i32 4096, i32 %104)
%106 = load i64, i64* @errno
%107 = icmp ne i64 %106, 0
br i1 %107, label %108, label %110
108: ; preds = %98
%109 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %110
110: ; preds = %108, %98
%111 = load i8*, i8** %2
%112 = call i32 @munmap(i8* %111, i32 4096)
%113 = load i64, i64* @errno
%114 = icmp ne i64 %113, 0
br i1 %114, label %115, label %117
115: ; preds = %110
%116 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %117
117: ; preds = %115, %110
%118 = load i32, i32* @PROT_READ
%119 = load i32, i32* @PROT_WRITE
%120 = or i32 %118, %119
%121 = load i32, i32* @PROT_EXEC
%122 = or i32 %120, %121
%123 = load i32, i32* @MAP_PRIVATE
%124 = load i32, i32* @MAP_ANONYMOUS
%125 = or i32 %123, %124
%126 = call i8* @mmap(i32* null, i32 4096, i32 %122, i32 %125, i32 -1, i32 0)
store i8* %126, i8** %2
%127 = load i8*, i8** %2
%128 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), i8* %127)
%129 = load i64, i64* @errno
%130 = icmp ne i64 %129, 0
br i1 %130, label %131, label %133
131: ; preds = %117
%132 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %133
133: ; preds = %131, %117
%134 = load i8*, i8** %2
%135 = call i32 @munmap(i8* %134, i32 4096)
%136 = load i64, i64* @errno
%137 = icmp ne i64 %136, 0
br i1 %137, label %138, label %140
138: ; preds = %133
%139 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %140
140: ; preds = %138, %133
ret i32 0
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@.str = [21 x i8] c"anon page, r-- = %p\0A\00"
@errno = global i64 0
@.str.1 = [3 x i8] c"> \00"
@PROT_WRITE = global i32 0
@.str.2 = [15 x i8] c"adding write> \00"
@.str.3 = [17 x i8] c"removing write> \00"
@PROT_EXEC = global i32 0
@.str.4 = [20 x i8] c"adding write+exec> \00"
@.str.5 = [9 x i8] c"munmap> \00"
@.str.6 = [21 x i8] c"anon page, rw- = %p\0A\00"
@.str.7 = [14 x i8] c"adding exec> \00"
@.str.8 = [21 x i8] c"anon page, r-x = %p\0A\00"
@.str.9 = [21 x i8] c"anon page, rwx = %p\0A\00"
define i32 @main() {
%1 = load i32, i32* @PROT_READ
%2 = load i32, i32* @MAP_PRIVATE
%3 = load i32, i32* @MAP_ANONYMOUS
%4 = or i32 %3, %2
%5 = tail call i8* @mmap(i32* null, i32 4096, i32 %1, i32 %4, i32 -1, i32 0)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = load i64, i64* @errno
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = tail call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %0
%12 = load i32, i32* @PROT_READ
%13 = load i32, i32* @PROT_WRITE
%14 = or i32 %13, %12
%15 = tail call i32 @mprotect(i8* %5, i32 4096, i32 %14)
%16 = load i64, i64* @errno
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %11
%19 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %11
%21 = load i32, i32* @PROT_READ
%22 = tail call i32 @mprotect(i8* %5, i32 4096, i32 %21)
%23 = load i64, i64* @errno
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %20
%26 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %25, %20
%28 = load i32, i32* @PROT_READ
%29 = load i32, i32* @PROT_WRITE
%30 = or i32 %29, %28
%31 = load i32, i32* @PROT_EXEC
%32 = or i32 %30, %31
%33 = tail call i32 @mprotect(i8* %5, i32 4096, i32 %32)
%34 = load i64, i64* @errno
%35 = icmp eq i64 %34, 0
br i1 %35, label %38, label %36
36: ; preds = %27
%37 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %38
38: ; preds = %36, %27
%39 = tail call i32 @munmap(i8* %5, i32 4096)
%40 = load i64, i64* @errno
%41 = icmp eq i64 %40, 0
br i1 %41, label %44, label %42
42: ; preds = %38
%43 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %44
44: ; preds = %42, %38
%45 = load i32, i32* @PROT_READ
%46 = load i32, i32* @PROT_WRITE
%47 = or i32 %46, %45
%48 = load i32, i32* @MAP_PRIVATE
%49 = load i32, i32* @MAP_ANONYMOUS
%50 = or i32 %49, %48
%51 = tail call i8* @mmap(i32* null, i32 4096, i32 %47, i32 %50, i32 -1, i32 0)
%52 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %51)
%53 = load i64, i64* @errno
%54 = icmp eq i64 %53, 0
br i1 %54, label %57, label %55
55: ; preds = %44
%56 = tail call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %57
57: ; preds = %55, %44
%58 = load i32, i32* @PROT_READ
%59 = load i32, i32* @PROT_WRITE
%60 = or i32 %59, %58
%61 = load i32, i32* @PROT_EXEC
%62 = or i32 %60, %61
%63 = tail call i32 @mprotect(i8* %51, i32 4096, i32 %62)
%64 = load i64, i64* @errno
%65 = icmp eq i64 %64, 0
br i1 %65, label %68, label %66
66: ; preds = %57
%67 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
br label %68
68: ; preds = %66, %57
%69 = tail call i32 @munmap(i8* %51, i32 4096)
%70 = load i64, i64* @errno
%71 = icmp eq i64 %70, 0
br i1 %71, label %74, label %72
72: ; preds = %68
%73 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %74
74: ; preds = %72, %68
%75 = load i32, i32* @PROT_READ
%76 = load i32, i32* @PROT_EXEC
%77 = or i32 %76, %75
%78 = load i32, i32* @MAP_PRIVATE
%79 = load i32, i32* @MAP_ANONYMOUS
%80 = or i32 %79, %78
%81 = tail call i8* @mmap(i32* null, i32 4096, i32 %77, i32 %80, i32 -1, i32 0)
%82 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* %81)
%83 = load i64, i64* @errno
%84 = icmp eq i64 %83, 0
br i1 %84, label %87, label %85
85: ; preds = %74
%86 = tail call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %87
87: ; preds = %85, %74
%88 = load i32, i32* @PROT_READ
%89 = load i32, i32* @PROT_WRITE
%90 = or i32 %89, %88
%91 = load i32, i32* @PROT_EXEC
%92 = or i32 %90, %91
%93 = tail call i32 @mprotect(i8* %81, i32 4096, i32 %92)
%94 = load i64, i64* @errno
%95 = icmp eq i64 %94, 0
br i1 %95, label %98, label %96
96: ; preds = %87
%97 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %98
98: ; preds = %96, %87
%99 = tail call i32 @munmap(i8* %81, i32 4096)
%100 = load i64, i64* @errno
%101 = icmp eq i64 %100, 0
br i1 %101, label %104, label %102
102: ; preds = %98
%103 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %104
104: ; preds = %102, %98
%105 = load i32, i32* @PROT_READ
%106 = load i32, i32* @PROT_WRITE
%107 = or i32 %106, %105
%108 = load i32, i32* @PROT_EXEC
%109 = or i32 %107, %108
%110 = load i32, i32* @MAP_PRIVATE
%111 = load i32, i32* @MAP_ANONYMOUS
%112 = or i32 %111, %110
%113 = tail call i8* @mmap(i32* null, i32 4096, i32 %109, i32 %112, i32 -1, i32 0)
%114 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), i8* %113)
%115 = load i64, i64* @errno
%116 = icmp eq i64 %115, 0
br i1 %116, label %119, label %117
117: ; preds = %104
%118 = tail call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %119
119: ; preds = %117, %104
%120 = tail call i32 @munmap(i8* %113, i32 4096)
%121 = load i64, i64* @errno
%122 = icmp eq i64 %121, 0
br i1 %122, label %125, label %123
123: ; preds = %119
%124 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %125
125: ; preds = %123, %119
ret i32 0
}