#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, double);
const char *nice_freq(double freq) {
  static char buf[30];
  if (freq >= 1E9)
    snprintf(buf, sizeof(buf), "%.3fGHz", freq / 1E9);
  else if (freq >= 1E6)
    snprintf(buf, sizeof(buf), "%.3fMHz", freq / 1E6);
  else if (freq >= 1E3)
    snprintf(buf, sizeof(buf), "%.3fkHz", freq / 1E3);
  else
    snprintf(buf, sizeof(buf), "%f", freq);
  return (buf);
}


x86 assembly (clang, -O0):
<nice_freq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xed6(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1162 <nice_freq+0x52>
movsd  -0x8(%rbp),%xmm0
movsd  0xebf(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0x2ef4(%rip),%rdi
mov    $0x1e,%esi
lea    0xec0(%rip),%rdx
call   1030 <snprintf@plt>
jmp    1213 <nice_freq+0x103>
movsd  -0x8(%rbp),%xmm0
movsd  0xe99(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11a7 <nice_freq+0x97>
movsd  -0x8(%rbp),%xmm0
movsd  0xe82(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0x2eaf(%rip),%rdi
mov    $0x1e,%esi
lea    0xe83(%rip),%rdx
call   1030 <snprintf@plt>
jmp    120e <nice_freq+0xfe>
movsd  -0x8(%rbp),%xmm0
movsd  0xe5c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11ec <nice_freq+0xdc>
movsd  -0x8(%rbp),%xmm0
movsd  0xe45(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0x2e6a(%rip),%rdi
mov    $0x1e,%esi
lea    0xe46(%rip),%rdx
call   1030 <snprintf@plt>
jmp    1209 <nice_freq+0xf9>
movsd  -0x8(%rbp),%xmm0
lea    0x2e48(%rip),%rdi
mov    $0x1e,%esi
lea    0xe2c(%rip),%rdx
call   1030 <snprintf@plt>
jmp    120e <nice_freq+0xfe>
jmp    1213 <nice_freq+0x103>
lea    0x2e26(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nice_freq>:
push   %rax
ucomisd 0xee7(%rip),%xmm0
jae    113f <nice_freq+0x2f>
ucomisd 0xee5(%rip),%xmm0
jae    1157 <nice_freq+0x47>
ucomisd 0xee3(%rip),%xmm0
jae    116f <nice_freq+0x5f>
lea    0x2f0a(%rip),%rdi
lea    0xef3(%rip),%rdx
jmp    1185 <nice_freq+0x75>
divsd  0xeb9(%rip),%xmm0
lea    0x2ef2(%rip),%rdi
lea    0xec3(%rip),%rdx
jmp    1185 <nice_freq+0x75>
divsd  0xea9(%rip),%xmm0
lea    0x2eda(%rip),%rdi
lea    0xeb3(%rip),%rdx
jmp    1185 <nice_freq+0x75>
divsd  0xe99(%rip),%xmm0
lea    0x2ec2(%rip),%rdi
lea    0xea3(%rip),%rdx
mov    $0x1e,%esi
call   1030 <snprintf@plt>
lea    0x2eaa(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@nice_freq.buf = internal global [30 x i8] zeroinitializer
@.str = [8 x i8] c"%.3fGHz\00"
@.str.1 = [8 x i8] c"%.3fMHz\00"
@.str.2 = [8 x i8] c"%.3fkHz\00"
@.str.3 = [3 x i8] c"%f\00"
define i8* @nice_freq(double %0) {
%2 = alloca double
store double %0, double* %2
%3 = load double, double* %2
%4 = fcmp oge double %3, 1.000000e+09
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = load double, double* %2
%7 = fdiv double %6, 1.000000e+09
%8 = call i32 @snprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @nice_freq.buf, i64 0, i64 0), i32 30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %7)
br label %28
9: ; preds = %1
%10 = load double, double* %2
%11 = fcmp oge double %10, 1.000000e+06
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load double, double* %2
%14 = fdiv double %13, 1.000000e+06
%15 = call i32 @snprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @nice_freq.buf, i64 0, i64 0), i32 30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double %14)
br label %27
16: ; preds = %9
%17 = load double, double* %2
%18 = fcmp oge double %17, 1.000000e+03
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load double, double* %2
%21 = fdiv double %20, 1.000000e+03
%22 = call i32 @snprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @nice_freq.buf, i64 0, i64 0), i32 30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %21)
br label %26
23: ; preds = %16
%24 = load double, double* %2
%25 = call i32 @snprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @nice_freq.buf, i64 0, i64 0), i32 30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), double %24)
br label %26
26: ; preds = %23, %19
br label %27
27: ; preds = %26, %12
br label %28
28: ; preds = %27, %5
ret i8* getelementptr inbounds ([30 x i8], [30 x i8]* @nice_freq.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@nice_freq.buf = internal global [30 x i8] zeroinitializer
@.str = [8 x i8] c"%.3fGHz\00"
@.str.1 = [8 x i8] c"%.3fMHz\00"
@.str.2 = [8 x i8] c"%.3fkHz\00"
@.str.3 = [3 x i8] c"%f\00"
define i8* @nice_freq(double %0) {
%2 = fcmp ult double %0, 1.000000e+09
br i1 %2, label %6, label %3
3: ; preds = %1
%4 = fdiv double %0, 1.000000e+09
%5 = tail call i32 @snprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @nice_freq.buf, i64 0, i64 0), i32 30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %4)
br label %18
6: ; preds = %1
%7 = fcmp ult double %0, 1.000000e+06
br i1 %7, label %11, label %8
8: ; preds = %6
%9 = fdiv double %0, 1.000000e+06
%10 = tail call i32 @snprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @nice_freq.buf, i64 0, i64 0), i32 30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double %9)
br label %18
11: ; preds = %6
%12 = fcmp ult double %0, 1.000000e+03
br i1 %12, label %16, label %13
13: ; preds = %11
%14 = fdiv double %0, 1.000000e+03
%15 = tail call i32 @snprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @nice_freq.buf, i64 0, i64 0), i32 30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %14)
br label %18
16: ; preds = %11
%17 = tail call i32 @snprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @nice_freq.buf, i64 0, i64 0), i32 30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), double %0)
br label %18
18: ; preds = %8, %16, %13, %3
ret i8* getelementptr inbounds ([30 x i8], [30 x i8]* @nice_freq.buf, i64 0, i64 0)
}