#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 *format_count(char *sout, double x) {
  if (x > 1e9) {
    sprintf(sout, "%8.2fbi", x / 1e9);
  } else if (x > 1e6) {
    sprintf(sout, "%8.2fmi", x / 1e6);
  } else if (x > 1e3) {
    sprintf(sout, "%8.2fki", x / 1e3);
  } else {
    sprintf(sout, "%8.2f  ", x);
  }
  return (sout);
}


x86 assembly (clang, -O0):
<format_count>:
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 <format_count+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 <format_count+0xe7>
movsd  -0x10(%rbp),%xmm0
movsd  0xe9d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    119b <format_count+0x8b>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
movsd  0xe82(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe8f(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11f2 <format_count+0xe2>
movsd  -0x10(%rbp),%xmm0
movsd  0xe68(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11d8 <format_count+0xc8>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
movsd  0xe4d(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe5a(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11ed <format_count+0xdd>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
lea    0xe48(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11f2 <format_count+0xe2>
jmp    11f7 <format_count+0xe7>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_count>:
push   %rbx
mov    %rdi,%rbx
ucomisd 0xee4(%rip),%xmm0
jbe    112f <format_count+0x1f>
divsd  0xeda(%rip),%xmm0
lea    0xeeb(%rip),%rsi
jmp    116c <format_count+0x5c>
ucomisd 0xed1(%rip),%xmm0
jbe    114a <format_count+0x3a>
divsd  0xec7(%rip),%xmm0
lea    0xed8(%rip),%rsi
jmp    116c <format_count+0x5c>
ucomisd 0xebe(%rip),%xmm0
jbe    1165 <format_count+0x55>
divsd  0xeb4(%rip),%xmm0
lea    0xec5(%rip),%rsi
jmp    116c <format_count+0x5c>
lea    0xec4(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%8.2fbi\00"
@.str.1 = [8 x i8] c"%8.2fmi\00"
@.str.2 = [8 x i8] c"%8.2fki\00"
@.str.3 = [8 x i8] c"%8.2f \00"
define i8* @format_count(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, 1.000000e+09
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i8*, i8** %3
%9 = load double, double* %4
%10 = fdiv double %9, 1.000000e+09
%11 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([8 x i8], [8 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, 1.000000e+06
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i8*, i8** %3
%17 = load double, double* %4
%18 = fdiv double %17, 1.000000e+06
%19 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([8 x i8], [8 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.000000e+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.000000e+03
%27 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([8 x i8], [8 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 ([8 x i8], [8 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
%35 = load i8*, i8** %3
ret i8* %35
}

LLVM IR (-O2):
@.str = [8 x i8] c"%8.2fbi\00"
@.str.1 = [8 x i8] c"%8.2fmi\00"
@.str.2 = [8 x i8] c"%8.2fki\00"
@.str.3 = [8 x i8] c"%8.2f \00"
define i8* @format_count(i8* returned writeonly %0, double %1) {
%3 = fcmp ogt double %1, 1.000000e+09
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = fdiv double %1, 1.000000e+09
%6 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %5)
br label %19
7: ; preds = %2
%8 = fcmp ogt double %1, 1.000000e+06
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = fdiv double %1, 1.000000e+06
%11 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double %10)
br label %19
12: ; preds = %7
%13 = fcmp ogt double %1, 1.000000e+03
br i1 %13, label %14, label %17
14: ; preds = %12
%15 = fdiv double %1, 1.000000e+03
%16 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 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 ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), double %1)
br label %19
19: ; preds = %9, %17, %14, %4
ret i8* %0
}