#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 *, long long);
char *human_size(long long s, char *hs) {
  if (s >= (1024 * 1024 * 1024)) {
    sprintf(hs, "%.2fGB", (s * 1.0) / (1024 * 1024 * 1024));
  } else if (s >= 1024 * 1024) {
    sprintf(hs, "%.2fMB", (s * 1.0) / (1024 * 1024));
  } else if (s > 1024) {
    sprintf(hs, "%.2fKB", (s * 1.0) / 1024);
  } else {
    sprintf(hs, "%lldB", s);
  }
  return hs;
}


x86 assembly (clang, -O0):
<human_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x40000000,-0x8(%rbp)
40
jl     1166 <human_size+0x56>
mov    -0x10(%rbp),%rdi
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  0xec8(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xecc(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdx
lea    0xec4(%rip),%rsi
call   1030 <sprintf@plt>
jmp    1210 <human_size+0x100>
cmpq   $0x100000,-0x8(%rbp)
jl     11ac <human_size+0x9c>
mov    -0x10(%rbp),%rdi
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  0xe82(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe7e(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdx
lea    0xe85(%rip),%rsi
call   1030 <sprintf@plt>
jmp    120b <human_size+0xfb>
cmpq   $0x400,-0x8(%rbp)
jle    11f2 <human_size+0xe2>
mov    -0x10(%rbp),%rdi
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  0xe3c(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe28(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdx
lea    0xe46(%rip),%rsi
call   1030 <sprintf@plt>
jmp    1206 <human_size+0xf6>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe34(%rip),%rsi
call   1030 <sprintf@plt>
jmp    120b <human_size+0xfb>
jmp    1210 <human_size+0x100>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<human_size>:
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%rdx
cmp    $0x40000000,%rdi
jl     113b <human_size+0x2b>
cvtsi2sd %rdx,%xmm0
mulsd  0xee3(%rip),%xmm0
cvttsd2si %xmm0,%rdx
lea    0xedf(%rip),%rsi
jmp    118a <human_size+0x7a>
cmp    $0x100000,%rdx
jl     115f <human_size+0x4f>
cvtsi2sd %rdx,%xmm0
mulsd  0xeb7(%rip),%xmm0
cvttsd2si %xmm0,%rdx
lea    0xec2(%rip),%rsi
jmp    118a <human_size+0x7a>
cmp    $0x401,%rdx
jl     1183 <human_size+0x73>
cvtsi2sd %rdx,%xmm0
mulsd  0xe8b(%rip),%xmm0
cvttsd2si %xmm0,%rdx
lea    0xea5(%rip),%rsi
jmp    118a <human_size+0x7a>
lea    0xea3(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%.2fGB\00"
@.str.1 = [7 x i8] c"%.2fMB\00"
@.str.2 = [7 x i8] c"%.2fKB\00"
@.str.3 = [6 x i8] c"%lldB\00"
define i8* @human_size(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
store i64 %0, i64* %3
store i8* %1, i8** %4
%5 = load i64, i64* %3
%6 = icmp sge i64 %5, 1073741824
br i1 %6, label %7, label %15
7: ; preds = %2
%8 = load i8*, i8** %4
%9 = load i64, i64* %3
%10 = sitofp i64 %9 to double
%11 = fmul double %10, 1.000000e+00
%12 = fdiv double %11, 0x41D0000000000000
%13 = fptosi double %12 to i64
%14 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %13)
br label %43
15: ; preds = %2
%16 = load i64, i64* %3
%17 = icmp sge i64 %16, 1048576
br i1 %17, label %18, label %26
18: ; preds = %15
%19 = load i8*, i8** %4
%20 = load i64, i64* %3
%21 = sitofp i64 %20 to double
%22 = fmul double %21, 1.000000e+00
%23 = fdiv double %22, 0x4130000000000000
%24 = fptosi double %23 to i64
%25 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %24)
br label %42
26: ; preds = %15
%27 = load i64, i64* %3
%28 = icmp sgt i64 %27, 1024
br i1 %28, label %29, label %37
29: ; preds = %26
%30 = load i8*, i8** %4
%31 = load i64, i64* %3
%32 = sitofp i64 %31 to double
%33 = fmul double %32, 1.000000e+00
%34 = fdiv double %33, 1.024000e+03
%35 = fptosi double %34 to i64
%36 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i64 %35)
br label %41
37: ; preds = %26
%38 = load i8*, i8** %4
%39 = load i64, i64* %3
%40 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64 %39)
br label %41
41: ; preds = %37, %29
br label %42
42: ; preds = %41, %18
br label %43
43: ; preds = %42, %7
%44 = load i8*, i8** %4
ret i8* %44
}

LLVM IR (-O2):
@.str = [7 x i8] c"%.2fGB\00"
@.str.1 = [7 x i8] c"%.2fMB\00"
@.str.2 = [7 x i8] c"%.2fKB\00"
@.str.3 = [6 x i8] c"%lldB\00"
define i8* @human_size(i64 %0, i8* returned writeonly %1) {
%3 = icmp sgt i64 %0, 1073741823
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = sitofp i64 %0 to double
%6 = fmul double %5, 0x3E10000000000000
%7 = fptosi double %6 to i64
%8 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %7)
br label %25
9: ; preds = %2
%10 = icmp sgt i64 %0, 1048575
br i1 %10, label %11, label %16
11: ; preds = %9
%12 = sitofp i64 %0 to double
%13 = fmul double %12, 0x3EB0000000000000
%14 = fptosi double %13 to i64
%15 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %14)
br label %25
16: ; preds = %9
%17 = icmp sgt i64 %0, 1024
br i1 %17, label %18, label %23
18: ; preds = %16
%19 = sitofp i64 %0 to double
%20 = fmul double %19, 0x3F50000000000000
%21 = fptosi double %20 to i64
%22 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i64 %21)
br label %25
23: ; preds = %16
%24 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64 %0)
br label %25
25: ; preds = %11, %23, %18, %4
ret i8* %1
}