#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(int);
int /*<<< orphan*/ sprintf(char *, char *, double, char);
char *fatdino_bytesToHuman(unsigned int bytes) {
  int unit = 0;
  char *result = malloc(10);
  double res = bytes;
  while (res > 1024) {
    res = res / 1024;
    unit++;
  }
  const char units[9] = {'\0', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'};
  char cunit = units[unit];
  if (cunit != '\0')
    sprintf(result, "%.2f %cB", res, cunit);
  else
    sprintf(result, "%.0f B", res, cunit);
  return result;
}


x86 assembly (clang, -O0):
<fatdino_bytesToHuman>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0xa,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xea6(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1188 <fatdino_bytesToHuman+0x68>
movsd  -0x18(%rbp),%xmm0
movsd  0xe8f(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    114d <fatdino_bytesToHuman+0x2d>
mov    0xe79(%rip),%rax
mov    %rax,-0x21(%rbp)
mov    0xe77(%rip),%al
mov    %al,-0x19(%rbp)
movslq -0x8(%rbp),%rax
mov    -0x21(%rbp,%rax,1),%al
mov    %al,-0x22(%rbp)
movsbl -0x22(%rbp),%eax
cmp    $0x0,%eax
je     11d2 <fatdino_bytesToHuman+0xb2>
mov    -0x10(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
lea    0xe4d(%rip),%rsi
movsbl -0x22(%rbp),%edx
call   1040 <sprintf@plt>
jmp    11eb <fatdino_bytesToHuman+0xcb>
mov    -0x10(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
lea    0xe38(%rip),%rsi
movsbl -0x22(%rbp),%edx
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fatdino_bytesToHuman>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0xa,%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
mov    %ebp,%eax
cvtsi2sd %rax,%xmm0
cmp    $0x401,%ebp
jb     117d <fatdino_bytesToHuman+0x5d>
lea    0xec8(%rip),%rax
movsd  0xeb0(%rip),%xmm1
movsd  0xeb0(%rip),%xmm2
nopl   0x0(%rax,%rax,1)
mulsd  %xmm1,%xmm0
add    $0x1,%rax
ucomisd %xmm2,%xmm0
ja     1160 <fatdino_bytesToHuman+0x40>
movsbl (%rax),%edx
lea    0xea1(%rip),%rsi
mov    %rbx,%rdi
jmp    1189 <fatdino_bytesToHuman+0x69>
lea    0xe9e(%rip),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1040 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.fatdino_bytesToHuman.units = [9 x i8] c"\00KMGTPEZY"
@.str = [9 x i8] c"%.2f %cB\00"
@.str.1 = [7 x i8] c"%.0f B\00"
define i8* @fatdino_bytesToHuman(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca double
%6 = alloca [9 x i8]
%7 = alloca i8
store i32 %0, i32* %2
store i32 0, i32* %3
%8 = call i8* @malloc(i32 10)
store i8* %8, i8** %4
%9 = load i32, i32* %2
%10 = uitofp i32 %9 to double
store double %10, double* %5
br label %11
11: ; preds = %14, %1
%12 = load double, double* %5
%13 = fcmp ogt double %12, 1.024000e+03
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load double, double* %5
%16 = fdiv double %15, 1.024000e+03
store double %16, double* %5
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %11
19: ; preds = %11
%20 = bitcast [9 x i8]* %6 to i8*
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 %22
%24 = load i8, i8* %23
store i8 %24, i8* %7
%25 = load i8, i8* %7
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %19
%29 = load i8*, i8** %4
%30 = load double, double* %5
%31 = load i8, i8* %7
%32 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double %30, i8 signext %31)
br label %38
33: ; preds = %19
%34 = load i8*, i8** %4
%35 = load double, double* %5
%36 = load i8, i8* %7
%37 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %35, i8 signext %36)
br label %38
38: ; preds = %33, %28
%39 = load i8*, i8** %4
ret i8* %39
}

LLVM IR (-O2):
@__const.fatdino_bytesToHuman.units = [9 x i8] c"\00KMGTPEZY"
@.str = [9 x i8] c"%.2f %cB\00"
@.str.1 = [7 x i8] c"%.0f B\00"
define noalias i8* @fatdino_bytesToHuman(i32 %0) {
%2 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%3 = uitofp i32 %0 to double
%4 = icmp ugt i32 %0, 1024
br i1 %4, label %5, label %16
5: ; preds = %1, %5
%6 = phi i32 [ %9, %5 ], [ 0, %1 ]
%7 = phi double [ %8, %5 ], [ %3, %1 ]
%8 = fmul double %7, 0x3F50000000000000
%9 = add nuw nsw i32 %6, 1
%10 = fcmp ogt double %8, 1.024000e+03
br i1 %10, label %5, label %11
11: ; preds = %5
%12 = zext i32 %9 to i64
%13 = getelementptr inbounds [9 x i8], [9 x i8]* @__const.fatdino_bytesToHuman.units, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double %8, i8 signext %14)
br label %18
16: ; preds = %1
%17 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %3, i8 signext 0)
br label %18
18: ; preds = %16, %11
ret i8* %2
}