#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(void *, 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);
  unsigned long va = 0;
  void *p;
  int fd;
  unsigned long a, b;
  fd = open("/dev/zero", O_RDONLY);
  if (fd == -1)
    return 1;
  p = mmap((void *)va, 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)
movq   $0x0,-0x10(%rbp)
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
lea    0xe78(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11a6 <main+0x56>
movl   $0x1,-0x4(%rbp)
jmp    12f8 <main+0x1a8>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    0x2e3c(%rip),%rax
mov    (%rax),%edx
mov    0x2dfb(%rip),%rax
mov    (%rax),%ecx
mov    0x2e12(%rip),%rax
or     (%rax),%ecx
mov    0x2de1(%rip),%rax
or     (%rax),%ecx
mov    -0x1c(%rbp),%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2dbc(%rip),%rcx
cmp    (%rcx),%rax
jne    1227 <main+0xd7>
mov    0x2dc4(%rip),%rax
mov    (%rax),%rax
mov    0x2d92(%rip),%rcx
cmp    (%rcx),%rax
jne    121b <main+0xcb>
movl   $0x2,-0x4(%rbp)
jmp    12f8 <main+0x1a8>
movl   $0x1,-0x4(%rbp)
jmp    12f8 <main+0x1a8>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xdbe(%rip),%rdi
call   1040 <pass@plt>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xdc7(%rip),%rdi
call   1030 <fail@plt>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xdd1(%rip),%rdi
call   1030 <fail@plt>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xddb(%rip),%rdi
call   1030 <fail@plt>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xde5(%rip),%rdi
call   1030 <fail@plt>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xdef(%rip),%rdi
call   1030 <fail@plt>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xdf9(%rip),%rdi
call   1030 <fail@plt>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xe03(%rip),%rdi
call   1030 <fail@plt>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xe1d(%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 i64
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %1
%8 = load i32, i32* @_SC_PAGESIZE
%9 = call i32 @sysconf(i32 %8)
store i32 %9, i32* %2
store i64 0, i64* %3
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %0
store i32 1, i32* %1
br label %71
15: ; preds = %0
%16 = load i64, i64* %3
%17 = inttoptr i64 %16 to i8*
%18 = load i32, i32* %2
%19 = load i32, i32* @PROT_NONE
%20 = load i32, i32* @MAP_PRIVATE
%21 = load i32, i32* @MAP_FILE
%22 = or i32 %20, %21
%23 = load i32, i32* @MAP_FIXED
%24 = or i32 %22, %23
%25 = load i32, i32* %5
%26 = call i8* @mmap(i8* %17, i32 %18, i32 %19, i32 %24, i32 %25, i32 0)
store i8* %26, i8** %4
%27 = load i8*, i8** %4
%28 = load i8*, i8** @MAP_FAILED
%29 = icmp eq i8* %27, %28
br i1 %29, label %30, label %36
30: ; preds = %15
%31 = load i64, i64* @errno
%32 = load i64, i64* @EPERM
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %35
34: ; preds = %30
store i32 2, i32* %1
br label %71
35: ; preds = %30
store i32 1, i32* %1
br label %71
36: ; preds = %15
%37 = load i8*, i8** %4
%38 = ptrtoint i8* %37 to i64
store i64 %38, i64* %6
%39 = load i8*, i8** %4
%40 = ptrtoint i8* %39 to i64
%41 = load i32, i32* %2
%42 = zext i32 %41 to i64
%43 = add i64 %40, %42
store i64 %43, i64* %7
%44 = load i64, i64* %6
%45 = load i64, i64* %7
%46 = call i32 @pass(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i64 %44, i64 %45)
%47 = load i64, i64* %6
%48 = load i64, i64* %7
%49 = call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i64 %47, i64 %48)
%50 = load i64, i64* %6
%51 = load i64, i64* %7
%52 = call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i64 %50, i64 %51)
%53 = load i64, i64* %6
%54 = load i64, i64* %7
%55 = call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i64 %53, i64 %54)
%56 = load i64, i64* %6
%57 = load i64, i64* %7
%58 = call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i64 %56, i64 %57)
%59 = load i64, i64* %6
%60 = load i64, i64* %7
%61 = call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i64 %59, i64 %60)
%62 = load i64, i64* %6
%63 = load i64, i64* %7
%64 = call i32 @fail(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i64 %62, i64 %63)
%65 = load i64, i64* %6
%66 = load i64, i64* %7
%67 = call i32 @fail(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.8, i64 0, i64 0), i64 %65, i64 %66)
%68 = load i64, i64* %6
%69 = load i64, i64* %7
%70 = call i32 @fail(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.9, i64 0, i64 0), i64 %68, i64 %69)
store i32 0, i32* %1
br label %71
71: ; preds = %36, %35, %34, %14
%72 = load i32, i32* %1
ret i32 %72
}

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(i8* 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
}