#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 fx_with_units(char *out, double number) {
  if (number < 1e3) {
    sprintf(out, "%.3lf Hz", number);
  } else if (number < 1e6) {
    sprintf(out, "%.3lf KHz", number * 1e-3);
  } else if (number < 1e9) {
    sprintf(out, "%.3lf MHz", number * 1e-6);
  } else if (number < 1e12) {
    sprintf(out, "%.3lf GHz", number * 1e-9);
  }
}


x86 assembly (clang, -O0):
<fx_with_units>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  0xed7(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    114e <fx_with_units+0x3e>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
lea    0xef4(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11f7 <fx_with_units+0xe7>
movsd  0xeb2(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1183 <fx_with_units+0x73>
mov    -0x8(%rbp),%rdi
movsd  0xec3(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
lea    0xec8(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11f2 <fx_with_units+0xe2>
movsd  0xe85(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11b8 <fx_with_units+0xa8>
mov    -0x8(%rbp),%rdi
movsd  0xe86(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
lea    0xe9d(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11ed <fx_with_units+0xdd>
movsd  0xe58(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11e8 <fx_with_units+0xd8>
mov    -0x8(%rbp),%rdi
movsd  0xe49(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
lea    0xe72(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11ed <fx_with_units+0xdd>
jmp    11f2 <fx_with_units+0xe2>
jmp    11f7 <fx_with_units+0xe7>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fx_with_units>:
movsd  0xee8(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    112a <fx_with_units+0x1a>
lea    0xf13(%rip),%rsi
jmp    1030 <sprintf@plt>
movsd  0xed6(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    114c <fx_with_units+0x3c>
mulsd  0xef0(%rip),%xmm0
lea    0xefa(%rip),%rsi
jmp    1030 <sprintf@plt>
movsd  0xebc(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    116e <fx_with_units+0x5e>
mulsd  0xec6(%rip),%xmm0
lea    0xee2(%rip),%rsi
jmp    1030 <sprintf@plt>
movsd  0xea2(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1190 <fx_with_units+0x80>
mulsd  0xe9c(%rip),%xmm0
lea    0xeca(%rip),%rsi
jmp    1030 <sprintf@plt>
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%.3lf Hz\00"
@.str.1 = [10 x i8] c"%.3lf KHz\00"
@.str.2 = [10 x i8] c"%.3lf MHz\00"
@.str.3 = [10 x i8] c"%.3lf GHz\00"
define void @fx_with_units(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 olt double %5, 1.000000e+03
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i8*, i8** %3
%9 = load double, double* %4
%10 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double %9)
br label %38
11: ; preds = %2
%12 = load double, double* %4
%13 = fcmp olt double %12, 1.000000e+06
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i8*, i8** %3
%16 = load double, double* %4
%17 = fmul double %16, 1.000000e-03
%18 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %17)
br label %37
19: ; preds = %11
%20 = load double, double* %4
%21 = fcmp olt double %20, 1.000000e+09
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i8*, i8** %3
%24 = load double, double* %4
%25 = fmul double %24, 0x3EB0C6F7A0B5ED8D
%26 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double %25)
br label %36
27: ; preds = %19
%28 = load double, double* %4
%29 = fcmp olt double %28, 1.000000e+12
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = load i8*, i8** %3
%32 = load double, double* %4
%33 = fmul double %32, 1.000000e-09
%34 = call i32 @sprintf(i8* %31, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), double %33)
br label %35
35: ; preds = %30, %27
br label %36
36: ; preds = %35, %22
br label %37
37: ; preds = %36, %14
br label %38
38: ; preds = %37, %7
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"%.3lf Hz\00"
@.str.1 = [10 x i8] c"%.3lf KHz\00"
@.str.2 = [10 x i8] c"%.3lf MHz\00"
@.str.3 = [10 x i8] c"%.3lf GHz\00"
define void @fx_with_units(i8* nocapture writeonly %0, double %1) {
%3 = fcmp olt double %1, 1.000000e+03
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double %1)
br label %21
6: ; preds = %2
%7 = fcmp olt double %1, 1.000000e+06
br i1 %7, label %8, label %11
8: ; preds = %6
%9 = fmul double %1, 1.000000e-03
%10 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %9)
br label %21
11: ; preds = %6
%12 = fcmp olt double %1, 1.000000e+09
br i1 %12, label %13, label %16
13: ; preds = %11
%14 = fmul double %1, 0x3EB0C6F7A0B5ED8D
%15 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double %14)
br label %21
16: ; preds = %11
%17 = fcmp olt double %1, 1.000000e+12
br i1 %17, label %18, label %21
18: ; preds = %16
%19 = fmul double %1, 1.000000e-09
%20 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), double %19)
br label %21
21: ; preds = %8, %16, %18, %13, %4
ret void
}