char *scalef(i)
float i;
{
  static char buffer[255];
  if (i / (float)(1024 * 1024) > 1)
    sprintf(buffer, "%.2f megabytes", i / (float)(1024 * 1024));
  else if (i / (float)1024)
    sprintf(buffer, "%.2f kilobytes", i / (float)1024);
  else
    sprintf(buffer, "%f bytes", i);
  return (buffer);
}


x86 assembly (clang, -O0):
<scalef>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
movss  0xed6(%rip),%xmm1
divss  %xmm1,%xmm0
movss  0xec6(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    1172 <scalef+0x62>
movss  -0x4(%rbp),%xmm0
movss  0xeb4(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0x2ee1(%rip),%rdi
lea    0xea6(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    11ec <scalef+0xdc>
movss  -0x4(%rbp),%xmm0
movss  0xe89(%rip),%xmm1
divss  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    119a <scalef+0x8a>
jp     119a <scalef+0x8a>
jmp    11c9 <scalef+0xb9>
movss  -0x4(%rbp),%xmm0
movss  0xe61(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0x2e8a(%rip),%rdi
lea    0xe5e(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    11e7 <scalef+0xd7>
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0x2e67(%rip),%rdi
lea    0xe4a(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    11ec <scalef+0xdc>
lea    0x2e4d(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scalef>:
push   %rbx
cvtsd2ss %xmm0,%xmm2
movss  0xee3(%rip),%xmm0
mulss  %xmm2,%xmm0
movss  0xedb(%rip),%xmm1
mulss  %xmm2,%xmm1
xorps  %xmm3,%xmm3
ucomiss %xmm3,%xmm1
jne    113a <scalef+0x2a>
jp     113a <scalef+0x2a>
movaps %xmm2,%xmm1
lea    0xeda(%rip),%rax
lea    0xee2(%rip),%rcx
cmovne %rax,%rcx
cmovp  %rax,%rcx
movss  0xeb0(%rip),%xmm2
ucomiss %xmm2,%xmm0
cmpltss %xmm0,%xmm2
movaps %xmm2,%xmm3
andnps %xmm1,%xmm3
andps  %xmm0,%xmm2
orps   %xmm3,%xmm2
lea    0xe99(%rip),%rsi
cmovbe %rcx,%rsi
xorps  %xmm0,%xmm0
cvtss2sd %xmm2,%xmm0
lea    0x2ebb(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1,%al
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@scalef.buffer = internal global [255 x i8] zeroinitializer
@.str = [15 x i8] c"%.2f megabytes\00"
@.str.1 = [15 x i8] c"%.2f kilobytes\00"
@.str.2 = [9 x i8] c"%f bytes\00"
define i8* @scalef(double %0) {
%2 = alloca float
%3 = fptrunc double %0 to float
store float %3, float* %2
%4 = load float, float* %2
%5 = fdiv float %4, 0x4130000000000000
%6 = fcmp ogt float %5, 1.000000e+00
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = load float, float* %2
%9 = fdiv float %8, 0x4130000000000000
%10 = fpext float %9 to double
%11 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([255 x i8], [255 x i8]* @scalef.buffer, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), double %10)
br label %26
12: ; preds = %1
%13 = load float, float* %2
%14 = fdiv float %13, 1.024000e+03
%15 = fcmp une float %14, 0.000000e+00
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load float, float* %2
%18 = fdiv float %17, 1.024000e+03
%19 = fpext float %18 to double
%20 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([255 x i8], [255 x i8]* @scalef.buffer, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), double %19)
br label %25
21: ; preds = %12
%22 = load float, float* %2
%23 = fpext float %22 to double
%24 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([255 x i8], [255 x i8]* @scalef.buffer, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %23)
br label %25
25: ; preds = %21, %16
br label %26
26: ; preds = %25, %7
ret i8* getelementptr inbounds ([255 x i8], [255 x i8]* @scalef.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
@scalef.buffer = internal global [255 x i8] zeroinitializer
@.str = [15 x i8] c"%.2f megabytes\00"
@.str.1 = [15 x i8] c"%.2f kilobytes\00"
@.str.2 = [9 x i8] c"%f bytes\00"
define i8* @scalef(double %0) {
%2 = fptrunc double %0 to float
%3 = fmul float %2, 0x3EB0000000000000
%4 = fcmp ogt float %3, 1.000000e+00
%5 = fmul float %2, 0x3F50000000000000
%6 = fcmp une float %5, 0.000000e+00
%7 = select i1 %6, float %5, float %2
%8 = select i1 %6, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0)
%9 = select i1 %4, float %3, float %7
%10 = select i1 %4, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %8
%11 = fpext float %9 to double
%12 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([255 x i8], [255 x i8]* @scalef.buffer, i64 0, i64 0), i8* dereferenceable(1) %10, double %11)
ret i8* getelementptr inbounds ([255 x i8], [255 x i8]* @scalef.buffer, i64 0, i64 0)
}