#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 */
typedef int uint64_t;

/* Variables and functions */
int /*<<< orphan*/ read_direct(int, int, int);
int /*<<< orphan*/ read_sync(int, int, int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ write_direct(int, int, int);
int /*<<< orphan*/ write_pattern();
int /*<<< orphan*/ write_sync(int, int, int);
int main(int argc, char **argv) {
  uint64_t i, j, k;
  int read = 1;
  int write = 1;
  if (argc >= 2 && strcmp(argv[1], "read") == 0)
    write = 0;
  if (argc >= 2 && strcmp(argv[1], "write") == 0)
    read = 0;
  if (read) {
    write_pattern();
    for (i = 0; i < 4096; i += 512)
      for (j = 4 * 1024 * 1024 - 4096; j < 4 * 1024 * 1024 + 4096; j += 512)
        for (k = 1024; k <= 16384; k *= 2) {
          read_direct(i, j, k);
          read_sync(i, j, k);
        }
  }
  unlink("foo");
  if (write) {
    for (i = 0; i < 4096; i += 512)
      for (j = 4 * 1024 * 1024 - 4096 + 512; j < 4 * 1024 * 1024 + 4096;
           j += 512)
        for (k = 1024; k <= 16384; k *= 2) {
          write_direct(i, j, k);
          write_sync(i, j, k);
        }
  }
  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)
movl   $0x1,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11c3 <main+0x53>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe53(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    11c3 <main+0x53>
movl   $0x0,-0x24(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11f2 <main+0x82>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe29(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    11f2 <main+0x82>
movl   $0x0,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1298 <main+0x128>
mov    $0x0,%al
call   1060 <write_pattern@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x1000,-0x14(%rbp)
jge    1293 <main+0x123>
movl   $0x3ff000,-0x18(%rbp)
cmpl   $0x401000,-0x18(%rbp)
jge    127e <main+0x10e>
movl   $0x400,-0x1c(%rbp)
cmpl   $0x4000,-0x1c(%rbp)
jg     1269 <main+0xf9>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1040 <read_direct@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1050 <read_sync@plt>
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1232 <main+0xc2>
jmp    126e <main+0xfe>
mov    -0x18(%rbp),%eax
add    $0x200,%eax
mov    %eax,-0x18(%rbp)
jmp    121e <main+0xae>
jmp    1283 <main+0x113>
mov    -0x14(%rbp),%eax
add    $0x200,%eax
mov    %eax,-0x14(%rbp)
jmp    120a <main+0x9a>
jmp    1298 <main+0x128>
lea    0xd6c(%rip),%rdi
call   1030 <unlink@plt>
cmpl   $0x0,-0x24(%rbp)
je     1343 <main+0x1d3>
movl   $0x0,-0x14(%rbp)
cmpl   $0x1000,-0x14(%rbp)
jge    133e <main+0x1ce>
movl   $0x3ff200,-0x18(%rbp)
cmpl   $0x401000,-0x18(%rbp)
jge    1329 <main+0x1b9>
movl   $0x400,-0x1c(%rbp)
cmpl   $0x4000,-0x1c(%rbp)
jg     1314 <main+0x1a4>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1070 <write_direct@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1080 <write_sync@plt>
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12dd <main+0x16d>
jmp    1319 <main+0x1a9>
mov    -0x18(%rbp),%eax
add    $0x200,%eax
mov    %eax,-0x18(%rbp)
jmp    12c9 <main+0x159>
jmp    132e <main+0x1be>
mov    -0x14(%rbp),%eax
add    $0x200,%eax
mov    %eax,-0x14(%rbp)
jmp    12b5 <main+0x145>
jmp    1343 <main+0x1d3>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %r14d,%r14d
mov    $0x0,%r15d
cmp    $0x2,%edi
jl     11b6 <main+0x46>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe6f(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
sete   %r15b
mov    0x8(%rbx),%rdi
lea    0xe5d(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1291 <main+0x121>
xor    %eax,%eax
call   1060 <write_pattern@plt>
nopl   (%rax)
mov    $0x3ff000,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14d,%edi
mov    %ebx,%esi
mov    $0x400,%edx
call   1040 <read_direct@plt>
mov    %r14d,%edi
mov    %ebx,%esi
mov    $0x400,%edx
call   1050 <read_sync@plt>
mov    %r14d,%edi
mov    %ebx,%esi
mov    $0x800,%edx
call   1040 <read_direct@plt>
mov    %r14d,%edi
mov    %ebx,%esi
mov    $0x800,%edx
call   1050 <read_sync@plt>
mov    %r14d,%edi
mov    %ebx,%esi
mov    $0x1000,%edx
call   1040 <read_direct@plt>
mov    %r14d,%edi
mov    %ebx,%esi
mov    $0x1000,%edx
call   1050 <read_sync@plt>
mov    %r14d,%edi
mov    %ebx,%esi
mov    $0x2000,%edx
call   1040 <read_direct@plt>
mov    %r14d,%edi
mov    %ebx,%esi
mov    $0x2000,%edx
call   1050 <read_sync@plt>
mov    %r14d,%edi
mov    %ebx,%esi
mov    $0x4000,%edx
call   1040 <read_direct@plt>
mov    %r14d,%edi
mov    %ebx,%esi
mov    $0x4000,%edx
call   1050 <read_sync@plt>
lea    0x200(%rbx),%eax
cmp    $0x400e00,%ebx
mov    %eax,%ebx
jb     11d0 <main+0x60>
lea    0x200(%r14),%eax
cmp    $0xe00,%r14d
mov    %eax,%r14d
jb     11c0 <main+0x50>
lea    0xd73(%rip),%rdi
call   1030 <unlink@plt>
test   %r15b,%r15b
jne    1381 <main+0x211>
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    $0x3ff200,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14d,%edi
mov    %ebx,%esi
mov    $0x400,%edx
call   1070 <write_direct@plt>
mov    %r14d,%edi
mov    %ebx,%esi
mov    $0x400,%edx
call   1080 <write_sync@plt>
mov    %r14d,%edi
mov    %ebx,%esi
mov    $0x800,%edx
call   1070 <write_direct@plt>
mov    %r14d,%edi
mov    %ebx,%esi
mov    $0x800,%edx
call   1080 <write_sync@plt>
mov    %r14d,%edi
mov    %ebx,%esi
mov    $0x1000,%edx
call   1070 <write_direct@plt>
mov    %r14d,%edi
mov    %ebx,%esi
mov    $0x1000,%edx
call   1080 <write_sync@plt>
mov    %r14d,%edi
mov    %ebx,%esi
mov    $0x2000,%edx
call   1070 <write_direct@plt>
mov    %r14d,%edi
mov    %ebx,%esi
mov    $0x2000,%edx
call   1080 <write_sync@plt>
mov    %r14d,%edi
mov    %ebx,%esi
mov    $0x4000,%edx
call   1070 <write_direct@plt>
mov    %r14d,%edi
mov    %ebx,%esi
mov    $0x4000,%edx
call   1080 <write_sync@plt>
lea    0x200(%rbx),%eax
cmp    $0x400e00,%ebx
mov    %eax,%ebx
jb     12c0 <main+0x150>
lea    0x200(%r14),%eax
cmp    $0xe00,%r14d
mov    %eax,%r14d
jb     12b0 <main+0x140>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"read\00"
@.str.1 = [6 x i8] c"write\00"
@.str.2 = [4 x i8] c"foo\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%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 i32 1, i32* %9
store i32 1, i32* %10
%11 = load i32, i32* %4
%12 = icmp sge i32 %11, 2
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %13
store i32 0, i32* %10
br label %20
20: ; preds = %19, %13, %2
%21 = load i32, i32* %4
%22 = icmp sge i32 %21, 2
br i1 %22, label %23, label %30
23: ; preds = %20
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 0, i32* %9
br label %30
30: ; preds = %29, %23, %20
%31 = load i32, i32* %9
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %67
33: ; preds = %30
%34 = call i32 (...) @write_pattern()
store i32 0, i32* %6
br label %35
35: ; preds = %63, %33
%36 = load i32, i32* %6
%37 = icmp slt i32 %36, 4096
br i1 %37, label %38, label %66
38: ; preds = %35
store i32 4190208, i32* %7
br label %39
39: ; preds = %59, %38
%40 = load i32, i32* %7
%41 = icmp slt i32 %40, 4198400
br i1 %41, label %42, label %62
42: ; preds = %39
store i32 1024, i32* %8
br label %43
43: ; preds = %55, %42
%44 = load i32, i32* %8
%45 = icmp sle i32 %44, 16384
br i1 %45, label %46, label %58
46: ; preds = %43
%47 = load i32, i32* %6
%48 = load i32, i32* %7
%49 = load i32, i32* %8
%50 = call i32 @read_direct(i32 %47, i32 %48, i32 %49)
%51 = load i32, i32* %6
%52 = load i32, i32* %7
%53 = load i32, i32* %8
%54 = call i32 @read_sync(i32 %51, i32 %52, i32 %53)
br label %55
55: ; preds = %46
%56 = load i32, i32* %8
%57 = mul nsw i32 %56, 2
store i32 %57, i32* %8
br label %43
58: ; preds = %43
br label %59
59: ; preds = %58
%60 = load i32, i32* %7
%61 = add nsw i32 %60, 512
store i32 %61, i32* %7
br label %39
62: ; preds = %39
br label %63
63: ; preds = %62
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 512
store i32 %65, i32* %6
br label %35
66: ; preds = %35
br label %67
67: ; preds = %66, %30
%68 = call i32 @unlink(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%69 = load i32, i32* %10
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %104
71: ; preds = %67
store i32 0, i32* %6
br label %72
72: ; preds = %100, %71
%73 = load i32, i32* %6
%74 = icmp slt i32 %73, 4096
br i1 %74, label %75, label %103
75: ; preds = %72
store i32 4190720, i32* %7
br label %76
76: ; preds = %96, %75
%77 = load i32, i32* %7
%78 = icmp slt i32 %77, 4198400
br i1 %78, label %79, label %99
79: ; preds = %76
store i32 1024, i32* %8
br label %80
80: ; preds = %92, %79
%81 = load i32, i32* %8
%82 = icmp sle i32 %81, 16384
br i1 %82, label %83, label %95
83: ; preds = %80
%84 = load i32, i32* %6
%85 = load i32, i32* %7
%86 = load i32, i32* %8
%87 = call i32 @write_direct(i32 %84, i32 %85, i32 %86)
%88 = load i32, i32* %6
%89 = load i32, i32* %7
%90 = load i32, i32* %8
%91 = call i32 @write_sync(i32 %88, i32 %89, i32 %90)
br label %92
92: ; preds = %83
%93 = load i32, i32* %8
%94 = mul nsw i32 %93, 2
store i32 %94, i32* %8
br label %80
95: ; preds = %80
br label %96
96: ; preds = %95
%97 = load i32, i32* %7
%98 = add nsw i32 %97, 512
store i32 %98, i32* %7
br label %76
99: ; preds = %76
br label %100
100: ; preds = %99
%101 = load i32, i32* %6
%102 = add nsw i32 %101, 512
store i32 %102, i32* %6
br label %72
103: ; preds = %72
br label %104
104: ; preds = %103, %67
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"read\00"
@.str.1 = [6 x i8] c"write\00"
@.str.2 = [4 x i8] c"foo\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %12
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
%9 = load i8*, i8** %5
%10 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %34, label %12
12: ; preds = %2, %4
%13 = phi i1 [ %8, %4 ], [ false, %2 ]
%14 = tail call i32 (...) @write_pattern()
br label %15
15: ; preds = %12, %31
%16 = phi i32 [ 0, %12 ], [ %32, %31 ]
br label %17
17: ; preds = %15, %17
%18 = phi i32 [ 4190208, %15 ], [ %29, %17 ]
%19 = tail call i32 @read_direct(i32 %16, i32 %18, i32 1024)
%20 = tail call i32 @read_sync(i32 %16, i32 %18, i32 1024)
%21 = tail call i32 @read_direct(i32 %16, i32 %18, i32 2048)
%22 = tail call i32 @read_sync(i32 %16, i32 %18, i32 2048)
%23 = tail call i32 @read_direct(i32 %16, i32 %18, i32 4096)
%24 = tail call i32 @read_sync(i32 %16, i32 %18, i32 4096)
%25 = tail call i32 @read_direct(i32 %16, i32 %18, i32 8192)
%26 = tail call i32 @read_sync(i32 %16, i32 %18, i32 8192)
%27 = tail call i32 @read_direct(i32 %16, i32 %18, i32 16384)
%28 = tail call i32 @read_sync(i32 %16, i32 %18, i32 16384)
%29 = add nuw nsw i32 %18, 512
%30 = icmp ult i32 %18, 4197888
br i1 %30, label %17, label %31
31: ; preds = %17
%32 = add nuw nsw i32 %16, 512
%33 = icmp ult i32 %16, 3584
br i1 %33, label %15, label %34
34: ; preds = %31, %4
%35 = phi i1 [ %8, %4 ], [ %13, %31 ]
%36 = tail call i32 @unlink(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br i1 %35, label %56, label %37
37: ; preds = %34, %53
%38 = phi i32 [ %54, %53 ], [ 0, %34 ]
br label %39
39: ; preds = %37, %39
%40 = phi i32 [ 4190720, %37 ], [ %51, %39 ]
%41 = tail call i32 @write_direct(i32 %38, i32 %40, i32 1024)
%42 = tail call i32 @write_sync(i32 %38, i32 %40, i32 1024)
%43 = tail call i32 @write_direct(i32 %38, i32 %40, i32 2048)
%44 = tail call i32 @write_sync(i32 %38, i32 %40, i32 2048)
%45 = tail call i32 @write_direct(i32 %38, i32 %40, i32 4096)
%46 = tail call i32 @write_sync(i32 %38, i32 %40, i32 4096)
%47 = tail call i32 @write_direct(i32 %38, i32 %40, i32 8192)
%48 = tail call i32 @write_sync(i32 %38, i32 %40, i32 8192)
%49 = tail call i32 @write_direct(i32 %38, i32 %40, i32 16384)
%50 = tail call i32 @write_sync(i32 %38, i32 %40, i32 16384)
%51 = add nuw nsw i32 %40, 512
%52 = icmp ult i32 %40, 4197888
br i1 %52, label %39, label %53
53: ; preds = %39
%54 = add nuw nsw i32 %38, 512
%55 = icmp ult i32 %38, 3584
br i1 %55, label %37, label %56
56: ; preds = %53, %34
ret i32 0
}