#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 */
scalar_t__ EPERM;
void *MAP_FAILED;
int MAP_FILE;
int MAP_FIXED;
int MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_NONE;
int /*<<< orphan*/ _SC_PAGESIZE;
scalar_t__ errno;
int /*<<< orphan*/ fail(char *, unsigned long, unsigned long);
void *mmap(int /*<<< orphan*/ *, unsigned int const, int /*<<< orphan*/, int,
           int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ pass(char *, unsigned long, unsigned long);
unsigned int sysconf(int /*<<< orphan*/);
int main(void) {
  const unsigned int PAGE_SIZE = sysconf(_SC_PAGESIZE);
  void *p;
  int fd;
  unsigned long a, b;
  fd = open("/dev/zero", O_RDONLY);
  if (fd == -1)
    return 1;
  p = mmap(NULL, PAGE_SIZE, PROT_NONE, MAP_PRIVATE | MAP_FILE | MAP_FIXED, fd,
           0);
  if (p == MAP_FAILED) {
    if (errno == EPERM)
      return 2;
    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    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
lea    0xe80(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    119e <main+0x4e>
movl   $0x1,-0x4(%rbp)
jmp    12f0 <main+0x1a0>
mov    -0x8(%rbp),%esi
mov    0x2e48(%rip),%rax
mov    (%rax),%edx
mov    0x2e07(%rip),%rax
mov    (%rax),%ecx
mov    0x2e1e(%rip),%rax
or     (%rax),%ecx
mov    0x2ded(%rip),%rax
or     (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2dc4(%rip),%rcx
cmp    (%rcx),%rax
jne    121f <main+0xcf>
mov    0x2dcc(%rip),%rax
mov    (%rax),%rax
mov    0x2d9a(%rip),%rcx
cmp    (%rcx),%rax
jne    1213 <main+0xc3>
movl   $0x2,-0x4(%rbp)
jmp    12f0 <main+0x1a0>
movl   $0x1,-0x4(%rbp)
jmp    12f0 <main+0x1a0>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xdc6(%rip),%rdi
call   1040 <pass@plt>
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xdcf(%rip),%rdi
call   1030 <fail@plt>
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xdd9(%rip),%rdi
call   1030 <fail@plt>
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xde3(%rip),%rdi
call   1030 <fail@plt>
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xded(%rip),%rdi
call   1030 <fail@plt>
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xdf7(%rip),%rdi
call   1030 <fail@plt>
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe01(%rip),%rdi
call   1030 <fail@plt>
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe0b(%rip),%rdi
call   1030 <fail@plt>
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe25(%rip),%rdi
call   1030 <fail@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
mov    %eax,%ebp
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe89(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1278 <main+0x128>
mov    0x2e64(%rip),%rdx
mov    0x2e25(%rip),%rsi
mov    0x2e3e(%rip),%rcx
mov    (%rcx),%ecx
or     (%rsi),%ecx
mov    (%rdx),%edx
mov    0x2e09(%rip),%rsi
or     (%rsi),%ecx
xor    %r14d,%r14d
xor    %edi,%edi
mov    %ebp,%esi
mov    %eax,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,%rbx
mov    0x2de3(%rip),%rax
cmp    (%rax),%rbx
je     1280 <main+0x130>
mov    %ebp,%r15d
add    %rbx,%r15
lea    0xe2f(%rip),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1040 <pass@plt>
lea    0xe3a(%rip),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <fail@plt>
lea    0xe46(%rip),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <fail@plt>
lea    0xe52(%rip),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <fail@plt>
lea    0xe5e(%rip),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <fail@plt>
lea    0xe6a(%rip),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <fail@plt>
lea    0xe76(%rip),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <fail@plt>
lea    0xe82(%rip),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <fail@plt>
lea    0xe9e(%rip),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <fail@plt>
jmp    129f <main+0x14f>
mov    $0x1,%r14d
jmp    129f <main+0x14f>
mov    0x2d39(%rip),%rax
mov    (%rax),%rax
mov    0x2d07(%rip),%rcx
xor    %r14d,%r14d
cmp    (%rcx),%rax
sete   %r14b
add    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
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
@MAP_FAILED = global i8* null
@errno = global i64 0
@EPERM = global i64 0
@.str.1 = [29 x i8] c"/proc/self/map_files/%lx-%lx\00"
@.str.2 = [30 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/0%lx-%lx\00"
@.str.7 = [30 x i8] c"/proc/self/map_files/%lx-0%lx\00"
@.str.8 = [46 x i8] c"/proc/self/map_files/10000000000000000%lx-%lx\00"
@.str.9 = [46 x i8] c"/proc/self/map_files/%lx-10000000000000000%lx\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
store i32 0, i32* %1
%7 = load i32, i32* @_SC_PAGESIZE
%8 = call i32 @sysconf(i32 %7)
store i32 %8, i32* %2
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %14
13: ; preds = %0
store i32 1, i32* %1
br label %68
14: ; preds = %0
%15 = load i32, i32* %2
%16 = load i32, i32* @PROT_NONE
%17 = load i32, i32* @MAP_PRIVATE
%18 = load i32, i32* @MAP_FILE
%19 = or i32 %17, %18
%20 = load i32, i32* @MAP_FIXED
%21 = or i32 %19, %20
%22 = load i32, i32* %4
%23 = call i8* @mmap(i32* null, i32 %15, i32 %16, i32 %21, i32 %22, i32 0)
store i8* %23, i8** %3
%24 = load i8*, i8** %3
%25 = load i8*, i8** @MAP_FAILED
%26 = icmp eq i8* %24, %25
br i1 %26, label %27, label %33
27: ; preds = %14
%28 = load i64, i64* @errno
%29 = load i64, i64* @EPERM
%30 = icmp eq i64 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %27
store i32 2, i32* %1
br label %68
32: ; preds = %27
store i32 1, i32* %1
br label %68
33: ; preds = %14
%34 = load i8*, i8** %3
%35 = ptrtoint i8* %34 to i64
store i64 %35, i64* %5
%36 = load i8*, i8** %3
%37 = ptrtoint i8* %36 to i64
%38 = load i32, i32* %2
%39 = zext i32 %38 to i64
%40 = add i64 %37, %39
store i64 %40, i64* %6
%41 = load i64, i64* %5
%42 = load i64, i64* %6
%43 = call i32 @pass(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i64 %41, i64 %42)
%44 = load i64, i64* %5
%45 = load i64, i64* %6
%46 = call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i64 %44, i64 %45)
%47 = load i64, i64* %5
%48 = load i64, i64* %6
%49 = call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i64 %47, i64 %48)
%50 = load i64, i64* %5
%51 = load i64, i64* %6
%52 = call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i64 %50, i64 %51)
%53 = load i64, i64* %5
%54 = load i64, i64* %6
%55 = call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i64 %53, i64 %54)
%56 = load i64, i64* %5
%57 = load i64, i64* %6
%58 = call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i64 %56, i64 %57)
%59 = load i64, i64* %5
%60 = load i64, i64* %6
%61 = call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i64 %59, i64 %60)
%62 = load i64, i64* %5
%63 = load i64, i64* %6
%64 = call i32 @fail(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.8, i64 0, i64 0), i64 %62, i64 %63)
%65 = load i64, i64* %5
%66 = load i64, i64* %6
%67 = call i32 @fail(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.9, i64 0, i64 0), i64 %65, i64 %66)
store i32 0, i32* %1
br label %68
68: ; preds = %33, %32, %31, %13
%69 = load i32, i32* %1
ret i32 %69
}

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
@MAP_FAILED = global i8* null
@errno = global i64 0
@EPERM = global i64 0
@.str.1 = [29 x i8] c"/proc/self/map_files/%lx-%lx\00"
@.str.2 = [30 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/0%lx-%lx\00"
@.str.7 = [30 x i8] c"/proc/self/map_files/%lx-0%lx\00"
@.str.8 = [46 x i8] c"/proc/self/map_files/10000000000000000%lx-%lx\00"
@.str.9 = [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 %34, label %6
6: ; preds = %0
%7 = load i32, i32* @PROT_NONE
%8 = load i32, i32* @MAP_PRIVATE
%9 = load i32, i32* @MAP_FILE
%10 = or i32 %9, %8
%11 = load i32, i32* @MAP_FIXED
%12 = or i32 %10, %11
%13 = tail call i8* @mmap(i32* null, i32 %2, i32 %7, i32 %12, i32 %4, i32 0)
%14 = load i8*, i8** @MAP_FAILED
%15 = icmp eq i8* %13, %14
br i1 %15, label %16, label %21
16: ; preds = %6
%17 = load i64, i64* @errno
%18 = load i64, i64* @EPERM
%19 = icmp eq i64 %17, %18
%20 = select i1 %19, i32 2, i32 1
br label %34
21: ; preds = %6
%22 = ptrtoint i8* %13 to i64
%23 = zext i32 %2 to i64
%24 = add i64 %22, %23
%25 = tail call i32 @pass(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i64 %22, i64 %24)
%26 = tail call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i64 %22, i64 %24)
%27 = tail call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i64 %22, i64 %24)
%28 = tail call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i64 %22, i64 %24)
%29 = tail call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i64 %22, i64 %24)
%30 = tail call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i64 %22, i64 %24)
%31 = tail call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i64 %22, i64 %24)
%32 = tail call i32 @fail(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.8, i64 0, i64 0), i64 %22, i64 %24)
%33 = tail call i32 @fail(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.9, i64 0, i64 0), i64 %22, i64 %24)
br label %34
34: ; preds = %16, %0, %21
%35 = phi i32 [ 0, %21 ], [ 1, %0 ], [ %20, %16 ]
ret i32 %35
}