#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_FIXED;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ exit(int);
void *mmap(void *, int, int, int, int, int /*<<< orphan*/);
scalar_t__ munmap(void *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  void *p;
  if ((p = mmap((void *)0x1F7F100000, 4096, PROT_READ | PROT_WRITE,
                MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, -1, 0)) ==
      (void *)-1) {
    perror("mmap");
    exit(1);
  }
  if (munmap(p, 4096) < 0) {
    perror("munmap");
    exit(1);
  }
  if ((p = mmap((void *)0x1F7F101000, 4096, PROT_READ,
                MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)) == (void *)-1) {
    perror("mmap");
    exit(1);
  }
  if ((p = mmap((void *)0x1F7F101000, 4096, PROT_READ,
                MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)) == (void *)-1) {
    perror("mmap");
    exit(1);
  }
  printf("made it through alive!\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%edx
mov    0x2e5a(%rip),%rax
or     (%rax),%edx
mov    0x2e49(%rip),%rax
mov    (%rax),%ecx
mov    0x2e38(%rip),%rax
or     (%rax),%ecx
mov    0x2e4f(%rip),%rax
or     (%rax),%ecx
movabs $0x1f7f100000,%rdi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    11da <main+0x8a>
lea    0xe35(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    $0x1000,%esi
call   1050 <munmap@plt>
cmp    $0x0,%rax
jge    1208 <main+0xb8>
lea    0xe0c(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%edx
mov    0x2db0(%rip),%rax
mov    (%rax),%ecx
mov    0x2dbf(%rip),%rax
or     (%rax),%ecx
movabs $0x1f7f101000,%rdi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    126a <main+0x11a>
lea    0xda5(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%edx
mov    0x2d4e(%rip),%rax
mov    (%rax),%ecx
mov    0x2d5d(%rip),%rax
or     (%rax),%ecx
movabs $0x1f7f101000,%rdi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    12cc <main+0x17c>
lea    0xd43(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xd39(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
movabs $0x1f7f101000,%r14
mov    0x2e8f(%rip),%r15
mov    0x2e60(%rip),%rax
mov    (%rax),%edx
or     (%r15),%edx
mov    0x2e4c(%rip),%r12
mov    0x2e3d(%rip),%rax
mov    (%rax),%ecx
or     (%r12),%ecx
mov    0x2e50(%rip),%rbx
or     (%rbx),%ecx
lea    -0x1000(%r14),%rdi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
cmp    $0xffffffffffffffff,%rax
je     1217 <main+0xc7>
mov    %rax,%rdi
mov    $0x1000,%esi
call   1050 <munmap@plt>
test   %rax,%rax
jns    11cd <main+0x7d>
lea    0xe3a(%rip),%rdi
jmp    121e <main+0xce>
mov    (%r15),%edx
mov    (%rbx),%ecx
or     (%r12),%ecx
mov    %r14,%rdi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
cmp    $0xffffffffffffffff,%rax
je     1217 <main+0xc7>
mov    (%r15),%edx
mov    (%rbx),%ecx
or     (%r12),%ecx
mov    %r14,%rdi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
cmp    $0xffffffffffffffff,%rax
jne    122d <main+0xdd>
lea    0xde2(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xdd8(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FIXED = global i32 0
@MAP_ANONYMOUS = global i32 0
@.str = [5 x i8] c"mmap\00"
@.str.1 = [7 x i8] c"munmap\00"
@.str.2 = [24 x i8] c"made it through alive!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* @PROT_READ
%8 = load i32, i32* @PROT_WRITE
%9 = or i32 %7, %8
%10 = load i32, i32* @MAP_PRIVATE
%11 = load i32, i32* @MAP_FIXED
%12 = or i32 %10, %11
%13 = load i32, i32* @MAP_ANONYMOUS
%14 = or i32 %12, %13
%15 = call i8* @mmap(i8* inttoptr (i64 135275741184 to i8*), i32 4096, i32 %9, i32 %14, i32 -1, i32 0)
store i8* %15, i8** %6
%16 = icmp eq i8* %15, inttoptr (i64 -1 to i8*)
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8*, i8** %6
%22 = call i64 @munmap(i8* %21, i32 4096)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %20
%28 = load i32, i32* @PROT_READ
%29 = load i32, i32* @MAP_PRIVATE
%30 = load i32, i32* @MAP_ANONYMOUS
%31 = or i32 %29, %30
%32 = call i8* @mmap(i8* inttoptr (i64 135275745280 to i8*), i32 4096, i32 %28, i32 %31, i32 -1, i32 0)
store i8* %32, i8** %6
%33 = icmp eq i8* %32, inttoptr (i64 -1 to i8*)
br i1 %33, label %34, label %37
34: ; preds = %27
%35 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %27
%38 = load i32, i32* @PROT_READ
%39 = load i32, i32* @MAP_PRIVATE
%40 = load i32, i32* @MAP_ANONYMOUS
%41 = or i32 %39, %40
%42 = call i8* @mmap(i8* inttoptr (i64 135275745280 to i8*), i32 4096, i32 %38, i32 %41, i32 -1, i32 0)
store i8* %42, i8** %6
%43 = icmp eq i8* %42, inttoptr (i64 -1 to i8*)
br i1 %43, label %44, label %47
44: ; preds = %37
%45 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %37
%48 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%49 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FIXED = global i32 0
@MAP_ANONYMOUS = global i32 0
@.str = [5 x i8] c"mmap\00"
@.str.1 = [7 x i8] c"munmap\00"
@str = [23 x i8] c"made it through alive!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @PROT_READ
%4 = load i32, i32* @PROT_WRITE
%5 = or i32 %4, %3
%6 = load i32, i32* @MAP_PRIVATE
%7 = load i32, i32* @MAP_FIXED
%8 = or i32 %7, %6
%9 = load i32, i32* @MAP_ANONYMOUS
%10 = or i32 %8, %9
%11 = tail call i8* @mmap(i8* inttoptr (i64 135275741184 to i8*), i32 4096, i32 %5, i32 %10, i32 -1, i32 0)
%12 = icmp eq i8* %11, inttoptr (i64 -1 to i8*)
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = tail call i64 @munmap(i8* %11, i32 4096)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %16
%23 = load i32, i32* @PROT_READ
%24 = load i32, i32* @MAP_PRIVATE
%25 = load i32, i32* @MAP_ANONYMOUS
%26 = or i32 %25, %24
%27 = tail call i8* @mmap(i8* inttoptr (i64 135275745280 to i8*), i32 4096, i32 %23, i32 %26, i32 -1, i32 0)
%28 = icmp eq i8* %27, inttoptr (i64 -1 to i8*)
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %22
%33 = load i32, i32* @PROT_READ
%34 = load i32, i32* @MAP_PRIVATE
%35 = load i32, i32* @MAP_ANONYMOUS
%36 = or i32 %35, %34
%37 = tail call i8* @mmap(i8* inttoptr (i64 135275745280 to i8*), i32 4096, i32 %33, i32 %36, i32 -1, i32 0)
%38 = icmp eq i8* %37, inttoptr (i64 -1 to i8*)
br i1 %38, label %39, label %42
39: ; preds = %32
%40 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%41 = tail call i32 @exit(i32 1)
unreachable
42: ; preds = %32
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%44 = tail call i32 @exit(i32 0)
unreachable
}