#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 */
struct timeval {
  int tv_sec;
  long tv_usec;
};

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ disk_close(int);
int disk_open(char *, int, int);
scalar_t__ disk_page_write(int, char *, int, size_t);
int /*<<< orphan*/ disk_sync(int);
int /*<<< orphan*/ disk_unlink(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
size_t getpagesize();
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
main() {
  char *file_name_1 = "./sample_data_full";
  char *file_name_2 = "./sample_data_stride";
  char buf_1[1024 * 16];
  char buf_2[1024 * 16];
  int i, fd;
  size_t page_size = getpagesize();
  size_t page_count = 1024 * 10;
  long difftime_us;
  struct timeval start_time;
  struct timeval end_time;
  disk_unlink(file_name_1);
  disk_unlink(file_name_2);
  for (i = 0; i < page_size; i++) {
    buf_1[i] = 'A';
  }
  for (i = 0; i < page_size; i++) {
    buf_1[i] = 'B';
  }
  fprintf(stderr, "full write test: start\n");
  gettimeofday(&start_time, 0);
  do {
    fd = disk_open(file_name_1, O_RDWR | O_CREAT, 0644);
    if (fd == -1) {
      fprintf(stderr, "file open error\n");
      break;
    }
    for (i = 0; i < page_count; i += 1) {
      if (disk_page_write(fd, buf_1, i, page_size) != 0) {
        fprintf(stderr, "page write error\n");
        break;
      }
    }
    if (i < page_count)
      break;
    disk_sync(fd);
    disk_close(fd);
  } while (0);
  gettimeofday(&end_time, 0);
  difftime_us = (end_time.tv_sec * 1000000 + end_time.tv_usec) -
                (start_time.tv_sec * 1000000 + start_time.tv_usec);
  fprintf(stderr, "full write test: end (time=%f)\n", difftime_us / 1000000.0);
  fprintf(stderr, "stride write test: start\n");
  gettimeofday(&start_time, 0);
  do {
    fd = disk_open(file_name_2, O_RDWR | O_CREAT, 0644);
    if (fd == -1) {
      fprintf(stderr, "file open error\n");
      break;
    }
    for (i = 0; i < page_count; i += 2) {
      if (disk_page_write(fd, buf_2, i, page_size) != 0) {
        fprintf(stderr, "page write error\n");
        break;
      }
    }
    if (i < page_count)
      break;
    disk_sync(fd);
    disk_close(fd);
  } while (0);
  gettimeofday(&end_time, 0);
  difftime_us = (end_time.tv_sec * 1000000 + end_time.tv_usec) -
                (start_time.tv_sec * 1000000 + start_time.tv_usec);
  fprintf(stderr, "stride write test: end (time=%f)\n",
          difftime_us / 1000000.0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8060,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6f(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe77(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1090 <getpagesize@plt>
mov    %rax,-0x8030(%rbp)
movq   $0x2800,-0x8038(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <disk_unlink@plt>
mov    -0x18(%rbp),%rdi
call   1050 <disk_unlink@plt>
movl   $0x0,-0x8024(%rbp)
movslq -0x8024(%rbp),%rax
cmp    -0x8030(%rbp),%rax
jae    1214 <main+0x94>
movslq -0x8024(%rbp),%rax
movb   $0x41,-0x4020(%rbp,%rax,1)
41
mov    -0x8024(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8024(%rbp)
jmp    11dd <main+0x5d>
movl   $0x0,-0x8024(%rbp)
movslq -0x8024(%rbp),%rax
cmp    -0x8030(%rbp),%rax
jae    1255 <main+0xd5>
movslq -0x8024(%rbp),%rax
movb   $0x42,-0x4020(%rbp,%rax,1)
42
mov    -0x8024(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8024(%rbp)
jmp    121e <main+0x9e>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
lea    0xdcb(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x8050(%rbp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d5b(%rip),%rax
mov    (%rax),%esi
mov    0x2d6a(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   10a0 <disk_open@plt>
mov    %eax,-0x8028(%rbp)
cmpl   $0xffffffff,-0x8028(%rbp)
jne    12c9 <main+0x149>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
lea    0xd8b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1374 <main+0x1f4>
movl   $0x0,-0x8024(%rbp)
movslq -0x8024(%rbp),%rax
cmp    -0x8038(%rbp),%rax
jae    1345 <main+0x1c5>
mov    -0x8028(%rbp),%edi
lea    -0x4020(%rbp),%rsi
mov    -0x8024(%rbp),%edx
mov    -0x8030(%rbp),%rcx
call   1040 <disk_page_write@plt>
cmp    $0x0,%rax
je     132c <main+0x1ac>
mov    0x2cb9(%rip),%rax
mov    (%rax),%edi
lea    0xd39(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1345 <main+0x1c5>
jmp    1331 <main+0x1b1>
mov    -0x8024(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8024(%rbp)
jmp    12d3 <main+0x153>
movslq -0x8024(%rbp),%rax
cmp    -0x8038(%rbp),%rax
jae    135e <main+0x1de>
jmp    1374 <main+0x1f4>
mov    -0x8028(%rbp),%edi
call   1080 <disk_sync@plt>
mov    -0x8028(%rbp),%edi
call   1070 <disk_close@plt>
lea    -0x8060(%rbp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
imul   $0xf4240,-0x8060(%rbp),%eax
cltq
add    -0x8058(%rbp),%rax
imul   $0xf4240,-0x8050(%rbp),%ecx
movslq %ecx,%rcx
add    -0x8048(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x8040(%rbp)
mov    0x2c16(%rip),%rax
mov    (%rax),%edi
cvtsi2sdq -0x8040(%rbp),%xmm0
ff ff
movsd  0xc33(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xc93(%rip),%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
mov    0x2bea(%rip),%rax
mov    (%rax),%edi
lea    0xc9c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x8050(%rbp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    -0x18(%rbp),%rdi
mov    0x2bd1(%rip),%rax
mov    (%rax),%esi
mov    0x2be0(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   10a0 <disk_open@plt>
mov    %eax,-0x8028(%rbp)
cmpl   $0xffffffff,-0x8028(%rbp)
jne    1453 <main+0x2d3>
mov    0x2b92(%rip),%rax
mov    (%rax),%edi
lea    0xc01(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    14fe <main+0x37e>
movl   $0x0,-0x8024(%rbp)
movslq -0x8024(%rbp),%rax
cmp    -0x8038(%rbp),%rax
jae    14cf <main+0x34f>
mov    -0x8028(%rbp),%edi
lea    -0x8020(%rbp),%rsi
mov    -0x8024(%rbp),%edx
mov    -0x8030(%rbp),%rcx
call   1040 <disk_page_write@plt>
cmp    $0x0,%rax
je     14b6 <main+0x336>
mov    0x2b2f(%rip),%rax
mov    (%rax),%edi
lea    0xbaf(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    14cf <main+0x34f>
jmp    14bb <main+0x33b>
mov    -0x8024(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x8024(%rbp)
jmp    145d <main+0x2dd>
movslq -0x8024(%rbp),%rax
cmp    -0x8038(%rbp),%rax
jae    14e8 <main+0x368>
jmp    14fe <main+0x37e>
mov    -0x8028(%rbp),%edi
call   1080 <disk_sync@plt>
mov    -0x8028(%rbp),%edi
call   1070 <disk_close@plt>
lea    -0x8060(%rbp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
imul   $0xf4240,-0x8060(%rbp),%eax
cltq
add    -0x8058(%rbp),%rax
imul   $0xf4240,-0x8050(%rbp),%ecx
movslq %ecx,%rcx
add    -0x8048(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x8040(%rbp)
mov    0x2a8c(%rip),%rax
mov    (%rax),%edi
cvtsi2sdq -0x8040(%rbp),%xmm0
ff ff
movsd  0xaa9(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xb43(%rip),%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
mov    -0x4(%rbp),%eax
add    $0x8060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8028,%rsp
xor    %eax,%eax
call   10a0 <getpagesize@plt>
mov    %rax,%r14
lea    0xe56(%rip),%rdi
call   1060 <disk_unlink@plt>
lea    0xe5d(%rip),%rdi
call   1060 <disk_unlink@plt>
test   %r14,%r14
je     11da <main+0x4a>
lea    0x20(%rsp),%rdi
mov    $0x42,%esi
mov    %r14,%rdx
call   1040 <memset@plt>
mov    0x2def(%rip),%r12
mov    (%r12),%edi
lea    0xe44(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x2dd8(%rip),%r15
mov    0x2de9(%rip),%r13
mov    0x0(%r13),%esi
or     (%r15),%esi
lea    0xdeb(%rip),%rdi
mov    $0x1a4,%edx
call   10b0 <disk_open@plt>
cmp    $0xffffffff,%eax
je     126f <main+0xdf>
mov    %eax,%ebx
lea    0x20(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %r14,%rcx
call   1050 <disk_page_write@plt>
test   %rax,%rax
jne    1283 <main+0xf3>
add    $0x1,%ebp
cmp    $0x2800,%ebp
jne    1240 <main+0xb0>
mov    %ebx,%edi
call   1090 <disk_sync@plt>
mov    %ebx,%edi
call   1080 <disk_close@plt>
jmp    1295 <main+0x105>
mov    (%r12),%edi
lea    0xdce(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    129c <main+0x10c>
mov    (%r12),%edi
lea    0xdcb(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2d44(%rip),%r15
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
movslq (%rsp),%rax
imul   $0xf4240,%rax,%rax
movslq 0x10(%rsp),%rcx
imul   $0xf4240,%rcx,%rcx
add    0x8(%rsp),%rax
add    0x18(%rsp),%rcx
sub    %rcx,%rax
mov    (%r12),%edi
cvtsi2sd %rax,%xmm0
divsd  0xd25(%rip),%xmm0
lea    0xd89(%rip),%rsi
mov    $0x1,%al
call   1070 <fprintf@plt>
mov    (%r12),%edi
lea    0xd97(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x0(%r13),%esi
or     (%r15),%esi
lea    0xd06(%rip),%rdi
mov    $0x1a4,%edx
call   10b0 <disk_open@plt>
cmp    $0xffffffff,%eax
je     136f <main+0x1df>
mov    %eax,%ebp
mov    $0xfffffffe,%ebx
lea    0x4020(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x2,%ebx
mov    %ebp,%edi
mov    %r15,%rsi
mov    %ebx,%edx
mov    %r14,%rcx
call   1050 <disk_page_write@plt>
test   %rax,%rax
jne    137c <main+0x1ec>
cmp    $0x27fd,%ebx
jbe    1340 <main+0x1b0>
mov    %ebp,%edi
call   1090 <disk_sync@plt>
mov    %ebp,%edi
call   1080 <disk_close@plt>
jmp    138e <main+0x1fe>
mov    (%r12),%edi
lea    0xcce(%rip),%rsi
jmp    1387 <main+0x1f7>
mov    (%r12),%edi
lea    0xcd2(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
movslq (%rsp),%rax
imul   $0xf4240,%rax,%rax
movslq 0x10(%rsp),%rcx
imul   $0xf4240,%rcx,%rcx
add    0x8(%rsp),%rax
add    0x18(%rsp),%rcx
sub    %rcx,%rax
mov    (%r12),%edi
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  0xc30(%rip),%xmm0
lea    0xcce(%rip),%rsi
mov    $0x1,%al
call   1070 <fprintf@plt>
xor    %eax,%eax
add    $0x8028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [19 x i8] c"./sample_data_full\00"
@.str.1 = [21 x i8] c"./sample_data_stride\00"
@stderr = global i32 0
@.str.2 = [24 x i8] c"full write test: start\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.3 = [17 x i8] c"file open error\0A\00"
@.str.4 = [18 x i8] c"page write error\0A\00"
@.str.5 = [32 x i8] c"full write test: end (time=%f)\0A\00"
@.str.6 = [26 x i8] c"stride write test: start\0A\00"
@.str.7 = [34 x i8] c"stride write test: end (time=%f)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [16384 x i8]
%5 = alloca [16384 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca %struct.timeval
%12 = alloca %struct.timeval
store i32 0, i32* %1
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8** %3
%13 = call i64 (...) @getpagesize()
store i64 %13, i64* %8
store i64 10240, i64* %9
%14 = load i8*, i8** %2
%15 = call i32 @disk_unlink(i8* %14)
%16 = load i8*, i8** %3
%17 = call i32 @disk_unlink(i8* %16)
store i32 0, i32* %6
br label %18
18: ; preds = %27, %0
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = load i64, i64* %8
%22 = icmp ult i64 %20, %21
br i1 %22, label %23, label %30
23: ; preds = %18
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [16384 x i8], [16384 x i8]* %4, i64 0, i64 %25
store i8 65, i8* %26
br label %27
27: ; preds = %23
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
br label %18
30: ; preds = %18
store i32 0, i32* %6
br label %31
31: ; preds = %40, %30
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = load i64, i64* %8
%35 = icmp ult i64 %33, %34
br i1 %35, label %36, label %43
36: ; preds = %31
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [16384 x i8], [16384 x i8]* %4, i64 0, i64 %38
store i8 66, i8* %39
br label %40
40: ; preds = %36
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %31
43: ; preds = %31
%44 = load i32, i32* @stderr
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%46 = call i32 @gettimeofday(%struct.timeval* %11, i32 0)
br label %47
47: ; preds = %43
%48 = load i8*, i8** %2
%49 = load i32, i32* @O_RDWR
%50 = load i32, i32* @O_CREAT
%51 = or i32 %49, %50
%52 = call i32 @disk_open(i8* %48, i32 %51, i32 420)
store i32 %52, i32* %7
%53 = load i32, i32* %7
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %58
55: ; preds = %47
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %89
58: ; preds = %47
store i32 0, i32* %6
br label %59
59: ; preds = %75, %58
%60 = load i32, i32* %6
%61 = sext i32 %60 to i64
%62 = load i64, i64* %9
%63 = icmp ult i64 %61, %62
br i1 %63, label %64, label %78
64: ; preds = %59
%65 = load i32, i32* %7
%66 = getelementptr inbounds [16384 x i8], [16384 x i8]* %4, i64 0, i64 0
%67 = load i32, i32* %6
%68 = load i64, i64* %8
%69 = call i64 @disk_page_write(i32 %65, i8* %66, i32 %67, i64 %68)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %64
%72 = load i32, i32* @stderr
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %78
74: ; preds = %64
br label %75
75: ; preds = %74
%76 = load i32, i32* %6
%77 = add nsw i32 %76, 1
store i32 %77, i32* %6
br label %59
78: ; preds = %71, %59
%79 = load i32, i32* %6
%80 = sext i32 %79 to i64
%81 = load i64, i64* %9
%82 = icmp ult i64 %80, %81
br i1 %82, label %83, label %84
83: ; preds = %78
br label %89
84: ; preds = %78
%85 = load i32, i32* %7
%86 = call i32 @disk_sync(i32 %85)
%87 = load i32, i32* %7
%88 = call i32 @disk_close(i32 %87)
br label %89
89: ; preds = %84, %83, %55
%90 = call i32 @gettimeofday(%struct.timeval* %12, i32 0)
%91 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%92 = load i32, i32* %91
%93 = mul nsw i32 %92, 1000000
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
%96 = load i64, i64* %95
%97 = add nsw i64 %94, %96
%98 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%99 = load i32, i32* %98
%100 = mul nsw i32 %99, 1000000
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
%103 = load i64, i64* %102
%104 = add nsw i64 %101, %103
%105 = sub nsw i64 %97, %104
store i64 %105, i64* %10
%106 = load i32, i32* @stderr
%107 = load i64, i64* %10
%108 = sitofp i64 %107 to double
%109 = fdiv double %108, 1.000000e+06
%110 = call i32 (i32, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), double %109)
%111 = load i32, i32* @stderr
%112 = call i32 (i32, i8*, ...) @fprintf(i32 %111, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
%113 = call i32 @gettimeofday(%struct.timeval* %11, i32 0)
br label %114
114: ; preds = %89
%115 = load i8*, i8** %3
%116 = load i32, i32* @O_RDWR
%117 = load i32, i32* @O_CREAT
%118 = or i32 %116, %117
%119 = call i32 @disk_open(i8* %115, i32 %118, i32 420)
store i32 %119, i32* %7
%120 = load i32, i32* %7
%121 = icmp eq i32 %120, -1
br i1 %121, label %122, label %125
122: ; preds = %114
%123 = load i32, i32* @stderr
%124 = call i32 (i32, i8*, ...) @fprintf(i32 %123, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %156
125: ; preds = %114
store i32 0, i32* %6
br label %126
126: ; preds = %142, %125
%127 = load i32, i32* %6
%128 = sext i32 %127 to i64
%129 = load i64, i64* %9
%130 = icmp ult i64 %128, %129
br i1 %130, label %131, label %145
131: ; preds = %126
%132 = load i32, i32* %7
%133 = getelementptr inbounds [16384 x i8], [16384 x i8]* %5, i64 0, i64 0
%134 = load i32, i32* %6
%135 = load i64, i64* %8
%136 = call i64 @disk_page_write(i32 %132, i8* %133, i32 %134, i64 %135)
%137 = icmp ne i64 %136, 0
br i1 %137, label %138, label %141
138: ; preds = %131
%139 = load i32, i32* @stderr
%140 = call i32 (i32, i8*, ...) @fprintf(i32 %139, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %145
141: ; preds = %131
br label %142
142: ; preds = %141
%143 = load i32, i32* %6
%144 = add nsw i32 %143, 2
store i32 %144, i32* %6
br label %126
145: ; preds = %138, %126
%146 = load i32, i32* %6
%147 = sext i32 %146 to i64
%148 = load i64, i64* %9
%149 = icmp ult i64 %147, %148
br i1 %149, label %150, label %151
150: ; preds = %145
br label %156
151: ; preds = %145
%152 = load i32, i32* %7
%153 = call i32 @disk_sync(i32 %152)
%154 = load i32, i32* %7
%155 = call i32 @disk_close(i32 %154)
br label %156
156: ; preds = %151, %150, %122
%157 = call i32 @gettimeofday(%struct.timeval* %12, i32 0)
%158 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%159 = load i32, i32* %158
%160 = mul nsw i32 %159, 1000000
%161 = sext i32 %160 to i64
%162 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
%163 = load i64, i64* %162
%164 = add nsw i64 %161, %163
%165 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%166 = load i32, i32* %165
%167 = mul nsw i32 %166, 1000000
%168 = sext i32 %167 to i64
%169 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
%170 = load i64, i64* %169
%171 = add nsw i64 %168, %170
%172 = sub nsw i64 %164, %171
store i64 %172, i64* %10
%173 = load i32, i32* @stderr
%174 = load i64, i64* %10
%175 = sitofp i64 %174 to double
%176 = fdiv double %175, 1.000000e+06
%177 = call i32 (i32, i8*, ...) @fprintf(i32 %173, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), double %176)
%178 = load i32, i32* %1
ret i32 %178
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@.str = [19 x i8] c"./sample_data_full\00"
@.str.1 = [21 x i8] c"./sample_data_stride\00"
@stderr = global i32 0
@.str.2 = [24 x i8] c"full write test: start\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.3 = [17 x i8] c"file open error\0A\00"
@.str.4 = [18 x i8] c"page write error\0A\00"
@.str.5 = [32 x i8] c"full write test: end (time=%f)\0A\00"
@.str.6 = [26 x i8] c"stride write test: start\0A\00"
@.str.7 = [34 x i8] c"stride write test: end (time=%f)\0A\00"
define i32 @main() {
%1 = alloca [16384 x i8]
%2 = alloca [16384 x i8]
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = getelementptr inbounds [16384 x i8], [16384 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [16384 x i8], [16384 x i8]* %2, i64 0, i64 0
%7 = tail call i64 (...) @getpagesize()
%8 = bitcast %struct.timeval* %3 to i8*
%9 = bitcast %struct.timeval* %4 to i8*
%10 = tail call i32 @disk_unlink(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @disk_unlink(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %7, 0
br i1 %12, label %15, label %13
13: ; preds = %0
%14 = getelementptr inbounds [16384 x i8], [16384 x i8]* %1, i64 0, i64 0
br label %15
15: ; preds = %0, %13
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @gettimeofday(%struct.timeval* %3, i32 0)
%19 = load i32, i32* @O_RDWR
%20 = load i32, i32* @O_CREAT
%21 = or i32 %20, %19
%22 = call i32 @disk_open(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %21, i32 420)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %30
24: ; preds = %15
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %40
27: ; preds = %30
%28 = add nuw nsw i32 %31, 1
%29 = icmp eq i32 %28, 10240
br i1 %29, label %37, label %30
30: ; preds = %15, %27
%31 = phi i32 [ %28, %27 ], [ 0, %15 ]
%32 = call i64 @disk_page_write(i32 %22, i8* %5, i32 %31, i64 %7)
%33 = icmp eq i64 %32, 0
br i1 %33, label %27, label %34
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %40
37: ; preds = %27
%38 = call i32 @disk_sync(i32 %22)
%39 = call i32 @disk_close(i32 %22)
br label %40
40: ; preds = %34, %37, %24
%41 = call i32 @gettimeofday(%struct.timeval* %4, i32 0)
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%43 = load i32, i32* %42
%44 = mul nsw i32 %43, 1000000
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%47 = load i64, i64* %46
%48 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%49 = load i32, i32* %48
%50 = mul nsw i32 %49, 1000000
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%53 = load i64, i64* %52
%54 = add i64 %47, %45
%55 = add i64 %53, %51
%56 = sub i64 %54, %55
%57 = load i32, i32* @stderr
%58 = sitofp i64 %56 to double
%59 = fdiv double %58, 1.000000e+06
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), double %59)
%61 = load i32, i32* @stderr
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
%63 = call i32 @gettimeofday(%struct.timeval* %3, i32 0)
%64 = load i32, i32* @O_RDWR
%65 = load i32, i32* @O_CREAT
%66 = or i32 %65, %64
%67 = call i32 @disk_open(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %66, i32 420)
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %75
69: ; preds = %40
%70 = load i32, i32* @stderr
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %85
72: ; preds = %75
%73 = add nuw nsw i32 %76, 2
%74 = icmp ult i32 %76, 10238
br i1 %74, label %75, label %82
75: ; preds = %40, %72
%76 = phi i32 [ %73, %72 ], [ 0, %40 ]
%77 = call i64 @disk_page_write(i32 %67, i8* %6, i32 %76, i64 %7)
%78 = icmp eq i64 %77, 0
br i1 %78, label %72, label %79
79: ; preds = %75
%80 = load i32, i32* @stderr
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %85
82: ; preds = %72
%83 = call i32 @disk_sync(i32 %67)
%84 = call i32 @disk_close(i32 %67)
br label %85
85: ; preds = %79, %82, %69
%86 = call i32 @gettimeofday(%struct.timeval* %4, i32 0)
%87 = load i32, i32* %42
%88 = mul nsw i32 %87, 1000000
%89 = sext i32 %88 to i64
%90 = load i64, i64* %46
%91 = load i32, i32* %48
%92 = mul nsw i32 %91, 1000000
%93 = sext i32 %92 to i64
%94 = load i64, i64* %52
%95 = add i64 %90, %89
%96 = add i64 %94, %93
%97 = sub i64 %95, %96
%98 = load i32, i32* @stderr
%99 = sitofp i64 %97 to double
%100 = fdiv double %99, 1.000000e+06
%101 = call i32 (i32, i8*, ...) @fprintf(i32 %98, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), double %100)
ret i32 0
}