#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);
char *scale(double v, char *buf) {
  if (v > (1024.0 * 1024.0)) {
    if (v > (1024.0 * 1024.0 * 1024.0)) {
      sprintf(buf, "%6.1fG", v * (1.0 / (1024.0 * 1024.0 * 1024.0)));
    } else {
      sprintf(buf, "%6.1fM", v * (1.0 / (1024.0 * 1024.0)));
    }
  } else {
    if (v > 1024.0) {
      sprintf(buf, "%6.1fk", v * (1.0 / 1024.0));
    } else {
      sprintf(buf, "%4.0f", v);
    }
  }
  return buf;
}


x86 assembly (clang, -O0):
<scale>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xed2(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1193 <scale+0x83>
movsd  -0x8(%rbp),%xmm0
movsd  0xed3(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1171 <scale+0x61>
mov    -0x10(%rbp),%rdi
movsd  0xecd(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
lea    0xec9(%rip),%rsi
call   1030 <sprintf@plt>
jmp    118e <scale+0x7e>
mov    -0x10(%rbp),%rdi
movsd  0xea3(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
lea    0xeae(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11e6 <scale+0xd6>
movsd  -0x8(%rbp),%xmm0
movsd  0xe68(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11cc <scale+0xbc>
mov    -0x10(%rbp),%rdi
movsd  0xe5a(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
lea    0xe7c(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11e1 <scale+0xd1>
mov    -0x10(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
lea    0xe69(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11e6 <scale+0xd6>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scale>:
push   %rbx
mov    %rdi,%rbx
ucomisd 0xee4(%rip),%xmm0
jbe    1139 <scale+0x29>
ucomisd 0xef2(%rip),%xmm0
jbe    1154 <scale+0x44>
mulsd  0xef8(%rip),%xmm0
lea    0xef9(%rip),%rsi
jmp    116c <scale+0x5c>
ucomisd 0xec7(%rip),%xmm0
jbe    1165 <scale+0x55>
mulsd  0xec5(%rip),%xmm0
lea    0xeec(%rip),%rsi
jmp    116c <scale+0x5c>
mulsd  0xec4(%rip),%xmm0
lea    0xed4(%rip),%rsi
jmp    116c <scale+0x5c>
lea    0xed9(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%6.1fG\00"
@.str.1 = [7 x i8] c"%6.1fM\00"
@.str.2 = [7 x i8] c"%6.1fk\00"
@.str.3 = [6 x i8] c"%4.0f\00"
define i8* @scale(double %0, i8* %1) {
%3 = alloca double
%4 = alloca i8*
store double %0, double* %3
store i8* %1, i8** %4
%5 = load double, double* %3
%6 = fcmp ogt double %5, 0x4130000000000000
br i1 %6, label %7, label %21
7: ; preds = %2
%8 = load double, double* %3
%9 = fcmp ogt double %8, 0x41D0000000000000
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = load i8*, i8** %4
%12 = load double, double* %3
%13 = fmul double %12, 0x3E10000000000000
%14 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %13)
br label %20
15: ; preds = %7
%16 = load i8*, i8** %4
%17 = load double, double* %3
%18 = fmul double %17, 0x3EB0000000000000
%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 %20
20: ; preds = %15, %10
br label %34
21: ; preds = %2
%22 = load double, double* %3
%23 = fcmp ogt double %22, 1.024000e+03
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = load i8*, i8** %4
%26 = load double, double* %3
%27 = fmul double %26, 0x3F50000000000000
%28 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %27)
br label %33
29: ; preds = %21
%30 = load i8*, i8** %4
%31 = load double, double* %3
%32 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %31)
br label %33
33: ; preds = %29, %24
br label %34
34: ; preds = %33, %20
%35 = load i8*, i8** %4
ret i8* %35
}

LLVM IR (-O2):
@.str = [7 x i8] c"%6.1fG\00"
@.str.1 = [7 x i8] c"%6.1fM\00"
@.str.2 = [7 x i8] c"%6.1fk\00"
@.str.3 = [6 x i8] c"%4.0f\00"
define i8* @scale(double %0, i8* returned writeonly %1) {
%3 = fcmp ogt double %0, 0x4130000000000000
br i1 %3, label %4, label %12
4: ; preds = %2
%5 = fcmp ogt double %0, 0x41D0000000000000
br i1 %5, label %6, label %9
6: ; preds = %4
%7 = fmul double %0, 0x3E10000000000000
%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), double %7)
br label %19
9: ; preds = %4
%10 = fmul double %0, 0x3EB0000000000000
%11 = 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), double %10)
br label %19
12: ; preds = %2
%13 = fcmp ogt double %0, 1.024000e+03
br i1 %13, label %14, label %17
14: ; preds = %12
%15 = fmul double %0, 0x3F50000000000000
%16 = 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), double %15)
br label %19
17: ; preds = %12
%18 = 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), double %0)
br label %19
19: ; preds = %14, %17, %6, %9
ret i8* %1
}