#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 autoscale(char *str, double bytes) {
  if (bytes > (double)1024 * 1024 * 1024)
    sprintf(str, "%.2f G", (bytes / (double)(1024 * 1024 * 1024)));
  else if (bytes > (double)1024 * 1024)
    sprintf(str, "%.2f M", (bytes / (double)(1024 * 1024)));
  else if (bytes > (double)1024)
    sprintf(str, "%.2f K", (bytes / (double)(1024)));
  else
    sprintf(str, "%.2f ", bytes);
}


x86 assembly (clang, -O0):
<autoscale>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xed2(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    115e <autoscale+0x4e>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
movsd  0xeb7(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xec4(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11f7 <autoscale+0xe7>
movsd  -0x10(%rbp),%xmm0
movsd  0xe9d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    119b <autoscale+0x8b>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
movsd  0xe82(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe8e(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11f2 <autoscale+0xe2>
movsd  -0x10(%rbp),%xmm0
movsd  0xe68(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11d8 <autoscale+0xc8>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
movsd  0xe4d(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe58(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11ed <autoscale+0xdd>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
lea    0xe45(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11f2 <autoscale+0xe2>
jmp    11f7 <autoscale+0xe7>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<autoscale>:
ucomisd 0xee8(%rip),%xmm0
jbe    112e <autoscale+0x1e>
mulsd  0xf06(%rip),%xmm0
lea    0xf07(%rip),%rsi
jmp    1030 <sprintf@plt>
ucomisd 0xed2(%rip),%xmm0
jbe    114c <autoscale+0x3c>
mulsd  0xee0(%rip),%xmm0
lea    0xef0(%rip),%rsi
jmp    1030 <sprintf@plt>
ucomisd 0xebc(%rip),%xmm0
jbe    116a <autoscale+0x5a>
mulsd  0xeba(%rip),%xmm0
lea    0xed9(%rip),%rsi
jmp    1030 <sprintf@plt>
lea    0xed4(%rip),%rsi
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"%.2f G\00"
@.str.1 = [7 x i8] c"%.2f M\00"
@.str.2 = [7 x i8] c"%.2f K\00"
@.str.3 = [6 x i8] c"%.2f \00"
define void @autoscale(i8* %0, double %1) {
%3 = alloca i8*
%4 = alloca double
store i8* %0, i8** %3
store double %1, double* %4
%5 = load double, double* %4
%6 = fcmp ogt double %5, 0x41D0000000000000
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i8*, i8** %3
%9 = load double, double* %4
%10 = fdiv double %9, 0x41D0000000000000
%11 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %10)
br label %34
12: ; preds = %2
%13 = load double, double* %4
%14 = fcmp ogt double %13, 0x4130000000000000
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i8*, i8** %3
%17 = load double, double* %4
%18 = fdiv double %17, 0x4130000000000000
%19 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %18)
br label %33
20: ; preds = %12
%21 = load double, double* %4
%22 = fcmp ogt double %21, 1.024000e+03
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = load i8*, i8** %3
%25 = load double, double* %4
%26 = fdiv double %25, 1.024000e+03
%27 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %26)
br label %32
28: ; preds = %20
%29 = load i8*, i8** %3
%30 = load double, double* %4
%31 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %30)
br label %32
32: ; preds = %28, %23
br label %33
33: ; preds = %32, %15
br label %34
34: ; preds = %33, %7
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%.2f G\00"
@.str.1 = [7 x i8] c"%.2f M\00"
@.str.2 = [7 x i8] c"%.2f K\00"
@.str.3 = [6 x i8] c"%.2f \00"
define void @autoscale(i8* nocapture writeonly %0, double %1) {
%3 = fcmp ogt double %1, 0x41D0000000000000
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = fmul double %1, 0x3E10000000000000
%6 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %5)
br label %19
7: ; preds = %2
%8 = fcmp ogt double %1, 0x4130000000000000
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = fmul double %1, 0x3EB0000000000000
%11 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %10)
br label %19
12: ; preds = %7
%13 = fcmp ogt double %1, 1.024000e+03
br i1 %13, label %14, label %17
14: ; preds = %12
%15 = fmul double %1, 0x3F50000000000000
%16 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %15)
br label %19
17: ; preds = %12
%18 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %1)
br label %19
19: ; preds = %9, %17, %14, %4
ret void
}