#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_rate(char *str, int len, double num) {
  num *= 8.0;
  if (num >= 1000.0 * 1000.0 * 1000.0)
    snprintf(str, len, "%.3f(Gbit/s)", num / (1000.0 * 1000.0 * 1000.0));
  else if (num >= 1000.0 * 1000.0)
    snprintf(str, len, "%.3f(Mbit/s)", num / (1000.0 * 1000.0));
  else if (num >= 1000.0)
    snprintf(str, len, "%.3f(kbit/s)", num / 1000.0);
  else
    snprintf(str, len, "%.3f(bit/s)", num);
}


x86 assembly (clang, -O0):
<conv_unit_rate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  0xedc(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xebd(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1176 <conv_unit_rate+0x66>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
movsd  -0x18(%rbp),%xmm0
movsd  0xe9f(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xeb4(%rip),%rdx
call   1030 <snprintf@plt>
jmp    1218 <conv_unit_rate+0x108>
movsd  -0x18(%rbp),%xmm0
movsd  0xe8d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11b6 <conv_unit_rate+0xa6>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
movsd  -0x18(%rbp),%xmm0
movsd  0xe6f(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe81(%rip),%rdx
call   1030 <snprintf@plt>
jmp    1213 <conv_unit_rate+0x103>
movsd  -0x18(%rbp),%xmm0
movsd  0xe55(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11f6 <conv_unit_rate+0xe6>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
movsd  -0x18(%rbp),%xmm0
movsd  0xe37(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe4e(%rip),%rdx
call   1030 <snprintf@plt>
jmp    120e <conv_unit_rate+0xfe>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
movsd  -0x18(%rbp),%xmm0
lea    0xe3e(%rip),%rdx
call   1030 <snprintf@plt>
jmp    1213 <conv_unit_rate+0x103>
jmp    1218 <conv_unit_rate+0x108>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<conv_unit_rate>:
mulsd  0xee8(%rip),%xmm0
ucomisd 0xee8(%rip),%xmm0
jae    1142 <conv_unit_rate+0x32>
ucomisd 0xee6(%rip),%xmm0
jae    1156 <conv_unit_rate+0x46>
ucomisd 0xee4(%rip),%xmm0
jae    116a <conv_unit_rate+0x5a>
lea    0xf0a(%rip),%rdx
jmp    1030 <snprintf@plt>
divsd  0xebe(%rip),%xmm0
lea    0xecf(%rip),%rdx
jmp    1030 <snprintf@plt>
divsd  0xeb2(%rip),%xmm0
lea    0xec8(%rip),%rdx
jmp    1030 <snprintf@plt>
divsd  0xea6(%rip),%xmm0
lea    0xec1(%rip),%rdx
jmp    1030 <snprintf@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"%.3f(Gbit/s)\00"
@.str.1 = [13 x i8] c"%.3f(Mbit/s)\00"
@.str.2 = [13 x i8] c"%.3f(kbit/s)\00"
@.str.3 = [12 x i8] c"%.3f(bit/s)\00"
define void @conv_unit_rate(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 = fmul double %7, 8.000000e+00
store double %8, double* %6
%9 = load double, double* %6
%10 = fcmp oge double %9, 1.000000e+09
br i1 %10, label %11, label %17
11: ; preds = %3
%12 = load i8*, i8** %4
%13 = load i32, i32* %5
%14 = load double, double* %6
%15 = fdiv double %14, 1.000000e+09
%16 = call i32 @snprintf(i8* %12, i32 %13, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), double %15)
br label %42
17: ; preds = %3
%18 = load double, double* %6
%19 = fcmp oge double %18, 1.000000e+06
br i1 %19, label %20, label %26
20: ; preds = %17
%21 = load i8*, i8** %4
%22 = load i32, i32* %5
%23 = load double, double* %6
%24 = fdiv double %23, 1.000000e+06
%25 = call i32 @snprintf(i8* %21, i32 %22, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), double %24)
br label %41
26: ; preds = %17
%27 = load double, double* %6
%28 = fcmp oge double %27, 1.000000e+03
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = load i8*, i8** %4
%31 = load i32, i32* %5
%32 = load double, double* %6
%33 = fdiv double %32, 1.000000e+03
%34 = call i32 @snprintf(i8* %30, i32 %31, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), double %33)
br label %40
35: ; preds = %26
%36 = load i8*, i8** %4
%37 = load i32, i32* %5
%38 = load double, double* %6
%39 = call i32 @snprintf(i8* %36, i32 %37, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), double %38)
br label %40
40: ; preds = %35, %29
br label %41
41: ; preds = %40, %20
br label %42
42: ; preds = %41, %11
ret void
}

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