#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, char);
void iw_print_bitrate(char *buffer, int buflen, int bitrate) {
  double rate = bitrate;
  char scale;
  int divisor;
  if (rate >= 1e9) {
    scale = 'G';
    divisor = 1e9;
  } else {
    if (rate >= 1e6) {
      scale = 'M';
      divisor = 1e6;
    } else {
      scale = 'k';
      divisor = 1e3;
    }
  }
  snprintf(buffer, buflen, "%g %cb/s", rate / divisor, scale);
}


x86 assembly (clang, -O0):
<iw_print_bitrate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cvtsi2sdl -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xec7(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1153 <iw_print_bitrate+0x43>
movb   $0x47,-0x19(%rbp)
movl   $0x3b9aca00,-0x20(%rbp)
jmp    118a <iw_print_bitrate+0x7a>
movsd  -0x18(%rbp),%xmm0
movsd  0xea8(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     117a <iw_print_bitrate+0x6a>
movb   $0x4d,-0x19(%rbp)
movl   $0xf4240,-0x20(%rbp)
jmp    1185 <iw_print_bitrate+0x75>
movb   $0x6b,-0x19(%rbp)
movl   $0x3e8,-0x20(%rbp)
jmp    118a <iw_print_bitrate+0x7a>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x20(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xe6a(%rip),%rdx
movsbl -0x19(%rbp),%ecx
call   1030 <snprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iw_print_bitrate>:
xor    %r9d,%r9d
cmp    $0xf4240,%edx
setge  %r8b
mov    $0x4d,%ecx
mov    $0x6b,%eax
cmovge %ecx,%eax
mov    $0x47,%ecx
cmp    $0x3b9aca00,%edx
cmovl  %eax,%ecx
jge    114c <iw_print_bitrate+0x3c>
mov    %r8b,%r9b
lea    0xebc(%rip),%rax
movsd  (%rax,%r9,8),%xmm1
jmp    1154 <iw_print_bitrate+0x44>
movsd  0xebc(%rip),%xmm1
cvtsi2sd %edx,%xmm0
divsd  %xmm1,%xmm0
lea    0xeb5(%rip),%rdx
jmp    1030 <snprintf@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"%g %cb/s\00"
define void @iw_print_bitrate(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca i8
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %6
%11 = sitofp i32 %10 to double
store double %11, double* %7
%12 = load double, double* %7
%13 = fcmp oge double %12, 1.000000e+09
br i1 %13, label %14, label %15
14: ; preds = %3
store i8 71, i8* %8
store i32 1000000000, i32* %9
br label %21
15: ; preds = %3
%16 = load double, double* %7
%17 = fcmp oge double %16, 1.000000e+06
br i1 %17, label %18, label %19
18: ; preds = %15
store i8 77, i8* %8
store i32 1000000, i32* %9
br label %20
19: ; preds = %15
store i8 107, i8* %8
store i32 1000, i32* %9
br label %20
20: ; preds = %19, %18
br label %21
21: ; preds = %20, %14
%22 = load i8*, i8** %4
%23 = load i32, i32* %5
%24 = load double, double* %7
%25 = load i32, i32* %9
%26 = sitofp i32 %25 to double
%27 = fdiv double %24, %26
%28 = load i8, i8* %8
%29 = call i32 @snprintf(i8* %22, i32 %23, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double %27, i8 signext %28)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"%g %cb/s\00"
define void @iw_print_bitrate(i8* %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %2, 999999999
%5 = icmp sgt i32 %2, 999999
%6 = select i1 %5, i8 77, i8 107
%7 = select i1 %5, double 1.000000e+06, double 1.000000e+03
%8 = select i1 %4, i8 71, i8 %6
%9 = select i1 %4, double 1.000000e+09, double %7
%10 = sitofp i32 %2 to double
%11 = fdiv double %10, %9
%12 = tail call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double %11, i8 signext %8)
ret void
}