#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 timespec {
  double tv_sec;
  double tv_nsec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ RAND_pseudo_bytes(unsigned char *, double);
int /*<<< orphan*/ atof(char *);
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
int fsync(int);
scalar_t__ malloc(double);
int open(char *, int, ...);
double pow(double, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int pwrite(int, char *, double, int /*<<< orphan*/);
int rename(char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int /*<<< orphan*/ swap(char **, char **);
int main(int argc, char *argv[]) {
  char *dir = "/mnt/benchmark/";
  char *srcfname = "/mnt/benchmark/a";
  char *dstfname = "/mnt/benchmark/b";
  struct timespec start, end;
  double elapsed;
  int filefd, dirfd;
  int i, j;
  int status, status1;
  char *data;
  int errno;
  char *filesystem = argv[1];
  double fsize = pow(2.0, atof(argv[2]));
  char *filename = argv[3];
  FILE *result = fopen(filename, "ab");
  if (result == NULL) {
    printf("Can't open result file");
    exit(0);
  }
  data = (char *)malloc(fsize);
  RAND_pseudo_bytes((unsigned char *)data, fsize);
  if ((filefd = open(srcfname, O_CREAT | O_WRONLY, 0644)) < 0) {
    fprintf(stderr, "open file failed\n");
    return -1;
  }
  status = pwrite(filefd, data, fsize, 0);
  if (status != fsize) {
    printf("pwrite failed. Only write: %d", status);
    exit(-1);
  }
  status1 = fsync(filefd);
  if (status1 != 0)
    printf("Failed to sync file: %s\n", strerror(errno));
  dirfd = open(dir, O_RDONLY);
  if (dirfd < 0) {
    printf("Can't open dir: %s", strerror(errno));
    exit(-1);
  }
  for (j = 0; j < 100; j++) {
    clock_gettime(CLOCK_MONOTONIC, &start);
    status = rename(srcfname, dstfname);
    status1 = fsync(dirfd);
    clock_gettime(CLOCK_MONOTONIC, &end);
    if (status != 0) {
      printf("Failed to rename: %s\n", strerror(errno));
      exit(-1);
    }
    if (status1 != 0) {
      printf("Failed to sync dir: %s\n", strerror(errno));
      exit(-1);
    }
    elapsed = (end.tv_sec - start.tv_sec) +
              (end.tv_nsec - start.tv_nsec) / 1000000000.0;
    fprintf(result, "%s, %lf, %lf\n", filesystem, fsize, elapsed);
    printf("%s, %lf, %lf\n", filesystem, fsize, elapsed);
    swap(&srcfname, &dstfname);
  }
  free(data);
  close(filefd);
  close(dirfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xde0(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xde5(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xdeb(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x80(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <atof@plt>
mov    %eax,%edi
movsd  0xd93(%rip),%xmm0
call   10f0 <pow@plt>
movsd  %xmm0,-0x88(%rbp)
ff
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x90(%rbp)
mov    -0x90(%rbp),%rdi
lea    0xdab(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jne    12c6 <main+0xb6>
lea    0xd8d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
movsd  -0x88(%rbp),%xmm0
ff
call   1090 <malloc@plt>
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rdi
movsd  -0x88(%rbp),%xmm0
ff
call   10a0 <RAND_pseudo_bytes@plt>
mov    -0x20(%rbp),%rdi
mov    0x2d05(%rip),%rax
mov    (%rax),%esi
mov    0x2cbc(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
mov    $0x0,%al
call   10d0 <open@plt>
mov    %eax,-0x54(%rbp)
cmp    $0x0,%eax
jge    133a <main+0x12a>
mov    0x2cab(%rip),%rax
movslq (%rax),%rdi
lea    0xd35(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1551 <main+0x341>
mov    -0x54(%rbp),%edi
mov    -0x70(%rbp),%rsi
movsd  -0x88(%rbp),%xmm0
ff
xor    %edx,%edx
call   10b0 <pwrite@plt>
mov    %eax,-0x64(%rbp)
cvtsi2sdl -0x64(%rbp),%xmm0
ucomisd -0x88(%rbp),%xmm0
ff
jne    1371 <main+0x161>
jp     1371 <main+0x161>
jmp    138c <main+0x17c>
mov    -0x64(%rbp),%esi
lea    0xcf3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
mov    -0x54(%rbp),%edi
call   10c0 <fsync@plt>
mov    %eax,-0x68(%rbp)
cmpl   $0x0,-0x68(%rbp)
je     13ba <main+0x1aa>
mov    -0x74(%rbp),%edi
call   1130 <strerror@plt>
mov    %rax,%rsi
lea    0xcd9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2c1b(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10d0 <open@plt>
mov    %eax,-0x58(%rbp)
cmpl   $0x0,-0x58(%rbp)
jge    13fe <main+0x1ee>
mov    -0x74(%rbp),%edi
call   1130 <strerror@plt>
mov    %rax,%rsi
lea    0xcb8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
movl   $0x0,-0x60(%rbp)
cmpl   $0x64,-0x60(%rbp)
jge    1531 <main+0x321>
mov    0x2bc2(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
call   1050 <clock_gettime@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1100 <rename@plt>
mov    %eax,-0x64(%rbp)
mov    -0x58(%rbp),%edi
call   10c0 <fsync@plt>
mov    %eax,-0x68(%rbp)
mov    0x2b95(%rip),%rax
mov    (%rax),%edi
lea    -0x48(%rbp),%rsi
call   1050 <clock_gettime@plt>
cmpl   $0x0,-0x64(%rbp)
je     147b <main+0x26b>
mov    -0x74(%rbp),%edi
call   1130 <strerror@plt>
mov    %rax,%rsi
lea    0xc4e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
cmpl   $0x0,-0x68(%rbp)
je     14a8 <main+0x298>
mov    -0x74(%rbp),%edi
call   1130 <strerror@plt>
mov    %rax,%rsi
lea    0xc37(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
movsd  -0x48(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
subsd  -0x30(%rbp),%xmm1
movsd  0xb44(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x98(%rbp),%rdi
mov    -0x80(%rbp),%rdx
movsd  -0x88(%rbp),%xmm0
ff
movsd  -0x50(%rbp),%xmm1
lea    0xbf6(%rip),%rsi
mov    $0x2,%al
call   1080 <fprintf@plt>
mov    -0x80(%rbp),%rsi
movsd  -0x88(%rbp),%xmm0
ff
movsd  -0x50(%rbp),%xmm1
lea    0xbd7(%rip),%rdi
mov    $0x2,%al
call   1060 <printf@plt>
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1120 <swap@plt>
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    1405 <main+0x1f5>
mov    -0x70(%rbp),%rdi
call   1030 <free@plt>
mov    -0x54(%rbp),%edi
call   1070 <close@plt>
mov    -0x58(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%rbp
lea    0xde8(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xded(%rip),%rax
mov    %rax,0x10(%rsp)
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%rdi
call   1040 <atof@plt>
movsd  0xda2(%rip),%xmm0
mov    %eax,%edi
call   10f0 <pow@plt>
movsd  %xmm0,(%rsp)
mov    0x18(%rbp),%rdi
lea    0xdcd(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,0x28(%rsp)
test   %rax,%rax
je     149a <main+0x27a>
movsd  (%rsp),%xmm0
call   1090 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
movsd  (%rsp),%xmm0
call   10a0 <RAND_pseudo_bytes@plt>
mov    0x2d4f(%rip),%rax
mov    0x2d08(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xd65(%rip),%rdi
mov    $0x1a4,%edx
xor    %eax,%eax
call   10d0 <open@plt>
test   %eax,%eax
js     1438 <main+0x218>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r14,%rsi
movsd  (%rsp),%xmm0
xor    %edx,%edx
call   10b0 <pwrite@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  (%rsp),%xmm1
ucomisd %xmm0,%xmm1
jne    14af <main+0x28f>
jp     14af <main+0x28f>
mov    %ebp,%edi
call   10c0 <fsync@plt>
test   %eax,%eax
je     131f <main+0xff>
call   1140 <strerror@plt>
lea    0xd77(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,0xc(%rsp)
mov    %r14,0x20(%rsp)
mov    0x2cb1(%rip),%rax
mov    (%rax),%esi
lea    0xcd8(%rip),%rdi
xor    %eax,%eax
call   10d0 <open@plt>
mov    %eax,0x8(%rsp)
test   %eax,%eax
js     14c9 <main+0x2a9>
mov    $0x64,%r14d
mov    0x2c80(%rip),%rbp
lea    0xd87(%rip),%r12
nop
mov    0x0(%rbp),%edi
lea    0x50(%rsp),%rsi
call   1050 <clock_gettime@plt>
mov    0x18(%rsp),%rdi
mov    0x10(%rsp),%rsi
call   1100 <rename@plt>
mov    %eax,%r15d
mov    0x8(%rsp),%edi
call   10c0 <fsync@plt>
mov    %eax,%r13d
mov    0x0(%rbp),%edi
lea    0x40(%rsp),%rsi
call   1050 <clock_gettime@plt>
test   %r15d,%r15d
jne    146c <main+0x24c>
test   %r13d,%r13d
movsd  (%rsp),%xmm0
jne    147a <main+0x25a>
movapd 0x40(%rsp),%xmm2
subpd  0x50(%rsp),%xmm2
movapd %xmm2,%xmm1
unpckhpd %xmm2,%xmm1
divsd  0xc3d(%rip),%xmm1
addsd  %xmm2,%xmm1
movapd %xmm1,0x30(%rsp)
mov    0x28(%rsp),%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    $0x2,%al
call   1080 <fprintf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
movsd  (%rsp),%xmm0
movapd 0x30(%rsp),%xmm1
mov    $0x2,%al
call   1060 <printf@plt>
lea    0x18(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1130 <swap@plt>
add    $0xffffffff,%r14d
jne    1360 <main+0x140>
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
mov    0xc(%rsp),%edi
call   1070 <close@plt>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
xor    %eax,%eax
jmp    145d <main+0x23d>
mov    0x2b89(%rip),%rax
movslq (%rax),%rcx
lea    0xc13(%rip),%rdi
mov    $0x11,%esi
mov    $0x1,%edx
call   1120 <fwrite@plt>
mov    $0xffffffff,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
call   1140 <strerror@plt>
lea    0xc40(%rip),%rdi
jmp    1486 <main+0x266>
call   1140 <strerror@plt>
lea    0xc48(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
lea    0xba4(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
lea    0xbb8(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
call   1140 <strerror@plt>
lea    0xbd0(%rip),%rdi
jmp    1486 <main+0x266>

LLVM IR (-O0):
%struct.timespec = type { double, double }
@.str = [16 x i8] c"/mnt/benchmark/\00"
@.str.1 = [17 x i8] c"/mnt/benchmark/a\00"
@.str.2 = [17 x i8] c"/mnt/benchmark/b\00"
@.str.3 = [3 x i8] c"ab\00"
@.str.4 = [23 x i8] c"Can't open result file\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.5 = [18 x i8] c"open file failed\0A\00"
@.str.6 = [30 x i8] c"pwrite failed. Only write: %d\00"
@.str.7 = [25 x i8] c"Failed to sync file: %s\0A\00"
@O_RDONLY = global i32 0
@.str.8 = [19 x i8] c"Can't open dir: %s\00"
@CLOCK_MONOTONIC = global i32 0
@.str.9 = [22 x i8] c"Failed to rename: %s\0A\00"
@.str.10 = [24 x i8] c"Failed to sync dir: %s\0A\00"
@.str.11 = [14 x i8] c"%s, %lf, %lf\0A\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 i8*
%9 = alloca %struct.timespec
%10 = alloca %struct.timespec
%11 = alloca double
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i8*
%19 = alloca i32
%20 = alloca i8*
%21 = alloca double
%22 = alloca i8*
%23 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8** %8
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
store i8* %26, i8** %20
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @atof(i8* %29)
%31 = call double @pow(double 2.000000e+00, i32 %30)
store double %31, double* %21
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 3
%34 = load i8*, i8** %33
store i8* %34, i8** %22
%35 = load i8*, i8** %22
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %36, i32** %23
%37 = load i32*, i32** %23
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %42
39: ; preds = %2
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%41 = call i32 @exit(i32 0)
unreachable
42: ; preds = %2
%43 = load double, double* %21
%44 = call i64 @malloc(double %43)
%45 = inttoptr i64 %44 to i8*
store i8* %45, i8** %18
%46 = load i8*, i8** %18
%47 = load double, double* %21
%48 = call i32 @RAND_pseudo_bytes(i8* %46, double %47)
%49 = load i8*, i8** %7
%50 = load i32, i32* @O_CREAT
%51 = load i32, i32* @O_WRONLY
%52 = or i32 %50, %51
%53 = call i32 (i8*, i32, ...) @open(i8* %49, i32 %52, i32 420)
store i32 %53, i32* %12
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %60
55: ; preds = %42
%56 = load i32, i32* @stderr
%57 = sext i32 %56 to i64
%58 = inttoptr i64 %57 to i32*
%59 = call i32 (i32*, i8*, ...) @fprintf(i32* %58, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %155
60: ; preds = %42
%61 = load i32, i32* %12
%62 = load i8*, i8** %18
%63 = load double, double* %21
%64 = call i32 @pwrite(i32 %61, i8* %62, double %63, i32 0)
store i32 %64, i32* %16
%65 = load i32, i32* %16
%66 = sitofp i32 %65 to double
%67 = load double, double* %21
%68 = fcmp une double %66, %67
br i1 %68, label %69, label %73
69: ; preds = %60
%70 = load i32, i32* %16
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i32 %70)
%72 = call i32 @exit(i32 -1)
unreachable
73: ; preds = %60
%74 = load i32, i32* %12
%75 = call i32 @fsync(i32 %74)
store i32 %75, i32* %17
%76 = load i32, i32* %17
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %82
78: ; preds = %73
%79 = load i32, i32* %19
%80 = call i8* @strerror(i32 %79)
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %80)
br label %82
82: ; preds = %78, %73
%83 = load i8*, i8** %6
%84 = load i32, i32* @O_RDONLY
%85 = call i32 (i8*, i32, ...) @open(i8* %83, i32 %84)
store i32 %85, i32* %13
%86 = load i32, i32* %13
%87 = icmp slt i32 %86, 0
br i1 %87, label %88, label %93
88: ; preds = %82
%89 = load i32, i32* %19
%90 = call i8* @strerror(i32 %89)
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %90)
%92 = call i32 @exit(i32 -1)
unreachable
93: ; preds = %82
store i32 0, i32* %15
br label %94
94: ; preds = %145, %93
%95 = load i32, i32* %15
%96 = icmp slt i32 %95, 100
br i1 %96, label %97, label %148
97: ; preds = %94
%98 = load i32, i32* @CLOCK_MONOTONIC
%99 = call i32 @clock_gettime(i32 %98, %struct.timespec* %9)
%100 = load i8*, i8** %7
%101 = load i8*, i8** %8
%102 = call i32 @rename(i8* %100, i8* %101)
store i32 %102, i32* %16
%103 = load i32, i32* %13
%104 = call i32 @fsync(i32 %103)
store i32 %104, i32* %17
%105 = load i32, i32* @CLOCK_MONOTONIC
%106 = call i32 @clock_gettime(i32 %105, %struct.timespec* %10)
%107 = load i32, i32* %16
%108 = icmp ne i32 %107, 0
br i1 %108, label %109, label %114
109: ; preds = %97
%110 = load i32, i32* %19
%111 = call i8* @strerror(i32 %110)
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i8* %111)
%113 = call i32 @exit(i32 -1)
unreachable
114: ; preds = %97
%115 = load i32, i32* %17
%116 = icmp ne i32 %115, 0
br i1 %116, label %117, label %122
117: ; preds = %114
%118 = load i32, i32* %19
%119 = call i8* @strerror(i32 %118)
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), i8* %119)
%121 = call i32 @exit(i32 -1)
unreachable
122: ; preds = %114
%123 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 0
%124 = load double, double* %123
%125 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i32 0, i32 0
%126 = load double, double* %125
%127 = fsub double %124, %126
%128 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 1
%129 = load double, double* %128
%130 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i32 0, i32 1
%131 = load double, double* %130
%132 = fsub double %129, %131
%133 = fdiv double %132, 1.000000e+09
%134 = fadd double %127, %133
store double %134, double* %11
%135 = load i32*, i32** %23
%136 = load i8*, i8** %20
%137 = load double, double* %21
%138 = load double, double* %11
%139 = call i32 (i32*, i8*, ...) @fprintf(i32* %135, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0), i8* %136, double %137, double %138)
%140 = load i8*, i8** %20
%141 = load double, double* %21
%142 = load double, double* %11
%143 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0), i8* %140, double %141, double %142)
%144 = call i32 @swap(i8** %7, i8** %8)
br label %145
145: ; preds = %122
%146 = load i32, i32* %15
%147 = add nsw i32 %146, 1
store i32 %147, i32* %15
br label %94
148: ; preds = %94
%149 = load i8*, i8** %18
%150 = call i32 @free(i8* %149)
%151 = load i32, i32* %12
%152 = call i32 @close(i32 %151)
%153 = load i32, i32* %13
%154 = call i32 @close(i32 %153)
store i32 0, i32* %3
br label %155
155: ; preds = %148, %55
%156 = load i32, i32* %3
ret i32 %156
}

LLVM IR (-O2):
%struct.timespec = type { double, double }
@.str = [16 x i8] c"/mnt/benchmark/\00"
@.str.1 = [17 x i8] c"/mnt/benchmark/a\00"
@.str.2 = [17 x i8] c"/mnt/benchmark/b\00"
@.str.3 = [3 x i8] c"ab\00"
@.str.4 = [23 x i8] c"Can't open result file\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.5 = [18 x i8] c"open file failed\0A\00"
@.str.6 = [30 x i8] c"pwrite failed. Only write: %d\00"
@.str.7 = [25 x i8] c"Failed to sync file: %s\0A\00"
@O_RDONLY = global i32 0
@.str.8 = [19 x i8] c"Can't open dir: %s\00"
@CLOCK_MONOTONIC = global i32 0
@.str.9 = [22 x i8] c"Failed to rename: %s\0A\00"
@.str.10 = [24 x i8] c"Failed to sync dir: %s\0A\00"
@.str.11 = [14 x i8] c"%s, %lf, %lf\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca <2 x double>
%6 = bitcast <2 x double>* %5 to %struct.timespec*
%7 = alloca <2 x double>
%8 = bitcast <2 x double>* %7 to %struct.timespec*
%9 = bitcast i8** %3 to i8*
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8** %3
%10 = bitcast i8** %4 to i8*
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8** %4
%11 = bitcast <2 x double>* %5 to i8*
%12 = bitcast <2 x double>* %7 to i8*
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32 @atof(i8* %16)
%18 = tail call double @pow(double 2.000000e+00, i32 %17)
%19 = getelementptr inbounds i8*, i8** %1, i64 3
%20 = load i8*, i8** %19
%21 = tail call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %2
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%25 = tail call i32 @exit(i32 0)
unreachable
26: ; preds = %2
%27 = tail call i64 @malloc(double %18)
%28 = inttoptr i64 %27 to i8*
%29 = tail call i32 @RAND_pseudo_bytes(i8* %28, double %18)
%30 = load i32, i32* @O_CREAT
%31 = load i32, i32* @O_WRONLY
%32 = or i32 %31, %30
%33 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %32, i32 420)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %26
%36 = load i32, i32* @stderr
%37 = sext i32 %36 to i64
%38 = inttoptr i64 %37 to i32*
%39 = tail call i64 @fwrite(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i64 17, i64 1, i32* %38)
br label %99
40: ; preds = %26
%41 = tail call i32 @pwrite(i32 %33, i8* %28, double %18, i32 0)
%42 = sitofp i32 %41 to double
%43 = fcmp une double %18, %42
br i1 %43, label %44, label %47
44: ; preds = %40
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i32 %41)
%46 = tail call i32 @exit(i32 -1)
unreachable
47: ; preds = %40
%48 = tail call i32 @fsync(i32 %33)
%49 = icmp eq i32 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %47
%51 = tail call i8* @strerror(i32 undef)
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %50, %47
%54 = load i32, i32* @O_RDONLY
%55 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %54)
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %61
57: ; preds = %53
%58 = tail call i8* @strerror(i32 undef)
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %58)
%60 = tail call i32 @exit(i32 -1)
unreachable
61: ; preds = %53, %82
%62 = phi i32 [ %93, %82 ], [ 0, %53 ]
%63 = load i32, i32* @CLOCK_MONOTONIC
%64 = call i32 @clock_gettime(i32 %63, %struct.timespec* %6)
%65 = load i8*, i8** %3
%66 = load i8*, i8** %4
%67 = call i32 @rename(i8* %65, i8* %66)
%68 = call i32 @fsync(i32 %55)
%69 = load i32, i32* @CLOCK_MONOTONIC
%70 = call i32 @clock_gettime(i32 %69, %struct.timespec* %8)
%71 = icmp eq i32 %67, 0
br i1 %71, label %76, label %72
72: ; preds = %61
%73 = call i8* @strerror(i32 undef)
%74 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i8* %73)
%75 = call i32 @exit(i32 -1)
unreachable
76: ; preds = %61
%77 = icmp eq i32 %68, 0
br i1 %77, label %82, label %78
78: ; preds = %76
%79 = call i8* @strerror(i32 undef)
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), i8* %79)
%81 = call i32 @exit(i32 -1)
unreachable
82: ; preds = %76
%83 = load <2 x double>, <2 x double>* %7
%84 = load <2 x double>, <2 x double>* %5
%85 = fsub <2 x double> %83, %84
%86 = extractelement <2 x double> %85, i64 1
%87 = fdiv double %86, 1.000000e+09
%88 = extractelement <2 x double> %85, i64 0
%89 = fadd double %88, %87
%90 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0), i8* %14, double %18, double %89)
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0), i8* %14, double %18, double %89)
%92 = call i32 @swap(i8** %3, i8** %4)
%93 = add nuw nsw i32 %62, 1
%94 = icmp eq i32 %93, 100
br i1 %94, label %95, label %61
95: ; preds = %82
%96 = call i32 @free(i8* %28)
%97 = call i32 @close(i32 %33)
%98 = call i32 @close(i32 %55)
br label %99
99: ; preds = %95, %35
%100 = phi i32 [ -1, %35 ], [ 0, %95 ]
ret i32 %100
}