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


x86 assembly (clang, -O0):
<iw_print_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    1156 <iw_print_freq_value+0x46>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
movsd  -0x18(%rbp),%xmm0
lea    0xece(%rip),%rdx
mov    $0x1,%al
call   1030 <snprintf@plt>
jmp    11db <iw_print_freq_value+0xcb>
movsd  -0x18(%rbp),%xmm0
movsd  0xea5(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     117d <iw_print_freq_value+0x6d>
movb   $0x47,-0x19(%rbp)
movl   $0x3b9aca00,-0x20(%rbp)
jmp    11b4 <iw_print_freq_value+0xa4>
movsd  -0x18(%rbp),%xmm0
movsd  0xe86(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11a4 <iw_print_freq_value+0x94>
movb   $0x4d,-0x19(%rbp)
movl   $0xf4240,-0x20(%rbp)
jmp    11af <iw_print_freq_value+0x9f>
movb   $0x6b,-0x19(%rbp)
movl   $0x3e8,-0x20(%rbp)
jmp    11b4 <iw_print_freq_value+0xa4>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x20(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsbl -0x19(%rbp),%ecx
lea    0xe47(%rip),%rdx
mov    $0x1,%al
call   1030 <snprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iw_print_freq_value>:
movsd  0xee8(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    112c <iw_print_freq_value+0x1c>
lea    0xf03(%rip),%rdx
mov    $0x1,%al
jmp    1030 <snprintf@plt>
xor    %eax,%eax
ucomisd 0xed2(%rip),%xmm0
mov    $0x6b,%ecx
mov    $0x4d,%edx
cmovb  %ecx,%edx
setb   %r8b
movsd  0xec1(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    $0x47,%ecx
cmovb  %edx,%ecx
jae    116c <iw_print_freq_value+0x5c>
mov    %r8b,%al
lea    0xeb1(%rip),%rdx
movsd  (%rdx,%rax,8),%xmm1
divsd  %xmm1,%xmm0
lea    0xeb4(%rip),%rdx
mov    $0x1,%al
jmp    1030 <snprintf@plt>

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

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