#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 O_CREAT;
int O_SYNC;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
double now();
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ unlink(char *);
int write(int, char *, int);
void nfs_bench(int run) {
  char *dest = "/revosave/nfsbench";
  char *dev = NULL;
  double t1, t2;
  int i, fd = -1, megs, s;
  char buf[8192];
  for (s = 0; s <= 1; s++) {
    system("/bin/sync");
    sleep(5);
    if ((fd = open(dest, O_WRONLY | O_CREAT | O_TRUNC |
                             (s == 0 ? 0 : O_SYNC))) == -1) {
      printf("NFS open error\n");
      exit(1);
    }
    t1 = now();
    megs = 32 * run;
    for (i = 0; i < 1024 / 8 * megs; i++) {
      if (write(fd, buf, 8192) != 8192) {
        printf("Write error\n");
      }
    }
    close(fd);
    t2 = now();
    printf("%dMB written in %f s (sync=%d) = %f MB/s\n", megs, t2 - t1, s,
           (double)megs / (t2 - t1));
    unlink(dest);
  }
}


x86 assembly (clang, -O0):
<nfs_bench>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2060,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe5b(%rip),%rax
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x30(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0x1,-0x38(%rbp)
jg     1338 <nfs_bench+0x1a8>
lea    0xe43(%rip),%rdi
call   1050 <system@plt>
mov    $0x5,%edi
call   10b0 <sleep@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x2050(%rbp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
mov    0x2dfe(%rip),%rcx
or     (%rcx),%eax
mov    0x2ded(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x2044(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    1222 <nfs_bench+0x92>
xor    %eax,%eax
mov    %eax,-0x2054(%rbp)
jmp    1231 <nfs_bench+0xa1>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2054(%rbp)
mov    -0x2050(%rbp),%rdi
mov    -0x2044(%rbp),%esi
mov    -0x2054(%rbp),%eax
or     %eax,%esi
call   1080 <open@plt>
mov    %eax,-0x30(%rbp)
cmp    $0xffffffff,%eax
jne    126f <nfs_bench+0xdf>
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   1090 <now@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x5,%eax
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x34(%rbp),%ecx
shl    $0x7,%ecx
cmp    %ecx,%eax
jge    12dc <nfs_bench+0x14c>
mov    -0x30(%rbp),%edi
lea    -0x2040(%rbp),%rsi
mov    $0x2000,%edx
call   1040 <write@plt>
cmp    $0x2000,%eax
je     12c9 <nfs_bench+0x139>
lea    0xd6b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12ce <nfs_bench+0x13e>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    128b <nfs_bench+0xfb>
mov    -0x30(%rbp),%edi
call   1070 <close@plt>
mov    $0x0,%al
call   1090 <now@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x34(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
mov    -0x38(%rbp),%edx
cvtsi2sdl -0x34(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
subsd  -0x20(%rbp),%xmm2
divsd  %xmm2,%xmm1
lea    0xd20(%rip),%rdi
mov    $0x2,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11bf <nfs_bench+0x2f>
add    $0x2060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nfs_bench>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2028,%rsp
mov    %edi,%r14d
mov    %edi,%eax
shl    $0xc,%eax
cmp    $0x2,%eax
mov    $0x1,%r15d
cmovge %eax,%r15d
lea    0xe46(%rip),%rdi
call   1060 <system@plt>
mov    $0x5,%edi
call   10c0 <sleep@plt>
mov    0x2ddd(%rip),%rax
mov    0x2e0e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dfb(%rip),%rax
or     (%rax),%esi
lea    0xe02(%rip),%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     13a6 <nfs_bench+0x206>
mov    %eax,%ebp
mov    %r14d,%eax
shl    $0x5,%eax
mov    %eax,0x14(%rsp)
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x18(%rsp)
xor    %eax,%eax
call   10a0 <now@plt>
movsd  %xmm0,0x8(%rsp)
test   %r14d,%r14d
jle    1275 <nfs_bench+0xd5>
lea    0x20(%rsp),%r13
lea    0xe07(%rip),%r12
mov    %r15d,%ebx
jmp    1255 <nfs_bench+0xb5>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0xffffffff,%ebx
je     1275 <nfs_bench+0xd5>
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x2000,%edx
call   1050 <write@plt>
cmp    $0x2000,%eax
je     1250 <nfs_bench+0xb0>
mov    %r12,%rdi
call   1040 <puts@plt>
jmp    1250 <nfs_bench+0xb0>
mov    %ebp,%edi
call   1080 <close@plt>
xor    %eax,%eax
call   10a0 <now@plt>
subsd  0x8(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
divsd  %xmm0,%xmm1
lea    0xd83(%rip),%rdi
mov    0x14(%rsp),%ebx
mov    %ebx,%esi
xor    %edx,%edx
mov    $0x2,%al
call   1070 <printf@plt>
lea    0xd50(%rip),%rbp
mov    %rbp,%rdi
call   1030 <unlink@plt>
lea    0xd54(%rip),%rdi
call   1060 <system@plt>
mov    $0x5,%edi
call   10c0 <sleep@plt>
mov    0x2d23(%rip),%rax
mov    (%rax),%esi
mov    0x2ce2(%rip),%rax
or     (%rax),%esi
mov    0x2d09(%rip),%rax
or     (%rax),%esi
mov    0x2ce8(%rip),%rax
or     (%rax),%esi
mov    %rbp,%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     13a6 <nfs_bench+0x206>
mov    %eax,%ebp
xor    %eax,%eax
call   10a0 <now@plt>
movsd  %xmm0,0x8(%rsp)
test   %r14d,%r14d
jle    1356 <nfs_bench+0x1b6>
lea    0x20(%rsp),%r12
lea    0xd24(%rip),%r14
jmp    1336 <nfs_bench+0x196>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0xffffffff,%r15d
je     1356 <nfs_bench+0x1b6>
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x2000,%edx
call   1050 <write@plt>
cmp    $0x2000,%eax
je     1330 <nfs_bench+0x190>
mov    %r14,%rdi
call   1040 <puts@plt>
jmp    1330 <nfs_bench+0x190>
mov    %ebp,%edi
call   1080 <close@plt>
xor    %eax,%eax
call   10a0 <now@plt>
subsd  0x8(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
divsd  %xmm0,%xmm1
lea    0xca2(%rip),%rdi
mov    %ebx,%esi
mov    $0x1,%edx
mov    $0x2,%al
call   1070 <printf@plt>
lea    0xc70(%rip),%rdi
add    $0x2028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <unlink@plt>
lea    0xca6(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"/revosave/nfsbench\00"
@.str.1 = [10 x i8] c"/bin/sync\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_SYNC = global i32 0
@.str.2 = [16 x i8] c"NFS open error\0A\00"
@.str.3 = [13 x i8] c"Write error\0A\00"
@.str.4 = [42 x i8] c"%dMB written in %f s (sync=%d) = %f MB/s\0A\00"
define void @nfs_bench(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [8192 x i8]
store i32 %0, i32* %2
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8** %3
store i8* null, i8** %4
store i32 -1, i32* %8
store i32 0, i32* %10
br label %12
12: ; preds = %75, %1
%13 = load i32, i32* %10
%14 = icmp sle i32 %13, 1
br i1 %14, label %15, label %78
15: ; preds = %12
%16 = call i32 @system(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @sleep(i32 5)
%18 = load i8*, i8** %3
%19 = load i32, i32* @O_WRONLY
%20 = load i32, i32* @O_CREAT
%21 = or i32 %19, %20
%22 = load i32, i32* @O_TRUNC
%23 = or i32 %21, %22
%24 = load i32, i32* %10
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %15
br label %29
27: ; preds = %15
%28 = load i32, i32* @O_SYNC
br label %29
29: ; preds = %27, %26
%30 = phi i32 [ 0, %26 ], [ %28, %27 ]
%31 = or i32 %23, %30
%32 = call i32 @open(i8* %18, i32 %31)
store i32 %32, i32* %8
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %29
%38 = call double (...) @now()
store double %38, double* %5
%39 = load i32, i32* %2
%40 = mul nsw i32 32, %39
store i32 %40, i32* %9
store i32 0, i32* %7
br label %41
41: ; preds = %54, %37
%42 = load i32, i32* %7
%43 = load i32, i32* %9
%44 = mul nsw i32 128, %43
%45 = icmp slt i32 %42, %44
br i1 %45, label %46, label %57
46: ; preds = %41
%47 = load i32, i32* %8
%48 = getelementptr inbounds [8192 x i8], [8192 x i8]* %11, i64 0, i64 0
%49 = call i32 @write(i32 %47, i8* %48, i32 8192)
%50 = icmp ne i32 %49, 8192
br i1 %50, label %51, label %53
51: ; preds = %46
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %53
53: ; preds = %51, %46
br label %54
54: ; preds = %53
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
store i32 %56, i32* %7
br label %41
57: ; preds = %41
%58 = load i32, i32* %8
%59 = call i32 @close(i32 %58)
%60 = call double (...) @now()
store double %60, double* %6
%61 = load i32, i32* %9
%62 = load double, double* %6
%63 = load double, double* %5
%64 = fsub double %62, %63
%65 = load i32, i32* %10
%66 = load i32, i32* %9
%67 = sitofp i32 %66 to double
%68 = load double, double* %6
%69 = load double, double* %5
%70 = fsub double %68, %69
%71 = fdiv double %67, %70
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 %61, double %64, i32 %65, double %71)
%73 = load i8*, i8** %3
%74 = call i32 @unlink(i8* %73)
br label %75
75: ; preds = %57
%76 = load i32, i32* %10
%77 = add nsw i32 %76, 1
store i32 %77, i32* %10
br label %12
78: ; preds = %12
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"/revosave/nfsbench\00"
@.str.1 = [10 x i8] c"/bin/sync\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_SYNC = global i32 0
@.str.4 = [42 x i8] c"%dMB written in %f s (sync=%d) = %f MB/s\0A\00"
@str = [12 x i8] c"Write error\00"
@str.5 = [15 x i8] c"NFS open error\00"
define void @nfs_bench(i32 %0) {
%2 = alloca [8192 x i8]
%3 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 0
%4 = shl nsw i32 %0, 5
%5 = shl i32 %0, 12
%6 = icmp sgt i32 %0, 0
%7 = sitofp i32 %4 to double
%8 = call i32 @llvm.smax.i32(i32 %5, i32 1)
%9 = tail call i32 @system(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @sleep(i32 5)
%11 = load i32, i32* @O_WRONLY
%12 = load i32, i32* @O_CREAT
%13 = or i32 %12, %11
%14 = load i32, i32* @O_TRUNC
%15 = or i32 %13, %14
%16 = tail call i32 @open(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %32, %1
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.5, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %1
%22 = tail call double (...) @now()
br i1 %6, label %23, label %32
23: ; preds = %21, %29
%24 = phi i32 [ %30, %29 ], [ 0, %21 ]
%25 = call i32 @write(i32 %16, i8* %3, i32 8192)
%26 = icmp eq i32 %25, 8192
br i1 %26, label %29, label %27
27: ; preds = %23
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %29
29: ; preds = %23, %27
%30 = add nuw nsw i32 %24, 1
%31 = icmp eq i32 %30, %8
br i1 %31, label %32, label %23
32: ; preds = %29, %21
%33 = tail call i32 @close(i32 %16)
%34 = tail call double (...) @now()
%35 = fsub double %34, %22
%36 = fdiv double %7, %35
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 %4, double %35, i32 0, double %36)
%38 = tail call i32 @unlink(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%39 = tail call i32 @system(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%40 = tail call i32 @sleep(i32 5)
%41 = load i32, i32* @O_WRONLY
%42 = load i32, i32* @O_CREAT
%43 = or i32 %42, %41
%44 = load i32, i32* @O_TRUNC
%45 = or i32 %43, %44
%46 = load i32, i32* @O_SYNC
%47 = or i32 %45, %46
%48 = tail call i32 @open(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %47)
%49 = icmp eq i32 %48, -1
br i1 %49, label %18, label %50
50: ; preds = %32
%51 = tail call double (...) @now()
br i1 %6, label %52, label %61
52: ; preds = %50, %58
%53 = phi i32 [ %59, %58 ], [ 0, %50 ]
%54 = call i32 @write(i32 %48, i8* %3, i32 8192)
%55 = icmp eq i32 %54, 8192
br i1 %55, label %58, label %56
56: ; preds = %52
%57 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %58
58: ; preds = %56, %52
%59 = add nuw nsw i32 %53, 1
%60 = icmp eq i32 %59, %8
br i1 %60, label %61, label %52
61: ; preds = %58, %50
%62 = tail call i32 @close(i32 %48)
%63 = tail call double (...) @now()
%64 = fsub double %63, %51
%65 = fdiv double %7, %64
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 %4, double %64, i32 1, double %65)
%67 = tail call i32 @unlink(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
ret void
}