#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(void *, int **);
void *mmap(void *, int, int, int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
main() {
  void *p;
  int *q[40];
  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 != (void *)-1) {
    p = (char *)p + (0x10000 / 2 - 2 * sizeof(int));
    ;
    q[39] = 0;
    f(p, q);
    if (q[39] != (int *)p + 39)
      abort();
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
lea    0xe8e(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x154(%rbp)
mov    0x2e54(%rip),%rax
movslq (%rax),%rax
cmp    $0x7fffffff,%rax
jne    11a2 <main+0x52>
mov    $0x1,%al
test   $0x1,%al
jne    11a2 <main+0x52>
jmp    11a9 <main+0x59>
xor    %edi,%edi
call   1070 <exit@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%edx
mov    0x2e0f(%rip),%rax
or     (%rax),%edx
mov    0x2dfe(%rip),%rax
mov    (%rax),%ecx
or     $0x0,%ecx
mov    -0x154(%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     123f <main+0xef>
mov    -0x10(%rbp),%rax
add    $0x7ff8,%rax
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x150(%rbp),%rsi
call   1040 <f@plt>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    $0x9c,%rcx
cmp    %rcx,%rax
je     123a <main+0xea>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    123f <main+0xef>
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 [40 x i32*]
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %4
%7 = load i32, i32* @INT_MAX
%8 = sext i32 %7 to i64
%9 = icmp ne i64 %8, 2147483647
br i1 %9, label %11, label %10
10: ; preds = %0
br i1 true, label %11, label %13
11: ; preds = %10, %0
%12 = call i32 @exit(i32 0)
unreachable
13: ; preds = %10
%14 = load i32, i32* @PROT_READ
%15 = load i32, i32* @PROT_WRITE
%16 = or i32 %14, %15
%17 = load i32, i32* @MAP_PRIVATE
%18 = or i32 0, %17
%19 = load i32, i32* %4
%20 = call i8* @mmap(i8* inttoptr (i64 2147450880 to i8*), i32 65536, i32 %16, i32 %18, i32 %19, i32 0)
store i8* %20, i8** %2
%21 = load i8*, i8** %2
%22 = icmp ne i8* %21, inttoptr (i64 -1 to i8*)
br i1 %22, label %23, label %39
23: ; preds = %13
%24 = load i8*, i8** %2
%25 = getelementptr inbounds i8, i8* %24, i64 32760
store i8* %25, i8** %2
%26 = getelementptr inbounds [40 x i32*], [40 x i32*]* %3, i64 0, i64 39
store i32* null, i32** %26
%27 = load i8*, i8** %2
%28 = getelementptr inbounds [40 x i32*], [40 x i32*]* %3, i64 0, i64 0
%29 = call i32 @f(i8* %27, i32** %28)
%30 = getelementptr inbounds [40 x i32*], [40 x i32*]* %3, i64 0, i64 39
%31 = load i32*, i32** %30
%32 = load i8*, i8** %2
%33 = bitcast i8* %32 to i32*
%34 = getelementptr inbounds i32, i32* %33, i64 39
%35 = icmp ne i32* %31, %34
br i1 %35, label %36, label %38
36: ; preds = %23
%37 = call i32 (...) @abort()
unreachable
38: ; preds = %23
br label %39
39: ; preds = %38, %13
%40 = 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
}