#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*/ u;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int xasprintf(int /*<<< orphan*/ *, char **, char *, long double, char const);
char *humansize(long double size) {
  assert(size > 0);
  static const char u[] = "BKMGTPE";
  char *res = NULL;
  size_t i = 0;
  int ret = 0;
  while (size >= 1024 && i < sizeof(u)) {
    size /= 1024;
    i++;
  }
  ret = xasprintf(NULL, &res, "%.2Lf%c", size, u[i]);
  if (ret < 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)
movl   $0x0,-0x34(%rbp)
fldt   -0x20(%rbp)
xor    %eax,%eax
flds   0xe98(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
mov    %al,-0x35(%rbp)
jb     1187 <humansize+0x67>
jmp    117c <humansize+0x5c>
cmpq   $0x8,-0x30(%rbp)
setb   %al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
test   $0x1,%al
jne    1197 <humansize+0x77>
jmp    11b6 <humansize+0x96>
fldt   -0x20(%rbp)
flds   0xe60(%rip)
fdivrp %st,%st(1)
fstpt  -0x20(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    115d <humansize+0x3d>
fldt   -0x20(%rbp)
mov    -0x30(%rbp),%rcx
lea    0xe40(%rip),%rax
mov    (%rax,%rcx,1),%al
xor    %ecx,%ecx
mov    %rsp,%rcx
fstpt  (%rcx)
movsbl %al,%ecx
lea    0xe34(%rip),%rdx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x28(%rbp),%rsi
call   1040 <xasprintf@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    11ff <humansize+0xdf>
movq   $0x0,-0x8(%rbp)
jmp    1207 <humansize+0xe7>
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    11f2 <humansize+0xd2>
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   %eax,%eax
js     11e9 <humansize+0xc9>
mov    0x18(%rsp),%rbx
mov    %rbx,%rax
add    $0x30,%rsp
pop    %rbx
ret
fmuls  0xe0c(%rip)
mov    $0x7,%eax
fucomi %st(1),%st
fstp   %st(1)
jb     11bd <humansize+0x9d>
fmuls  0xdfb(%rip)
mov    $0x8,%eax
jmp    11bd <humansize+0x9d>

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

LLVM IR (-O2):
@humansize.u = 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.u, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = call i32 @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 i32 %36, 0
%38 = load i8*, i8** %2
%39 = select i1 %37, i8* null, i8* %38
ret i8* %39
}