float trip_rate_condense(const unsigned rate, char *prefix) {
  static const char trip_prefix[5] = {'\0', 'k', 'm', 'g', 't'};
  static const float trip_magnitude[5] = {
      0.0,
      1000.0f,
      1000.0f * 1000.0f,
      1000.0f * 1000.0f * 1000.0f,
      1000.0f * 1000.0f * 1000.0f * 1000.0f,
  };
  unsigned i;
  for (i = 0; i < 5; i++) {
    if (rate < trip_magnitude[i] && i != 0) {
      *prefix = trip_prefix[i - 1];
      return (float)rate / trip_magnitude[i - 1];
    } else
      continue;
  }
  return (float)rate;
}


x86 assembly (clang, -O0):
<trip_rate_condense>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jae    1199 <trip_rate_condense+0x99>
mov    -0x8(%rbp),%eax
cvtsi2ss %rax,%xmm1
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
lea    0xee0(%rip),%rax
movss  (%rax,%rcx,4),%xmm0
ucomiss %xmm1,%xmm0
jbe    1186 <trip_rate_condense+0x86>
cmpl   $0x0,-0x14(%rbp)
je     1186 <trip_rate_condense+0x86>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
lea    0xeab(%rip),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%eax
cvtsi2ss %rax,%xmm0
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,%eax
mov    %eax,%ecx
lea    0xe99(%rip),%rax
divss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11a6 <trip_rate_condense+0xa6>
jmp    118b <trip_rate_condense+0x8b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1112 <trip_rate_condense+0x12>
mov    -0x8(%rbp),%eax
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<trip_rate_condense>:
mov    %edi,%eax
cvtsi2ss %rax,%xmm0
cmp    $0x3e8,%edi
jae    1113 <trip_rate_condense+0x13>
xor    %eax,%eax
jmp    1137 <trip_rate_condense+0x37>
mov    $0x1,%eax
cmp    $0xf4240,%edi
jb     1137 <trip_rate_condense+0x37>
mov    $0x2,%eax
movss  0xed3(%rip),%xmm1
ucomiss %xmm0,%xmm1
ja     1137 <trip_rate_condense+0x37>
mov    $0x3,%eax
lea    0xed2(%rip),%rcx
mov    (%rax,%rcx,1),%cl
mov    %cl,(%rsi)
lea    0xed6(%rip),%rcx
divss  (%rcx,%rax,4),%xmm0
ret

LLVM IR (-O0):
@trip_rate_condense.trip_prefix = internal constant [5 x i8] c"\00kmgt"
@trip_rate_condense.trip_magnitude = internal constant [5 x float] [float 0.000000e+00, float 1.000000e+03, float 1.000000e+06, float 1.000000e+09, float 0x426D1A94A0000000]
define float @trip_rate_condense(i32 %0, i8* %1) {
%3 = alloca float
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 0, i32* %6
br label %7
7: ; preds = %37, %2
%8 = load i32, i32* %6
%9 = icmp ult i32 %8, 5
br i1 %9, label %10, label %40
10: ; preds = %7
%11 = load i32, i32* %4
%12 = uitofp i32 %11 to float
%13 = load i32, i32* %6
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds [5 x float], [5 x float]* @trip_rate_condense.trip_magnitude, i64 0, i64 %14
%16 = load float, float* %15
%17 = fcmp olt float %12, %16
br i1 %17, label %18, label %36
18: ; preds = %10
%19 = load i32, i32* %6
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %36
21: ; preds = %18
%22 = load i32, i32* %6
%23 = sub i32 %22, 1
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds [5 x i8], [5 x i8]* @trip_rate_condense.trip_prefix, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = load i8*, i8** %5
store i8 %26, i8* %27
%28 = load i32, i32* %4
%29 = uitofp i32 %28 to float
%30 = load i32, i32* %6
%31 = sub i32 %30, 1
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds [5 x float], [5 x float]* @trip_rate_condense.trip_magnitude, i64 0, i64 %32
%34 = load float, float* %33
%35 = fdiv float %29, %34
store float %35, float* %3
br label %43
36: ; preds = %18, %10
br label %37
37: ; preds = %36
%38 = load i32, i32* %6
%39 = add i32 %38, 1
store i32 %39, i32* %6
br label %7
40: ; preds = %7
%41 = load i32, i32* %4
%42 = uitofp i32 %41 to float
store float %42, float* %3
br label %43
43: ; preds = %40, %21
%44 = load float, float* %3
ret float %44
}

LLVM IR (-O2):
@trip_rate_condense.trip_prefix = internal unnamed_addr constant [5 x i8] c"\00kmgt"
@trip_rate_condense.trip_magnitude = internal unnamed_addr constant [5 x float] [float 0.000000e+00, float 1.000000e+03, float 1.000000e+06, float 1.000000e+09, float 0x426D1A94A0000000]
define float @trip_rate_condense(i32 %0, i8* nocapture writeonly %1) {
%3 = uitofp i32 %0 to float
%4 = icmp ult i32 %0, 1000
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = icmp ult i32 %0, 1000000
br i1 %6, label %10, label %7
7: ; preds = %5
%8 = fcmp olt float %3, 1.000000e+09
br i1 %8, label %10, label %9
9: ; preds = %7
br label %10
10: ; preds = %2, %5, %7, %9
%11 = phi i64 [ 0, %2 ], [ 1, %5 ], [ 2, %7 ], [ 3, %9 ]
%12 = getelementptr inbounds [5 x i8], [5 x i8]* @trip_rate_condense.trip_prefix, i64 0, i64 %11
%13 = load i8, i8* %12
store i8 %13, i8* %1
%14 = getelementptr inbounds [5 x float], [5 x float]* @trip_rate_condense.trip_magnitude, i64 0, i64 %11
%15 = load float, float* %14
%16 = fdiv float %3, %15
ret float %16
}