#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*/ sprintf(char *, char *, double);
void make_human_readable(char *human_readable, long int number) {
  if (number > ((double)1024 * 1024 * 1024 * 1024))
    sprintf(human_readable, "%.2lf TB",
            (double)number / ((double)1024 * 1024 * 1024 * 1024));
  else if (number > ((double)1024 * 1024 * 1024))
    sprintf(human_readable, "%.2lf GB",
            (double)(number / ((double)1024 * 1024 * 1024)));
  else if (number > ((double)1024 * 1024))
    sprintf(human_readable, "%.2lf MB", (double)number / ((double)1024 * 1024));
  else if (number > ((double)1024))
    sprintf(human_readable, "%.2lf kB", (double)number / ((double)1024));
  else
    sprintf(human_readable, "%.2lf B", (double)number);
}


x86 assembly (clang, -O0):
<make_human_readable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cvtsi2sdq -0x10(%rbp),%xmm0
movsd  0xed2(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    115f <make_human_readable+0x4f>
mov    -0x8(%rbp),%rdi
cvtsi2sdq -0x10(%rbp),%xmm0
movsd  0xeb6(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xecb(%rip),%rsi
call   1030 <sprintf@plt>
jmp    1241 <make_human_readable+0x131>
cvtsi2sdq -0x10(%rbp),%xmm0
movsd  0xe9b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    119e <make_human_readable+0x8e>
mov    -0x8(%rbp),%rdi
cvtsi2sdq -0x10(%rbp),%xmm0
movsd  0xe7f(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe95(%rip),%rsi
call   1030 <sprintf@plt>
jmp    123c <make_human_readable+0x12c>
cvtsi2sdq -0x10(%rbp),%xmm0
movsd  0xe64(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11dd <make_human_readable+0xcd>
mov    -0x8(%rbp),%rdi
cvtsi2sdq -0x10(%rbp),%xmm0
movsd  0xe48(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe5f(%rip),%rsi
call   1030 <sprintf@plt>
jmp    1237 <make_human_readable+0x127>
cvtsi2sdq -0x10(%rbp),%xmm0
movsd  0xe2d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    121c <make_human_readable+0x10c>
mov    -0x8(%rbp),%rdi
cvtsi2sdq -0x10(%rbp),%xmm0
movsd  0xe11(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe29(%rip),%rsi
call   1030 <sprintf@plt>
jmp    1232 <make_human_readable+0x122>
mov    -0x8(%rbp),%rdi
cvtsi2sdq -0x10(%rbp),%xmm0
lea    0xe17(%rip),%rsi
call   1030 <sprintf@plt>
jmp    1237 <make_human_readable+0x127>
jmp    123c <make_human_readable+0x12c>
jmp    1241 <make_human_readable+0x131>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_human_readable>:
cvtsi2sd %rsi,%xmm0
movabs $0x10000000001,%rax
cmp    %rax,%rsi
jl     1138 <make_human_readable+0x28>
mulsd  0xeec(%rip),%xmm0
lea    0xeed(%rip),%rsi
jmp    1030 <sprintf@plt>
cmp    $0x40000001,%rsi
jl     1155 <make_human_readable+0x45>
mulsd  0xec7(%rip),%xmm0
lea    0xed9(%rip),%rsi
jmp    1030 <sprintf@plt>
cmp    $0x100001,%rsi
jl     1172 <make_human_readable+0x62>
mulsd  0xea2(%rip),%xmm0
lea    0xec5(%rip),%rsi
jmp    1030 <sprintf@plt>
cmp    $0x401,%rsi
jl     118f <make_human_readable+0x7f>
mulsd  0xe7d(%rip),%xmm0
lea    0xeb1(%rip),%rsi
jmp    1030 <sprintf@plt>
lea    0xeae(%rip),%rsi
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"%.2lf TB\00"
@.str.1 = [9 x i8] c"%.2lf GB\00"
@.str.2 = [9 x i8] c"%.2lf MB\00"
@.str.3 = [9 x i8] c"%.2lf kB\00"
@.str.4 = [8 x i8] c"%.2lf B\00"
define void @make_human_readable(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%5 = load i64, i64* %4
%6 = sitofp i64 %5 to double
%7 = fcmp ogt double %6, 0x4270000000000000
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = load i64, i64* %4
%11 = sitofp i64 %10 to double
%12 = fdiv double %11, 0x4270000000000000
%13 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double %12)
br label %52
14: ; preds = %2
%15 = load i64, i64* %4
%16 = sitofp i64 %15 to double
%17 = fcmp ogt double %16, 0x41D0000000000000
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i8*, i8** %3
%20 = load i64, i64* %4
%21 = sitofp i64 %20 to double
%22 = fdiv double %21, 0x41D0000000000000
%23 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %22)
br label %51
24: ; preds = %14
%25 = load i64, i64* %4
%26 = sitofp i64 %25 to double
%27 = fcmp ogt double %26, 0x4130000000000000
br i1 %27, label %28, label %34
28: ; preds = %24
%29 = load i8*, i8** %3
%30 = load i64, i64* %4
%31 = sitofp i64 %30 to double
%32 = fdiv double %31, 0x4130000000000000
%33 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %32)
br label %50
34: ; preds = %24
%35 = load i64, i64* %4
%36 = sitofp i64 %35 to double
%37 = fcmp ogt double %36, 1.024000e+03
br i1 %37, label %38, label %44
38: ; preds = %34
%39 = load i8*, i8** %3
%40 = load i64, i64* %4
%41 = sitofp i64 %40 to double
%42 = fdiv double %41, 1.024000e+03
%43 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), double %42)
br label %49
44: ; preds = %34
%45 = load i8*, i8** %3
%46 = load i64, i64* %4
%47 = sitofp i64 %46 to double
%48 = call i32 @sprintf(i8* %45, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), double %47)
br label %49
49: ; preds = %44, %38
br label %50
50: ; preds = %49, %28
br label %51
51: ; preds = %50, %18
br label %52
52: ; preds = %51, %8
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"%.2lf TB\00"
@.str.1 = [9 x i8] c"%.2lf GB\00"
@.str.2 = [9 x i8] c"%.2lf MB\00"
@.str.3 = [9 x i8] c"%.2lf kB\00"
@.str.4 = [8 x i8] c"%.2lf B\00"
define void @make_human_readable(i8* nocapture writeonly %0, i64 %1) {
%3 = sitofp i64 %1 to double
%4 = icmp sgt i64 %1, 1099511627776
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = fmul double %3, 0x3D70000000000000
%7 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double %6)
br label %25
8: ; preds = %2
%9 = icmp sgt i64 %1, 1073741824
br i1 %9, label %10, label %13
10: ; preds = %8
%11 = fmul double %3, 0x3E10000000000000
%12 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %11)
br label %25
13: ; preds = %8
%14 = icmp sgt i64 %1, 1048576
br i1 %14, label %15, label %18
15: ; preds = %13
%16 = fmul double %3, 0x3EB0000000000000
%17 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %16)
br label %25
18: ; preds = %13
%19 = icmp sgt i64 %1, 1024
br i1 %19, label %20, label %23
20: ; preds = %18
%21 = fmul double %3, 0x3F50000000000000
%22 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), double %21)
br label %25
23: ; preds = %18
%24 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), double %3)
br label %25
25: ; preds = %10, %20, %23, %15, %5
ret void
}