#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 unsigned long long uint64_t;
struct statvfs {
  scalar_t__ f_bfree;
  scalar_t__ f_bsize;
};

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, ...);
scalar_t__ statvfs(char *, struct statvfs *);
void put_vfs_free(char *out, void *arg) {
  struct statvfs vfs_info;
  if (statvfs((char *)arg, &vfs_info) < 0) {
    sprintf(out, "??");
    return;
  }
  uint64_t bytes = (uint64_t)vfs_info.f_bsize * (uint64_t)vfs_info.f_bfree;
  if (bytes > (1024ULL * 1024 * 1024 * 1024))
    sprintf(out, "%.02f TB", (double)bytes / (1024ULL * 1024 * 1024 * 1024));
  else if (bytes > (1024ULL * 1024 * 1024))
    sprintf(out, "%.01f GB", (double)bytes / (1024ULL * 1024 * 1024));
  else if (bytes > (1024ULL * 1024))
    sprintf(out, "%.01f MB", (double)bytes / (1024ULL * 1024));
  else if (bytes > (1024ULL))
    sprintf(out, "%.01f KB", (double)bytes / (1024ULL));
  else {
    sprintf(out, "%.01f B", (double)bytes);
  }
}


x86 assembly (clang, -O0):
<put_vfs_free>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <statvfs@plt>
cmp    $0x0,%rax
jge    115e <put_vfs_free+0x3e>
mov    -0x8(%rbp),%rdi
lea    0xeee(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    1319 <put_vfs_free+0x1f9>
mov    -0x18(%rbp),%rax
imul   -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
movabs $0x10000000000,%rax
cmp    %rax,-0x28(%rbp)
jbe    11c9 <put_vfs_free+0xa9>
mov    -0x8(%rbp),%rdi
movaps 0xe76(%rip),%xmm1
movq   -0x28(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe75(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe86(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe86(%rip),%rsi
mov    $0x1,%al
call   1040 <sprintf@plt>
jmp    1319 <put_vfs_free+0x1f9>
cmpq   $0x40000000,-0x28(%rbp)
40
jbe    1221 <put_vfs_free+0x101>
mov    -0x8(%rbp),%rdi
movaps 0xe1e(%rip),%xmm1
movq   -0x28(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe1d(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe26(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe37(%rip),%rsi
mov    $0x1,%al
call   1040 <sprintf@plt>
jmp    1314 <put_vfs_free+0x1f4>
cmpq   $0x100000,-0x28(%rbp)
jbe    1279 <put_vfs_free+0x159>
mov    -0x8(%rbp),%rdi
movaps 0xdc6(%rip),%xmm1
movq   -0x28(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xdc5(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xdc6(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xde8(%rip),%rsi
mov    $0x1,%al
call   1040 <sprintf@plt>
jmp    130f <put_vfs_free+0x1ef>
cmpq   $0x400,-0x28(%rbp)
jbe    12d1 <put_vfs_free+0x1b1>
mov    -0x8(%rbp),%rdi
movaps 0xd6e(%rip),%xmm1
movq   -0x28(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xd6d(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xd66(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xd99(%rip),%rsi
mov    $0x1,%al
call   1040 <sprintf@plt>
jmp    130a <put_vfs_free+0x1ea>
mov    -0x8(%rbp),%rdi
movaps 0xd24(%rip),%xmm1
movq   -0x28(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xd23(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
lea    0xd64(%rip),%rsi
mov    $0x1,%al
call   1040 <sprintf@plt>
jmp    130f <put_vfs_free+0x1ef>
jmp    1314 <put_vfs_free+0x1f4>
jmp    1319 <put_vfs_free+0x1f9>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<put_vfs_free>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rax
mov    %rdi,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
call   1030 <statvfs@plt>
test   %rax,%rax
js     1189 <put_vfs_free+0x69>
mov    (%rsp),%rax
imul   0x8(%rsp),%rax
movabs $0x10000000001,%rcx
cmp    %rcx,%rax
jb     1197 <put_vfs_free+0x77>
movq   %rax,%xmm1
punpckldq 0xe9f(%rip),%xmm1
subpd  0xea7(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xebb(%rip),%xmm0
lea    0xebf(%rip),%rsi
jmp    124c <put_vfs_free+0x12c>
movb   $0x0,0x2(%rbx)
movw   $0x3f3f,(%rbx)
jmp    1256 <put_vfs_free+0x136>
cmp    $0x40000001,%rax
jb     11d1 <put_vfs_free+0xb1>
movq   %rax,%xmm1
punpckldq 0xe54(%rip),%xmm1
subpd  0xe5c(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xe68(%rip),%xmm0
lea    0xe7d(%rip),%rsi
jmp    124c <put_vfs_free+0x12c>
cmp    $0x100001,%rax
jb     120b <put_vfs_free+0xeb>
movq   %rax,%xmm1
punpckldq 0xe1a(%rip),%xmm1
subpd  0xe22(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xe26(%rip),%xmm0
lea    0xe4c(%rip),%rsi
jmp    124c <put_vfs_free+0x12c>
movq   %rax,%xmm1
punpckldq 0xde8(%rip),%xmm1
subpd  0xdf0(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
cmp    $0x401,%rax
jb     1245 <put_vfs_free+0x125>
mulsd  0xde4(%rip),%xmm0
lea    0xe1b(%rip),%rsi
jmp    124c <put_vfs_free+0x12c>
lea    0xe1b(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <sprintf@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.statvfs = type { i64, i64 }
@.str = [3 x i8] c"??\00"
@.str.1 = [9 x i8] c"%.02f TB\00"
@.str.2 = [9 x i8] c"%.01f GB\00"
@.str.3 = [9 x i8] c"%.01f MB\00"
@.str.4 = [9 x i8] c"%.01f KB\00"
@.str.5 = [8 x i8] c"%.01f B\00"
define void @put_vfs_free(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.statvfs
%6 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i64 @statvfs(i8* %7, %struct.statvfs* %5)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = call i32 (i8*, i8*, ...) @sprintf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %62
13: ; preds = %2
%14 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %5, i32 0, i32 1
%15 = load i64, i64* %14
%16 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %5, i32 0, i32 0
%17 = load i64, i64* %16
%18 = mul i64 %15, %17
store i64 %18, i64* %6
%19 = load i64, i64* %6
%20 = icmp ugt i64 %19, 1099511627776
br i1 %20, label %21, label %27
21: ; preds = %13
%22 = load i8*, i8** %3
%23 = load i64, i64* %6
%24 = uitofp i64 %23 to double
%25 = fdiv double %24, 0x4270000000000000
%26 = call i32 (i8*, i8*, ...) @sprintf(i8* %22, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %25)
br label %62
27: ; preds = %13
%28 = load i64, i64* %6
%29 = icmp ugt i64 %28, 1073741824
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = load i8*, i8** %3
%32 = load i64, i64* %6
%33 = uitofp i64 %32 to double
%34 = fdiv double %33, 0x41D0000000000000
%35 = call i32 (i8*, i8*, ...) @sprintf(i8* %31, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %34)
br label %61
36: ; preds = %27
%37 = load i64, i64* %6
%38 = icmp ugt i64 %37, 1048576
br i1 %38, label %39, label %45
39: ; preds = %36
%40 = load i8*, i8** %3
%41 = load i64, i64* %6
%42 = uitofp i64 %41 to double
%43 = fdiv double %42, 0x4130000000000000
%44 = call i32 (i8*, i8*, ...) @sprintf(i8* %40, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), double %43)
br label %60
45: ; preds = %36
%46 = load i64, i64* %6
%47 = icmp ugt i64 %46, 1024
br i1 %47, label %48, label %54
48: ; preds = %45
%49 = load i8*, i8** %3
%50 = load i64, i64* %6
%51 = uitofp i64 %50 to double
%52 = fdiv double %51, 1.024000e+03
%53 = call i32 (i8*, i8*, ...) @sprintf(i8* %49, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), double %52)
br label %59
54: ; preds = %45
%55 = load i8*, i8** %3
%56 = load i64, i64* %6
%57 = uitofp i64 %56 to double
%58 = call i32 (i8*, i8*, ...) @sprintf(i8* %55, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), double %57)
br label %59
59: ; preds = %54, %48
br label %60
60: ; preds = %59, %39
br label %61
61: ; preds = %60, %30
br label %62
62: ; preds = %10, %61, %21
ret void
}

LLVM IR (-O2):
%struct.statvfs = type { i64, i64 }
@.str = [3 x i8] c"??\00"
@.str.1 = [9 x i8] c"%.02f TB\00"
@.str.2 = [9 x i8] c"%.01f GB\00"
@.str.3 = [9 x i8] c"%.01f MB\00"
@.str.4 = [9 x i8] c"%.01f KB\00"
@.str.5 = [8 x i8] c"%.01f B\00"
define void @put_vfs_free(i8* nocapture writeonly %0, i8* %1) {
%3 = alloca %struct.statvfs
%4 = bitcast %struct.statvfs* %3 to i8*
%5 = call i64 @statvfs(i8* %1, %struct.statvfs* %3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %2
br label %39
8: ; preds = %2
%9 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %3, i64 0, i32 1
%10 = load i64, i64* %9
%11 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %3, i64 0, i32 0
%12 = load i64, i64* %11
%13 = mul i64 %12, %10
%14 = icmp ugt i64 %13, 1099511627776
br i1 %14, label %15, label %19
15: ; preds = %8
%16 = uitofp i64 %13 to double
%17 = fmul double %16, 0x3D70000000000000
%18 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %17)
br label %39
19: ; preds = %8
%20 = icmp ugt i64 %13, 1073741824
br i1 %20, label %21, label %25
21: ; preds = %19
%22 = uitofp i64 %13 to double
%23 = fmul double %22, 0x3E10000000000000
%24 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %23)
br label %39
25: ; preds = %19
%26 = icmp ugt i64 %13, 1048576
br i1 %26, label %27, label %31
27: ; preds = %25
%28 = uitofp i64 %13 to double
%29 = fmul double %28, 0x3EB0000000000000
%30 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), double %29)
br label %39
31: ; preds = %25
%32 = icmp ugt i64 %13, 1024
%33 = uitofp i64 %13 to double
br i1 %32, label %34, label %37
34: ; preds = %31
%35 = fmul double %33, 0x3F50000000000000
%36 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), double %35)
br label %39
37: ; preds = %31
%38 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), double %33)
br label %39
39: ; preds = %15, %27, %37, %34, %21, %7
ret void
}