#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*/ snprintf(char *, int, char *, double, ...);
void pfl_fmt_human(char buf[8], double num) {
  int mag;
  for (mag = 0; num >= 1024.0; mag++)
    num /= 1024.0;
  if (mag > 6)
    snprintf(buf, 8, "%.1e", num);
  else if (mag == 0)
    snprintf(buf, 8, "%6dB", (int)(num + .5));
  else
    snprintf(buf, 8, "%6.1f%c", num, "BKMGTPE"[mag]);
}


x86 assembly (clang, -O0):
<pfl_fmt_human>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xecb(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1163 <pfl_fmt_human+0x53>
movsd  -0x10(%rbp),%xmm0
movsd  0xeb4(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1128 <pfl_fmt_human+0x18>
cmpl   $0x6,-0x14(%rbp)
jle    118e <pfl_fmt_human+0x7e>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
mov    $0x8,%esi
lea    0xe8e(%rip),%rdx
mov    $0x1,%al
call   1030 <snprintf@plt>
jmp    11f9 <pfl_fmt_human+0xe9>
cmpl   $0x0,-0x14(%rbp)
jne    11c9 <pfl_fmt_human+0xb9>
mov    -0x8(%rbp),%rdi
movsd  0xe64(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%eax
cvtsi2sd %eax,%xmm0
mov    $0x8,%esi
lea    0xe58(%rip),%rdx
mov    $0x1,%al
call   1030 <snprintf@plt>
jmp    11f4 <pfl_fmt_human+0xe4>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
movslq -0x14(%rbp),%rcx
lea    0xe45(%rip),%rax
movsbl (%rax,%rcx,1),%ecx
mov    $0x8,%esi
lea    0xe2d(%rip),%rdx
mov    $0x1,%al
call   1030 <snprintf@plt>
jmp    11f9 <pfl_fmt_human+0xe9>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pfl_fmt_human>:
ucomisd 0xee8(%rip),%xmm0
jae    1133 <pfl_fmt_human+0x23>
addsd  0xeee(%rip),%xmm0
cvttpd2dq %xmm0,%xmm0
cvtdq2pd %xmm0,%xmm0
lea    0xeec(%rip),%rdx
jmp    116d <pfl_fmt_human+0x5d>
xor    %eax,%eax
movsd  0xecb(%rip),%xmm1
movsd  0xebb(%rip),%xmm2
cs nopw 0x0(%rax,%rax,1)
nop
mulsd  %xmm1,%xmm0
add    $0x1,%rax
ucomisd %xmm2,%xmm0
jae    1150 <pfl_fmt_human+0x40>
lea    -0x1(%rax),%ecx
cmp    $0x6,%ecx
jb     1179 <pfl_fmt_human+0x69>
lea    0xeab(%rip),%rdx
mov    $0x8,%esi
mov    $0x1,%al
jmp    1030 <snprintf@plt>
lea    0xeaa(%rip),%rcx
movsbl (%rax,%rcx,1),%ecx
lea    0xe97(%rip),%rdx
mov    $0x8,%esi
mov    $0x1,%al
jmp    1030 <snprintf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%.1e\00"
@.str.1 = [5 x i8] c"%6dB\00"
@.str.2 = [8 x i8] c"%6.1f%c\00"
@.str.3 = [8 x i8] c"BKMGTPE\00"
define void @pfl_fmt_human(i8* %0, double %1) {
%3 = alloca i8*
%4 = alloca double
%5 = alloca i32
store i8* %0, i8** %3
store double %1, double* %4
store i32 0, i32* %5
br label %6
6: ; preds = %12, %2
%7 = load double, double* %4
%8 = fcmp oge double %7, 1.024000e+03
br i1 %8, label %9, label %15
9: ; preds = %6
%10 = load double, double* %4
%11 = fdiv double %10, 1.024000e+03
store double %11, double* %4
br label %12
12: ; preds = %9
%13 = load i32, i32* %5
%14 = add nsw i32 %13, 1
store i32 %14, i32* %5
br label %6
15: ; preds = %6
%16 = load i32, i32* %5
%17 = icmp sgt i32 %16, 6
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i8*, i8** %3
%20 = load double, double* %4
%21 = call i32 (i8*, i32, i8*, double, ...) @snprintf(i8* %19, i32 8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %20)
br label %42
22: ; preds = %15
%23 = load i32, i32* %5
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %22
%26 = load i8*, i8** %3
%27 = load double, double* %4
%28 = fadd double %27, 5.000000e-01
%29 = fptosi double %28 to i32
%30 = sitofp i32 %29 to double
%31 = call i32 (i8*, i32, i8*, double, ...) @snprintf(i8* %26, i32 8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %30)
br label %41
32: ; preds = %22
%33 = load i8*, i8** %3
%34 = load double, double* %4
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [8 x i8], [8 x i8]* @.str.3, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = call i32 (i8*, i32, i8*, double, ...) @snprintf(i8* %33, i32 8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %34, i32 %39)
br label %41
41: ; preds = %32, %25
br label %42
42: ; preds = %41, %18
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%.1e\00"
@.str.1 = [5 x i8] c"%6dB\00"
@.str.2 = [8 x i8] c"%6.1f%c\00"
@.str.3 = [8 x i8] c"BKMGTPE\00"
define void @pfl_fmt_human(i8* %0, double %1) {
%3 = fcmp ult double %1, 1.024000e+03
br i1 %3, label %14, label %4
4: ; preds = %2, %4
%5 = phi i32 [ %8, %4 ], [ 0, %2 ]
%6 = phi double [ %7, %4 ], [ %1, %2 ]
%7 = fmul double %6, 0x3F50000000000000
%8 = add nuw nsw i32 %5, 1
%9 = fcmp ult double %7, 1.024000e+03
br i1 %9, label %10, label %4
10: ; preds = %4
%11 = icmp ugt i32 %5, 5
br i1 %11, label %12, label %19
12: ; preds = %10
%13 = tail call i32 (i8*, i32, i8*, double, ...) @snprintf(i8* %0, i32 8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %7)
br label %25
14: ; preds = %2
%15 = fadd double %1, 5.000000e-01
%16 = fptosi double %15 to i32
%17 = sitofp i32 %16 to double
%18 = tail call i32 (i8*, i32, i8*, double, ...) @snprintf(i8* %0, i32 8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %17)
br label %25
19: ; preds = %10
%20 = zext i32 %8 to i64
%21 = getelementptr inbounds [8 x i8], [8 x i8]* @.str.3, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = tail call i32 (i8*, i32, i8*, double, ...) @snprintf(i8* %0, i32 8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %7, i32 %23)
br label %25
25: ; preds = %14, %19, %12
ret void
}