void resolve_time_format(double *value, const char **format) {
  if (*value >= 1000 * 1000 * 1000) {
    *format = "%7.2fs";
    *value /= 1000 * 1000 * 1000;
  } else if (*value >= 1000 * 1000) {
    *format = "%6.1fms";
    *value /= 1000 * 1000;
  } else if (*value >= 1000) {
    *format = "%6.1fus";
    *value /= 1000;
  } else {
    *format = "%6.fns";
  }
}


x86 assembly (clang, -O0):
<resolve_time_format>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xee4(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1151 <resolve_time_format+0x51>
mov    -0x10(%rbp),%rax
lea    0xee7(%rip),%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xebc(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
jmp    11f3 <resolve_time_format+0xf3>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xea7(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1196 <resolve_time_format+0x96>
mov    -0x10(%rbp),%rax
lea    0xea9(%rip),%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xe7f(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
jmp    11ee <resolve_time_format+0xee>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xe6a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11db <resolve_time_format+0xdb>
mov    -0x10(%rbp),%rax
lea    0xe6c(%rip),%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xe42(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
jmp    11e9 <resolve_time_format+0xe9>
mov    -0x10(%rbp),%rax
lea    0xe49(%rip),%rcx
mov    %rcx,(%rax)
jmp    11ee <resolve_time_format+0xee>
jmp    11f3 <resolve_time_format+0xf3>
pop    %rbp
ret

x86 assembly (clang, -O2):
<resolve_time_format>:
movsd  (%rdi),%xmm0
ucomisd 0xef4(%rip),%xmm0
jae    112d <resolve_time_format+0x2d>
ucomisd 0xef2(%rip),%xmm0
jae    1144 <resolve_time_format+0x44>
ucomisd 0xef0(%rip),%xmm0
jae    115b <resolve_time_format+0x5b>
lea    0xf06(%rip),%rax
mov    %rax,(%rsi)
ret
lea    0xee4(%rip),%rax
mov    %rax,(%rsi)
divsd  0xec1(%rip),%xmm0
movsd  %xmm0,(%rdi)
ret
lea    0xed4(%rip),%rax
mov    %rax,(%rsi)
divsd  0xeb2(%rip),%xmm0
movsd  %xmm0,(%rdi)
ret
lea    0xec5(%rip),%rax
mov    %rax,(%rsi)
divsd  0xea3(%rip),%xmm0
movsd  %xmm0,(%rdi)
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%7.2fs\00"
@.str.1 = [8 x i8] c"%6.1fms\00"
@.str.2 = [8 x i8] c"%6.1fus\00"
@.str.3 = [7 x i8] c"%6.fns\00"
define void @resolve_time_format(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 = load double, double* %5
%7 = fcmp oge double %6, 1.000000e+09
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i8**, i8*** %4
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = load double*, double** %3
%11 = load double, double* %10
%12 = fdiv double %11, 1.000000e+09
store double %12, double* %10
br label %35
13: ; preds = %2
%14 = load double*, double** %3
%15 = load double, double* %14
%16 = fcmp oge double %15, 1.000000e+06
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load i8**, i8*** %4
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %18
%19 = load double*, double** %3
%20 = load double, double* %19
%21 = fdiv double %20, 1.000000e+06
store double %21, double* %19
br label %34
22: ; preds = %13
%23 = load double*, double** %3
%24 = load double, double* %23
%25 = fcmp oge double %24, 1.000000e+03
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i8**, i8*** %4
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %27
%28 = load double*, double** %3
%29 = load double, double* %28
%30 = fdiv double %29, 1.000000e+03
store double %30, double* %28
br label %33
31: ; preds = %22
%32 = load i8**, i8*** %4
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8** %32
br label %33
33: ; preds = %31, %26
br label %34
34: ; preds = %33, %17
br label %35
35: ; preds = %34, %8
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%7.2fs\00"
@.str.1 = [8 x i8] c"%6.1fms\00"
@.str.2 = [8 x i8] c"%6.1fus\00"
@.str.3 = [7 x i8] c"%6.fns\00"
define void @resolve_time_format(double* nocapture %0, i8** nocapture writeonly %1) {
%3 = load double, double* %0
%4 = fcmp ult double %3, 1.000000e+09
br i1 %4, label %7, label %5
5: ; preds = %2
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %1
%6 = fdiv double %3, 1.000000e+09
store double %6, double* %0
br label %16
7: ; preds = %2
%8 = fcmp ult double %3, 1.000000e+06
br i1 %8, label %11, label %9
9: ; preds = %7
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %1
%10 = fdiv double %3, 1.000000e+06
store double %10, double* %0
br label %16
11: ; preds = %7
%12 = fcmp ult double %3, 1.000000e+03
br i1 %12, label %15, label %13
13: ; preds = %11
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %1
%14 = fdiv double %3, 1.000000e+03
store double %14, double* %0
br label %16
15: ; preds = %11
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8** %1
br label %16
16: ; preds = %9, %15, %13, %5
ret void
}