#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, double);
void sprintf_time(double x, char *buf) {
  if (x < 1.0E-6)
    sprintf(buf, "%.2f ns", x * 1.0E9);
  else if (x < 1.0E-3)
    sprintf(buf, "%.2f us", x * 1.0E6);
  else if (x < 1.0)
    sprintf(buf, "%.2f ms", x * 1.0E3);
  else
    sprintf(buf, "%.2f s", x);
}


x86 assembly (clang, -O0):
<sprintf_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
movsd  0xed7(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1156 <sprintf_time+0x46>
mov    -0x10(%rbp),%rdi
movsd  0xee8(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
lea    0xee4(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11df <sprintf_time+0xcf>
movsd  0xeaa(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    118b <sprintf_time+0x7b>
mov    -0x10(%rbp),%rdi
movsd  0xeab(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
lea    0xeb7(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11da <sprintf_time+0xca>
movsd  0xe7d(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11c0 <sprintf_time+0xb0>
mov    -0x10(%rbp),%rdi
movsd  0xe6e(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
lea    0xe8a(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11d5 <sprintf_time+0xc5>
mov    -0x10(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
lea    0xe78(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11da <sprintf_time+0xca>
jmp    11df <sprintf_time+0xcf>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sprintf_time>:
movsd  0xee8(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1132 <sprintf_time+0x22>
mulsd  0xf02(%rip),%xmm0
lea    0xf03(%rip),%rsi
jmp    1030 <sprintf@plt>
movsd  0xece(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1154 <sprintf_time+0x44>
mulsd  0xed8(%rip),%xmm0
lea    0xee9(%rip),%rsi
jmp    1030 <sprintf@plt>
movsd  0xeb4(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1176 <sprintf_time+0x66>
mulsd  0xeae(%rip),%xmm0
lea    0xecf(%rip),%rsi
jmp    1030 <sprintf@plt>
lea    0xecb(%rip),%rsi
jmp    1030 <sprintf@plt>

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

LLVM IR (-O2):
@.str = [8 x i8] c"%.2f ns\00"
@.str.1 = [8 x i8] c"%.2f us\00"
@.str.2 = [8 x i8] c"%.2f ms\00"
@.str.3 = [7 x i8] c"%.2f s\00"
define void @sprintf_time(double %0, i8* nocapture writeonly %1) {
%3 = fcmp olt double %0, 0x3EB0C6F7A0B5ED8D
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = fmul double %0, 1.000000e+09
%6 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %5)
br label %19
7: ; preds = %2
%8 = fcmp olt double %0, 1.000000e-03
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = fmul double %0, 1.000000e+06
%11 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double %10)
br label %19
12: ; preds = %7
%13 = fcmp olt double %0, 1.000000e+00
br i1 %13, label %14, label %17
14: ; preds = %12
%15 = fmul double %0, 1.000000e+03
%16 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %15)
br label %19
17: ; preds = %12
%18 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %0)
br label %19
19: ; preds = %9, %17, %14, %4
ret void
}