#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 bytesToHuman(char *s, long long n) {
  double d;
  if (n < 0) {
    *s = '-';
    s++;
    n = -n;
  }
  if (n < 1024) {
    sprintf(s, "%lluB", n);
    return;
  } else if (n < (1024 * 1024)) {
    d = (double)n / (1024);
    sprintf(s, "%.2fK", d);
  } else if (n < (1024LL * 1024 * 1024)) {
    d = (double)n / (1024 * 1024);
    sprintf(s, "%.2fM", d);
  } else if (n < (1024LL * 1024 * 1024 * 1024)) {
    d = (double)n / (1024LL * 1024 * 1024);
    sprintf(s, "%.2fG", d);
  }
}


x86 assembly (clang, -O0):
<bytesToHuman>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    1148 <bytesToHuman+0x38>
mov    -0x8(%rbp),%rax
movb   $0x2d,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
xor    %eax,%eax
sub    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x400,-0x10(%rbp)
jge    1171 <bytesToHuman+0x61>
mov    -0x8(%rbp),%rdi
cvtsi2sdq -0x10(%rbp),%xmm0
lea    0xeb1(%rip),%rsi
call   1030 <sprintf@plt>
jmp    123e <bytesToHuman+0x12e>
cmpq   $0x100000,-0x10(%rbp)
jge    11b0 <bytesToHuman+0xa0>
cvtsi2sdq -0x10(%rbp),%xmm0
movsd  0xe83(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
lea    0xe78(%rip),%rsi
call   1030 <sprintf@plt>
jmp    1239 <bytesToHuman+0x129>
cmpq   $0x40000000,-0x10(%rbp)
40
jge    11ef <bytesToHuman+0xdf>
cvtsi2sdq -0x10(%rbp),%xmm0
movsd  0xe3c(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
lea    0xe3f(%rip),%rsi
call   1030 <sprintf@plt>
jmp    1234 <bytesToHuman+0x124>
movabs $0x10000000000,%rax
cmp    %rax,-0x10(%rbp)
jge    122f <bytesToHuman+0x11f>
cvtsi2sdq -0x10(%rbp),%xmm0
movsd  0xdef(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
lea    0xe00(%rip),%rsi
call   1030 <sprintf@plt>
jmp    1234 <bytesToHuman+0x124>
jmp    1239 <bytesToHuman+0x129>
jmp    123e <bytesToHuman+0x12e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bytesToHuman>:
test   %rsi,%rsi
js     112f <bytesToHuman+0x1f>
cmp    $0x3ff,%rsi
ja     1142 <bytesToHuman+0x32>
cvtsi2sd %rsi,%xmm0
lea    0xeee(%rip),%rsi
jmp    1030 <sprintf@plt>
movb   $0x2d,(%rdi)
add    $0x1,%rdi
neg    %rsi
cmp    $0x3ff,%rsi
jbe    111e <bytesToHuman+0xe>
cmp    $0xfffff,%rsi
ja     1164 <bytesToHuman+0x54>
cvtsi2sd %rsi,%xmm0
mulsd  0xeb8(%rip),%xmm0
lea    0xebf(%rip),%rsi
jmp    1030 <sprintf@plt>
cmp    $0x3fffffff,%rsi
ja     1186 <bytesToHuman+0x76>
cvtsi2sd %rsi,%xmm0
mulsd  0xe8e(%rip),%xmm0
lea    0xea3(%rip),%rsi
jmp    1030 <sprintf@plt>
mov    %rsi,%rax
shr    $0x28,%rax
jne    11a8 <bytesToHuman+0x98>
cvtsi2sd %rsi,%xmm0
mulsd  0xe64(%rip),%xmm0
lea    0xe87(%rip),%rsi
jmp    1030 <sprintf@plt>
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%lluB\00"
@.str.1 = [6 x i8] c"%.2fK\00"
@.str.2 = [6 x i8] c"%.2fM\00"
@.str.3 = [6 x i8] c"%.2fG\00"
define void @bytesToHuman(i8* nocapture writeonly %0, i64 %1) {
%3 = icmp slt i64 %1, 0
br i1 %3, label %4, label %7
4: ; preds = %2
store i8 45, i8* %0
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = sub nsw i64 0, %1
br label %7
7: ; preds = %4, %2
%8 = phi i8* [ %5, %4 ], [ %0, %2 ]
%9 = phi i64 [ %6, %4 ], [ %1, %2 ]
%10 = icmp ult i64 %9, 1024
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = sitofp i64 %9 to double
%13 = tail call i32 @sprintf(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %12)
br label %32
14: ; preds = %7
%15 = icmp ult i64 %9, 1048576
br i1 %15, label %16, label %20
16: ; preds = %14
%17 = sitofp i64 %9 to double
%18 = fmul double %17, 0x3F50000000000000
%19 = tail call i32 @sprintf(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double %18)
br label %32
20: ; preds = %14
%21 = icmp ult i64 %9, 1073741824
br i1 %21, label %22, label %26
22: ; preds = %20
%23 = sitofp i64 %9 to double
%24 = fmul double %23, 0x3EB0000000000000
%25 = tail call i32 @sprintf(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %24)
br label %32
26: ; preds = %20
%27 = icmp ult i64 %9, 1099511627776
br i1 %27, label %28, label %32
28: ; preds = %26
%29 = sitofp i64 %9 to double
%30 = fmul double %29, 0x3E10000000000000
%31 = tail call i32 @sprintf(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %30)
br label %32
32: ; preds = %22, %28, %26, %16, %11
ret void
}