char *pretty_freespace(const char *desc, unsigned long long *free_k,
                       unsigned long long *total_k) {
  char *quantities[] = {"KiB", "MiB", "GiB", "TiB", "PiB",
                        "EiB", "ZiB", "YiB", 0};
  char *result, **quantity;
  double free_space, total_space;
  free_space = *free_k;
  total_space = *total_k;
  result = malloc(1024 * sizeof(char));
  if (total_space == 0) {
    snprintf(result, 1024, "%s: none", desc);
    return result;
  }
  quantity = quantities;
  while (total_space > 1023 && *(quantity + 1)) {
    quantity++;
    free_space = free_space / 1024;
    total_space = total_space / 1024;
  }
  if (sysinfo_get_percent() != 0)
    snprintf(result, 1024, "%s: %.1f%s, %.1f%% free", desc, total_space,
             *quantity, percentage(free_k, total_k));
  else
    snprintf(result, 1024, "%s: %.1f%s/%.1f%s free", desc, free_space,
             *quantity, total_space, *quantity);
  return result;
}


x86 assembly (clang, -O0):
<pretty_freespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2cb2(%rip),%rax
mov    %rax,-0x30(%rbp)
movaps 0x2c97(%rip),%xmm0
movaps %xmm0,-0x40(%rbp)
movaps 0x2c7c(%rip),%xmm0
movaps %xmm0,-0x50(%rbp)
movaps 0x2c61(%rip),%xmm0
movaps %xmm0,-0x60(%rbp)
movaps 0x2c46(%rip),%xmm0
movaps %xmm0,-0x70(%rbp)
mov    -0x18(%rbp),%rax
movq   (%rax),%xmm0
movaps 0xe63(%rip),%xmm2
punpckldq %xmm2,%xmm0
movapd 0xe67(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm3
unpckhpd %xmm0,%xmm0
addsd  %xmm3,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
mov    -0x20(%rbp),%rax
movq   (%rax),%xmm0
punpckldq %xmm2,%xmm0
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,-0x78(%rbp)
movsd  -0x90(%rbp),%xmm0
ff
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1234 <pretty_freespace+0xf4>
jp     1234 <pretty_freespace+0xf4>
mov    -0x78(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x400,%esi
lea    0xe30(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    -0x78(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1398 <pretty_freespace+0x258>
lea    -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
movsd  -0x90(%rbp),%xmm0
ff
xor    %eax,%eax
movsd  0xdd2(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x91(%rbp)
jbe    1270 <pretty_freespace+0x130>
mov    -0x80(%rbp),%rax
cmpq   $0x0,0x8(%rax)
setne  %al
mov    %al,-0x91(%rbp)
mov    -0x91(%rbp),%al
test   $0x1,%al
jne    1283 <pretty_freespace+0x143>
jmp    12cc <pretty_freespace+0x18c>
mov    -0x80(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x80(%rbp)
movsd  -0x88(%rbp),%xmm0
ff
movsd  0xd89(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x90(%rbp),%xmm0
ff
movsd  0xd6d(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
jmp    123c <pretty_freespace+0xfc>
mov    $0x0,%al
call   1060 <sysinfo_get_percent@plt>
cmp    $0x0,%eax
je     1357 <pretty_freespace+0x217>
mov    -0x78(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0xb0(%rbp)
movsd  -0x90(%rbp),%xmm0
ff
movsd  %xmm0,-0xa8(%rbp)
ff
mov    -0x80(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1040 <percentage@plt>
mov    -0xb8(%rbp),%rdi
mov    -0xb0(%rbp),%rcx
movsd  -0xa8(%rbp),%xmm0
ff
mov    -0xa0(%rbp),%r8
mov    %eax,%r9d
mov    $0x400,%esi
lea    0xd0e(%rip),%rdx
mov    $0x1,%al
call   1030 <snprintf@plt>
jmp    1390 <pretty_freespace+0x250>
mov    -0x78(%rbp),%rdi
mov    -0x10(%rbp),%rcx
movsd  -0x88(%rbp),%xmm0
ff
mov    -0x80(%rbp),%rax
mov    (%rax),%r8
movsd  -0x90(%rbp),%xmm1
ff
mov    -0x80(%rbp),%rax
mov    (%rax),%r9
mov    $0x400,%esi
lea    0xce8(%rip),%rdx
mov    $0x2,%al
call   1030 <snprintf@plt>
mov    -0x78(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pretty_freespace>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%r14
mov    0x2cb2(%rip),%rax
mov    %rax,0x60(%rsp)
movaps 0x2c96(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0x2c7a(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0x2c5e(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0x2c42(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
mov    (%rsi),%rbp
mov    (%rdx),%rbx
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
test   %rbx,%rbx
je     122b <pretty_freespace+0xeb>
movq   %rbx,%xmm0
movdqa 0xe44(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xe48(%rip),%xmm2
subpd  %xmm2,%xmm0
movapd %xmm0,%xmm3
unpckhpd %xmm0,%xmm3
addsd  %xmm0,%xmm3
movq   %rbp,%xmm0
punpckldq %xmm1,%xmm0
subpd  %xmm2,%xmm0
movapd %xmm0,%xmm2
unpckhpd %xmm0,%xmm2
addsd  %xmm0,%xmm2
cmp    $0x400,%rbx
jb     1246 <pretty_freespace+0x106>
lea    0x20(%rsp),%rbx
movsd  0xe19(%rip),%xmm0
movsd  0xe19(%rip),%xmm1
nop
cmpq   $0x0,0x8(%rbx)
je     124b <pretty_freespace+0x10b>
add    $0x8,%rbx
mulsd  %xmm0,%xmm2
mulsd  %xmm0,%xmm3
ucomisd %xmm1,%xmm3
ja     1210 <pretty_freespace+0xd0>
jmp    124b <pretty_freespace+0x10b>
lea    0xe1e(%rip),%rdx
mov    $0x400,%esi
mov    %r12,%rdi
mov    %r14,%rcx
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    12bf <pretty_freespace+0x17f>
lea    0x20(%rsp),%rbx
movapd %xmm2,0x10(%rsp)
movapd %xmm3,(%rsp)
xor    %eax,%eax
call   1060 <sysinfo_get_percent@plt>
mov    (%rbx),%rbx
test   %eax,%eax
je     1296 <pretty_freespace+0x156>
mov    %r13,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <percentage@plt>
lea    0xde1(%rip),%rdx
mov    $0x400,%esi
mov    %r12,%rdi
mov    %r14,%rcx
movaps (%rsp),%xmm0
mov    %rbx,%r8
mov    %eax,%r9d
mov    $0x1,%al
call   1030 <snprintf@plt>
jmp    12bf <pretty_freespace+0x17f>
lea    0xdd4(%rip),%rdx
mov    $0x400,%esi
mov    %r12,%rdi
mov    %r14,%rcx
movaps 0x10(%rsp),%xmm0
mov    %rbx,%r8
movapd (%rsp),%xmm1
mov    %rbx,%r9
mov    $0x2,%al
call   1030 <snprintf@plt>
mov    %r12,%rax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"KiB\00"
@.str.1 = [4 x i8] c"MiB\00"
@.str.2 = [4 x i8] c"GiB\00"
@.str.3 = [4 x i8] c"TiB\00"
@.str.4 = [4 x i8] c"PiB\00"
@.str.5 = [4 x i8] c"EiB\00"
@.str.6 = [4 x i8] c"ZiB\00"
@.str.7 = [4 x i8] c"YiB\00"
@__const.pretty_freespace.quantities = [9 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i32 0, i32 0), i8* null]
@.str.8 = [9 x i8] c"%s: none\00"
@.str.9 = [24 x i8] c"%s: %.1f%s, %.1f%% free\00"
@.str.10 = [23 x i8] c"%s: %.1f%s/%.1f%s free\00"
define i8* @pretty_freespace(i8* %0, i64* %1, i64* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64*
%7 = alloca i64*
%8 = alloca [9 x i8*]
%9 = alloca i8*
%10 = alloca i8**
%11 = alloca double
%12 = alloca double
store i8* %0, i8** %5
store i64* %1, i64** %6
store i64* %2, i64** %7
%13 = bitcast [9 x i8*]* %8 to i8*
%14 = load i64*, i64** %6
%15 = load i64, i64* %14
%16 = uitofp i64 %15 to double
store double %16, double* %11
%17 = load i64*, i64** %7
%18 = load i64, i64* %17
%19 = uitofp i64 %18 to double
store double %19, double* %12
%20 = call i8* @malloc(i64 1024)
store i8* %20, i8** %9
%21 = load double, double* %12
%22 = fcmp oeq double %21, 0.000000e+00
br i1 %22, label %23, label %28
23: ; preds = %3
%24 = load i8*, i8** %9
%25 = load i8*, i8** %5
%26 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %24, i64 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* %25)
%27 = load i8*, i8** %9
store i8* %27, i8** %4
br label %72
28: ; preds = %3
%29 = getelementptr inbounds [9 x i8*], [9 x i8*]* %8, i64 0, i64 0
store i8** %29, i8*** %10
br label %30
30: ; preds = %40, %28
%31 = load double, double* %12
%32 = fcmp ogt double %31, 1.023000e+03
br i1 %32, label %33, label %38
33: ; preds = %30
%34 = load i8**, i8*** %10
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = icmp ne i8* %36, null
br label %38
38: ; preds = %33, %30
%39 = phi i1 [ false, %30 ], [ %37, %33 ]
br i1 %39, label %40, label %47
40: ; preds = %38
%41 = load i8**, i8*** %10
%42 = getelementptr inbounds i8*, i8** %41, i32 1
store i8** %42, i8*** %10
%43 = load double, double* %11
%44 = fdiv double %43, 1.024000e+03
store double %44, double* %11
%45 = load double, double* %12
%46 = fdiv double %45, 1.024000e+03
store double %46, double* %12
br label %30
47: ; preds = %38
%48 = call i32 (...) @sysinfo_get_percent()
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %60
50: ; preds = %47
%51 = load i8*, i8** %9
%52 = load i8*, i8** %5
%53 = load double, double* %12
%54 = load i8**, i8*** %10
%55 = load i8*, i8** %54
%56 = load i64*, i64** %6
%57 = load i64*, i64** %7
%58 = call i32 (i64*, i64*, ...) bitcast (i32 (...)* @percentage to i32 (i64*, i64*, ...)*)(i64* %56, i64* %57)
%59 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %51, i64 1024, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i8* %52, double %53, i8* %55, i32 %58)
br label %70
60: ; preds = %47
%61 = load i8*, i8** %9
%62 = load i8*, i8** %5
%63 = load double, double* %11
%64 = load i8**, i8*** %10
%65 = load i8*, i8** %64
%66 = load double, double* %12
%67 = load i8**, i8*** %10
%68 = load i8*, i8** %67
%69 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %61, i64 1024, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), i8* %62, double %63, i8* %65, double %66, i8* %68)
br label %70
70: ; preds = %60, %50
%71 = load i8*, i8** %9
store i8* %71, i8** %4
br label %72
72: ; preds = %70, %23
%73 = load i8*, i8** %4
ret i8* %73
}

LLVM IR (-O2):
@.str = [4 x i8] c"KiB\00"
@.str.1 = [4 x i8] c"MiB\00"
@.str.2 = [4 x i8] c"GiB\00"
@.str.3 = [4 x i8] c"TiB\00"
@.str.4 = [4 x i8] c"PiB\00"
@.str.5 = [4 x i8] c"EiB\00"
@.str.6 = [4 x i8] c"ZiB\00"
@.str.7 = [4 x i8] c"YiB\00"
@__const.pretty_freespace.quantities = [9 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i32 0, i32 0), i8* null]
@.str.8 = [9 x i8] c"%s: none\00"
@.str.9 = [24 x i8] c"%s: %.1f%s, %.1f%% free\00"
@.str.10 = [23 x i8] c"%s: %.1f%s/%.1f%s free\00"
define i8* @pretty_freespace(i8* %0, i64* %1, i64* %2) {
%4 = alloca [9 x i8*]
%5 = bitcast [9 x i8*]* %4 to i8*
%6 = load i64, i64* %1
%7 = load i64, i64* %2
%8 = tail call dereferenceable_or_null(1024) i8* @malloc(i64 1024)
%9 = icmp eq i64 %7, 0
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* dereferenceable(1) %8, i64 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* %0)
br label %40
12: ; preds = %3
%13 = uitofp i64 %7 to double
%14 = uitofp i64 %6 to double
%15 = getelementptr inbounds [9 x i8*], [9 x i8*]* %4, i64 0, i64 0
%16 = icmp ugt i64 %7, 1023
br i1 %16, label %17, label %28
17: ; preds = %12, %24
%18 = phi double [ %26, %24 ], [ %13, %12 ]
%19 = phi double [ %25, %24 ], [ %14, %12 ]
%20 = phi i8** [ %21, %24 ], [ %15, %12 ]
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = icmp eq i8* %22, null
br i1 %23, label %28, label %24
24: ; preds = %17
%25 = fmul double %19, 0x3F50000000000000
%26 = fmul double %18, 0x3F50000000000000
%27 = fcmp ogt double %26, 1.023000e+03
br i1 %27, label %17, label %28
28: ; preds = %17, %24, %12
%29 = phi i8** [ %15, %12 ], [ %21, %24 ], [ %20, %17 ]
%30 = phi double [ %14, %12 ], [ %25, %24 ], [ %19, %17 ]
%31 = phi double [ %13, %12 ], [ %26, %24 ], [ %18, %17 ]
%32 = tail call i32 (...) @sysinfo_get_percent()
%33 = icmp eq i32 %32, 0
%34 = load i8*, i8** %29
br i1 %33, label %38, label %35
35: ; preds = %28
%36 = tail call i32 (i64*, i64*, ...) bitcast (i32 (...)* @percentage to i32 (i64*, i64*, ...)*)(i64* %1, i64* %2)
%37 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* dereferenceable(1) %8, i64 1024, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i8* %0, double %31, i8* %34, i32 %36)
br label %40
38: ; preds = %28
%39 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* dereferenceable(1) %8, i64 1024, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), i8* %0, double %30, i8* %34, double %31, i8* %34)
br label %40
40: ; preds = %35, %38, %10
ret i8* %8
}