#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned long long);
void humanize_bytes(char buf[], int bufsize, unsigned long long n) {
  double b;
  memset(buf, 0, bufsize);
  b = (double)n;
  if (b > 1099511627776.0)
    snprintf(buf, bufsize, "%.2f TiB", b / 1099511627776.0);
  else if (b > 1073741824.0)
    snprintf(buf, bufsize, "%.2f GiB", b / 1073741824.0);
  else if (b > 1048576.0)
    snprintf(buf, bufsize, "%.2f MiB", b / 1048576.0);
  else if (b > 1024.0)
    snprintf(buf, bufsize, "%.2f KiB", b / 1024.0);
  else
    snprintf(buf, bufsize, "%llu Bytes", n);
}


x86 assembly (clang, -O0):
<humanize_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
movaps 0xee8(%rip),%xmm1
movq   -0x18(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xee7(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe86(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11d3 <humanize_bytes+0xb3>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
movsd  -0x20(%rbp),%xmm0
movsd  0xe68(%rip),%xmm1
divsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rcx
mov    %rcx,%rdx
sar    $0x3f,%rdx
movsd  0xe6d(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
and    %rdx,%rax
or     %rax,%rcx
lea    0xe87(%rip),%rdx
call   1030 <snprintf@plt>
jmp    132b <humanize_bytes+0x20b>
movsd  -0x20(%rbp),%xmm0
movsd  0xe28(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1239 <humanize_bytes+0x119>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
movsd  -0x20(%rbp),%xmm0
movsd  0xe0a(%rip),%xmm1
divsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rcx
mov    %rcx,%rdx
sar    $0x3f,%rdx
movsd  0xe07(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
and    %rdx,%rax
or     %rax,%rcx
lea    0xe2a(%rip),%rdx
call   1030 <snprintf@plt>
jmp    1326 <humanize_bytes+0x206>
movsd  -0x20(%rbp),%xmm0
movsd  0xdca(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    129f <humanize_bytes+0x17f>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
movsd  -0x20(%rbp),%xmm0
movsd  0xdac(%rip),%xmm1
divsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rcx
mov    %rcx,%rdx
sar    $0x3f,%rdx
movsd  0xda1(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
and    %rdx,%rax
or     %rax,%rcx
lea    0xdcd(%rip),%rdx
call   1030 <snprintf@plt>
jmp    1321 <humanize_bytes+0x201>
movsd  -0x20(%rbp),%xmm0
movsd  0xd6c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1305 <humanize_bytes+0x1e5>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
movsd  -0x20(%rbp),%xmm0
movsd  0xd4e(%rip),%xmm1
divsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rcx
mov    %rcx,%rdx
sar    $0x3f,%rdx
movsd  0xd3b(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
and    %rdx,%rax
or     %rax,%rcx
lea    0xd70(%rip),%rdx
call   1030 <snprintf@plt>
jmp    131c <humanize_bytes+0x1fc>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rcx
lea    0xd5d(%rip),%rdx
call   1030 <snprintf@plt>
jmp    1321 <humanize_bytes+0x201>
jmp    1326 <humanize_bytes+0x206>
jmp    132b <humanize_bytes+0x20b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<humanize_bytes>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbp
mov    %esi,%r14d
mov    %rdi,%rbx
xor    %esi,%esi
mov    %r14d,%edx
call   1040 <memset@plt>
movq   %rbp,%xmm1
punpckldq 0xebc(%rip),%xmm1
subpd  0xec4(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
movabs $0x10000000001,%rax
cmp    %rax,%rbp
jb     119a <humanize_bytes+0x7a>
mulsd  0xed1(%rip),%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,%rdx
subsd  0xea9(%rip),%xmm0
cvttsd2si %xmm0,%rcx
sar    $0x3f,%rdx
and    %rdx,%rcx
or     %rax,%rcx
lea    0xeb3(%rip),%rdx
jmp    1243 <humanize_bytes+0x123>
cmp    $0x40000001,%rbp
jb     11d3 <humanize_bytes+0xb3>
mulsd  0xe8d(%rip),%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,%rdx
subsd  0xe6d(%rip),%xmm0
cvttsd2si %xmm0,%rcx
sar    $0x3f,%rdx
and    %rdx,%rcx
or     %rax,%rcx
lea    0xe80(%rip),%rdx
jmp    1243 <humanize_bytes+0x123>
cmp    $0x100001,%rbp
jb     120c <humanize_bytes+0xec>
mulsd  0xe4c(%rip),%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,%rdx
subsd  0xe34(%rip),%xmm0
cvttsd2si %xmm0,%rcx
sar    $0x3f,%rdx
and    %rdx,%rcx
or     %rax,%rcx
lea    0xe50(%rip),%rdx
jmp    1243 <humanize_bytes+0x123>
cmp    $0x401,%rbp
jb     1252 <humanize_bytes+0x132>
mulsd  0xe03(%rip),%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,%rdx
subsd  0xdfb(%rip),%xmm0
cvttsd2si %xmm0,%rcx
sar    $0x3f,%rdx
and    %rdx,%rcx
or     %rax,%rcx
lea    0xe20(%rip),%rdx
mov    %rbx,%rdi
mov    %r14d,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <snprintf@plt>
lea    0xe13(%rip),%rdx
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %rbp,%rcx
jmp    1249 <humanize_bytes+0x129>

LLVM IR (-O0):
@.str = [9 x i8] c"%.2f TiB\00"
@.str.1 = [9 x i8] c"%.2f GiB\00"
@.str.2 = [9 x i8] c"%.2f MiB\00"
@.str.3 = [9 x i8] c"%.2f KiB\00"
@.str.4 = [11 x i8] c"%llu Bytes\00"
define void @humanize_bytes(i8* %0, i32 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca double
store i8* %0, i8** %4
store i32 %1, i32* %5
store i64 %2, i64* %6
%8 = load i8*, i8** %4
%9 = load i32, i32* %5
%10 = call i32 @memset(i8* %8, i32 0, i32 %9)
%11 = load i64, i64* %6
%12 = uitofp i64 %11 to double
store double %12, double* %7
%13 = load double, double* %7
%14 = fcmp ogt double %13, 0x4270000000000000
br i1 %14, label %15, label %22
15: ; preds = %3
%16 = load i8*, i8** %4
%17 = load i32, i32* %5
%18 = load double, double* %7
%19 = fdiv double %18, 0x4270000000000000
%20 = fptoui double %19 to i64
%21 = call i32 @snprintf(i8* %16, i32 %17, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 %20)
br label %60
22: ; preds = %3
%23 = load double, double* %7
%24 = fcmp ogt double %23, 0x41D0000000000000
br i1 %24, label %25, label %32
25: ; preds = %22
%26 = load i8*, i8** %4
%27 = load i32, i32* %5
%28 = load double, double* %7
%29 = fdiv double %28, 0x41D0000000000000
%30 = fptoui double %29 to i64
%31 = call i32 @snprintf(i8* %26, i32 %27, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i64 %30)
br label %59
32: ; preds = %22
%33 = load double, double* %7
%34 = fcmp ogt double %33, 0x4130000000000000
br i1 %34, label %35, label %42
35: ; preds = %32
%36 = load i8*, i8** %4
%37 = load i32, i32* %5
%38 = load double, double* %7
%39 = fdiv double %38, 0x4130000000000000
%40 = fptoui double %39 to i64
%41 = call i32 @snprintf(i8* %36, i32 %37, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i64 %40)
br label %58
42: ; preds = %32
%43 = load double, double* %7
%44 = fcmp ogt double %43, 1.024000e+03
br i1 %44, label %45, label %52
45: ; preds = %42
%46 = load i8*, i8** %4
%47 = load i32, i32* %5
%48 = load double, double* %7
%49 = fdiv double %48, 1.024000e+03
%50 = fptoui double %49 to i64
%51 = call i32 @snprintf(i8* %46, i32 %47, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 %50)
br label %57
52: ; preds = %42
%53 = load i8*, i8** %4
%54 = load i32, i32* %5
%55 = load i64, i64* %6
%56 = call i32 @snprintf(i8* %53, i32 %54, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i64 %55)
br label %57
57: ; preds = %52, %45
br label %58
58: ; preds = %57, %35
br label %59
59: ; preds = %58, %25
br label %60
60: ; preds = %59, %15
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"%.2f TiB\00"
@.str.1 = [9 x i8] c"%.2f GiB\00"
@.str.2 = [9 x i8] c"%.2f MiB\00"
@.str.3 = [9 x i8] c"%.2f KiB\00"
@.str.4 = [11 x i8] c"%llu Bytes\00"
define void @humanize_bytes(i8* %0, i32 %1, i64 %2) {
%4 = tail call i32 @memset(i8* %0, i32 0, i32 %1)
%5 = uitofp i64 %2 to double
%6 = icmp ugt i64 %2, 1099511627776
br i1 %6, label %7, label %11
7: ; preds = %3
%8 = fmul double %5, 0x3D70000000000000
%9 = fptoui double %8 to i64
%10 = tail call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 %9)
br label %31
11: ; preds = %3
%12 = icmp ugt i64 %2, 1073741824
br i1 %12, label %13, label %17
13: ; preds = %11
%14 = fmul double %5, 0x3E10000000000000
%15 = fptoui double %14 to i64
%16 = tail call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i64 %15)
br label %31
17: ; preds = %11
%18 = icmp ugt i64 %2, 1048576
br i1 %18, label %19, label %23
19: ; preds = %17
%20 = fmul double %5, 0x3EB0000000000000
%21 = fptoui double %20 to i64
%22 = tail call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i64 %21)
br label %31
23: ; preds = %17
%24 = icmp ugt i64 %2, 1024
br i1 %24, label %25, label %29
25: ; preds = %23
%26 = fmul double %5, 0x3F50000000000000
%27 = fptoui double %26 to i64
%28 = tail call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 %27)
br label %31
29: ; preds = %23
%30 = tail call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i64 %2)
br label %31
31: ; preds = %13, %25, %29, %19, %7
ret void
}