#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 */
char *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ PROT_READ;
int create_file(char *, int);
int /*<<< orphan*/ getchar();
char *mmap(int /*<<< orphan*/ *, int, int /*<<< orphan*/, int /*<<< orphan*/,
           int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ unlink(char *);
int main(int argc, char **argv) {
  char *p;
  char *fname = "./mapit.dat";
  int i;
  int sum;
  int fd = create_file(fname, (4096 * 200));
  if (fd < 0)
    return -1;
  p = mmap(NULL, (4096 * 200), PROT_READ, MAP_SHARED, fd, 0);
  if (p == MAP_FAILED || p == NULL) {
    perror("mmap");
    return -1;
  }
  sum = 0;
  for (i = 0; i < (4096 * 200); ++i) {
    sum += p[i];
  }
  getchar();
  munmap(p, (4096 * 200));
  unlink(fname);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0xc8000,%esi
call   1080 <create_file@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    11a8 <main+0x48>
movl   $0xffffffff,-0x4(%rbp)
jmp    126a <main+0x10a>
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
mov    0x2e30(%rip),%rax
mov    (%rax),%ecx
mov    -0x2c(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0xc8000,%esi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2df2(%rip),%rcx
cmp    (%rcx),%rax
je     11f2 <main+0x92>
cmpq   $0x0,-0x18(%rbp)
jne    120a <main+0xaa>
lea    0xe13(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126a <main+0x10a>
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0xc8000,-0x24(%rbp)
jge    1245 <main+0xe5>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1218 <main+0xb8>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    -0x18(%rbp),%rdi
mov    $0xc8000,%esi
call   1060 <munmap@plt>
mov    -0x20(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xe96(%rip),%rdi
mov    $0xc8000,%esi
call   1080 <create_file@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
js     11d7 <main+0x77>
mov    0x2e74(%rip),%rcx
mov    (%rcx),%edx
mov    0x2e5b(%rip),%rcx
mov    (%rcx),%ecx
xor    %edi,%edi
mov    $0xc8000,%esi
mov    %eax,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
test   %rax,%rax
je     11e0 <main+0x80>
mov    %rax,%rbx
mov    0x2e20(%rip),%rax
cmp    (%rax),%rbx
je     11e0 <main+0x80>
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %rbx,%rdi
mov    $0xc8000,%esi
call   1060 <munmap@plt>
lea    0xe2e(%rip),%rdi
call   1030 <unlink@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe25(%rip),%rdi
call   1070 <perror@plt>
jmp    11d7 <main+0x77>

LLVM IR (-O0):
@.str = [12 x i8] c"./mapit.dat\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.1 = [5 x i8] c"mmap\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %7
%11 = load i8*, i8** %7
%12 = call i32 @create_file(i8* %11, i32 819200)
store i32 %12, i32* %10
%13 = load i32, i32* %10
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -1, i32* %3
br label %51
16: ; preds = %2
%17 = load i32, i32* @PROT_READ
%18 = load i32, i32* @MAP_SHARED
%19 = load i32, i32* %10
%20 = call i8* @mmap(i32* null, i32 819200, i32 %17, i32 %18, i32 %19, i32 0)
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = load i8*, i8** @MAP_FAILED
%23 = icmp eq i8* %21, %22
br i1 %23, label %27, label %24
24: ; preds = %16
%25 = load i8*, i8** %6
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %29
27: ; preds = %24, %16
%28 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %51
29: ; preds = %24
store i32 0, i32* %9
store i32 0, i32* %8
br label %30
30: ; preds = %42, %29
%31 = load i32, i32* %8
%32 = icmp slt i32 %31, 819200
br i1 %32, label %33, label %45
33: ; preds = %30
%34 = load i8*, i8** %6
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = load i32, i32* %9
%41 = add nsw i32 %40, %39
store i32 %41, i32* %9
br label %42
42: ; preds = %33
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %30
45: ; preds = %30
%46 = call i32 (...) @getchar()
%47 = load i8*, i8** %6
%48 = call i32 @munmap(i8* %47, i32 819200)
%49 = load i8*, i8** %7
%50 = call i32 @unlink(i8* %49)
store i32 0, i32* %3
br label %51
51: ; preds = %45, %27, %15
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@.str = [12 x i8] c"./mapit.dat\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.1 = [5 x i8] c"mmap\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @create_file(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 819200)
%4 = icmp slt i32 %3, 0
br i1 %4, label %19, label %5
5: ; preds = %2
%6 = load i32, i32* @PROT_READ
%7 = load i32, i32* @MAP_SHARED
%8 = tail call i8* @mmap(i32* null, i32 819200, i32 %6, i32 %7, i32 %3, i32 0)
%9 = load i8*, i8** @MAP_FAILED
%10 = icmp eq i8* %8, %9
%11 = icmp eq i8* %8, null
%12 = or i1 %11, %10
br i1 %12, label %17, label %13
13: ; preds = %5
%14 = tail call i32 (...) @getchar()
%15 = tail call i32 @munmap(i8* %8, i32 819200)
%16 = tail call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %19
17: ; preds = %5
%18 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %2, %13, %17
%20 = phi i32 [ -1, %17 ], [ 0, %13 ], [ -1, %2 ]
ret i32 %20
}