void display_factored_time_delta(double time, int align) {
  char buffer[128];
  if (fabs(time) < 1000.0) {
    snprintf(buffer, sizeof(buffer), "%+.0lfus", time);
    printf("%*s", align, buffer);
  } else if (fabs(time) < 1000000.0) {
    snprintf(buffer, sizeof(buffer), "%+.1lfms", time / 1000.0);
    printf("%*s", align, buffer);
  } else if (fabs(time) < 100000000000.0) {
    snprintf(buffer, sizeof(buffer), "%+.1lfs", time / 1000000.0);
    printf("%*s", align, buffer);
  } else
    printf("%.*s", align, "                            ");
}


x86 assembly (clang, -O0):
<display_factored_time_delta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movsd  -0x8(%rbp),%xmm1
movaps 0xee1(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xeb5(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1191 <display_factored_time_delta+0x71>
lea    -0x90(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
mov    $0x80,%esi
lea    0xec3(%rip),%rdx
mov    $0x1,%al
call   1040 <snprintf@plt>
mov    -0xc(%rbp),%esi
lea    -0x90(%rbp),%rdx
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1287 <display_factored_time_delta+0x167>
movsd  -0x8(%rbp),%xmm1
movaps 0xe83(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe5f(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11fb <display_factored_time_delta+0xdb>
lea    -0x90(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
movsd  0xe39(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    $0x80,%esi
lea    0xe66(%rip),%rdx
mov    $0x1,%al
call   1040 <snprintf@plt>
mov    -0xc(%rbp),%esi
lea    -0x90(%rbp),%rdx
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1282 <display_factored_time_delta+0x162>
movsd  -0x8(%rbp),%xmm1
movaps 0xe19(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xdfd(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1265 <display_factored_time_delta+0x145>
lea    -0x90(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
movsd  0xdd7(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    $0x80,%esi
lea    0xe05(%rip),%rdx
mov    $0x1,%al
call   1040 <snprintf@plt>
mov    -0xc(%rbp),%esi
lea    -0x90(%rbp),%rdx
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    127d <display_factored_time_delta+0x15d>
mov    -0xc(%rbp),%esi
lea    0xddf(%rip),%rdi
lea    0xddd(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1282 <display_factored_time_delta+0x162>
jmp    1287 <display_factored_time_delta+0x167>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_factored_time_delta>:
push   %rbp
push   %rbx
sub    $0x88,%rsp
mov    %edi,%ebp
movapd 0xecd(%rip),%xmm1
andpd  %xmm0,%xmm1
movsd  0xed1(%rip),%xmm2
ucomisd %xmm1,%xmm2
jbe    114e <display_factored_time_delta+0x2e>
lea    0xedc(%rip),%rdx
jmp    118a <display_factored_time_delta+0x6a>
movsd  0xec2(%rip),%xmm2
ucomisd %xmm1,%xmm2
jbe    116d <display_factored_time_delta+0x4d>
divsd  0xeac(%rip),%xmm0
lea    0xeca(%rip),%rdx
jmp    118a <display_factored_time_delta+0x6a>
movsd  0xeab(%rip),%xmm2
ucomisd %xmm1,%xmm2
jbe    11b9 <display_factored_time_delta+0x99>
divsd  0xe95(%rip),%xmm0
lea    0xeb4(%rip),%rdx
mov    %rsp,%rbx
mov    $0x80,%esi
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <snprintf@plt>
lea    0xe8e(%rip),%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x88,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe86(%rip),%rdi
lea    0xe84(%rip),%rdx
mov    %ebp,%esi
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"%+.0lfus\00"
@.str.1 = [4 x i8] c"%*s\00"
@.str.2 = [9 x i8] c"%+.1lfms\00"
@.str.3 = [8 x i8] c"%+.1lfs\00"
@.str.4 = [5 x i8] c"%.*s\00"
@.str.5 = [29 x i8] c" \00"
define void @display_factored_time_delta(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca [128 x i8]
store double %0, double* %3
store i32 %1, i32* %4
%6 = load double, double* %3
%7 = call double @llvm.fabs.f64(double %6)
%8 = fcmp olt double %7, 1.000000e+03
br i1 %8, label %9, label %16
9: ; preds = %2
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%11 = load double, double* %3
%12 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %10, i64 128, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double %11)
%13 = load i32, i32* %4
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %13, i8* %14)
br label %45
16: ; preds = %2
%17 = load double, double* %3
%18 = call double @llvm.fabs.f64(double %17)
%19 = fcmp olt double %18, 1.000000e+06
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%22 = load double, double* %3
%23 = fdiv double %22, 1.000000e+03
%24 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %21, i64 128, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %23)
%25 = load i32, i32* %4
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %25, i8* %26)
br label %44
28: ; preds = %16
%29 = load double, double* %3
%30 = call double @llvm.fabs.f64(double %29)
%31 = fcmp olt double %30, 1.000000e+11
br i1 %31, label %32, label %40
32: ; preds = %28
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%34 = load double, double* %3
%35 = fdiv double %34, 1.000000e+06
%36 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %33, i64 128, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), double %35)
%37 = load i32, i32* %4
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %37, i8* %38)
br label %43
40: ; preds = %28
%41 = load i32, i32* %4
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %41, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %43
43: ; preds = %40, %32
br label %44
44: ; preds = %43, %20
br label %45
45: ; preds = %44, %9
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"%+.0lfus\00"
@.str.1 = [4 x i8] c"%*s\00"
@.str.2 = [9 x i8] c"%+.1lfms\00"
@.str.3 = [8 x i8] c"%+.1lfs\00"
@.str.4 = [5 x i8] c"%.*s\00"
@.str.5 = [29 x i8] c" \00"
define void @display_factored_time_delta(double %0, i32 %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = tail call double @llvm.fabs.f64(double %0)
%6 = fcmp olt double %5, 1.000000e+03
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %4, i64 128, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double %0)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %1, i8* %4)
br label %24
10: ; preds = %2
%11 = fcmp olt double %5, 1.000000e+06
br i1 %11, label %12, label %16
12: ; preds = %10
%13 = fdiv double %0, 1.000000e+03
%14 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %4, i64 128, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %13)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %1, i8* %4)
br label %24
16: ; preds = %10
%17 = fcmp olt double %5, 1.000000e+11
br i1 %17, label %18, label %22
18: ; preds = %16
%19 = fdiv double %0, 1.000000e+06
%20 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %4, i64 128, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), double %19)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %1, i8* %4)
br label %24
22: ; preds = %16
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %24
24: ; preds = %12, %22, %18, %7
ret void
}