#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*/ asprintf(char **, char *, float, char);
char *humanize_size(float size) {
  char sizes[] = {'B', 'K', 'M', 'G'};
  char human_size = sizes[0];
  int i = 1;
  while (size >= 1024) {
    human_size = sizes[i];
    i++;
    size /= 1024;
  }
  char *str_size;
  asprintf(&str_size, "%.1f %c", size, human_size);
  return str_size;
}


x86 assembly (clang, -O0):
<humanize_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
mov    0xee1(%rip),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%al
mov    %al,-0x9(%rbp)
movl   $0x1,-0x10(%rbp)
movss  -0x4(%rbp),%xmm0
movss  0xec0(%rip),%xmm1
ucomiss %xmm1,%xmm0
jb     1178 <humanize_size+0x68>
movslq -0x10(%rbp),%rax
mov    -0x8(%rbp,%rax,1),%al
mov    %al,-0x9(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
movss  -0x4(%rbp),%xmm0
movss  0xe96(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1133 <humanize_size+0x23>
movss  -0x4(%rbp),%xmm0
lea    -0x18(%rbp),%rdi
lea    0xe80(%rip),%rsi
movsbl -0x9(%rbp),%edx
call   1030 <asprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<humanize_size>:
push   %rax
mov    $0x42,%al
ucomiss 0xee6(%rip),%xmm0
jb     114f <humanize_size+0x3f>
lea    0xee5(%rip),%rax
movss  0xed9(%rip),%xmm1
movss  0xecd(%rip),%xmm2
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mulss  %xmm1,%xmm0
add    $0x1,%rax
ucomiss %xmm2,%xmm0
jae    1140 <humanize_size+0x30>
mov    (%rax),%al
movsbl %al,%edx
lea    0xeb3(%rip),%rsi
mov    %rsp,%rdi
call   1030 <asprintf@plt>
mov    (%rsp),%rax
pop    %rcx
ret

LLVM IR (-O0):
@__const.humanize_size.sizes = [4 x i8] c"BKMG"
@.str = [8 x i8] c"%.1f %c\00"
define i8* @humanize_size(float %0) {
%2 = alloca float
%3 = alloca [4 x i8]
%4 = alloca i8
%5 = alloca i32
%6 = alloca i8*
store float %0, float* %2
%7 = bitcast [4 x i8]* %3 to i8*
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%9 = load i8, i8* %8
store i8 %9, i8* %4
store i32 1, i32* %5
br label %10
10: ; preds = %13, %1
%11 = load float, float* %2
%12 = fcmp oge float %11, 1.024000e+03
br i1 %12, label %13, label %22
13: ; preds = %10
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 %15
%17 = load i8, i8* %16
store i8 %17, i8* %4
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
%20 = load float, float* %2
%21 = fdiv float %20, 1.024000e+03
store float %21, float* %2
br label %10
22: ; preds = %10
%23 = load float, float* %2
%24 = load i8, i8* %4
%25 = call i32 @asprintf(i8** %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), float %23, i8 signext %24)
%26 = load i8*, i8** %6
ret i8* %26
}

LLVM IR (-O2):
@__const.humanize_size.sizes = [4 x i8] c"BKMG"
@.str = [8 x i8] c"%.1f %c\00"
define i8* @humanize_size(float %0) {
%2 = alloca i8*
%3 = fcmp ult float %0, 1.024000e+03
br i1 %3, label %14, label %4
4: ; preds = %1, %4
%5 = phi i32 [ %7, %4 ], [ 1, %1 ]
%6 = phi float [ %8, %4 ], [ %0, %1 ]
%7 = add nuw nsw i32 %5, 1
%8 = fmul float %6, 0x3F50000000000000
%9 = fcmp ult float %8, 1.024000e+03
br i1 %9, label %10, label %4
10: ; preds = %4
%11 = zext i32 %5 to i64
%12 = getelementptr inbounds [4 x i8], [4 x i8]* @__const.humanize_size.sizes, i64 0, i64 %11
%13 = load i8, i8* %12
br label %14
14: ; preds = %10, %1
%15 = phi float [ %8, %10 ], [ %0, %1 ]
%16 = phi i8 [ %13, %10 ], [ 66, %1 ]
%17 = bitcast i8** %2 to i8*
%18 = call i32 @asprintf(i8** %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), float %15, i8 signext %16)
%19 = load i8*, i8** %2
ret i8* %19
}