#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 INT_MAX;
int MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ f(int, char *);
char *mmap(void *, int, int, int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
main() {
  char *p;
  int dev_zero;
  dev_zero = open("/dev/zero", O_RDONLY);
  if (INT_MAX != 0x7fffffffL || sizeof(char *) != sizeof(int))
    exit(0);
  p = mmap((void *)0x7fff8000, 0x10000, PROT_READ | PROT_WRITE,
           0 | 0 | MAP_PRIVATE, dev_zero, 0);
  if (p != (char *)-1) {
    p += (0x10000 / 2 - 2 * sizeof(char));
    ;
    p[39] = 0;
    f(0, p);
    if (p[39] != (char)-2)
      abort();
    p[39] = 0;
    f(-1, p);
    if (p[39] != 0)
      abort();
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e5a(%rip),%rax
movslq (%rax),%rax
cmp    $0x7fffffff,%rax
jne    119c <main+0x4c>
mov    $0x1,%al
test   $0x1,%al
jne    119c <main+0x4c>
jmp    11a3 <main+0x53>
xor    %edi,%edi
call   1070 <exit@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edx
mov    0x2e15(%rip),%rax
or     (%rax),%edx
mov    0x2e04(%rip),%rax
mov    (%rax),%ecx
or     $0x0,%ecx
mov    -0x14(%rbp),%r8d
mov    $0x7fff8000,%edi
mov    $0x10000,%esi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x10(%rbp)
je     1258 <main+0x108>
mov    -0x10(%rbp),%rax
add    $0x7ffe,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,0x27(%rax)
mov    -0x10(%rbp),%rsi
xor    %edi,%edi
call   1040 <f@plt>
mov    -0x10(%rbp),%rax
movsbl 0x27(%rax),%eax
cmp    $0xfffffffe,%eax
je     1225 <main+0xd5>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,0x27(%rax)
mov    -0x10(%rbp),%rsi
mov    $0xffffffff,%edi
call   1040 <f@plt>
mov    -0x10(%rbp),%rax
movsbl 0x27(%rax),%eax
cmp    $0x0,%eax
je     1253 <main+0x103>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1258 <main+0x108>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2ec0(%rip),%rax
mov    (%rax),%esi
lea    0xecf(%rip),%rdi
call   1030 <open@plt>
xor    %edi,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/zero\00"
@O_RDONLY = global i32 0
@INT_MAX = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %3
%6 = load i32, i32* @INT_MAX
%7 = sext i32 %6 to i64
%8 = icmp ne i64 %7, 2147483647
br i1 %8, label %10, label %9
9: ; preds = %0
br i1 true, label %10, label %12
10: ; preds = %9, %0
%11 = call i32 @exit(i32 0)
unreachable
12: ; preds = %9
%13 = load i32, i32* @PROT_READ
%14 = load i32, i32* @PROT_WRITE
%15 = or i32 %13, %14
%16 = load i32, i32* @MAP_PRIVATE
%17 = or i32 0, %16
%18 = load i32, i32* %3
%19 = call i8* @mmap(i8* inttoptr (i64 2147450880 to i8*), i32 65536, i32 %15, i32 %17, i32 %18, i32 0)
store i8* %19, i8** %2
%20 = load i8*, i8** %2
%21 = icmp ne i8* %20, inttoptr (i64 -1 to i8*)
br i1 %21, label %22, label %49
22: ; preds = %12
%23 = load i8*, i8** %2
%24 = getelementptr inbounds i8, i8* %23, i64 32766
store i8* %24, i8** %2
%25 = load i8*, i8** %2
%26 = getelementptr inbounds i8, i8* %25, i64 39
store i8 0, i8* %26
%27 = load i8*, i8** %2
%28 = call i32 @f(i32 0, i8* %27)
%29 = load i8*, i8** %2
%30 = getelementptr inbounds i8, i8* %29, i64 39
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, -2
br i1 %33, label %34, label %36
34: ; preds = %22
%35 = call i32 (...) @abort()
unreachable
36: ; preds = %22
%37 = load i8*, i8** %2
%38 = getelementptr inbounds i8, i8* %37, i64 39
store i8 0, i8* %38
%39 = load i8*, i8** %2
%40 = call i32 @f(i32 -1, i8* %39)
%41 = load i8*, i8** %2
%42 = getelementptr inbounds i8, i8* %41, i64 39
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %36
%47 = call i32 (...) @abort()
unreachable
48: ; preds = %36
br label %49
49: ; preds = %48, %12
%50 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/zero\00"
@O_RDONLY = global i32 0
@INT_MAX = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
define i32 @main() {
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 @exit(i32 0)
unreachable
}