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


x86 assembly (clang, -O0):
<scale>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x100000,%ecx
cltd
idiv   %ecx
cmp    $0x0,%eax
je     115e <scale+0x4e>
cvtsi2ssl -0x4(%rbp),%xmm0
movss  0xec8(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0x2ef5(%rip),%rdi
lea    0xeb6(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    11be <scale+0xae>
mov    -0x4(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
cmp    $0x0,%eax
je     11a1 <scale+0x91>
cvtsi2ssl -0x4(%rbp),%xmm0
movss  0xe81(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0x2eb2(%rip),%rdi
lea    0xe82(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    11b9 <scale+0xa9>
mov    -0x4(%rbp),%edx
lea    0x2e95(%rip),%rdi
lea    0xe74(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11be <scale+0xae>
lea    0x2e7b(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scale>:
push   %rax
mov    %edi,%edx
lea    0xfffff(%rdx),%eax
cmp    $0x1fffff,%eax
jae    1144 <scale+0x34>
lea    0x3ff(%rdx),%eax
cmp    $0x7ff,%eax
jae    1164 <scale+0x54>
lea    0x2f0c(%rip),%rdi
lea    0xeeb(%rip),%rsi
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    1189 <scale+0x79>
cvtsi2ss %edx,%xmm0
mulss  0xeb0(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0x2ee5(%rip),%rdi
lea    0xea6(%rip),%rsi
jmp    1182 <scale+0x72>
cvtsi2ss %edx,%xmm0
mulss  0xe94(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0x2ec5(%rip),%rdi
lea    0xe95(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
lea    0x2eb0(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@scale.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"%d bytes\00"
define i8* @scale(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = sdiv i32 %3, 1048576
%5 = icmp ne i32 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %1
%7 = load i32, i32* %2
%8 = sitofp i32 %7 to float
%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]* @scale.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 i32, i32* %2
%14 = sdiv i32 %13, 1024
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %12
%17 = load i32, i32* %2
%18 = sitofp i32 %17 to float
%19 = fdiv float %18, 1.024000e+03
%20 = fpext float %19 to double
%21 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([255 x i8], [255 x i8]* @scale.buffer, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), double %20)
br label %25
22: ; preds = %12
%23 = load i32, i32* %2
%24 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([255 x i8], [255 x i8]* @scale.buffer, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %22, %16
br label %26
26: ; preds = %25, %6
ret i8* getelementptr inbounds ([255 x i8], [255 x i8]* @scale.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
@scale.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"%d bytes\00"
define i8* @scale(i32 %0) {
%2 = add i32 %0, 1048575
%3 = icmp ult i32 %2, 2097151
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = sitofp i32 %0 to float
%6 = fmul float %5, 0x3EB0000000000000
%7 = fpext float %6 to double
%8 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([255 x i8], [255 x i8]* @scale.buffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), double %7)
br label %19
9: ; preds = %1
%10 = add nsw i32 %0, 1023
%11 = icmp ult i32 %10, 2047
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = sitofp i32 %0 to float
%14 = fmul float %13, 0x3F50000000000000
%15 = fpext float %14 to double
%16 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([255 x i8], [255 x i8]* @scale.buffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), double %15)
br label %19
17: ; preds = %9
%18 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([255 x i8], [255 x i8]* @scale.buffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %0)
br label %19
19: ; preds = %12, %17, %4
ret i8* getelementptr inbounds ([255 x i8], [255 x i8]* @scale.buffer, i64 0, i64 0)
}