#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_FILE;
int MAP_FIXED;
int MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_NONE;
int /*<<< orphan*/ _SC_PAGESIZE;
int /*<<< orphan*/ fail(char *, unsigned long, unsigned long);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
void *mmap(void *, int const, int /*<<< orphan*/, int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ pass(char *, unsigned long, unsigned long);
int /*<<< orphan*/ stderr;
int sysconf(int /*<<< orphan*/);
int main(void) {
  const int PAGE_SIZE = sysconf(_SC_PAGESIZE);
  const unsigned long va_max = 1UL << 20;
  unsigned long va;
  void *p;
  int fd;
  unsigned long a, b;
  fd = open("/dev/zero", O_RDONLY);
  if (fd == -1)
    return 1;
  for (va = 0; va < va_max; va += PAGE_SIZE) {
    p = mmap((void *)va, PAGE_SIZE, PROT_NONE,
             MAP_PRIVATE | MAP_FILE | MAP_FIXED, fd, 0);
    if (p == (void *)va)
      break;
  }
  if (va == va_max) {
    fprintf(stderr, "error: mmap doesn't like you\n");
    return 1;
  }
  a = (unsigned long)p;
  b = (unsigned long)p + PAGE_SIZE;
  pass("/proc/self/map_files/%lx-%lx", a, b);
  fail("/proc/self/map_files/ %lx-%lx", a, b);
  fail("/proc/self/map_files/%lx -%lx", a, b);
  fail("/proc/self/map_files/%lx- %lx", a, b);
  fail("/proc/self/map_files/%lx-%lx ", a, b);
  fail("/proc/self/map_files/0%lx-%lx", a, b);
  fail("/proc/self/map_files/%lx-0%lx", a, b);
  if (sizeof(long) == 4) {
    fail("/proc/self/map_files/100000000%lx-%lx", a, b);
    fail("/proc/self/map_files/%lx-100000000%lx", a, b);
  } else if (sizeof(long) == 8) {
    fail("/proc/self/map_files/10000000000000000%lx-%lx", a, b);
    fail("/proc/self/map_files/%lx-10000000000000000%lx", a, b);
  } else
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    %eax,-0x8(%rbp)
movq   $0x100000,-0x10(%rbp)
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
lea    0xe68(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11b6 <main+0x56>
movl   $0x1,-0x4(%rbp)
jmp    1334 <main+0x1d4>
movq   $0x0,-0x18(%rbp)
cmpq   $0x100000,-0x18(%rbp)
jae    1233 <main+0xd3>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    0x2e16(%rip),%rax
mov    (%rax),%edx
mov    0x2dd5(%rip),%rax
mov    (%rax),%ecx
mov    0x2dec(%rip),%rax
or     (%rax),%ecx
mov    0x2dbb(%rip),%rax
or     (%rax),%ecx
mov    -0x24(%rbp),%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmp    %rcx,%rax
jne    121d <main+0xbd>
jmp    1233 <main+0xd3>
jmp    1222 <main+0xc2>
movslq -0x8(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11be <main+0x5e>
cmpq   $0x100000,-0x18(%rbp)
jne    1262 <main+0x102>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
lea    0xdb9(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1334 <main+0x1d4>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x8(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xda0(%rip),%rdi
call   1040 <pass@plt>
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xda9(%rip),%rdi
call   1030 <fail@plt>
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xdb3(%rip),%rdi
call   1030 <fail@plt>
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xdbd(%rip),%rdi
call   1030 <fail@plt>
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xdc7(%rip),%rdi
call   1030 <fail@plt>
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xdd1(%rip),%rdi
call   1030 <fail@plt>
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xddb(%rip),%rdi
call   1030 <fail@plt>
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xde5(%rip),%rdi
call   1030 <fail@plt>
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xdff(%rip),%rdi
call   1030 <fail@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%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    0x2e5e(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    %eax,%r12d
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
lea    0xe74(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%r13d
mov    $0x1,%eax
cmp    $0xffffffff,%r13d
je     12be <main+0x15e>
movslq %r12d,%r14
xor    %ebx,%ebx
mov    0x2e01(%rip),%r15
nop
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
mov    0x2e18(%rip),%rax
mov    (%rax),%ecx
mov    0x2def(%rip),%rax
or     (%rax),%ecx
or     (%r15),%ecx
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r13d,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
cmp    %rbx,%rax
je     1214 <main+0xb4>
add    %r14,%rbx
cmp    $0x100000,%rbx
jb     11b0 <main+0x50>
mov    %rax,%rbp
jne    1217 <main+0xb7>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
lea    0xe05(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
jmp    12be <main+0x15e>
mov    %rbx,%rbp
add    %rbp,%r14
lea    0xe07(%rip),%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1040 <pass@plt>
lea    0xe12(%rip),%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1030 <fail@plt>
lea    0xe1e(%rip),%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1030 <fail@plt>
lea    0xe2a(%rip),%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1030 <fail@plt>
lea    0xe36(%rip),%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1030 <fail@plt>
lea    0xe42(%rip),%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1030 <fail@plt>
lea    0xe4e(%rip),%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1030 <fail@plt>
lea    0xe5a(%rip),%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1030 <fail@plt>
lea    0xe76(%rip),%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1030 <fail@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@_SC_PAGESIZE = global i32 0
@.str = [10 x i8] c"/dev/zero\00"
@O_RDONLY = global i32 0
@PROT_NONE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FILE = global i32 0
@MAP_FIXED = global i32 0
@stderr = global i32 0
@.str.1 = [30 x i8] c"error: mmap doesn't like you\0A\00"
@.str.2 = [29 x i8] c"/proc/self/map_files/%lx-%lx\00"
@.str.3 = [30 x i8] c"/proc/self/map_files/ %lx-%lx\00"
@.str.4 = [30 x i8] c"/proc/self/map_files/%lx -%lx\00"
@.str.5 = [30 x i8] c"/proc/self/map_files/%lx- %lx\00"
@.str.6 = [30 x i8] c"/proc/self/map_files/%lx-%lx \00"
@.str.7 = [30 x i8] c"/proc/self/map_files/0%lx-%lx\00"
@.str.8 = [30 x i8] c"/proc/self/map_files/%lx-0%lx\00"
@.str.9 = [46 x i8] c"/proc/self/map_files/10000000000000000%lx-%lx\00"
@.str.10 = [46 x i8] c"/proc/self/map_files/%lx-10000000000000000%lx\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
store i32 0, i32* %1
%9 = load i32, i32* @_SC_PAGESIZE
%10 = call i32 @sysconf(i32 %9)
store i32 %10, i32* %2
store i64 1048576, i64* %3
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %0
store i32 1, i32* %1
br label %84
16: ; preds = %0
store i64 0, i64* %4
br label %17
17: ; preds = %38, %16
%18 = load i64, i64* %4
%19 = icmp ult i64 %18, 1048576
br i1 %19, label %20, label %43
20: ; preds = %17
%21 = load i64, i64* %4
%22 = inttoptr i64 %21 to i8*
%23 = load i32, i32* %2
%24 = load i32, i32* @PROT_NONE
%25 = load i32, i32* @MAP_PRIVATE
%26 = load i32, i32* @MAP_FILE
%27 = or i32 %25, %26
%28 = load i32, i32* @MAP_FIXED
%29 = or i32 %27, %28
%30 = load i32, i32* %6
%31 = call i8* @mmap(i8* %22, i32 %23, i32 %24, i32 %29, i32 %30, i32 0)
store i8* %31, i8** %5
%32 = load i8*, i8** %5
%33 = load i64, i64* %4
%34 = inttoptr i64 %33 to i8*
%35 = icmp eq i8* %32, %34
br i1 %35, label %36, label %37
36: ; preds = %20
br label %43
37: ; preds = %20
br label %38
38: ; preds = %37
%39 = load i32, i32* %2
%40 = sext i32 %39 to i64
%41 = load i64, i64* %4
%42 = add i64 %41, %40
store i64 %42, i64* %4
br label %17
43: ; preds = %36, %17
%44 = load i64, i64* %4
%45 = icmp eq i64 %44, 1048576
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i32, i32* @stderr
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %84
49: ; preds = %43
%50 = load i8*, i8** %5
%51 = ptrtoint i8* %50 to i64
store i64 %51, i64* %7
%52 = load i8*, i8** %5
%53 = ptrtoint i8* %52 to i64
%54 = load i32, i32* %2
%55 = sext i32 %54 to i64
%56 = add i64 %53, %55
store i64 %56, i64* %8
%57 = load i64, i64* %7
%58 = load i64, i64* %8
%59 = call i32 @pass(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i64 %57, i64 %58)
%60 = load i64, i64* %7
%61 = load i64, i64* %8
%62 = call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i64 %60, i64 %61)
%63 = load i64, i64* %7
%64 = load i64, i64* %8
%65 = call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i64 %63, i64 %64)
%66 = load i64, i64* %7
%67 = load i64, i64* %8
%68 = call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i64 %66, i64 %67)
%69 = load i64, i64* %7
%70 = load i64, i64* %8
%71 = call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i64 %69, i64 %70)
%72 = load i64, i64* %7
%73 = load i64, i64* %8
%74 = call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i64 %72, i64 %73)
%75 = load i64, i64* %7
%76 = load i64, i64* %8
%77 = call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i64 %75, i64 %76)
%78 = load i64, i64* %7
%79 = load i64, i64* %8
%80 = call i32 @fail(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.9, i64 0, i64 0), i64 %78, i64 %79)
%81 = load i64, i64* %7
%82 = load i64, i64* %8
%83 = call i32 @fail(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.10, i64 0, i64 0), i64 %81, i64 %82)
store i32 0, i32* %1
br label %84
84: ; preds = %49, %46, %15
%85 = load i32, i32* %1
ret i32 %85
}

LLVM IR (-O2):
@_SC_PAGESIZE = global i32 0
@.str = [10 x i8] c"/dev/zero\00"
@O_RDONLY = global i32 0
@PROT_NONE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FILE = global i32 0
@MAP_FIXED = global i32 0
@stderr = global i32 0
@.str.1 = [30 x i8] c"error: mmap doesn't like you\0A\00"
@.str.2 = [29 x i8] c"/proc/self/map_files/%lx-%lx\00"
@.str.3 = [30 x i8] c"/proc/self/map_files/ %lx-%lx\00"
@.str.4 = [30 x i8] c"/proc/self/map_files/%lx -%lx\00"
@.str.5 = [30 x i8] c"/proc/self/map_files/%lx- %lx\00"
@.str.6 = [30 x i8] c"/proc/self/map_files/%lx-%lx \00"
@.str.7 = [30 x i8] c"/proc/self/map_files/0%lx-%lx\00"
@.str.8 = [30 x i8] c"/proc/self/map_files/%lx-0%lx\00"
@.str.9 = [46 x i8] c"/proc/self/map_files/10000000000000000%lx-%lx\00"
@.str.10 = [46 x i8] c"/proc/self/map_files/%lx-10000000000000000%lx\00"
define i32 @main() {
%1 = load i32, i32* @_SC_PAGESIZE
%2 = tail call i32 @sysconf(i32 %1)
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %42, label %6
6: ; preds = %0
%7 = sext i32 %2 to i64
br label %8
8: ; preds = %6, %19
%9 = phi i64 [ 0, %6 ], [ %20, %19 ]
%10 = inttoptr i64 %9 to i8*
%11 = load i32, i32* @PROT_NONE
%12 = load i32, i32* @MAP_PRIVATE
%13 = load i32, i32* @MAP_FILE
%14 = or i32 %13, %12
%15 = load i32, i32* @MAP_FIXED
%16 = or i32 %14, %15
%17 = tail call i8* @mmap(i8* %10, i32 %2, i32 %11, i32 %16, i32 %4, i32 0)
%18 = icmp eq i8* %17, %10
br i1 %18, label %27, label %19
19: ; preds = %8
%20 = add nsw i64 %9, %7
%21 = icmp ult i64 %20, 1048576
br i1 %21, label %8, label %22
22: ; preds = %19
%23 = icmp eq i64 %20, 1048576
br i1 %23, label %24, label %29
24: ; preds = %22
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %42
27: ; preds = %8
%28 = inttoptr i64 %9 to i8*
br label %29
29: ; preds = %27, %22
%30 = phi i8* [ %17, %22 ], [ %28, %27 ]
%31 = ptrtoint i8* %30 to i64
%32 = add i64 %31, %7
%33 = tail call i32 @pass(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i64 %31, i64 %32)
%34 = tail call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i64 %31, i64 %32)
%35 = tail call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i64 %31, i64 %32)
%36 = tail call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i64 %31, i64 %32)
%37 = tail call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i64 %31, i64 %32)
%38 = tail call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i64 %31, i64 %32)
%39 = tail call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i64 %31, i64 %32)
%40 = tail call i32 @fail(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.9, i64 0, i64 0), i64 %31, i64 %32)
%41 = tail call i32 @fail(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.10, i64 0, i64 0), i64 %31, i64 %32)
br label %42
42: ; preds = %0, %29, %24
%43 = phi i32 [ 1, %24 ], [ 0, %29 ], [ 1, %0 ]
ret i32 %43
}