#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 time_t;
struct statvfs {
  size_t f_bsize;
  scalar_t__ f_bfree;
  scalar_t__ f_frsize;
};

/* Variables and functions */
char *adjust_unit(double *);
int /*<<< orphan*/ assert(int);
int create_and_fill_file(char const *, int, size_t, int);
int /*<<< orphan*/ printf(char *, double, char *);
scalar_t__ statvfs(char const *, struct statvfs *);
int time(int /*<<< orphan*/ *);
void fill_fs(const char *path) {
  struct statvfs fs;
  double free_space1, free_space2;
  time_t t1, t2, dt;
  int i, fine;
  size_t block_size;
  double f, write_speed;
  char *unit;
  assert(statvfs(path, &fs) == 0);
  free_space1 = (double)fs.f_frsize * (double)fs.f_bfree;
  block_size = fs.f_bsize;
  f = free_space1;
  unit = adjust_unit(&f);
  printf("Free space: %.2f %s\n", f, unit);
  t1 = time(NULL);
  i = 0;
  fine = 1;
  do {
    fine = create_and_fill_file(path, i, block_size, (1024 * 1024 * 1024));
    i++;
  } while (fine);
  assert(statvfs(path, &fs) == 0);
  free_space2 = (double)fs.f_frsize * (double)fs.f_bfree;
  f = free_space2;
  unit = adjust_unit(&f);
  printf("Free space: %.2f %s\n", f, unit);
  t2 = time(NULL);
  dt = t2 - t1;
  dt = dt > 0 ? dt : 1;
  write_speed = (free_space1 - free_space2) / (double)dt;
  unit = adjust_unit(&write_speed);
  printf("Writing speed: %.2f %s/s\n", write_speed, unit);
}


x86 assembly (clang, -O0):
<fill_fs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <statvfs@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cvtsi2sdq -0x10(%rbp),%xmm0
cvtsi2sdq -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
lea    -0x58(%rbp),%rdi
call   1070 <adjust_unit@plt>
mov    %rax,-0x68(%rbp)
movsd  -0x58(%rbp),%xmm0
mov    -0x68(%rbp),%rsi
lea    0xe32(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x40(%rbp),%esi
mov    -0x50(%rbp),%rdx
mov    $0x40000000,%ecx
call   1080 <create_and_fill_file@plt>
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x44(%rbp)
jne    11ed <fill_fs+0x8d>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <statvfs@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cvtsi2sdq -0x10(%rbp),%xmm0
cvtsi2sdq -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
lea    -0x58(%rbp),%rdi
call   1070 <adjust_unit@plt>
mov    %rax,-0x68(%rbp)
movsd  -0x58(%rbp),%xmm0
mov    -0x68(%rbp),%rsi
lea    0xd8e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
sub    -0x34(%rbp),%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jle    12a1 <fill_fs+0x141>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x6c(%rbp)
jmp    12ae <fill_fs+0x14e>
mov    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    12ae <fill_fs+0x14e>
mov    -0x6c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
cvtsi2sdl -0x3c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
lea    -0x60(%rbp),%rdi
call   1070 <adjust_unit@plt>
mov    %rax,-0x68(%rbp)
movsd  -0x60(%rbp),%xmm0
mov    -0x68(%rbp),%rsi
lea    0xd2c(%rip),%rdi
call   1030 <printf@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_fs>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%r15
lea    0x10(%rsp),%rsi
call   1060 <statvfs@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
cvtsi2sdq 0x20(%rsp),%xmm0
cvtsi2sdq 0x18(%rsp),%xmm1
mulsd  %xmm0,%xmm1
mov    0x10(%rsp),%rbp
movsd  %xmm1,0x30(%rsp)
movsd  %xmm1,(%rsp)
mov    %rsp,%rdi
call   1070 <adjust_unit@plt>
movsd  (%rsp),%xmm0
lea    0xe45(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %ebx,%ebx
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%r14d
nop
mov    %r15,%rdi
mov    %ebx,%esi
mov    %rbp,%rdx
mov    $0x40000000,%ecx
call   1080 <create_and_fill_file@plt>
add    $0x1,%ebx
test   %eax,%eax
jne    11d0 <fill_fs+0x70>
lea    0x10(%rsp),%rsi
mov    %r15,%rdi
call   1060 <statvfs@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
xorps  %xmm0,%xmm0
cvtsi2sdq 0x20(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq 0x18(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x28(%rsp)
movsd  %xmm1,(%rsp)
mov    %rsp,%rdi
call   1070 <adjust_unit@plt>
movsd  (%rsp),%xmm0
lea    0xdc5(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <time@plt>
sub    %r14d,%eax
test   %eax,%eax
mov    $0x1,%ecx
cmovg  %eax,%ecx
movsd  0x30(%rsp),%xmm1
subsd  0x28(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1070 <adjust_unit@plt>
movsd  0x8(%rsp),%xmm0
lea    0xd8a(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.statvfs = type { i64, i64, i64 }
@.str = [21 x i8] c"Free space: %.2f %s\0A\00"
@.str.1 = [26 x i8] c"Writing speed: %.2f %s/s\0A\00"
define void @fill_fs(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.statvfs
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca double
%13 = alloca double
%14 = alloca i8*
store i8* %0, i8** %2
%15 = load i8*, i8** %2
%16 = call i64 @statvfs(i8* %15, %struct.statvfs* %3)
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %3, i32 0, i32 2
%21 = load i64, i64* %20
%22 = sitofp i64 %21 to double
%23 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %3, i32 0, i32 1
%24 = load i64, i64* %23
%25 = sitofp i64 %24 to double
%26 = fmul double %22, %25
store double %26, double* %4
%27 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %3, i32 0, i32 0
%28 = load i64, i64* %27
store i64 %28, i64* %11
%29 = load double, double* %4
store double %29, double* %12
%30 = call i8* @adjust_unit(double* %12)
store i8* %30, i8** %14
%31 = load double, double* %12
%32 = load i8*, i8** %14
%33 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), double %31, i8* %32)
%34 = call i32 @time(i32* null)
store i32 %34, i32* %6
store i32 0, i32* %9
store i32 1, i32* %10
br label %35
35: ; preds = %42, %1
%36 = load i8*, i8** %2
%37 = load i32, i32* %9
%38 = load i64, i64* %11
%39 = call i32 @create_and_fill_file(i8* %36, i32 %37, i64 %38, i32 1073741824)
store i32 %39, i32* %10
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
br label %42
42: ; preds = %35
%43 = load i32, i32* %10
%44 = icmp ne i32 %43, 0
br i1 %44, label %35, label %45
45: ; preds = %42
%46 = load i8*, i8** %2
%47 = call i64 @statvfs(i8* %46, %struct.statvfs* %3)
%48 = icmp eq i64 %47, 0
%49 = zext i1 %48 to i32
%50 = call i32 @assert(i32 %49)
%51 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %3, i32 0, i32 2
%52 = load i64, i64* %51
%53 = sitofp i64 %52 to double
%54 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %3, i32 0, i32 1
%55 = load i64, i64* %54
%56 = sitofp i64 %55 to double
%57 = fmul double %53, %56
store double %57, double* %5
%58 = load double, double* %5
store double %58, double* %12
%59 = call i8* @adjust_unit(double* %12)
store i8* %59, i8** %14
%60 = load double, double* %12
%61 = load i8*, i8** %14
%62 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), double %60, i8* %61)
%63 = call i32 @time(i32* null)
store i32 %63, i32* %7
%64 = load i32, i32* %7
%65 = load i32, i32* %6
%66 = sub nsw i32 %64, %65
store i32 %66, i32* %8
%67 = load i32, i32* %8
%68 = icmp sgt i32 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %45
%70 = load i32, i32* %8
br label %72
71: ; preds = %45
br label %72
72: ; preds = %71, %69
%73 = phi i32 [ %70, %69 ], [ 1, %71 ]
store i32 %73, i32* %8
%74 = load double, double* %4
%75 = load double, double* %5
%76 = fsub double %74, %75
%77 = load i32, i32* %8
%78 = sitofp i32 %77 to double
%79 = fdiv double %76, %78
store double %79, double* %13
%80 = call i8* @adjust_unit(double* %13)
store i8* %80, i8** %14
%81 = load double, double* %13
%82 = load i8*, i8** %14
%83 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), double %81, i8* %82)
ret void
}

LLVM IR (-O2):
%struct.statvfs = type { i64, i64, i64 }
@.str = [21 x i8] c"Free space: %.2f %s\0A\00"
@.str.1 = [26 x i8] c"Writing speed: %.2f %s/s\0A\00"
define void @fill_fs(i8* %0) {
%2 = alloca %struct.statvfs
%3 = alloca double
%4 = alloca double
%5 = bitcast %struct.statvfs* %2 to i8*
%6 = bitcast double* %3 to i8*
%7 = bitcast double* %4 to i8*
%8 = call i64 @statvfs(i8* %0, %struct.statvfs* %2)
%9 = icmp eq i64 %8, 0
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %2, i64 0, i32 2
%13 = load i64, i64* %12
%14 = sitofp i64 %13 to double
%15 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %2, i64 0, i32 1
%16 = load i64, i64* %15
%17 = sitofp i64 %16 to double
%18 = fmul double %14, %17
%19 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %2, i64 0, i32 0
%20 = load i64, i64* %19
store double %18, double* %3
%21 = call i8* @adjust_unit(double* %3)
%22 = load double, double* %3
%23 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), double %22, i8* %21)
%24 = call i32 @time(i32* null)
br label %25
25: ; preds = %25, %1
%26 = phi i32 [ 0, %1 ], [ %28, %25 ]
%27 = call i32 @create_and_fill_file(i8* %0, i32 %26, i64 %20, i32 1073741824)
%28 = add nuw nsw i32 %26, 1
%29 = icmp eq i32 %27, 0
br i1 %29, label %30, label %25
30: ; preds = %25
%31 = call i64 @statvfs(i8* %0, %struct.statvfs* %2)
%32 = icmp eq i64 %31, 0
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = load i64, i64* %12
%36 = sitofp i64 %35 to double
%37 = load i64, i64* %15
%38 = sitofp i64 %37 to double
%39 = fmul double %36, %38
store double %39, double* %3
%40 = call i8* @adjust_unit(double* %3)
%41 = load double, double* %3
%42 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), double %41, i8* %40)
%43 = call i32 @time(i32* null)
%44 = sub nsw i32 %43, %24
%45 = icmp sgt i32 %44, 1
%46 = select i1 %45, i32 %44, i32 1
%47 = fsub double %18, %39
%48 = sitofp i32 %46 to double
%49 = fdiv double %47, %48
store double %49, double* %4
%50 = call i8* @adjust_unit(double* %4)
%51 = load double, double* %4
%52 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), double %51, i8* %50)
ret void
}