#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 */
typedef int /*<<< orphan*/ units;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
scalar_t__ xasprintf(int /*<<< orphan*/ *, char **, char *, long double,
                     char const);
char *humansize(long double size) {
  assert(size > 0);
  static const char units[] = "BKMGTPE";
  char *res = NULL;
  size_t i = 0;
  while (size >= 1024 && i < sizeof(units)) {
    size /= 1024;
    i++;
  }
  if (xasprintf(NULL, &res, "%.2Lf%c", size, units[i]) < 0)
    return (NULL);
  return (res);
}


x86 assembly (clang, -O0):
<humansize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
fldt   0x10(%rbp)
fstpt  -0x20(%rbp)
fldt   -0x20(%rbp)
fldz
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
fldt   -0x20(%rbp)
xor    %eax,%eax
flds   0xe9f(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
mov    %al,-0x31(%rbp)
jb     1180 <humansize+0x60>
jmp    1175 <humansize+0x55>
cmpq   $0x8,-0x30(%rbp)
setb   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1190 <humansize+0x70>
jmp    11af <humansize+0x8f>
fldt   -0x20(%rbp)
flds   0xe67(%rip)
fdivrp %st,%st(1)
fstpt  -0x20(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1156 <humansize+0x36>
fldt   -0x20(%rbp)
mov    -0x30(%rbp),%rcx
lea    0xe47(%rip),%rax
mov    (%rax,%rcx,1),%al
xor    %ecx,%ecx
mov    %rsp,%rcx
fstpt  (%rcx)
movsbl %al,%ecx
lea    0xe3b(%rip),%rdx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x28(%rbp),%rsi
call   1040 <xasprintf@plt>
cmp    $0x0,%rax
jge    11f5 <humansize+0xd5>
movq   $0x0,-0x8(%rbp)
jmp    11fd <humansize+0xdd>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<humansize>:
push   %rbx
sub    $0x30,%rsp
fldt   0x40(%rsp)
fld    %st(0)
fstpt  0x24(%rsp)
fldz
xor    %edi,%edi
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
seta   %dil
call   1030 <assert@plt>
fldt   0x24(%rsp)
movq   $0x0,0x18(%rsp)
flds   0xeab(%rip)
fxch   %st(1)
fucomi %st(1),%st
jae    1161 <humansize+0x41>
fstp   %st(1)
xor    %eax,%eax
jmp    11bd <humansize+0x9d>
fmuls  0xe9d(%rip)
mov    $0x1,%eax
fucomi %st(1),%st
jb     11bb <humansize+0x9b>
fmuls  0xe8e(%rip)
mov    $0x2,%eax
fucomi %st(1),%st
jb     11bb <humansize+0x9b>
fmuls  0xe7f(%rip)
mov    $0x3,%eax
fucomi %st(1),%st
jb     11bb <humansize+0x9b>
fmuls  0xe70(%rip)
mov    $0x4,%eax
fucomi %st(1),%st
jb     11bb <humansize+0x9b>
fmuls  0xe61(%rip)
mov    $0x5,%eax
fucomi %st(1),%st
jb     11bb <humansize+0x9b>
fmuls  0xe52(%rip)
mov    $0x6,%eax
fucomi %st(1),%st
jae    11f3 <humansize+0xd3>
fstp   %st(1)
lea    0xe44(%rip),%rcx
movsbl (%rax,%rcx,1),%ecx
fstpt  (%rsp)
lea    0xe3e(%rip),%rdx
xor    %ebx,%ebx
lea    0x18(%rsp),%rsi
xor    %edi,%edi
call   1040 <xasprintf@plt>
test   %rax,%rax
js     11ea <humansize+0xca>
mov    0x18(%rsp),%rbx
mov    %rbx,%rax
add    $0x30,%rsp
pop    %rbx
ret
fmuls  0xe0b(%rip)
mov    $0x7,%eax
fucomi %st(1),%st
fstp   %st(1)
jb     11bd <humansize+0x9d>
fmuls  0xdfa(%rip)
mov    $0x8,%eax
jmp    11bd <humansize+0x9d>

LLVM IR (-O0):
@humansize.units = internal constant [8 x i8] c"BKMGTPE\00"
@.str = [8 x i8] c"%.2Lf%c\00"
define i8* @humansize(x86_fp80 %0) {
%2 = alloca i8*
%3 = alloca x86_fp80
%4 = alloca i8*
%5 = alloca i64
store x86_fp80 %0, x86_fp80* %3
%6 = load x86_fp80, x86_fp80* %3
%7 = fcmp ogt x86_fp80 %6, 0xK00000000000000000000
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
store i8* null, i8** %4
store i64 0, i64* %5
br label %10
10: ; preds = %18, %1
%11 = load x86_fp80, x86_fp80* %3
%12 = fcmp oge x86_fp80 %11, 0xK40098000000000000000
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i64, i64* %5
%15 = icmp ult i64 %14, 8
br label %16
16: ; preds = %13, %10
%17 = phi i1 [ false, %10 ], [ %15, %13 ]
br i1 %17, label %18, label %23
18: ; preds = %16
%19 = load x86_fp80, x86_fp80* %3
%20 = fdiv x86_fp80 %19, 0xK40098000000000000000
store x86_fp80 %20, x86_fp80* %3
%21 = load i64, i64* %5
%22 = add i64 %21, 1
store i64 %22, i64* %5
br label %10
23: ; preds = %16
%24 = load x86_fp80, x86_fp80* %3
%25 = load i64, i64* %5
%26 = getelementptr inbounds [8 x i8], [8 x i8]* @humansize.units, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = call i64 @xasprintf(i32* null, i8** %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), x86_fp80 %24, i8 signext %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %23
store i8* null, i8** %2
br label %33
31: ; preds = %23
%32 = load i8*, i8** %4
store i8* %32, i8** %2
br label %33
33: ; preds = %31, %30
%34 = load i8*, i8** %2
ret i8* %34
}

LLVM IR (-O2):
@humansize.units = internal unnamed_addr constant [8 x i8] c"BKMGTPE\00"
@.str = [8 x i8] c"%.2Lf%c\00"
define i8* @humansize(x86_fp80 %0) {
%2 = alloca i8*
%3 = fcmp ogt x86_fp80 %0, 0xK00000000000000000000
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%7 = fcmp ult x86_fp80 %0, 0xK40098000000000000000
br i1 %7, label %31, label %8
8: ; preds = %1
%9 = fmul x86_fp80 %0, 0xK3FF58000000000000000
%10 = fcmp ult x86_fp80 %9, 0xK40098000000000000000
br i1 %10, label %31, label %11
11: ; preds = %8
%12 = fmul x86_fp80 %9, 0xK3FF58000000000000000
%13 = fcmp ult x86_fp80 %12, 0xK40098000000000000000
br i1 %13, label %31, label %14
14: ; preds = %11
%15 = fmul x86_fp80 %12, 0xK3FF58000000000000000
%16 = fcmp ult x86_fp80 %15, 0xK40098000000000000000
br i1 %16, label %31, label %17
17: ; preds = %14
%18 = fmul x86_fp80 %15, 0xK3FF58000000000000000
%19 = fcmp ult x86_fp80 %18, 0xK40098000000000000000
br i1 %19, label %31, label %20
20: ; preds = %17
%21 = fmul x86_fp80 %18, 0xK3FF58000000000000000
%22 = fcmp ult x86_fp80 %21, 0xK40098000000000000000
br i1 %22, label %31, label %23
23: ; preds = %20
%24 = fmul x86_fp80 %21, 0xK3FF58000000000000000
%25 = fcmp ult x86_fp80 %24, 0xK40098000000000000000
br i1 %25, label %31, label %26
26: ; preds = %23
%27 = fmul x86_fp80 %24, 0xK3FF58000000000000000
%28 = fcmp ult x86_fp80 %27, 0xK40098000000000000000
br i1 %28, label %31, label %29
29: ; preds = %26
%30 = fmul x86_fp80 %27, 0xK3FF58000000000000000
br label %31
31: ; preds = %8, %11, %14, %17, %20, %23, %26, %29, %1
%32 = phi x86_fp80 [ %0, %1 ], [ %9, %8 ], [ %12, %11 ], [ %15, %14 ], [ %18, %17 ], [ %21, %20 ], [ %24, %23 ], [ %27, %26 ], [ %30, %29 ]
%33 = phi i64 [ 0, %1 ], [ 1, %8 ], [ 2, %11 ], [ 3, %14 ], [ 4, %17 ], [ 5, %20 ], [ 6, %23 ], [ 7, %26 ], [ 8, %29 ]
%34 = getelementptr inbounds [8 x i8], [8 x i8]* @humansize.units, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = call i64 @xasprintf(i32* null, i8** %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), x86_fp80 %32, i8 signext %35)
%37 = icmp slt i64 %36, 0
%38 = load i8*, i8** %2
%39 = select i1 %37, i8* null, i8* %38
ret i8* %39
}