#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 EINVAL;
void *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ PROT_WRITE;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int ftruncate(int, int);
int /*<<< orphan*/ memset(char *, int, int);
void *mmap(int /*<<< orphan*/ *, int, int /*<<< orphan*/, int /*<<< orphan*/,
           int, int /*<<< orphan*/);
int munmap(void *, int);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  void *mem;
  int i, fd, rc;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s FILE_PATH\n", argv[0]);
    return EINVAL;
  }
  fd = open(argv[1], O_RDWR | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR);
  if (fd < 0) {
    perror("open");
    return errno;
  }
  rc = ftruncate(fd, (4096 * 8));
  if (rc < 0) {
    perror("ftruncate");
    return errno;
  }
  mem = mmap(NULL, (4096 * 8), PROT_WRITE, MAP_SHARED, fd, 0);
  if (mem == MAP_FAILED) {
    perror("mmap");
    return errno;
  }
  close(fd);
  for (i = 0; i < (4096 * 8); i += (4096))
    memset(((char *)mem) + i, 0xFF, (4096));
  rc = munmap(mem, (4096 * 8));
  if (rc < 0) {
    perror("munmap");
    return errno;
  }
  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)
cmpl   $0x2,-0x8(%rbp)
je     11cd <main+0x4d>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1349 <main+0x1c9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
mov    0x2e0b(%rip),%rax
or     (%rax),%esi
mov    0x2e0a(%rip),%rax
or     (%rax),%esi
mov    0x2da9(%rip),%rax
mov    (%rax),%edx
mov    0x2dc8(%rip),%rax
or     (%rax),%edx
call   1090 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1231 <main+0xb1>
lea    0xdfa(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1349 <main+0x1c9>
mov    -0x20(%rbp),%edi
mov    $0x8000,%esi
call   1040 <ftruncate@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1268 <main+0xe8>
lea    0xdc8(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1349 <main+0x1c9>
mov    0x2d39(%rip),%rax
mov    (%rax),%edx
mov    0x2d68(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x8000,%esi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2cf2(%rip),%rcx
cmp    (%rcx),%rax
jne    12c4 <main+0x144>
lea    0xd76(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2cf6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1349 <main+0x1c9>
mov    -0x20(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8000,-0x1c(%rbp)
jge    130a <main+0x18a>
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    $0xff,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
mov    -0x1c(%rbp),%eax
add    $0x1000,%eax
mov    %eax,-0x1c(%rbp)
jmp    12d3 <main+0x153>
mov    -0x18(%rbp),%rdi
mov    $0x8000,%esi
call   1080 <munmap@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1342 <main+0x1c2>
lea    0xcfd(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2c78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1349 <main+0x1c9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    12eb <main+0x16b>
mov    0x8(%rsi),%rdi
mov    0x2e38(%rip),%rax
mov    0x2e51(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e4e(%rip),%rax
or     (%rax),%esi
mov    0x2ded(%rip),%rax
mov    0x2e0e(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
call   1090 <open@plt>
test   %eax,%eax
js     1315 <main+0x195>
mov    %eax,%ebp
mov    %eax,%edi
mov    $0x8000,%esi
call   1040 <ftruncate@plt>
test   %eax,%eax
js     131e <main+0x19e>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edx
mov    0x2def(%rip),%rax
mov    (%rax),%ecx
xor    %r14d,%r14d
xor    %edi,%edi
mov    $0x8000,%esi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
mov    0x2d7e(%rip),%rax
cmp    (%rax),%rbx
je     1327 <main+0x1a7>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %rbx,%rdi
mov    $0xff,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
lea    0x1000(%rbx),%rdi
mov    $0xff,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
lea    0x2000(%rbx),%rdi
mov    $0xff,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
lea    0x3000(%rbx),%rdi
mov    $0xff,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
lea    0x4000(%rbx),%rdi
mov    $0xff,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
lea    0x5000(%rbx),%rdi
mov    $0xff,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
lea    0x6000(%rbx),%rdi
mov    $0xff,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
add    $0x7000,%rdi
mov    $0xff,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
mov    $0x8000,%esi
call   1080 <munmap@plt>
test   %eax,%eax
jns    130d <main+0x18d>
lea    0xd40(%rip),%rdi
jmp    132e <main+0x1ae>
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd02(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2c8e(%rip),%rax
mov    (%rax),%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xcf9(%rip),%rdi
jmp    132e <main+0x1ae>
lea    0xcf5(%rip),%rdi
jmp    132e <main+0x1ae>
lea    0xcf6(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2c76(%rip),%rax
jmp    130a <main+0x18a>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"Usage: %s FILE_PATH\0A\00"
@EINVAL = global i32 0
@O_RDWR = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@errno = global i32 0
@.str.2 = [10 x i8] c"ftruncate\00"
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.3 = [5 x i8] c"mmap\00"
@.str.4 = [7 x i8] c"munmap\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EINVAL
store i32 %18, i32* %3
br label %80
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDWR
%24 = load i32, i32* @O_TRUNC
%25 = or i32 %23, %24
%26 = load i32, i32* @O_CREAT
%27 = or i32 %25, %26
%28 = load i32, i32* @S_IRUSR
%29 = load i32, i32* @S_IWUSR
%30 = or i32 %28, %29
%31 = call i32 @open(i8* %22, i32 %27, i32 %30)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %19
%35 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%36 = load i32, i32* @errno
store i32 %36, i32* %3
br label %80
37: ; preds = %19
%38 = load i32, i32* %8
%39 = call i32 @ftruncate(i32 %38, i32 32768)
store i32 %39, i32* %9
%40 = load i32, i32* %9
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %37
%43 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%44 = load i32, i32* @errno
store i32 %44, i32* %3
br label %80
45: ; preds = %37
%46 = load i32, i32* @PROT_WRITE
%47 = load i32, i32* @MAP_SHARED
%48 = load i32, i32* %8
%49 = call i8* @mmap(i32* null, i32 32768, i32 %46, i32 %47, i32 %48, i32 0)
store i8* %49, i8** %6
%50 = load i8*, i8** %6
%51 = load i8*, i8** @MAP_FAILED
%52 = icmp eq i8* %50, %51
br i1 %52, label %53, label %56
53: ; preds = %45
%54 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%55 = load i32, i32* @errno
store i32 %55, i32* %3
br label %80
56: ; preds = %45
%57 = load i32, i32* %8
%58 = call i32 @close(i32 %57)
store i32 0, i32* %7
br label %59
59: ; preds = %68, %56
%60 = load i32, i32* %7
%61 = icmp slt i32 %60, 32768
br i1 %61, label %62, label %71
62: ; preds = %59
%63 = load i8*, i8** %6
%64 = load i32, i32* %7
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
%67 = call i32 @memset(i8* %66, i32 255, i32 4096)
br label %68
68: ; preds = %62
%69 = load i32, i32* %7
%70 = add nsw i32 %69, 4096
store i32 %70, i32* %7
br label %59
71: ; preds = %59
%72 = load i8*, i8** %6
%73 = call i32 @munmap(i8* %72, i32 32768)
store i32 %73, i32* %9
%74 = load i32, i32* %9
%75 = icmp slt i32 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %71
%77 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%78 = load i32, i32* @errno
store i32 %78, i32* %3
br label %80
79: ; preds = %71
store i32 0, i32* %3
br label %80
80: ; preds = %79, %76, %53, %42, %34, %12
%81 = load i32, i32* %3
ret i32 %81
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"Usage: %s FILE_PATH\0A\00"
@EINVAL = global i32 0
@O_RDWR = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@errno = global i32 0
@.str.2 = [10 x i8] c"ftruncate\00"
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.3 = [5 x i8] c"mmap\00"
@.str.4 = [7 x i8] c"munmap\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EINVAL
br label %62
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDWR
%13 = load i32, i32* @O_TRUNC
%14 = or i32 %13, %12
%15 = load i32, i32* @O_CREAT
%16 = or i32 %14, %15
%17 = load i32, i32* @S_IRUSR
%18 = load i32, i32* @S_IWUSR
%19 = or i32 %18, %17
%20 = tail call i32 @open(i8* %11, i32 %16, i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %9
%23 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @errno
br label %62
25: ; preds = %9
%26 = tail call i32 @ftruncate(i32 %20, i32 32768)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* @errno
br label %62
31: ; preds = %25
%32 = load i32, i32* @PROT_WRITE
%33 = load i32, i32* @MAP_SHARED
%34 = tail call i8* @mmap(i32* null, i32 32768, i32 %32, i32 %33, i32 %20, i32 0)
%35 = load i8*, i8** @MAP_FAILED
%36 = icmp eq i8* %34, %35
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%39 = load i32, i32* @errno
br label %62
40: ; preds = %31
%41 = tail call i32 @close(i32 %20)
%42 = tail call i32 @memset(i8* %34, i32 255, i32 4096)
%43 = getelementptr inbounds i8, i8* %34, i64 4096
%44 = tail call i32 @memset(i8* %43, i32 255, i32 4096)
%45 = getelementptr inbounds i8, i8* %34, i64 8192
%46 = tail call i32 @memset(i8* %45, i32 255, i32 4096)
%47 = getelementptr inbounds i8, i8* %34, i64 12288
%48 = tail call i32 @memset(i8* %47, i32 255, i32 4096)
%49 = getelementptr inbounds i8, i8* %34, i64 16384
%50 = tail call i32 @memset(i8* %49, i32 255, i32 4096)
%51 = getelementptr inbounds i8, i8* %34, i64 20480
%52 = tail call i32 @memset(i8* %51, i32 255, i32 4096)
%53 = getelementptr inbounds i8, i8* %34, i64 24576
%54 = tail call i32 @memset(i8* %53, i32 255, i32 4096)
%55 = getelementptr inbounds i8, i8* %34, i64 28672
%56 = tail call i32 @memset(i8* %55, i32 255, i32 4096)
%57 = tail call i32 @munmap(i8* %34, i32 32768)
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %40
%60 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%61 = load i32, i32* @errno
br label %62
62: ; preds = %40, %59, %37, %28, %22, %4
%63 = phi i32 [ %8, %4 ], [ %24, %22 ], [ %30, %28 ], [ %39, %37 ], [ %61, %59 ], [ 0, %40 ]
ret i32 %63
}