#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 uint8_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, double);
void statsdump_print_humanize_iec(double number) {
  uint8_t i;
  for (i = 0; i < 6; i++) {
    if (number < 999.5) {
      printf("%.2lf", number);
      if (i > 0) {
        printf("%ci", "-KMGTP"[i]);
      }
      return;
    }
    number /= 1024.0;
  }
  printf("%.2lfEi", number);
}


x86 assembly (clang, -O0):
<statsdump_print_humanize_iec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x6,-0xc(%rbp)
jge    11a4 <statsdump_print_humanize_iec+0x94>
movsd  0xeca(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1180 <statsdump_print_humanize_iec+0x70>
movsd  -0x8(%rbp),%xmm0
lea    0xec3(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x0,-0xc(%rbp)
jle    117b <statsdump_print_humanize_iec+0x6b>
movslq -0xc(%rbp),%rax
lea    0xeb3(%rip),%rcx
movsbl (%rax,%rcx,1),%eax
cvtsi2sd %eax,%xmm0
lea    0xea0(%rip),%rdi
call   1030 <printf@plt>
jmp    11b5 <statsdump_print_humanize_iec+0xa5>
movsd  -0x8(%rbp),%xmm0
movsd  0xe7b(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1124 <statsdump_print_humanize_iec+0x14>
movsd  -0x8(%rbp),%xmm0
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<statsdump_print_humanize_iec>:
push   %rbx
movsd  0xee7(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    112c <statsdump_print_humanize_iec+0x1c>
lea    0xeea(%rip),%rdi
pop    %rbx
jmp    1030 <printf@plt>
mulsd  0xed4(%rip),%xmm0
mov    $0x1,%ebx
ucomisd %xmm0,%xmm1
ja     118b <statsdump_print_humanize_iec+0x7b>
mulsd  0xec1(%rip),%xmm0
mov    $0x2,%ebx
ucomisd %xmm0,%xmm1
ja     118b <statsdump_print_humanize_iec+0x7b>
mulsd  0xeae(%rip),%xmm0
mov    $0x3,%ebx
ucomisd %xmm0,%xmm1
ja     118b <statsdump_print_humanize_iec+0x7b>
mulsd  0xe9b(%rip),%xmm0
mov    $0x4,%ebx
ucomisd %xmm0,%xmm1
ja     118b <statsdump_print_humanize_iec+0x7b>
mulsd  0xe88(%rip),%xmm0
mov    $0x5,%ebx
ucomisd %xmm0,%xmm1
jbe    11b6 <statsdump_print_humanize_iec+0xa6>
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
lea    0xe7c(%rip),%rax
movsbl (%rbx,%rax,1),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
lea    0xe66(%rip),%rdi
pop    %rbx
jmp    1030 <printf@plt>
mulsd  0xe4a(%rip),%xmm0
lea    0xe5c(%rip),%rdi
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"%.2lf\00"
@.str.1 = [4 x i8] c"%ci\00"
@.str.2 = [7 x i8] c"-KMGTP\00"
@.str.3 = [8 x i8] c"%.2lfEi\00"
define void @statsdump_print_humanize_iec(double %0) {
%2 = alloca double
%3 = alloca i32
store double %0, double* %2
store i32 0, i32* %3
br label %4
4: ; preds = %26, %1
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 6
br i1 %6, label %7, label %29
7: ; preds = %4
%8 = load double, double* %2
%9 = fcmp olt double %8, 9.995000e+02
br i1 %9, label %10, label %23
10: ; preds = %7
%11 = load double, double* %2
%12 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %11)
%13 = load i32, i32* %3
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %10
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [7 x i8], [7 x i8]* @.str.2, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = sitofp i8 %19 to double
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %20)
br label %22
22: ; preds = %15, %10
br label %32
23: ; preds = %7
%24 = load double, double* %2
%25 = fdiv double %24, 1.024000e+03
store double %25, double* %2
br label %26
26: ; preds = %23
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %4
29: ; preds = %4
%30 = load double, double* %2
%31 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), double %30)
br label %32
32: ; preds = %29, %22
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%.2lf\00"
@.str.1 = [4 x i8] c"%ci\00"
@.str.2 = [7 x i8] c"-KMGTP\00"
@.str.3 = [8 x i8] c"%.2lfEi\00"
define void @statsdump_print_humanize_iec(double %0) {
%2 = fcmp olt double %0, 9.995000e+02
br i1 %2, label %3, label %13
3: ; preds = %1
%4 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %0)
br label %31
5: ; preds = %25, %22, %19, %16, %13
%6 = phi i64 [ 1, %13 ], [ 2, %16 ], [ 3, %19 ], [ 4, %22 ], [ 5, %25 ]
%7 = phi double [ %14, %13 ], [ %17, %16 ], [ %20, %19 ], [ %23, %22 ], [ %26, %25 ]
%8 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %7)
%9 = getelementptr inbounds [7 x i8], [7 x i8]* @.str.2, i64 0, i64 %6
%10 = load i8, i8* %9
%11 = sitofp i8 %10 to double
%12 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %11)
br label %31
13: ; preds = %1
%14 = fmul double %0, 0x3F50000000000000
%15 = fcmp olt double %14, 9.995000e+02
br i1 %15, label %5, label %16
16: ; preds = %13
%17 = fmul double %14, 0x3F50000000000000
%18 = fcmp olt double %17, 9.995000e+02
br i1 %18, label %5, label %19
19: ; preds = %16
%20 = fmul double %17, 0x3F50000000000000
%21 = fcmp olt double %20, 9.995000e+02
br i1 %21, label %5, label %22
22: ; preds = %19
%23 = fmul double %20, 0x3F50000000000000
%24 = fcmp olt double %23, 9.995000e+02
br i1 %24, label %5, label %25
25: ; preds = %22
%26 = fmul double %23, 0x3F50000000000000
%27 = fcmp olt double %26, 9.995000e+02
br i1 %27, label %5, label %28
28: ; preds = %25
%29 = fmul double %26, 0x3F50000000000000
%30 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), double %29)
br label %31
31: ; preds = %3, %5, %28
ret void
}