void core_get_metric_system_unit_prefix(double input, char *prefix,
                                        double *value) {
  if ((1000) <= input && input < (1000 * 1000)) {
    *prefix = 'k';
    *value = input / (1000);
  } else if ((1000 * 1000) <= input && input < (1000 * 1000 * 1000)) {
    *prefix = 'M';
    *value = input / (1000 * 1000);
  } else if ((1000 * 1000 * 1000) <= input && input < 1000000000LL) {
    *prefix = 'G';
    *value = input / (1000 * 1000 * 1000);
  } else {
    *prefix = ' ';
    *value = input;
  }
}


x86 assembly (clang, -O0):
<core_get_metric_system_unit_prefix>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xee2(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1160 <core_get_metric_system_unit_prefix+0x60>
movsd  0xed8(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1160 <core_get_metric_system_unit_prefix+0x60>
mov    -0x10(%rbp),%rax
movb   $0x6b,(%rax)
movsd  -0x8(%rbp),%xmm0
movsd  0xeb1(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    121c <core_get_metric_system_unit_prefix+0x11c>
movsd  -0x8(%rbp),%xmm0
movsd  0xe9b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11af <core_get_metric_system_unit_prefix+0xaf>
movsd  0xe91(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11af <core_get_metric_system_unit_prefix+0xaf>
mov    -0x10(%rbp),%rax
movb   $0x4d,(%rax)
movsd  -0x8(%rbp),%xmm0
movsd  0xe6a(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1217 <core_get_metric_system_unit_prefix+0x117>
movsd  -0x8(%rbp),%xmm0
movsd  0xe54(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11fe <core_get_metric_system_unit_prefix+0xfe>
movsd  0xe42(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11fe <core_get_metric_system_unit_prefix+0xfe>
mov    -0x10(%rbp),%rax
movb   $0x47,(%rax)
movsd  -0x8(%rbp),%xmm0
movsd  0xe23(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1212 <core_get_metric_system_unit_prefix+0x112>
mov    -0x10(%rbp),%rax
movb   $0x20,(%rax)
movsd  -0x8(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1217 <core_get_metric_system_unit_prefix+0x117>
jmp    121c <core_get_metric_system_unit_prefix+0x11c>
pop    %rbp
ret

x86 assembly (clang, -O2):
<core_get_metric_system_unit_prefix>:
ucomisd 0xef8(%rip),%xmm0
jb     1128 <core_get_metric_system_unit_prefix+0x28>
movsd  0xef6(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1128 <core_get_metric_system_unit_prefix+0x28>
movb   $0x6b,(%rdi)
divsd  0xedd(%rip),%xmm0
movsd  %xmm0,(%rsi)
ret
ucomisd 0xed8(%rip),%xmm0
jb     1150 <core_get_metric_system_unit_prefix+0x50>
movsd  0xed6(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1150 <core_get_metric_system_unit_prefix+0x50>
movb   $0x4d,(%rdi)
divsd  0xebd(%rip),%xmm0
movsd  %xmm0,(%rsi)
ret
movb   $0x20,(%rdi)
movsd  %xmm0,(%rsi)
ret

LLVM IR (-O0):
define void @core_get_metric_system_unit_prefix(double %0, i8* %1, double* %2) {
%4 = alloca double
%5 = alloca i8*
%6 = alloca double*
store double %0, double* %4
store i8* %1, i8** %5
store double* %2, double** %6
%7 = load double, double* %4
%8 = fcmp ole double 1.000000e+03, %7
br i1 %8, label %9, label %17
9: ; preds = %3
%10 = load double, double* %4
%11 = fcmp olt double %10, 1.000000e+06
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load i8*, i8** %5
store i8 107, i8* %13
%14 = load double, double* %4
%15 = fdiv double %14, 1.000000e+03
%16 = load double*, double** %6
store double %15, double* %16
br label %45
17: ; preds = %9, %3
%18 = load double, double* %4
%19 = fcmp ole double 1.000000e+06, %18
br i1 %19, label %20, label %28
20: ; preds = %17
%21 = load double, double* %4
%22 = fcmp olt double %21, 1.000000e+09
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = load i8*, i8** %5
store i8 77, i8* %24
%25 = load double, double* %4
%26 = fdiv double %25, 1.000000e+06
%27 = load double*, double** %6
store double %26, double* %27
br label %44
28: ; preds = %20, %17
%29 = load double, double* %4
%30 = fcmp ole double 1.000000e+09, %29
br i1 %30, label %31, label %39
31: ; preds = %28
%32 = load double, double* %4
%33 = fcmp olt double %32, 1.000000e+09
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = load i8*, i8** %5
store i8 71, i8* %35
%36 = load double, double* %4
%37 = fdiv double %36, 1.000000e+09
%38 = load double*, double** %6
store double %37, double* %38
br label %43
39: ; preds = %31, %28
%40 = load i8*, i8** %5
store i8 32, i8* %40
%41 = load double, double* %4
%42 = load double*, double** %6
store double %41, double* %42
br label %43
43: ; preds = %39, %34
br label %44
44: ; preds = %43, %23
br label %45
45: ; preds = %44, %12
ret void
}

LLVM IR (-O2):
define void @core_get_metric_system_unit_prefix(double %0, i8* nocapture writeonly %1, double* nocapture writeonly %2) {
%4 = fcmp oge double %0, 1.000000e+03
%5 = fcmp olt double %0, 1.000000e+06
%6 = and i1 %4, %5
br i1 %6, label %7, label %9
7: ; preds = %3
store i8 107, i8* %1
%8 = fdiv double %0, 1.000000e+03
br label %16
9: ; preds = %3
%10 = fcmp oge double %0, 1.000000e+06
%11 = fcmp olt double %0, 1.000000e+09
%12 = and i1 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %9
store i8 77, i8* %1
%14 = fdiv double %0, 1.000000e+06
br label %16
15: ; preds = %9
store i8 32, i8* %1
br label %16
16: ; preds = %13, %15, %7
%17 = phi double [ %14, %13 ], [ %0, %15 ], [ %8, %7 ]
store double %17, double* %2
ret void
}