const char *time_units(double *secs) {
  if (*secs > 1e-1) {
    return "s";
  } else if (*secs >= 1e-3) {
    *secs *= 1e3;
    return "ms";
  } else if (*secs >= 1e-6) {
    *secs *= 1e6;
    return "us";
  } else {
    *secs *= 1e9;
    return "ns";
  }
}


x86 assembly (clang, -O0):
<time_units>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xee8(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1132 <time_units+0x32>
lea    0xf08(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11cd <time_units+0xcd>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xec6(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1170 <time_units+0x70>
mov    -0x10(%rbp),%rax
movsd  0xed0(%rip),%xmm0
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
lea    0xec9(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11cd <time_units+0xcd>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xe90(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11ae <time_units+0xae>
mov    -0x10(%rbp),%rax
movsd  0xe8a(%rip),%xmm0
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
lea    0xe8e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11cd <time_units+0xcd>
mov    -0x10(%rbp),%rax
movsd  0xe5e(%rip),%xmm0
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
lea    0xe6d(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_units>:
movsd  (%rdi),%xmm0
ucomisd 0xef4(%rip),%xmm0
jbe    1116 <time_units+0x16>
lea    0xf1c(%rip),%rax
ret
xor    %eax,%eax
ucomisd 0xee8(%rip),%xmm0
lea    0xf0f(%rip),%rdx
lea    0xf05(%rip),%rcx
cmovb  %rdx,%rcx
setb   %dl
ucomisd 0xed3(%rip),%xmm0
jb     1149 <time_units+0x49>
movsd  0xed1(%rip),%xmm1
jmp    1157 <time_units+0x57>
mov    %dl,%al
lea    0xece(%rip),%rdx
movsd  (%rdx,%rax,8),%xmm1
lea    0xed2(%rip),%rax
cmovb  %rcx,%rax
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%rdi)
ret

LLVM IR (-O0):
@.str = [2 x i8] c"s\00"
@.str.1 = [3 x i8] c"ms\00"
@.str.2 = [3 x i8] c"us\00"
@.str.3 = [3 x i8] c"ns\00"
define i8* @time_units(double* %0) {
%2 = alloca i8*
%3 = alloca double*
store double* %0, double** %3
%4 = load double*, double** %3
%5 = load double, double* %4
%6 = fcmp ogt double %5, 1.000000e-01
br i1 %6, label %7, label %8
7: ; preds = %1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %2
br label %28
8: ; preds = %1
%9 = load double*, double** %3
%10 = load double, double* %9
%11 = fcmp oge double %10, 1.000000e-03
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = load double*, double** %3
%14 = load double, double* %13
%15 = fmul double %14, 1.000000e+03
store double %15, double* %13
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %28
16: ; preds = %8
%17 = load double*, double** %3
%18 = load double, double* %17
%19 = fcmp oge double %18, 0x3EB0C6F7A0B5ED8D
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load double*, double** %3
%22 = load double, double* %21
%23 = fmul double %22, 1.000000e+06
store double %23, double* %21
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %28
24: ; preds = %16
%25 = load double*, double** %3
%26 = load double, double* %25
%27 = fmul double %26, 1.000000e+09
store double %27, double* %25
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %28
28: ; preds = %24, %20, %12, %7
%29 = load i8*, i8** %2
ret i8* %29
}

LLVM IR (-O2):
@.str = [2 x i8] c"s\00"
@.str.1 = [3 x i8] c"ms\00"
@.str.2 = [3 x i8] c"us\00"
@.str.3 = [3 x i8] c"ns\00"
define i8* @time_units(double* nocapture %0) {
%2 = load double, double* %0
%3 = fcmp ogt double %2, 1.000000e-01
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = fcmp ult double %2, 1.000000e-03
%6 = fcmp ult double %2, 0x3EB0C6F7A0B5ED8D
%7 = select i1 %6, double 1.000000e+09, double 1.000000e+06
%8 = select i1 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%9 = select i1 %5, double %7, double 1.000000e+03
%10 = select i1 %5, i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)
%11 = fmul double %2, %9
store double %11, double* %0
br label %12
12: ; preds = %4, %1
%13 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %1 ], [ %10, %4 ]
ret i8* %13
}