#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 int /*<<< orphan*/ off_t;

/* Variables and functions */
int MAP_ANON;
void *MAP_FAILED;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
void *mmap(void *, size_t, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, size_t);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  void *addr, *addr2;
  size_t size = 16 * 1024;
  addr = mmap((void *)0, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE,
              -1, (off_t)0);
  assert(addr != MAP_FAILED);
  {
    size_t i;
    for (i = 0; i < size; ++i) {
      assert(((char *)addr)[i] == 0);
      ((char *)addr)[i] = i;
    }
  }
  addr2 = mmap(addr + (size / 2), size / 2, PROT_READ | PROT_WRITE,
               MAP_ANON | MAP_PRIVATE, -1, (off_t)0);
  assert(addr2 != MAP_FAILED);
  munmap(addr, size);
  addr = mmap((void *)addr, size, PROT_READ | PROT_WRITE,
              MAP_ANON | MAP_PRIVATE, -1, (off_t)0);
  assert(addr != MAP_FAILED);
  {
    size_t i;
    for (i = 0; i < size; ++i) {
      assert(((char *)addr)[i] == 0);
      ((char *)addr)[i] = i;
    }
  }
  fprintf(stderr, "\n%s OK\n", argv[0]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x4000,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
mov    0x2e8f(%rip),%rax
mov    (%rax),%edx
mov    0x2e5e(%rip),%rax
or     (%rax),%edx
mov    0x2e4d(%rip),%rax
mov    (%rax),%ecx
mov    0x2e3c(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2e11(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    120b <main+0xcb>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x30(%rbp),%rax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11bf <main+0x7f>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rax
shr    $0x1,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
shr    $0x1,%rsi
mov    0x2dcf(%rip),%rax
mov    (%rax),%edx
mov    0x2d9e(%rip),%rax
or     (%rax),%edx
mov    0x2d8d(%rip),%rax
mov    (%rax),%ecx
mov    0x2d7c(%rip),%rax
or     (%rax),%ecx
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2d55(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <munmap@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x2d69(%rip),%rax
mov    (%rax),%edx
mov    0x2d38(%rip),%rax
or     (%rax),%edx
mov    0x2d27(%rip),%rax
mov    (%rax),%ecx
mov    0x2d16(%rip),%rax
or     (%rax),%ecx
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2cef(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    132d <main+0x1ed>
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x38(%rbp),%rax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    12e1 <main+0x1a1>
mov    0x2ca4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xcbc(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,(%rsp)
mov    0x2ea2(%rip),%r15
mov    0x2e73(%rip),%r13
mov    0x0(%r13),%edx
or     (%r15),%edx
mov    0x2e5d(%rip),%rax
mov    0x2e4e(%rip),%r12
mov    (%r12),%ecx
or     (%rax),%ecx
xor    %ebp,%ebp
mov    $0x4000,%esi
xor    %edi,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
mov    0x2e1f(%rip),%r14
xor    %edi,%edi
cmp    (%r14),%rax
setne  %dil
call   1040 <assert@plt>
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
cmpb   $0x0,(%rbx,%rbp,1)
sete   %dil
call   1040 <assert@plt>
mov    %bpl,(%rbx,%rbp,1)
add    $0x1,%rbp
cmp    $0x4000,%rbp
jne    11b0 <main+0x70>
mov    %rbx,%rdi
mov    0x0(%r13),%edx
or     (%r15),%edx
add    $0x2000,%rdi
mov    (%r12),%ecx
mov    %r13,%r12
mov    0x2dd9(%rip),%r13
or     0x0(%r13),%ecx
mov    %r15,%rbp
xor    %r15d,%r15d
mov    $0x2000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
xor    %edi,%edi
cmp    (%r14),%rax
setne  %dil
call   1040 <assert@plt>
mov    $0x4000,%esi
mov    %rbx,%rdi
call   1060 <munmap@plt>
mov    (%r12),%edx
or     0x0(%rbp),%edx
mov    0x2d8b(%rip),%rax
mov    (%rax),%ecx
or     0x0(%r13),%ecx
mov    $0x4000,%esi
mov    %rbx,%rdi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
xor    %edi,%edi
cmp    (%r14),%rax
setne  %dil
call   1040 <assert@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %edi,%edi
cmpb   $0x0,(%rbx,%r15,1)
sete   %dil
call   1040 <assert@plt>
mov    %r15b,(%rbx,%r15,1)
add    $0x1,%r15
cmp    $0x4000,%r15
jne    1270 <main+0x130>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
mov    (%rsp),%rax
mov    (%rax),%rdx
lea    0xd58(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANON = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@stderr = global i32 0
@.str = [8 x i8] c"\0A%s OK\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 16384, i64* %8
%11 = load i64, i64* %8
%12 = load i32, i32* @PROT_READ
%13 = load i32, i32* @PROT_WRITE
%14 = or i32 %12, %13
%15 = load i32, i32* @MAP_ANON
%16 = load i32, i32* @MAP_PRIVATE
%17 = or i32 %15, %16
%18 = call i8* @mmap(i8* null, i64 %11, i32 %14, i32 %17, i32 -1, i32 0)
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = load i8*, i8** @MAP_FAILED
%21 = icmp ne i8* %19, %20
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
store i64 0, i64* %9
br label %24
24: ; preds = %42, %2
%25 = load i64, i64* %9
%26 = load i64, i64* %8
%27 = icmp ult i64 %25, %26
br i1 %27, label %28, label %45
28: ; preds = %24
%29 = load i8*, i8** %6
%30 = load i64, i64* %9
%31 = getelementptr inbounds i8, i8* %29, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 0
%35 = zext i1 %34 to i32
%36 = call i32 @assert(i32 %35)
%37 = load i64, i64* %9
%38 = trunc i64 %37 to i8
%39 = load i8*, i8** %6
%40 = load i64, i64* %9
%41 = getelementptr inbounds i8, i8* %39, i64 %40
store i8 %38, i8* %41
br label %42
42: ; preds = %28
%43 = load i64, i64* %9
%44 = add i64 %43, 1
store i64 %44, i64* %9
br label %24
45: ; preds = %24
%46 = load i8*, i8** %6
%47 = load i64, i64* %8
%48 = udiv i64 %47, 2
%49 = getelementptr i8, i8* %46, i64 %48
%50 = load i64, i64* %8
%51 = udiv i64 %50, 2
%52 = load i32, i32* @PROT_READ
%53 = load i32, i32* @PROT_WRITE
%54 = or i32 %52, %53
%55 = load i32, i32* @MAP_ANON
%56 = load i32, i32* @MAP_PRIVATE
%57 = or i32 %55, %56
%58 = call i8* @mmap(i8* %49, i64 %51, i32 %54, i32 %57, i32 -1, i32 0)
store i8* %58, i8** %7
%59 = load i8*, i8** %7
%60 = load i8*, i8** @MAP_FAILED
%61 = icmp ne i8* %59, %60
%62 = zext i1 %61 to i32
%63 = call i32 @assert(i32 %62)
%64 = load i8*, i8** %6
%65 = load i64, i64* %8
%66 = call i32 @munmap(i8* %64, i64 %65)
%67 = load i8*, i8** %6
%68 = load i64, i64* %8
%69 = load i32, i32* @PROT_READ
%70 = load i32, i32* @PROT_WRITE
%71 = or i32 %69, %70
%72 = load i32, i32* @MAP_ANON
%73 = load i32, i32* @MAP_PRIVATE
%74 = or i32 %72, %73
%75 = call i8* @mmap(i8* %67, i64 %68, i32 %71, i32 %74, i32 -1, i32 0)
store i8* %75, i8** %6
%76 = load i8*, i8** %6
%77 = load i8*, i8** @MAP_FAILED
%78 = icmp ne i8* %76, %77
%79 = zext i1 %78 to i32
%80 = call i32 @assert(i32 %79)
store i64 0, i64* %10
br label %81
81: ; preds = %99, %45
%82 = load i64, i64* %10
%83 = load i64, i64* %8
%84 = icmp ult i64 %82, %83
br i1 %84, label %85, label %102
85: ; preds = %81
%86 = load i8*, i8** %6
%87 = load i64, i64* %10
%88 = getelementptr inbounds i8, i8* %86, i64 %87
%89 = load i8, i8* %88
%90 = sext i8 %89 to i32
%91 = icmp eq i32 %90, 0
%92 = zext i1 %91 to i32
%93 = call i32 @assert(i32 %92)
%94 = load i64, i64* %10
%95 = trunc i64 %94 to i8
%96 = load i8*, i8** %6
%97 = load i64, i64* %10
%98 = getelementptr inbounds i8, i8* %96, i64 %97
store i8 %95, i8* %98
br label %99
99: ; preds = %85
%100 = load i64, i64* %10
%101 = add i64 %100, 1
store i64 %101, i64* %10
br label %81
102: ; preds = %81
%103 = load i32, i32* @stderr
%104 = load i8**, i8*** %5
%105 = getelementptr inbounds i8*, i8** %104, i64 0
%106 = load i8*, i8** %105
%107 = call i32 @fprintf(i32 %103, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %106)
ret i32 0
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANON = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@stderr = global i32 0
@.str = [8 x i8] c"\0A%s OK\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @PROT_READ
%4 = load i32, i32* @PROT_WRITE
%5 = or i32 %4, %3
%6 = load i32, i32* @MAP_ANON
%7 = load i32, i32* @MAP_PRIVATE
%8 = or i32 %7, %6
%9 = tail call i8* @mmap(i8* null, i64 16384, i32 %5, i32 %8, i32 -1, i32 0)
%10 = load i8*, i8** @MAP_FAILED
%11 = icmp ne i8* %9, %10
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
br label %14
14: ; preds = %2, %14
%15 = phi i64 [ 0, %2 ], [ %22, %14 ]
%16 = getelementptr inbounds i8, i8* %9, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = trunc i64 %15 to i8
store i8 %21, i8* %16
%22 = add nuw nsw i64 %15, 1
%23 = icmp eq i64 %22, 16384
br i1 %23, label %24, label %14
24: ; preds = %14
%25 = getelementptr i8, i8* %9, i64 8192
%26 = load i32, i32* @PROT_READ
%27 = load i32, i32* @PROT_WRITE
%28 = or i32 %27, %26
%29 = load i32, i32* @MAP_ANON
%30 = load i32, i32* @MAP_PRIVATE
%31 = or i32 %30, %29
%32 = tail call i8* @mmap(i8* %25, i64 8192, i32 %28, i32 %31, i32 -1, i32 0)
%33 = load i8*, i8** @MAP_FAILED
%34 = icmp ne i8* %32, %33
%35 = zext i1 %34 to i32
%36 = tail call i32 @assert(i32 %35)
%37 = tail call i32 @munmap(i8* %9, i64 16384)
%38 = load i32, i32* @PROT_READ
%39 = load i32, i32* @PROT_WRITE
%40 = or i32 %39, %38
%41 = load i32, i32* @MAP_ANON
%42 = load i32, i32* @MAP_PRIVATE
%43 = or i32 %42, %41
%44 = tail call i8* @mmap(i8* %9, i64 16384, i32 %40, i32 %43, i32 -1, i32 0)
%45 = load i8*, i8** @MAP_FAILED
%46 = icmp ne i8* %44, %45
%47 = zext i1 %46 to i32
%48 = tail call i32 @assert(i32 %47)
br label %49
49: ; preds = %24, %49
%50 = phi i64 [ 0, %24 ], [ %57, %49 ]
%51 = getelementptr inbounds i8, i8* %44, i64 %50
%52 = load i8, i8* %51
%53 = icmp eq i8 %52, 0
%54 = zext i1 %53 to i32
%55 = tail call i32 @assert(i32 %54)
%56 = trunc i64 %50 to i8
store i8 %56, i8* %51
%57 = add nuw nsw i64 %50, 1
%58 = icmp eq i64 %57, 16384
br i1 %58, label %59, label %49
59: ; preds = %49
%60 = load i32, i32* @stderr
%61 = load i8*, i8** %1
%62 = tail call i32 @fprintf(i32 %60, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %61)
ret i32 0
}