#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;
void *MAP_FAILED;
int MAP_PRIVATE;
int PROT_EXEC;
int PROT_READ;
int /*<<< orphan*/ assert(int);
void *mmap(void *, int, int, int, int, int /*<<< orphan*/);
int munmap(void *, int);
int main() {
  int ret;
  void *alloc =
      mmap(NULL, 0, PROT_EXEC | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  assert(alloc == MAP_FAILED);
  alloc = mmap(NULL, 4096, PROT_EXEC | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS,
               -1, 0);
  assert(alloc != MAP_FAILED);
  ret = munmap(alloc, 4096);
  assert(ret == 0);
  alloc = mmap(NULL, 4096 * 10, PROT_EXEC | PROT_READ,
               MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  assert(alloc != MAP_FAILED);
  ret = munmap(alloc, 4096);
  assert(ret == 0);
  alloc += 4096;
  ret = munmap(alloc + 4096 * 8, 4096);
  assert(ret == 0);
  ret = munmap(alloc + 4096, 4096);
  assert(ret == 0);
  void *alloc2 = mmap(alloc + 4096, 4096, PROT_EXEC | PROT_READ,
                      MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  assert(alloc2 != MAP_FAILED);
  ret = munmap(alloc, 4096 * 8);
  assert(ret == 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%edx
mov    0x2ea9(%rip),%rax
or     (%rax),%edx
mov    0x2e70(%rip),%rax
mov    (%rax),%ecx
mov    0x2e7f(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
mov    $0xffffffff,%r8d
mov    %r9d,%esi
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e39(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edx
mov    0x2e51(%rip),%rax
or     (%rax),%edx
mov    0x2e18(%rip),%rax
mov    (%rax),%ecx
mov    0x2e27(%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),%rax
mov    0x2ddf(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1000,%esi
call   1050 <munmap@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edx
mov    0x2dd5(%rip),%rax
or     (%rax),%edx
mov    0x2d9c(%rip),%rax
mov    (%rax),%ecx
mov    0x2dab(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xa000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2d63(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1000,%esi
call   1050 <munmap@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
add    $0x1000,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x8000,%rdi
mov    $0x1000,%esi
call   1050 <munmap@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
add    $0x1000,%rdi
mov    $0x1000,%esi
call   1050 <munmap@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
add    $0x1000,%rdi
mov    0x2cd7(%rip),%rax
mov    (%rax),%edx
mov    0x2cee(%rip),%rax
or     (%rax),%edx
mov    0x2cb5(%rip),%rax
mov    (%rax),%ecx
mov    0x2cc4(%rip),%rax
or     (%rax),%ecx
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2c80(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    $0x8000,%esi
call   1050 <munmap@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x20,%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),%rax
mov    0x2eaf(%rip),%r13
mov    0x0(%r13),%edx
or     (%rax),%edx
mov    %rax,%rbx
mov    0x2e6f(%rip),%rbp
mov    0x2e80(%rip),%r12
mov    (%r12),%ecx
or     0x0(%rbp),%ecx
xor    %edi,%edi
xor    %esi,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    0x2e40(%rip),%r15
xor    %edi,%edi
cmp    (%r15),%rax
sete   %dil
call   1040 <assert@plt>
mov    0x0(%r13),%edx
or     (%rbx),%edx
mov    %rbx,%r14
mov    (%r12),%ecx
or     0x0(%rbp),%ecx
xor    %edi,%edi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
xor    %edi,%edi
cmp    (%r15),%rax
setne  %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1050 <munmap@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    0x0(%r13),%edx
or     (%r14),%edx
mov    (%r12),%ecx
or     0x0(%rbp),%ecx
xor    %edi,%edi
mov    $0xa000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
xor    %edi,%edi
cmp    (%r15),%rax
setne  %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1050 <munmap@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
lea    0x1000(%rbx),%r14
lea    0x9000(%rbx),%rdi
mov    $0x1000,%esi
call   1050 <munmap@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
add    $0x2000,%rbx
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1050 <munmap@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    0x0(%r13),%edx
mov    0x2d5b(%rip),%rax
or     (%rax),%edx
mov    (%r12),%ecx
or     0x0(%rbp),%ecx
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
xor    %edi,%edi
cmp    (%r15),%rax
setne  %dil
call   1040 <assert@plt>
mov    %r14,%rdi
mov    $0x8000,%esi
call   1050 <munmap@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PROT_EXEC = global i32 0
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i32 0, i32* %1
%5 = load i32, i32* @PROT_EXEC
%6 = load i32, i32* @PROT_READ
%7 = or i32 %5, %6
%8 = load i32, i32* @MAP_PRIVATE
%9 = load i32, i32* @MAP_ANONYMOUS
%10 = or i32 %8, %9
%11 = call i8* @mmap(i8* null, i32 0, i32 %7, i32 %10, i32 -1, i32 0)
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = load i8*, i8** @MAP_FAILED
%14 = icmp eq i8* %12, %13
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i32, i32* @PROT_EXEC
%18 = load i32, i32* @PROT_READ
%19 = or i32 %17, %18
%20 = load i32, i32* @MAP_PRIVATE
%21 = load i32, i32* @MAP_ANONYMOUS
%22 = or i32 %20, %21
%23 = call i8* @mmap(i8* null, i32 4096, i32 %19, i32 %22, i32 -1, i32 0)
store i8* %23, i8** %3
%24 = load i8*, i8** %3
%25 = load i8*, i8** @MAP_FAILED
%26 = icmp ne i8* %24, %25
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = load i8*, i8** %3
%30 = call i32 @munmap(i8* %29, i32 4096)
store i32 %30, i32* %2
%31 = load i32, i32* %2
%32 = icmp eq i32 %31, 0
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = load i32, i32* @PROT_EXEC
%36 = load i32, i32* @PROT_READ
%37 = or i32 %35, %36
%38 = load i32, i32* @MAP_PRIVATE
%39 = load i32, i32* @MAP_ANONYMOUS
%40 = or i32 %38, %39
%41 = call i8* @mmap(i8* null, i32 40960, i32 %37, i32 %40, i32 -1, i32 0)
store i8* %41, i8** %3
%42 = load i8*, i8** %3
%43 = load i8*, i8** @MAP_FAILED
%44 = icmp ne i8* %42, %43
%45 = zext i1 %44 to i32
%46 = call i32 @assert(i32 %45)
%47 = load i8*, i8** %3
%48 = call i32 @munmap(i8* %47, i32 4096)
store i32 %48, i32* %2
%49 = load i32, i32* %2
%50 = icmp eq i32 %49, 0
%51 = zext i1 %50 to i32
%52 = call i32 @assert(i32 %51)
%53 = load i8*, i8** %3
%54 = getelementptr i8, i8* %53, i64 4096
store i8* %54, i8** %3
%55 = load i8*, i8** %3
%56 = getelementptr i8, i8* %55, i64 32768
%57 = call i32 @munmap(i8* %56, i32 4096)
store i32 %57, i32* %2
%58 = load i32, i32* %2
%59 = icmp eq i32 %58, 0
%60 = zext i1 %59 to i32
%61 = call i32 @assert(i32 %60)
%62 = load i8*, i8** %3
%63 = getelementptr i8, i8* %62, i64 4096
%64 = call i32 @munmap(i8* %63, i32 4096)
store i32 %64, i32* %2
%65 = load i32, i32* %2
%66 = icmp eq i32 %65, 0
%67 = zext i1 %66 to i32
%68 = call i32 @assert(i32 %67)
%69 = load i8*, i8** %3
%70 = getelementptr i8, i8* %69, i64 4096
%71 = load i32, i32* @PROT_EXEC
%72 = load i32, i32* @PROT_READ
%73 = or i32 %71, %72
%74 = load i32, i32* @MAP_PRIVATE
%75 = load i32, i32* @MAP_ANONYMOUS
%76 = or i32 %74, %75
%77 = call i8* @mmap(i8* %70, i32 4096, i32 %73, i32 %76, i32 -1, i32 0)
store i8* %77, i8** %4
%78 = load i8*, i8** %4
%79 = load i8*, i8** @MAP_FAILED
%80 = icmp ne i8* %78, %79
%81 = zext i1 %80 to i32
%82 = call i32 @assert(i32 %81)
%83 = load i8*, i8** %3
%84 = call i32 @munmap(i8* %83, i32 32768)
store i32 %84, i32* %2
%85 = load i32, i32* %2
%86 = icmp eq i32 %85, 0
%87 = zext i1 %86 to i32
%88 = call i32 @assert(i32 %87)
ret i32 0
}

LLVM IR (-O2):
@PROT_EXEC = global i32 0
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
define i32 @main() {
%1 = load i32, i32* @PROT_EXEC
%2 = load i32, i32* @PROT_READ
%3 = or i32 %2, %1
%4 = load i32, i32* @MAP_PRIVATE
%5 = load i32, i32* @MAP_ANONYMOUS
%6 = or i32 %5, %4
%7 = tail call i8* @mmap(i8* null, i32 0, i32 %3, i32 %6, i32 -1, i32 0)
%8 = load i8*, i8** @MAP_FAILED
%9 = icmp eq i8* %7, %8
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = load i32, i32* @PROT_EXEC
%13 = load i32, i32* @PROT_READ
%14 = or i32 %13, %12
%15 = load i32, i32* @MAP_PRIVATE
%16 = load i32, i32* @MAP_ANONYMOUS
%17 = or i32 %16, %15
%18 = tail call i8* @mmap(i8* null, i32 4096, i32 %14, i32 %17, i32 -1, i32 0)
%19 = load i8*, i8** @MAP_FAILED
%20 = icmp ne i8* %18, %19
%21 = zext i1 %20 to i32
%22 = tail call i32 @assert(i32 %21)
%23 = tail call i32 @munmap(i8* %18, i32 4096)
%24 = icmp eq i32 %23, 0
%25 = zext i1 %24 to i32
%26 = tail call i32 @assert(i32 %25)
%27 = load i32, i32* @PROT_EXEC
%28 = load i32, i32* @PROT_READ
%29 = or i32 %28, %27
%30 = load i32, i32* @MAP_PRIVATE
%31 = load i32, i32* @MAP_ANONYMOUS
%32 = or i32 %31, %30
%33 = tail call i8* @mmap(i8* null, i32 40960, i32 %29, i32 %32, i32 -1, i32 0)
%34 = load i8*, i8** @MAP_FAILED
%35 = icmp ne i8* %33, %34
%36 = zext i1 %35 to i32
%37 = tail call i32 @assert(i32 %36)
%38 = tail call i32 @munmap(i8* %33, i32 4096)
%39 = icmp eq i32 %38, 0
%40 = zext i1 %39 to i32
%41 = tail call i32 @assert(i32 %40)
%42 = getelementptr i8, i8* %33, i64 4096
%43 = getelementptr i8, i8* %33, i64 36864
%44 = tail call i32 @munmap(i8* %43, i32 4096)
%45 = icmp eq i32 %44, 0
%46 = zext i1 %45 to i32
%47 = tail call i32 @assert(i32 %46)
%48 = getelementptr i8, i8* %33, i64 8192
%49 = tail call i32 @munmap(i8* %48, i32 4096)
%50 = icmp eq i32 %49, 0
%51 = zext i1 %50 to i32
%52 = tail call i32 @assert(i32 %51)
%53 = load i32, i32* @PROT_EXEC
%54 = load i32, i32* @PROT_READ
%55 = or i32 %54, %53
%56 = load i32, i32* @MAP_PRIVATE
%57 = load i32, i32* @MAP_ANONYMOUS
%58 = or i32 %57, %56
%59 = tail call i8* @mmap(i8* %48, i32 4096, i32 %55, i32 %58, i32 -1, i32 0)
%60 = load i8*, i8** @MAP_FAILED
%61 = icmp ne i8* %59, %60
%62 = zext i1 %61 to i32
%63 = tail call i32 @assert(i32 %62)
%64 = tail call i32 @munmap(i8* %42, i32 32768)
%65 = icmp eq i32 %64, 0
%66 = zext i1 %65 to i32
%67 = tail call i32 @assert(i32 %66)
ret i32 0
}