void display_factored_time(double time, int align) {
  char buffer[128];
  if (time < 1000) {
    sprintf(buffer, "%.0lfus", time);
    printf("%*s", align, buffer);
  } else if (time < 1000000) {
    sprintf(buffer, "%.2lfms", time / 1000.0);
    printf("%*s", align, buffer);
  } else {
    sprintf(buffer, "%.2lfs", time / 1000000.0);
    printf("%*s", align, buffer);
  }
}


x86 assembly (clang, -O0):
<display_factored_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movsd  0xec5(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    117d <display_factored_time+0x5d>
lea    -0x90(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
lea    0xeb7(%rip),%rsi
mov    $0x1,%al
call   1040 <sprintf@plt>
mov    -0xc(%rbp),%esi
lea    -0x90(%rbp),%rdx
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1216 <display_factored_time+0xf6>
movsd  0xe83(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11d3 <display_factored_time+0xb3>
lea    -0x90(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
movsd  0xe5c(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe6d(%rip),%rsi
mov    $0x1,%al
call   1040 <sprintf@plt>
mov    -0xc(%rbp),%esi
lea    -0x90(%rbp),%rdx
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1211 <display_factored_time+0xf1>
lea    -0x90(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
movsd  0xe21(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe32(%rip),%rsi
mov    $0x1,%al
call   1040 <sprintf@plt>
mov    -0xc(%rbp),%esi
lea    -0x90(%rbp),%rdx
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1216 <display_factored_time+0xf6>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_factored_time>:
push   %rbx
sub    $0x80,%rsp
mov    %edi,%ebx
movsd  0xece(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1141 <display_factored_time+0x21>
lea    0xed1(%rip),%rsi
jmp    116f <display_factored_time+0x4f>
movsd  0xebf(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1160 <display_factored_time+0x40>
divsd  0xea9(%rip),%xmm0
lea    0xebe(%rip),%rsi
jmp    116f <display_factored_time+0x4f>
divsd  0xea0(%rip),%xmm0
lea    0xeb5(%rip),%rsi
mov    %rsp,%rdi
mov    $0x1,%al
call   1040 <sprintf@plt>
lea    0xe98(%rip),%rdi
mov    %rsp,%rdx
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x80,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [8 x i8] c"%.0lfus\00"
@.str.1 = [4 x i8] c"%*s\00"
@.str.2 = [8 x i8] c"%.2lfms\00"
@.str.3 = [7 x i8] c"%.2lfs\00"
define void @display_factored_time(double %0, i32 %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = fcmp olt double %0, 1.000000e+03
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = call i32 (i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %0)
br label %16
8: ; preds = %2
%9 = fcmp olt double %0, 1.000000e+06
br i1 %9, label %10, label %13
10: ; preds = %8
%11 = fdiv double %0, 1.000000e+03
%12 = call i32 (i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %11)
br label %16
13: ; preds = %8
%14 = fdiv double %0, 1.000000e+06
%15 = call i32 (i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %14)
br label %16
16: ; preds = %10, %13, %6
%17 = 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)
ret void
}