void iw_print_freq(char *buffer, int buflen, double freq, int channel,
                   int freq_flags) {
  char sep = ((freq_flags & 0x01) ? '=' : ':');
  char vbuf[16];
  iw_print_freq_value(vbuf, sizeof(vbuf), freq);
  if (freq < 1e3)
    snprintf(buffer, buflen, "Channel%c%s", sep, vbuf);
  else {
    if (channel >= 0)
      snprintf(buffer, buflen, "Frequency%c%s (Channel %d)", sep, vbuf,
               channel);
    else
      snprintf(buffer, buflen, "Frequency%c%s", sep, vbuf);
  }
}


x86 assembly (clang, -O0):
<iw_print_freq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x20(%rbp),%edx
and    $0x1,%edx
mov    $0x3a,%eax
mov    $0x3d,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x21(%rbp)
lea    -0x40(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
mov    $0x10,%esi
mov    $0x1,%al
call   1040 <iw_print_freq_value@plt>
movsd  0xe90(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    119e <iw_print_freq+0x7e>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rsi
movsbl -0x21(%rbp),%ecx
lea    -0x40(%rbp),%r8
lea    0xe76(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11f2 <iw_print_freq+0xd2>
cmpl   $0x0,-0x1c(%rbp)
jl     11cf <iw_print_freq+0xaf>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rsi
movsbl -0x21(%rbp),%ecx
lea    -0x40(%rbp),%r8
mov    -0x1c(%rbp),%r9d
lea    0xe51(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11ed <iw_print_freq+0xcd>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rsi
movsbl -0x21(%rbp),%ecx
lea    -0x40(%rbp),%r8
lea    0xe49(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11f2 <iw_print_freq+0xd2>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iw_print_freq>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r14d
movsd  %xmm0,0x10(%rsp)
mov    %esi,%ebp
mov    %rdi,%r15
xor    %eax,%eax
test   $0x1,%cl
setne  %al
lea    0x3a(%rax,%rax,2),%ebx
mov    %rsp,%rdi
mov    $0x10,%esi
mov    $0x1,%al
call   1040 <iw_print_freq_value@plt>
movsd  0xea5(%rip),%xmm0
ucomisd 0x10(%rsp),%xmm0
jbe    1172 <iw_print_freq+0x52>
movslq %ebp,%rsi
movzbl %bl,%ecx
lea    0xe98(%rip),%rdx
jmp    119d <iw_print_freq+0x7d>
movslq %ebp,%rsi
movzbl %bl,%ecx
test   %r14d,%r14d
js     1196 <iw_print_freq+0x76>
lea    0xe90(%rip),%rdx
mov    %rsp,%r8
mov    %r15,%rdi
mov    %r14d,%r9d
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    11aa <iw_print_freq+0x8a>
lea    0xe92(%rip),%rdx
mov    %rsp,%r8
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <snprintf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"Channel%c%s\00"
@.str.1 = [27 x i8] c"Frequency%c%s (Channel %d)\00"
@.str.2 = [14 x i8] c"Frequency%c%s\00"
define void @iw_print_freq(i8* %0, i32 %1, double %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
%12 = alloca [16 x i8]
store i8* %0, i8** %6
store i32 %1, i32* %7
store double %2, double* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%13 = load i32, i32* %10
%14 = and i32 %13, 1
%15 = icmp ne i32 %14, 0
%16 = zext i1 %15 to i64
%17 = select i1 %15, i32 61, i32 58
%18 = trunc i32 %17 to i8
store i8 %18, i8* %11
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%20 = load double, double* %8
%21 = call i32 (i8*, i64, double, ...) bitcast (i32 (...)* @iw_print_freq_value to i32 (i8*, i64, double, ...)*)(i8* %19, i64 16, double %20)
%22 = load double, double* %8
%23 = fcmp olt double %22, 1.000000e+03
br i1 %23, label %24, label %32
24: ; preds = %5
%25 = load i8*, i8** %6
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = load i8, i8* %11
%29 = sext i8 %28 to i32
%30 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%31 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %25, i64 %27, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %29, i8* %30)
br label %53
32: ; preds = %5
%33 = load i32, i32* %9
%34 = icmp sge i32 %33, 0
br i1 %34, label %35, label %44
35: ; preds = %32
%36 = load i8*, i8** %6
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = load i8, i8* %11
%40 = sext i8 %39 to i32
%41 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%42 = load i32, i32* %9
%43 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %36, i64 %38, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %40, i8* %41, i32 %42)
br label %52
44: ; preds = %32
%45 = load i8*, i8** %6
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = load i8, i8* %11
%49 = sext i8 %48 to i32
%50 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%51 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %45, i64 %47, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %49, i8* %50)
br label %52
52: ; preds = %44, %35
br label %53
53: ; preds = %52, %24
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"Channel%c%s\00"
@.str.1 = [27 x i8] c"Frequency%c%s (Channel %d)\00"
@.str.2 = [14 x i8] c"Frequency%c%s\00"
define void @iw_print_freq(i8* nocapture writeonly %0, i32 %1, double %2, i32 %3, i32 %4) {
%6 = alloca [16 x i8]
%7 = and i32 %4, 1
%8 = icmp eq i32 %7, 0
%9 = select i1 %8, i8 58, i8 61
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%11 = call i32 (i8*, i64, double, ...) bitcast (i32 (...)* @iw_print_freq_value to i32 (i8*, i64, double, ...)*)(i8* %10, i64 16, double %2)
%12 = fcmp olt double %2, 1.000000e+03
br i1 %12, label %13, label %17
13: ; preds = %5
%14 = sext i32 %1 to i64
%15 = zext i8 %9 to i32
%16 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %0, i64 %14, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %15, i8* %10)
br label %25
17: ; preds = %5
%18 = icmp sgt i32 %3, -1
%19 = sext i32 %1 to i64
%20 = zext i8 %9 to i32
br i1 %18, label %21, label %23
21: ; preds = %17
%22 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %0, i64 %19, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %20, i8* %10, i32 %3)
br label %25
23: ; preds = %17
%24 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %0, i64 %19, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %20, i8* %10)
br label %25
25: ; preds = %21, %23, %13
ret void
}