#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 */
char *malloc(long);
int /*<<< orphan*/ snprintf(char *, long, char *, float, char const *);
char *human_readable_size(long size) {
  long u = 1024, i, len = 128;
  char *buf = malloc(len);
  static const char *__units[] = {"b", "K", "M", "G", "T",
                                  "P", "E", "Z", "Y", NULL};
  for (i = 0; __units[i] != NULL; i++) {
    if ((size / u) == 0) {
      break;
    }
    u *= 1024;
  }
  if (!i) {
    snprintf(buf, len, "%ld %s", size, __units[0]);
  } else {
    float fsize = (float)((double)size / (u / 1024));
    snprintf(buf, len, "%.2f%s", fsize, __units[i]);
  }
  return buf;
}


x86 assembly (clang, -O0):
<human_readable_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x400,-0x10(%rbp)
movq   $0x80,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
lea    0x2ee4(%rip),%rax
cmpq   $0x0,(%rax,%rcx,8)
je     119d <human_readable_size+0x7d>
mov    -0x8(%rbp),%rax
cqto
idivq  -0x10(%rbp)
cmp    $0x0,%rax
jne    1180 <human_readable_size+0x60>
jmp    119d <human_readable_size+0x7d>
mov    -0x10(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1151 <human_readable_size+0x31>
cmpq   $0x0,-0x18(%rbp)
jne    11ce <human_readable_size+0xae>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
cvtsi2ssq -0x8(%rbp),%xmm0
mov    0x2e83(%rip),%rcx
lea    0xe4e(%rip),%rdx
call   1030 <snprintf@plt>
jmp    121c <human_readable_size+0xfc>
cvtsi2sdq -0x8(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    $0x400,%ecx
cqto
idiv   %rcx
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movss  -0x2c(%rbp),%xmm0
mov    -0x18(%rbp),%rcx
lea    0x2e34(%rip),%rax
mov    (%rax,%rcx,8),%rcx
lea    0xe02(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<human_readable_size>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x80,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
lea    0x3ff(%rbx),%rax
cmp    $0x7ff,%rax
jae    115b <human_readable_size+0x3b>
cvtsi2ss %rbx,%xmm0
lea    0xec3(%rip),%rdx
lea    0xeaa(%rip),%rcx
jmp    123d <human_readable_size+0x11d>
lea    0xfffff(%rbx),%rax
cmp    $0x1fffff,%rax
jae    1179 <human_readable_size+0x59>
mov    $0x1,%ecx
mov    $0x400,%eax
jmp    1219 <human_readable_size+0xf9>
lea    0x3fffffff(%rbx),%rax
cmp    $0x7fffffff,%rax
jae    1197 <human_readable_size+0x77>
mov    $0x2,%ecx
mov    $0x100000,%eax
jmp    1219 <human_readable_size+0xf9>
movabs $0xffffffffff,%rax
lea    (%rbx,%rax,1),%rcx
movabs $0x1ffffffffff,%rdx
cmp    %rdx,%rcx
jae    11c0 <human_readable_size+0xa0>
mov    $0x3,%ecx
mov    $0x40000000,%eax
jmp    1219 <human_readable_size+0xf9>
movabs $0x3ffffffffffff,%rdx
lea    (%rbx,%rdx,1),%rcx
movabs $0x7ffffffffffff,%rsi
cmp    %rsi,%rcx
jae    11e8 <human_readable_size+0xc8>
add    $0x1,%rax
mov    $0x4,%ecx
jmp    1219 <human_readable_size+0xf9>
movabs $0xfffffffffffffff,%rax
ff ff 0f
add    %rbx,%rax
movabs $0x1ffffffffffffffe,%rcx
ff ff 1f
cmp    %rcx,%rax
ja     1212 <human_readable_size+0xf2>
add    $0x1,%rdx
mov    $0x5,%ecx
mov    %rdx,%rax
jmp    1219 <human_readable_size+0xf9>
xor    %eax,%eax
mov    $0x9,%ecx
lea    0x2bb0(%rip),%rdx
cvtsi2sd %rbx,%xmm0
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    (%rdx,%rcx,8),%rcx
lea    0xddc(%rip),%rdx
mov    $0x80,%esi
mov    %r14,%rdi
call   1030 <snprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@human_readable_size.__units = internal global [10 x i8*] [i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i32 0, i32 0), i8* null]
@.str = [2 x i8] c"b\00"
@.str.1 = [2 x i8] c"K\00"
@.str.2 = [2 x i8] c"M\00"
@.str.3 = [2 x i8] c"G\00"
@.str.4 = [2 x i8] c"T\00"
@.str.5 = [2 x i8] c"P\00"
@.str.6 = [2 x i8] c"E\00"
@.str.7 = [2 x i8] c"Z\00"
@.str.8 = [2 x i8] c"Y\00"
@.str.9 = [7 x i8] c"%ld %s\00"
@.str.10 = [7 x i8] c"%.2f%s\00"
define i8* @human_readable_size(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8*
%7 = alloca float
store i64 %0, i64* %2
store i64 1024, i64* %3
store i64 128, i64* %5
%8 = load i64, i64* %5
%9 = call i8* @malloc(i64 %8)
store i8* %9, i8** %6
store i64 0, i64* %4
br label %10
10: ; preds = %24, %1
%11 = load i64, i64* %4
%12 = getelementptr inbounds [10 x i8*], [10 x i8*]* @human_readable_size.__units, i64 0, i64 %11
%13 = load i8*, i8** %12
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %27
15: ; preds = %10
%16 = load i64, i64* %2
%17 = load i64, i64* %3
%18 = sdiv i64 %16, %17
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
br label %27
21: ; preds = %15
%22 = load i64, i64* %3
%23 = mul nsw i64 %22, 1024
store i64 %23, i64* %3
br label %24
24: ; preds = %21
%25 = load i64, i64* %4
%26 = add nsw i64 %25, 1
store i64 %26, i64* %4
br label %10
27: ; preds = %20, %10
%28 = load i64, i64* %4
%29 = icmp ne i64 %28, 0
br i1 %29, label %37, label %30
30: ; preds = %27
%31 = load i8*, i8** %6
%32 = load i64, i64* %5
%33 = load i64, i64* %2
%34 = sitofp i64 %33 to float
%35 = load i8*, i8** getelementptr inbounds ([10 x i8*], [10 x i8*]* @human_readable_size.__units, i64 0, i64 0)
%36 = call i32 @snprintf(i8* %31, i64 %32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), float %34, i8* %35)
br label %52
37: ; preds = %27
%38 = load i64, i64* %2
%39 = sitofp i64 %38 to double
%40 = load i64, i64* %3
%41 = sdiv i64 %40, 1024
%42 = sitofp i64 %41 to double
%43 = fdiv double %39, %42
%44 = fptrunc double %43 to float
store float %44, float* %7
%45 = load i8*, i8** %6
%46 = load i64, i64* %5
%47 = load float, float* %7
%48 = load i64, i64* %4
%49 = getelementptr inbounds [10 x i8*], [10 x i8*]* @human_readable_size.__units, i64 0, i64 %48
%50 = load i8*, i8** %49
%51 = call i32 @snprintf(i8* %45, i64 %46, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), float %47, i8* %50)
br label %52
52: ; preds = %37, %30
%53 = load i8*, i8** %6
ret i8* %53
}

LLVM IR (-O2):
@human_readable_size.__units = internal unnamed_addr constant [10 x i8*] [i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i32 0, i32 0), i8* null]
@.str = [2 x i8] c"b\00"
@.str.1 = [2 x i8] c"K\00"
@.str.2 = [2 x i8] c"M\00"
@.str.3 = [2 x i8] c"G\00"
@.str.4 = [2 x i8] c"T\00"
@.str.5 = [2 x i8] c"P\00"
@.str.6 = [2 x i8] c"E\00"
@.str.7 = [2 x i8] c"Z\00"
@.str.8 = [2 x i8] c"Y\00"
@.str.9 = [7 x i8] c"%ld %s\00"
@.str.10 = [7 x i8] c"%.2f%s\00"
define i8* @human_readable_size(i64 %0) {
%2 = tail call dereferenceable_or_null(128) i8* @malloc(i64 128)
%3 = add i64 %0, 1023
%4 = icmp ult i64 %3, 2047
br i1 %4, label %23, label %5
5: ; preds = %1
%6 = add i64 %0, 1048575
%7 = icmp ult i64 %6, 2097151
br i1 %7, label %20, label %8
8: ; preds = %5
%9 = add i64 %0, 1073741823
%10 = icmp ult i64 %9, 2147483647
br i1 %10, label %20, label %11
11: ; preds = %8
%12 = add i64 %0, 1099511627775
%13 = icmp ult i64 %12, 2199023255551
br i1 %13, label %20, label %14
14: ; preds = %11
%15 = add i64 %0, 1125899906842623
%16 = icmp ult i64 %15, 2251799813685247
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = add i64 %0, 1152921504606846975
%19 = icmp ult i64 %18, 2305843009213693951
br i1 %19, label %20, label %26
20: ; preds = %5, %8, %11, %14, %17
%21 = phi i64 [ 1125899906842624, %17 ], [ 1099511627776, %14 ], [ 1073741824, %11 ], [ 1048576, %8 ], [ 1024, %5 ]
%22 = phi i64 [ 5, %17 ], [ 4, %14 ], [ 3, %11 ], [ 2, %8 ], [ 1, %5 ]
br label %26
23: ; preds = %1
%24 = sitofp i64 %0 to float
%25 = tail call i32 @snprintf(i8* %2, i64 128, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), float %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %36
26: ; preds = %20, %17
%27 = phi i64 [ 0, %17 ], [ %21, %20 ]
%28 = phi i64 [ 9, %17 ], [ %22, %20 ]
%29 = getelementptr inbounds [10 x i8*], [10 x i8*]* @human_readable_size.__units, i64 0, i64 %28
%30 = sitofp i64 %0 to double
%31 = sitofp i64 %27 to double
%32 = fdiv double %30, %31
%33 = fptrunc double %32 to float
%34 = load i8*, i8** %29
%35 = tail call i32 @snprintf(i8* %2, i64 128, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), float %33, i8* %34)
br label %36
36: ; preds = %26, %23
ret i8* %2
}