char buhr(double value) {
  const char units[] = " KMGT";
  int pot = 0;
  while (value > 1500 && ++pot <= 4)
    value /= 1000;
  return units[pot];
}


x86 assembly (clang, -O0):
<buhr>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
mov    0xf01(%rip),%eax
mov    %eax,-0xe(%rbp)
mov    0xefb(%rip),%ax
mov    %ax,-0xa(%rbp)
movl   $0x0,-0x14(%rbp)
movsd  -0x8(%rbp),%xmm0
xor    %eax,%eax
movsd  0xecd(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x15(%rbp)
jbe    1152 <buhr+0x52>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x4,%eax
setle  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1162 <buhr+0x62>
jmp    117d <buhr+0x7d>
movsd  -0x8(%rbp),%xmm0
movsd  0xe99(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1124 <buhr+0x24>
movslq -0x14(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<buhr>:
ucomisd 0xef8(%rip),%xmm0
jbe    116d <buhr+0x6d>
divsd  0xef6(%rip),%xmm0
mov    $0x1,%eax
ucomisd 0xee1(%rip),%xmm0
jbe    116f <buhr+0x6f>
divsd  0xedf(%rip),%xmm0
mov    $0x2,%eax
ucomisd 0xeca(%rip),%xmm0
jbe    116f <buhr+0x6f>
divsd  0xec8(%rip),%xmm0
mov    $0x3,%eax
ucomisd 0xeb3(%rip),%xmm0
jbe    116f <buhr+0x6f>
divsd  0xeb1(%rip),%xmm0
mov    $0x4,%eax
ucomisd 0xe9c(%rip),%xmm0
jbe    116f <buhr+0x6f>
mov    $0x5,%eax
jmp    116f <buhr+0x6f>
xor    %eax,%eax
lea    0xe9a(%rip),%rcx
mov    (%rax,%rcx,1),%al
ret

LLVM IR (-O0):
@__const.buhr.units = [6 x i8] c" KMGT\00"
define signext i8 @buhr(double %0) {
%2 = alloca double
%3 = alloca [6 x i8]
%4 = alloca i32
store double %0, double* %2
%5 = bitcast [6 x i8]* %3 to i8*
store i32 0, i32* %4
br label %6
6: ; preds = %15, %1
%7 = load double, double* %2
%8 = fcmp ogt double %7, 1.500000e+03
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = load i32, i32* %4
%11 = add nsw i32 %10, 1
store i32 %11, i32* %4
%12 = icmp sle i32 %11, 4
br label %13
13: ; preds = %9, %6
%14 = phi i1 [ false, %6 ], [ %12, %9 ]
br i1 %14, label %15, label %18
15: ; preds = %13
%16 = load double, double* %2
%17 = fdiv double %16, 1.000000e+03
store double %17, double* %2
br label %6
18: ; preds = %13
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 %20
%22 = load i8, i8* %21
ret i8 %22
}

LLVM IR (-O2):
@__const.buhr.units = [6 x i8] c" KMGT\00"
define signext i8 @buhr(double %0) {
%2 = fcmp ogt double %0, 1.500000e+03
br i1 %2, label %3, label %16
3: ; preds = %1
%4 = fdiv double %0, 1.000000e+03
%5 = fcmp ogt double %4, 1.500000e+03
br i1 %5, label %6, label %16
6: ; preds = %3
%7 = fdiv double %4, 1.000000e+03
%8 = fcmp ogt double %7, 1.500000e+03
br i1 %8, label %9, label %16
9: ; preds = %6
%10 = fdiv double %7, 1.000000e+03
%11 = fcmp ogt double %10, 1.500000e+03
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = fdiv double %10, 1.000000e+03
%14 = fcmp ogt double %13, 1.500000e+03
br i1 %14, label %15, label %16
15: ; preds = %12
br label %16
16: ; preds = %3, %6, %9, %12, %15, %1
%17 = phi i64 [ 0, %1 ], [ 1, %3 ], [ 2, %6 ], [ 3, %9 ], [ 4, %12 ], [ 5, %15 ]
%18 = getelementptr inbounds [6 x i8], [6 x i8]* @__const.buhr.units, i64 0, i64 %17
%19 = load i8, i8* %18
ret i8 %19
}