#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, float);
const char *human_readable(unsigned long x) {
  static char buffer[64];
  float y;
  if (x < 1024)
    sprintf(buffer, "%lu Bytes", x);
  else if (x < 1024UL * 1024UL) {
    y = (float)x / 1024.0f;
    sprintf(buffer, "%.1f kBytes", y);
  } else if (x < 1024UL * 1024UL * 1024UL) {
    y = (float)x / (1024.0f * 1024.0f);
    sprintf(buffer, "%.1f MBytes", y);
  } else {
    y = (float)x / (1024.0f * 1024.0f * 1024.0f);
    sprintf(buffer, "%.1f GBytes", y);
  }
  return buffer;
}


x86 assembly (clang, -O0):
<human_readable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x400,-0x8(%rbp)
jae    1184 <human_readable+0x74>
mov    -0x8(%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,-0x14(%rbp)
test   %rax,%rax
movss  %xmm0,-0x10(%rbp)
js     1167 <human_readable+0x57>
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
lea    0x2ecd(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1030 <sprintf@plt>
jmp    12f5 <human_readable+0x1e5>
cmpq   $0x100000,-0x8(%rbp)
jae    1202 <human_readable+0xf2>
mov    -0x8(%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,-0x1c(%rbp)
test   %rax,%rax
movss  %xmm0,-0x18(%rbp)
js     11cf <human_readable+0xbf>
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
movss  0xe2c(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
lea    0x2e4f(%rip),%rdi
lea    0xe1e(%rip),%rsi
call   1030 <sprintf@plt>
jmp    12f0 <human_readable+0x1e0>
cmpq   $0x40000000,-0x8(%rbp)
40
jae    1280 <human_readable+0x170>
mov    -0x8(%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,-0x24(%rbp)
test   %rax,%rax
movss  %xmm0,-0x20(%rbp)
js     124d <human_readable+0x13d>
movss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
movss  0xdaa(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
lea    0x2dd1(%rip),%rdi
lea    0xdac(%rip),%rsi
call   1030 <sprintf@plt>
jmp    12eb <human_readable+0x1db>
mov    -0x8(%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,-0x2c(%rbp)
test   %rax,%rax
movss  %xmm0,-0x28(%rbp)
js     12bd <human_readable+0x1ad>
movss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x28(%rbp),%xmm0
movss  0xd36(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
lea    0x2d61(%rip),%rdi
lea    0xd48(%rip),%rsi
call   1030 <sprintf@plt>
jmp    12f0 <human_readable+0x1e0>
jmp    12f5 <human_readable+0x1e5>
lea    0x2d44(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<human_readable>:
push   %rax
cmp    $0x3ff,%rdi
ja     1126 <human_readable+0x16>
test   %rdi,%rdi
js     113b <human_readable+0x2b>
cvtsi2ss %rdi,%xmm0
jmp    1150 <human_readable+0x40>
cmp    $0xfffff,%rdi
ja     1163 <human_readable+0x53>
test   %rdi,%rdi
js     118e <human_readable+0x7e>
cvtsi2ss %rdi,%xmm0
jmp    11a3 <human_readable+0x93>
mov    %rdi,%rax
shr    %rax
and    $0x1,%edi
or     %rax,%rdi
cvtsi2ss %rdi,%xmm0
addss  %xmm0,%xmm0
lea    0x2ee9(%rip),%rdi
lea    0xeae(%rip),%rsi
jmp    11f1 <human_readable+0xe1>
test   %rdi,%rdi
js     11bb <human_readable+0xab>
cvtsi2ss %rdi,%xmm0
cmp    $0x3fffffff,%rdi
jbe    11db <human_readable+0xcb>
mulss  0xe82(%rip),%xmm0
lea    0x2ebb(%rip),%rdi
lea    0xea2(%rip),%rsi
jmp    11f1 <human_readable+0xe1>
mov    %rdi,%rax
shr    %rax
and    $0x1,%edi
or     %rax,%rdi
cvtsi2ss %rdi,%xmm0
addss  %xmm0,%xmm0
mulss  0xe5d(%rip),%xmm0
lea    0x2e8e(%rip),%rdi
lea    0xe5d(%rip),%rsi
jmp    11f1 <human_readable+0xe1>
mov    %rdi,%rax
shr    %rax
mov    %edi,%ecx
and    $0x1,%ecx
or     %rax,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cmp    $0x3fffffff,%rdi
ja     1176 <human_readable+0x66>
mulss  0xe21(%rip),%xmm0
lea    0x2e56(%rip),%rdi
lea    0xe31(%rip),%rsi
call   1030 <sprintf@plt>
lea    0x2e43(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@human_readable.buffer = internal global [64 x i8] zeroinitializer
@.str = [10 x i8] c"%lu Bytes\00"
@.str.1 = [12 x i8] c"%.1f kBytes\00"
@.str.2 = [12 x i8] c"%.1f MBytes\00"
@.str.3 = [12 x i8] c"%.1f GBytes\00"
define i8* @human_readable(i64 %0) {
%2 = alloca i64
%3 = alloca float
store i64 %0, i64* %2
%4 = load i64, i64* %2
%5 = icmp ult i64 %4, 1024
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i64, i64* %2
%8 = uitofp i64 %7 to float
%9 = call i32 @sprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @human_readable.buffer, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), float %8)
br label %36
10: ; preds = %1
%11 = load i64, i64* %2
%12 = icmp ult i64 %11, 1048576
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i64, i64* %2
%15 = uitofp i64 %14 to float
%16 = fdiv float %15, 1.024000e+03
store float %16, float* %3
%17 = load float, float* %3
%18 = call i32 @sprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @human_readable.buffer, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), float %17)
br label %35
19: ; preds = %10
%20 = load i64, i64* %2
%21 = icmp ult i64 %20, 1073741824
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load i64, i64* %2
%24 = uitofp i64 %23 to float
%25 = fdiv float %24, 0x4130000000000000
store float %25, float* %3
%26 = load float, float* %3
%27 = call i32 @sprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @human_readable.buffer, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), float %26)
br label %34
28: ; preds = %19
%29 = load i64, i64* %2
%30 = uitofp i64 %29 to float
%31 = fdiv float %30, 0x41D0000000000000
store float %31, float* %3
%32 = load float, float* %3
%33 = call i32 @sprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @human_readable.buffer, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), float %32)
br label %34
34: ; preds = %28, %22
br label %35
35: ; preds = %34, %13
br label %36
36: ; preds = %35, %6
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @human_readable.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
@human_readable.buffer = internal global [64 x i8] zeroinitializer
@.str = [10 x i8] c"%lu Bytes\00"
@.str.1 = [12 x i8] c"%.1f kBytes\00"
@.str.2 = [12 x i8] c"%.1f MBytes\00"
@.str.3 = [12 x i8] c"%.1f GBytes\00"
define i8* @human_readable(i64 %0) {
%2 = icmp ult i64 %0, 1024
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = uitofp i64 %0 to float
%5 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @human_readable.buffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), float %4)
br label %21
6: ; preds = %1
%7 = icmp ult i64 %0, 1048576
br i1 %7, label %8, label %12
8: ; preds = %6
%9 = uitofp i64 %0 to float
%10 = fmul float %9, 0x3F50000000000000
%11 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @human_readable.buffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), float %10)
br label %21
12: ; preds = %6
%13 = icmp ult i64 %0, 1073741824
%14 = uitofp i64 %0 to float
br i1 %13, label %15, label %18
15: ; preds = %12
%16 = fmul float %14, 0x3EB0000000000000
%17 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @human_readable.buffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), float %16)
br label %21
18: ; preds = %12
%19 = fmul float %14, 0x3E10000000000000
%20 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @human_readable.buffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), float %19)
br label %21
21: ; preds = %8, %18, %15, %3
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @human_readable.buffer, i64 0, i64 0)
}