#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 sprintf(char *, char *, float);
int get_human_format(long long number, char *format) {
  if (number <= 1000) {
    return sprintf(format, "%lldB", number);
  } else if (number <= 1000000) {
    return sprintf(format, "%1.1fKBs", (float)number / 1000.0);
  } else if (number <= 1000000000) {
    return sprintf(format, "%1.1fMBs", (float)number / 1000000.0);
  } else {
    return sprintf(format, "%1.1fGBs", (float)number / 1000000000.0);
  }
}


x86 assembly (clang, -O0):
<get_human_format>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x3e8,-0x10(%rbp)
jg     114c <get_human_format+0x3c>
mov    -0x18(%rbp),%rdi
cvtsi2ssq -0x10(%rbp),%xmm0
lea    0xed9(%rip),%rsi
call   1030 <sprintf@plt>
mov    %eax,-0x4(%rbp)
jmp    11f9 <get_human_format+0xe9>
cmpq   $0xf4240,-0x10(%rbp)
jg     118c <get_human_format+0x7c>
mov    -0x18(%rbp),%rdi
cvtsi2ssq -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xea0(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
lea    0xe9f(%rip),%rsi
call   1030 <sprintf@plt>
mov    %eax,-0x4(%rbp)
jmp    11f9 <get_human_format+0xe9>
cmpq   $0x3b9aca00,-0x10(%rbp)
3b
jg     11cc <get_human_format+0xbc>
mov    -0x18(%rbp),%rdi
cvtsi2ssq -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe58(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
lea    0xe68(%rip),%rsi
call   1030 <sprintf@plt>
mov    %eax,-0x4(%rbp)
jmp    11f9 <get_human_format+0xe9>
mov    -0x18(%rbp),%rdi
cvtsi2ssq -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe1e(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
lea    0xe3f(%rip),%rsi
call   1030 <sprintf@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_human_format>:
mov    %rsi,%rax
cmp    $0x3e8,%rdi
jg     1130 <get_human_format+0x20>
cvtsi2ss %rdi,%xmm0
lea    0xee4(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <sprintf@plt>
cmp    $0xf4240,%rdi
ja     1155 <get_human_format+0x45>
cvtsi2ss %rdi,%xmm0
divss  0xec2(%rip),%xmm0
lea    0xec5(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <sprintf@plt>
cvtsi2ss %rdi,%xmm0
cmp    $0x3b9aca00,%rdi
ja     117a <get_human_format+0x6a>
divss  0xe99(%rip),%xmm0
lea    0xea9(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <sprintf@plt>
divss  0xe7e(%rip),%xmm0
lea    0xe9b(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"%lldB\00"
@.str.1 = [9 x i8] c"%1.1fKBs\00"
@.str.2 = [9 x i8] c"%1.1fMBs\00"
@.str.3 = [9 x i8] c"%1.1fGBs\00"
define i32 @get_human_format(i64 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
store i64 %0, i64* %4
store i8* %1, i8** %5
%6 = load i64, i64* %4
%7 = icmp sle i64 %6, 1000
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i8*, i8** %5
%10 = load i64, i64* %4
%11 = sitofp i64 %10 to float
%12 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), float %11)
store i32 %12, i32* %3
br label %43
13: ; preds = %2
%14 = load i64, i64* %4
%15 = icmp sle i64 %14, 1000000
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = load i8*, i8** %5
%18 = load i64, i64* %4
%19 = sitofp i64 %18 to float
%20 = fpext float %19 to double
%21 = fdiv double %20, 1.000000e+03
%22 = fptrunc double %21 to float
%23 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), float %22)
store i32 %23, i32* %3
br label %43
24: ; preds = %13
%25 = load i64, i64* %4
%26 = icmp sle i64 %25, 1000000000
br i1 %26, label %27, label %35
27: ; preds = %24
%28 = load i8*, i8** %5
%29 = load i64, i64* %4
%30 = sitofp i64 %29 to float
%31 = fpext float %30 to double
%32 = fdiv double %31, 1.000000e+06
%33 = fptrunc double %32 to float
%34 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), float %33)
store i32 %34, i32* %3
br label %43
35: ; preds = %24
%36 = load i8*, i8** %5
%37 = load i64, i64* %4
%38 = sitofp i64 %37 to float
%39 = fpext float %38 to double
%40 = fdiv double %39, 1.000000e+09
%41 = fptrunc double %40 to float
%42 = call i32 @sprintf(i8* %36, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), float %41)
store i32 %42, i32* %3
br label %43
43: ; preds = %35, %27, %16, %8
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [6 x i8] c"%lldB\00"
@.str.1 = [9 x i8] c"%1.1fKBs\00"
@.str.2 = [9 x i8] c"%1.1fMBs\00"
@.str.3 = [9 x i8] c"%1.1fGBs\00"
define i32 @get_human_format(i64 %0, i8* nocapture writeonly %1) {
%3 = icmp slt i64 %0, 1001
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = sitofp i64 %0 to float
%6 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), float %5)
br label %22
7: ; preds = %2
%8 = icmp ult i64 %0, 1000001
br i1 %8, label %9, label %13
9: ; preds = %7
%10 = sitofp i64 %0 to float
%11 = fdiv float %10, 1.000000e+03
%12 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), float %11)
br label %22
13: ; preds = %7
%14 = icmp ult i64 %0, 1000000001
%15 = sitofp i64 %0 to float
br i1 %14, label %16, label %19
16: ; preds = %13
%17 = fdiv float %15, 1.000000e+06
%18 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), float %17)
br label %22
19: ; preds = %13
%20 = fdiv float %15, 1.000000e+09
%21 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), float %20)
br label %22
22: ; preds = %19, %16, %9, %4
%23 = phi i32 [ %6, %4 ], [ %12, %9 ], [ %18, %16 ], [ %21, %19 ]
ret i32 %23
}