#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*/ snprintf(char *, int, char *, double);
void conv_unit_usec(char *str, int len, double usec) {
  if (usec >= 1000.0 * 1000.0)
    snprintf(str, len, "%.3f(s)", usec / (1000.0 * 1000.0));
  else if (usec >= 1000.0)
    snprintf(str, len, "%.3f(ms)", usec / 1000.0);
  else if (usec < 0)
    snprintf(str, len, "%.3f(us)", 0.0);
  else
    snprintf(str, len, "%.3f(us)", usec);
}


x86 assembly (clang, -O0):
<conv_unit_usec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xecf(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1164 <conv_unit_usec+0x54>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
movsd  -0x18(%rbp),%xmm0
movsd  0xeb1(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xeb6(%rip),%rdx
call   1030 <snprintf@plt>
jmp    11ef <conv_unit_usec+0xdf>
movsd  -0x18(%rbp),%xmm0
movsd  0xe97(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11a4 <conv_unit_usec+0x94>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
movsd  -0x18(%rbp),%xmm0
movsd  0xe79(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe7e(%rip),%rdx
call   1030 <snprintf@plt>
jmp    11ea <conv_unit_usec+0xda>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11cd <conv_unit_usec+0xbd>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    0xe61(%rip),%rdx
xorps  %xmm0,%xmm0
call   1030 <snprintf@plt>
jmp    11e5 <conv_unit_usec+0xd5>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
movsd  -0x18(%rbp),%xmm0
lea    0xe41(%rip),%rdx
call   1030 <snprintf@plt>
jmp    11ea <conv_unit_usec+0xda>
jmp    11ef <conv_unit_usec+0xdf>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<conv_unit_usec>:
ucomisd 0xee8(%rip),%xmm0
jae    113e <conv_unit_usec+0x2e>
ucomisd 0xee6(%rip),%xmm0
jae    1152 <conv_unit_usec+0x42>
xorpd  %xmm1,%xmm1
lea    0xef2(%rip),%rdx
ucomisd %xmm0,%xmm1
jbe    1161 <conv_unit_usec+0x51>
xorpd  %xmm0,%xmm0
jmp    1030 <snprintf@plt>
divsd  0xeba(%rip),%xmm0
lea    0xec3(%rip),%rdx
jmp    1030 <snprintf@plt>
divsd  0xeae(%rip),%xmm0
lea    0xeb7(%rip),%rdx
jmp    1030 <snprintf@plt>

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

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