#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*/ uintmax_t;
typedef double off_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, double, ...);
int strlen(char const *);
char *humansize(off_t n) {
  static char buf[16];
  const char postfixes[] = "BKMGTPE";
  double size;
  int i;
  for (size = n, i = 0; size >= 1024 && i < strlen(postfixes); i++)
    size /= 1024;
  if (!i)
    snprintf(buf, sizeof(buf), "%ju", (uintmax_t)n);
  else
    snprintf(buf, sizeof(buf), "%.1f%c", size, postfixes[i]);
  return buf;
}


x86 assembly (clang, -O0):
<humansize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    0xed4(%rip),%rax
mov    %rax,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movsd  -0x18(%rbp),%xmm0
xor    %eax,%eax
movsd  0xea8(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x1d(%rbp)
jb     1181 <humansize+0x61>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
setl   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1191 <humansize+0x71>
jmp    11b5 <humansize+0x95>
movsd  -0x18(%rbp),%xmm0
movsd  0xe62(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1149 <humansize+0x29>
cmpl   $0x0,-0x1c(%rbp)
jne    11e7 <humansize+0xc7>
cvttsd2si -0x8(%rbp),%eax
cvtsi2sd %eax,%xmm0
lea    0x2e71(%rip),%rdi
mov    $0x10,%esi
lea    0xe35(%rip),%rdx
mov    $0x1,%al
call   1040 <snprintf@plt>
jmp    120f <humansize+0xef>
movsd  -0x18(%rbp),%xmm0
movslq -0x1c(%rbp),%rax
movsbl -0x10(%rbp,%rax,1),%ecx
lea    0x2e44(%rip),%rdi
mov    $0x10,%esi
lea    0xe0c(%rip),%rdx
mov    $0x1,%al
call   1040 <snprintf@plt>
lea    0x2e2a(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<humansize>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
movabs $0x455054474d4b42,%rax
mov    %rax,0x8(%rsp)
movapd %xmm0,0x10(%rsp)
ucomisd 0xebd(%rip),%xmm0
jae    116b <humansize+0x4b>
cvttpd2dq 0x10(%rsp),%xmm0
cvtdq2pd %xmm0,%xmm0
lea    0x2eea(%rip),%rdi
lea    0xeb3(%rip),%rdx
mov    $0x10,%esi
mov    $0x1,%al
call   1040 <snprintf@plt>
jmp    11d7 <humansize+0xb7>
xor    %ebp,%ebp
lea    0x8(%rsp),%rbx
movapd 0x10(%rsp),%xmm0
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebp
jge    11ad <humansize+0x8d>
movsd  (%rsp),%xmm0
mulsd  0xe6a(%rip),%xmm0
add    $0x1,%ebp
ucomisd 0xe57(%rip),%xmm0
jae    1180 <humansize+0x60>
jmp    11b6 <humansize+0x96>
test   %ebp,%ebp
movsd  (%rsp),%xmm0
je     1145 <humansize+0x25>
mov    %ebp,%eax
movsbl 0x8(%rsp,%rax,1),%ecx
lea    0x2e7c(%rip),%rdi
lea    0xe49(%rip),%rdx
mov    $0x10,%esi
mov    $0x1,%al
call   1040 <snprintf@plt>
lea    0x2e62(%rip),%rax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@humansize.buf = internal global [16 x i8] zeroinitializer
@__const.humansize.postfixes = [8 x i8] c"BKMGTPE\00"
@.str = [4 x i8] c"%ju\00"
@.str.1 = [7 x i8] c"%.1f%c\00"
define i8* @humansize(double %0) {
%2 = alloca double
%3 = alloca [8 x i8]
%4 = alloca double
%5 = alloca i32
store double %0, double* %2
%6 = bitcast [8 x i8]* %3 to i8*
%7 = load double, double* %2
store double %7, double* %4
store i32 0, i32* %5
br label %8
8: ; preds = %21, %1
%9 = load double, double* %4
%10 = fcmp oge double %9, 1.024000e+03
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = load i32, i32* %5
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%14 = call i32 @strlen(i8* %13)
%15 = icmp slt i32 %12, %14
br label %16
16: ; preds = %11, %8
%17 = phi i1 [ false, %8 ], [ %15, %11 ]
br i1 %17, label %18, label %24
18: ; preds = %16
%19 = load double, double* %4
%20 = fdiv double %19, 1.024000e+03
store double %20, double* %4
br label %21
21: ; preds = %18
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %8
24: ; preds = %16
%25 = load i32, i32* %5
%26 = icmp ne i32 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %24
%28 = load double, double* %2
%29 = fptosi double %28 to i32
%30 = sitofp i32 %29 to double
%31 = call i32 (i8*, i32, i8*, double, ...) @snprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @humansize.buf, i64 0, i64 0), i32 16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %30)
br label %40
32: ; preds = %24
%33 = load double, double* %4
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = call i32 (i8*, i32, i8*, double, ...) @snprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @humansize.buf, i64 0, i64 0), i32 16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %33, i32 %38)
br label %40
40: ; preds = %32, %27
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @humansize.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@humansize.buf = internal global [16 x i8] zeroinitializer
@.str = [4 x i8] c"%ju\00"
@.str.1 = [7 x i8] c"%.1f%c\00"
define i8* @humansize(double %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to [8 x i8]*
%4 = bitcast i64* %2 to i8*
store i64 19510096296758082, i64* %2
%5 = fcmp ult double %0, 1.024000e+03
br i1 %5, label %17, label %6
6: ; preds = %1, %11
%7 = phi i32 [ %13, %11 ], [ 0, %1 ]
%8 = phi double [ %12, %11 ], [ %0, %1 ]
%9 = call i32 @strlen(i8* %4)
%10 = icmp slt i32 %7, %9
br i1 %10, label %11, label %15
11: ; preds = %6
%12 = fmul double %8, 0x3F50000000000000
%13 = add nuw nsw i32 %7, 1
%14 = fcmp ult double %12, 1.024000e+03
br i1 %14, label %21, label %6
15: ; preds = %6
%16 = icmp eq i32 %7, 0
br i1 %16, label %17, label %21
17: ; preds = %1, %15
%18 = fptosi double %0 to i32
%19 = sitofp i32 %18 to double
%20 = call i32 (i8*, i32, i8*, double, ...) @snprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @humansize.buf, i64 0, i64 0), i32 16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %19)
br label %29
21: ; preds = %11, %15
%22 = phi i32 [ %7, %15 ], [ %13, %11 ]
%23 = phi double [ %8, %15 ], [ %12, %11 ]
%24 = zext i32 %22 to i64
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = call i32 (i8*, i32, i8*, double, ...) @snprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @humansize.buf, i64 0, i64 0), i32 16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %23, i32 %27)
br label %29
29: ; preds = %21, %17
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @humansize.buf, i64 0, i64 0)
}