#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 /*<<< orphan*/ printf(char *, double);
void human_readable_filesize(size_t filesize) {
  static const unsigned long long bytes_in_KiB = 1024;
  static const unsigned long long bytes_in_MiB = 1048576;
  static const unsigned long long bytes_in_GiB = 1073741824;
  static const unsigned long long bytes_in_TiB = 1099511627776;
  static const unsigned long long bytes_in_PiB = 1125899906842624;
  static const unsigned long long bytes_in_EiB = 1152921504606846976;
  if (filesize < bytes_in_KiB)
    printf("%zu B ", filesize);
  else if (filesize < bytes_in_MiB)
    printf("%.2lf KiB ", (double)filesize / bytes_in_KiB);
  else if (filesize < bytes_in_GiB)
    printf("%.2lf MiB ", (double)filesize / bytes_in_MiB);
  else if (filesize < bytes_in_TiB)
    printf("%.2lf GiB ", (double)filesize / bytes_in_GiB);
  else if (filesize < bytes_in_PiB)
    printf("%.2lf TiB ", (double)filesize / bytes_in_TiB);
  else if (filesize < bytes_in_EiB)
    printf("%.2lf PiB ", (double)filesize / bytes_in_PiB);
}


x86 assembly (clang, -O0):
<human_readable_filesize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x400,-0x8(%rbp)
jae    1162 <human_readable_filesize+0x52>
movaps 0xeff(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xefe(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
lea    0xf28(%rip),%rdi
call   1030 <printf@plt>
jmp    1322 <human_readable_filesize+0x212>
cmpq   $0x100000,-0x8(%rbp)
jae    11b4 <human_readable_filesize+0xa4>
movaps 0xeb9(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xeb8(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe81(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xedd(%rip),%rdi
call   1030 <printf@plt>
jmp    131d <human_readable_filesize+0x20d>
cmpq   $0x40000000,-0x8(%rbp)
40
jae    1206 <human_readable_filesize+0xf6>
movaps 0xe67(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe66(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe27(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe96(%rip),%rdi
call   1030 <printf@plt>
jmp    1318 <human_readable_filesize+0x208>
movabs $0x10000000000,%rax
cmp    %rax,-0x8(%rbp)
jae    125e <human_readable_filesize+0x14e>
movaps 0xe0f(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe0e(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xdc7(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe49(%rip),%rdi
call   1030 <printf@plt>
jmp    1313 <human_readable_filesize+0x203>
movabs $0x4000000000000,%rax
cmp    %rax,-0x8(%rbp)
jae    12b6 <human_readable_filesize+0x1a6>
movaps 0xdb7(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xdb6(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xd67(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xdfc(%rip),%rdi
call   1030 <printf@plt>
jmp    130e <human_readable_filesize+0x1fe>
movabs $0x1000000000000000,%rax
cmp    %rax,-0x8(%rbp)
jae    1309 <human_readable_filesize+0x1f9>
movaps 0xd5f(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xd5e(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xd07(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xdaf(%rip),%rdi
call   1030 <printf@plt>
jmp    130e <human_readable_filesize+0x1fe>
jmp    1313 <human_readable_filesize+0x203>
jmp    1318 <human_readable_filesize+0x208>
jmp    131d <human_readable_filesize+0x20d>
jmp    1322 <human_readable_filesize+0x212>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<human_readable_filesize>:
cmp    $0x3ff,%rdi
ja     1146 <human_readable_filesize+0x36>
movq   %rdi,%xmm1
punpckldq 0xeda(%rip),%xmm1
subpd  0xee2(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
lea    0xf07(%rip),%rdi
jmp    1030 <printf@plt>
cmp    $0xfffff,%rdi
ja     1184 <human_readable_filesize+0x74>
movq   %rdi,%xmm1
punpckldq 0xea4(%rip),%xmm1
subpd  0xeac(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xec8(%rip),%xmm0
lea    0xed0(%rip),%rdi
jmp    1030 <printf@plt>
cmp    $0x3fffffff,%rdi
ja     11c2 <human_readable_filesize+0xb2>
movq   %rdi,%xmm1
punpckldq 0xe66(%rip),%xmm1
subpd  0xe6e(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xe82(%rip),%xmm0
lea    0xe9d(%rip),%rdi
jmp    1030 <printf@plt>
mov    %rdi,%rax
shr    $0x28,%rax
jne    1200 <human_readable_filesize+0xf0>
movq   %rdi,%xmm1
punpckldq 0xe28(%rip),%xmm1
subpd  0xe30(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xe3c(%rip),%xmm0
lea    0xe6a(%rip),%rdi
jmp    1030 <printf@plt>
mov    %rdi,%rax
shr    $0x32,%rax
jne    123e <human_readable_filesize+0x12e>
movq   %rdi,%xmm1
punpckldq 0xdea(%rip),%xmm1
subpd  0xdf2(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xdf6(%rip),%xmm0
lea    0xe37(%rip),%rdi
jmp    1030 <printf@plt>
mov    %rdi,%rax
shr    $0x3c,%rax
jne    127c <human_readable_filesize+0x16c>
movq   %rdi,%xmm1
punpckldq 0xdac(%rip),%xmm1
subpd  0xdb4(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xdb0(%rip),%xmm0
lea    0xe04(%rip),%rdi
jmp    1030 <printf@plt>
ret

LLVM IR (-O0):
@human_readable_filesize.bytes_in_KiB = internal constant i64 1024
@human_readable_filesize.bytes_in_MiB = internal constant i64 1048576
@human_readable_filesize.bytes_in_GiB = internal constant i64 1073741824
@human_readable_filesize.bytes_in_TiB = internal constant i64 1099511627776
@human_readable_filesize.bytes_in_PiB = internal constant i64 1125899906842624
@human_readable_filesize.bytes_in_EiB = internal constant i64 1152921504606846976
@.str = [7 x i8] c"%zu B \00"
@.str.1 = [11 x i8] c"%.2lf KiB \00"
@.str.2 = [11 x i8] c"%.2lf MiB \00"
@.str.3 = [11 x i8] c"%.2lf GiB \00"
@.str.4 = [11 x i8] c"%.2lf TiB \00"
@.str.5 = [11 x i8] c"%.2lf PiB \00"
define void @human_readable_filesize(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = load i64, i64* %2
%4 = icmp ult i64 %3, 1024
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = load i64, i64* %2
%7 = uitofp i64 %6 to double
%8 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %7)
br label %54
9: ; preds = %1
%10 = load i64, i64* %2
%11 = icmp ult i64 %10, 1048576
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load i64, i64* %2
%14 = uitofp i64 %13 to double
%15 = fdiv double %14, 1.024000e+03
%16 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double %15)
br label %53
17: ; preds = %9
%18 = load i64, i64* %2
%19 = icmp ult i64 %18, 1073741824
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i64, i64* %2
%22 = uitofp i64 %21 to double
%23 = fdiv double %22, 0x4130000000000000
%24 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), double %23)
br label %52
25: ; preds = %17
%26 = load i64, i64* %2
%27 = icmp ult i64 %26, 1099511627776
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i64, i64* %2
%30 = uitofp i64 %29 to double
%31 = fdiv double %30, 0x41D0000000000000
%32 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), double %31)
br label %51
33: ; preds = %25
%34 = load i64, i64* %2
%35 = icmp ult i64 %34, 1125899906842624
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = load i64, i64* %2
%38 = uitofp i64 %37 to double
%39 = fdiv double %38, 0x4270000000000000
%40 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), double %39)
br label %50
41: ; preds = %33
%42 = load i64, i64* %2
%43 = icmp ult i64 %42, 1152921504606846976
br i1 %43, label %44, label %49
44: ; preds = %41
%45 = load i64, i64* %2
%46 = uitofp i64 %45 to double
%47 = fdiv double %46, 0x4310000000000000
%48 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), double %47)
br label %49
49: ; preds = %44, %41
br label %50
50: ; preds = %49, %36
br label %51
51: ; preds = %50, %28
br label %52
52: ; preds = %51, %20
br label %53
53: ; preds = %52, %12
br label %54
54: ; preds = %53, %5
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%zu B \00"
@.str.1 = [11 x i8] c"%.2lf KiB \00"
@.str.2 = [11 x i8] c"%.2lf MiB \00"
@.str.3 = [11 x i8] c"%.2lf GiB \00"
@.str.4 = [11 x i8] c"%.2lf TiB \00"
@.str.5 = [11 x i8] c"%.2lf PiB \00"
define void @human_readable_filesize(i64 %0) {
%2 = icmp ult i64 %0, 1024
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = uitofp i64 %0 to double
%5 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %4)
br label %36
6: ; preds = %1
%7 = icmp ult i64 %0, 1048576
br i1 %7, label %8, label %12
8: ; preds = %6
%9 = uitofp i64 %0 to double
%10 = fmul double %9, 0x3F50000000000000
%11 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double %10)
br label %36
12: ; preds = %6
%13 = icmp ult i64 %0, 1073741824
br i1 %13, label %14, label %18
14: ; preds = %12
%15 = uitofp i64 %0 to double
%16 = fmul double %15, 0x3EB0000000000000
%17 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), double %16)
br label %36
18: ; preds = %12
%19 = icmp ult i64 %0, 1099511627776
br i1 %19, label %20, label %24
20: ; preds = %18
%21 = uitofp i64 %0 to double
%22 = fmul double %21, 0x3E10000000000000
%23 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), double %22)
br label %36
24: ; preds = %18
%25 = icmp ult i64 %0, 1125899906842624
br i1 %25, label %26, label %30
26: ; preds = %24
%27 = uitofp i64 %0 to double
%28 = fmul double %27, 0x3D70000000000000
%29 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), double %28)
br label %36
30: ; preds = %24
%31 = icmp ult i64 %0, 1152921504606846976
br i1 %31, label %32, label %36
32: ; preds = %30
%33 = uitofp i64 %0 to double
%34 = fmul double %33, 0x3CD0000000000000
%35 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), double %34)
br label %36
36: ; preds = %8, %20, %30, %32, %26, %14, %3
ret void
}