#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 iw_calcu_freq_value(char *buffer, int buflen, double freq) {
  if (freq < 1e3)
    snprintf(buffer, buflen, "%g", freq);
  else {
    int divisor;
    if (freq >= 1e9) {
      divisor = 1e9;
    } else {
      if (freq >= 1e6) {
        divisor = 1e6;
      } else {
        divisor = 1e3;
      }
    }
    snprintf(buffer, buflen, "%g", freq / divisor);
  }
}


x86 assembly (clang, -O0):
<iw_calcu_freq_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  0xed4(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1154 <iw_calcu_freq_value+0x44>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
movsd  -0x18(%rbp),%xmm0
lea    0xece(%rip),%rdx
call   1030 <snprintf@plt>
jmp    11c7 <iw_calcu_freq_value+0xb7>
movsd  -0x18(%rbp),%xmm0
movsd  0xea7(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1177 <iw_calcu_freq_value+0x67>
movl   $0x3b9aca00,-0x1c(%rbp)
jmp    11a6 <iw_calcu_freq_value+0x96>
movsd  -0x18(%rbp),%xmm0
movsd  0xe8c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     119a <iw_calcu_freq_value+0x8a>
movl   $0xf4240,-0x1c(%rbp)
jmp    11a1 <iw_calcu_freq_value+0x91>
movl   $0x3e8,-0x1c(%rbp)
jmp    11a6 <iw_calcu_freq_value+0x96>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xe56(%rip),%rdx
call   1030 <snprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iw_calcu_freq_value>:
movsd  0xee8(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     1158 <iw_calcu_freq_value+0x48>
xor    %eax,%eax
ucomisd 0xee0(%rip),%xmm0
setb   %al
lea    0xee6(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm1
movsd  0xed1(%rip),%xmm2
movapd %xmm2,%xmm3
cmpnlesd %xmm0,%xmm3
andpd  %xmm3,%xmm1
andnpd %xmm2,%xmm3
orpd   %xmm1,%xmm3
divsd  %xmm3,%xmm0
lea    0xec9(%rip),%rdx
jmp    1030 <snprintf@plt>

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

LLVM IR (-O2):
@.str = [3 x i8] c"%g\00"
define void @iw_calcu_freq_value(i8* %0, i32 %1, double %2) {
%4 = fcmp olt double %2, 1.000000e+03
br i1 %4, label %11, label %5
5: ; preds = %3
%6 = fcmp ult double %2, 1.000000e+09
%7 = fcmp ult double %2, 1.000000e+06
%8 = select i1 %7, double 1.000000e+03, double 1.000000e+06
%9 = select i1 %6, double %8, double 1.000000e+09
%10 = fdiv double %2, %9
br label %11
11: ; preds = %3, %5
%12 = phi double [ %10, %5 ], [ %2, %3 ]
%13 = tail call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), double %12)
ret void
}