float memoryUsageReadable(unsigned long long int n, char unit) {
  switch (unit) {
  case ' ':
    return (float)n;
  case 'K':
    return (float)(n >> 10);
  case 'M':
    return (float)(n >> 20);
  case 'G':
    return (float)(n >> 30);
  case 'T':
    return (float)(n >> 40);
  default:
    return (float)n;
  }
}


x86 assembly (clang, -O0):
<memoryUsageReadable>:
push   %rbp
mov    %rsp,%rbp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x20,%eax
je     1167 <memoryUsageReadable+0x67>
jmp    1123 <memoryUsageReadable+0x23>
mov    -0x18(%rbp),%eax
sub    $0x47,%eax
je     11e1 <memoryUsageReadable+0xe1>
jmp    1134 <memoryUsageReadable+0x34>
mov    -0x18(%rbp),%eax
sub    $0x4b,%eax
je     11b3 <memoryUsageReadable+0xb3>
jmp    1145 <memoryUsageReadable+0x45>
mov    -0x18(%rbp),%eax
sub    $0x4d,%eax
je     11ca <memoryUsageReadable+0xca>
jmp    1156 <memoryUsageReadable+0x56>
mov    -0x18(%rbp),%eax
sub    $0x54,%eax
je     11f8 <memoryUsageReadable+0xf8>
jmp    120e <memoryUsageReadable+0x10e>
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x20(%rbp)
test   %rax,%rax
movss  %xmm0,-0x1c(%rbp)
js     11a4 <memoryUsageReadable+0xa4>
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1255 <memoryUsageReadable+0x155>
mov    -0x10(%rbp),%rax
shr    $0xa,%rax
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1255 <memoryUsageReadable+0x155>
mov    -0x10(%rbp),%rax
shr    $0x14,%rax
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1255 <memoryUsageReadable+0x155>
mov    -0x10(%rbp),%rax
shr    $0x1e,%rax
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1255 <memoryUsageReadable+0x155>
mov    -0x10(%rbp),%rax
shr    $0x28,%rax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1255 <memoryUsageReadable+0x155>
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x28(%rbp)
test   %rax,%rax
movss  %xmm0,-0x24(%rbp)
js     124b <memoryUsageReadable+0x14b>
movss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<memoryUsageReadable>:
add    $0xffffffb9,%esi
cmp    $0xd,%esi
ja     1132 <memoryUsageReadable+0x32>
lea    0xef1(%rip),%rax
movslq (%rax,%rsi,4),%rcx
add    %rax,%rcx
jmp    *%rcx
shr    $0x1e,%rdi
test   %rdi,%rdi
jns    1137 <memoryUsageReadable+0x37>
jmp    1146 <memoryUsageReadable+0x46>
shr    $0xa,%rdi
test   %rdi,%rdi
jns    1137 <memoryUsageReadable+0x37>
jmp    1146 <memoryUsageReadable+0x46>
shr    $0x14,%rdi
test   %rdi,%rdi
js     1146 <memoryUsageReadable+0x46>
cvtsi2ss %rdi,%xmm0
ret
shr    $0x28,%rdi
test   %rdi,%rdi
jns    1137 <memoryUsageReadable+0x37>
mov    %rdi,%rax
shr    %rax
and    $0x1,%edi
or     %rax,%rdi
cvtsi2ss %rdi,%xmm0
addss  %xmm0,%xmm0
ret

LLVM IR (-O0):
define float @memoryUsageReadable(i64 %0, i8 signext %1) {
%3 = alloca float
%4 = alloca i64
%5 = alloca i8
store i64 %0, i64* %4
store i8 %1, i8* %5
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
switch i32 %7, label %27 [
i32 32, label %8
i32 75, label %11
i32 77, label %15
i32 71, label %19
i32 84, label %23
]
8: ; preds = %2
%9 = load i64, i64* %4
%10 = uitofp i64 %9 to float
store float %10, float* %3
br label %30
11: ; preds = %2
%12 = load i64, i64* %4
%13 = lshr i64 %12, 10
%14 = uitofp i64 %13 to float
store float %14, float* %3
br label %30
15: ; preds = %2
%16 = load i64, i64* %4
%17 = lshr i64 %16, 20
%18 = uitofp i64 %17 to float
store float %18, float* %3
br label %30
19: ; preds = %2
%20 = load i64, i64* %4
%21 = lshr i64 %20, 30
%22 = uitofp i64 %21 to float
store float %22, float* %3
br label %30
23: ; preds = %2
%24 = load i64, i64* %4
%25 = lshr i64 %24, 40
%26 = uitofp i64 %25 to float
store float %26, float* %3
br label %30
27: ; preds = %2
%28 = load i64, i64* %4
%29 = uitofp i64 %28 to float
store float %29, float* %3
br label %30
30: ; preds = %27, %23, %19, %15, %11, %8
%31 = load float, float* %3
ret float %31
}

LLVM IR (-O2):
define float @memoryUsageReadable(i64 %0, i8 signext %1) {
%3 = sext i8 %1 to i32
switch i32 %3, label %12 [
i32 84, label %10
i32 75, label %4
i32 77, label %6
i32 71, label %8
]
4: ; preds = %2
%5 = lshr i64 %0, 10
br label %12
6: ; preds = %2
%7 = lshr i64 %0, 20
br label %12
8: ; preds = %2
%9 = lshr i64 %0, 30
br label %12
10: ; preds = %2
%11 = lshr i64 %0, 40
br label %12
12: ; preds = %2, %10, %8, %6, %4
%13 = phi i64 [ %11, %10 ], [ %9, %8 ], [ %7, %6 ], [ %5, %4 ], [ %0, %2 ]
%14 = uitofp i64 %13 to float
ret float %14
}