#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 *, size_t, char const *, double);
void cvtstr(double value, char *str, size_t size) {
  const char *fmt;
  int precise;
  precise = ((double)value * 1000 == (double)(int)value * 1000);
  if (value >= ((long long)(1) << 60)) {
    fmt = precise ? "%.f EiB" : "%.3f EiB";
    snprintf(str, size, fmt, ((value) / ((long long)(1) << 60)));
  } else if (value >= ((long long)(1) << 50)) {
    fmt = precise ? "%.f PiB" : "%.3f PiB";
    snprintf(str, size, fmt, ((value) / ((long long)(1) << 50)));
  } else if (value >= ((long long)(1) << 40)) {
    fmt = precise ? "%.f TiB" : "%.3f TiB";
    snprintf(str, size, fmt, ((value) / ((long long)(1) << 40)));
  } else if (value >= ((long long)(1) << 30)) {
    fmt = precise ? "%.f GiB" : "%.3f GiB";
    snprintf(str, size, fmt, ((value) / ((long long)(1) << 30)));
  } else if (value >= ((long long)(1) << 20)) {
    fmt = precise ? "%.f MiB" : "%.3f MiB";
    snprintf(str, size, fmt, ((value) / ((long long)(1) << 20)));
  } else if (value >= ((long long)(1) << 10)) {
    fmt = precise ? "%.f KiB" : "%.3f KiB";
    snprintf(str, size, fmt, ((value) / ((long long)(1) << 10)));
  } else {
    snprintf(str, size, "%f bytes", value);
  }
}


x86 assembly (clang, -O0):
<cvtstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movsd  0xedb(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
cvttsd2si -0x8(%rbp),%eax
cvtsi2sd %eax,%xmm1
movsd  0xec5(%rip),%xmm2
mulsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x24(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe98(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11b5 <cvtstr+0xa5>
mov    -0x24(%rbp),%edx
lea    0xec4(%rip),%rax
lea    0xeb5(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
movsd  -0x8(%rbp),%xmm0
movsd  0xe59(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <snprintf@plt>
jmp    13a9 <cvtstr+0x299>
movsd  -0x8(%rbp),%xmm0
movsd  0xe4e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     120f <cvtstr+0xff>
mov    -0x24(%rbp),%edx
lea    0xe7b(%rip),%rax
lea    0xe6c(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
movsd  -0x8(%rbp),%xmm0
movsd  0xe0f(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <snprintf@plt>
jmp    13a4 <cvtstr+0x294>
movsd  -0x8(%rbp),%xmm0
movsd  0xdfc(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1269 <cvtstr+0x159>
mov    -0x24(%rbp),%edx
lea    0xe32(%rip),%rax
lea    0xe23(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
movsd  -0x8(%rbp),%xmm0
movsd  0xdbd(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <snprintf@plt>
jmp    139f <cvtstr+0x28f>
movsd  -0x8(%rbp),%xmm0
movsd  0xdaa(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     12c3 <cvtstr+0x1b3>
mov    -0x24(%rbp),%edx
lea    0xde9(%rip),%rax
lea    0xdda(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
movsd  -0x8(%rbp),%xmm0
movsd  0xd6b(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <snprintf@plt>
jmp    139a <cvtstr+0x28a>
movsd  -0x8(%rbp),%xmm0
movsd  0xd58(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     131d <cvtstr+0x20d>
mov    -0x24(%rbp),%edx
lea    0xda0(%rip),%rax
lea    0xd91(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
movsd  -0x8(%rbp),%xmm0
movsd  0xd19(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <snprintf@plt>
jmp    1395 <cvtstr+0x285>
movsd  -0x8(%rbp),%xmm0
movsd  0xd06(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1377 <cvtstr+0x267>
mov    -0x24(%rbp),%edx
lea    0xd57(%rip),%rax
lea    0xd48(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
movsd  -0x8(%rbp),%xmm0
movsd  0xcc7(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <snprintf@plt>
jmp    1390 <cvtstr+0x280>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movsd  -0x8(%rbp),%xmm0
lea    0xd13(%rip),%rdx
call   1030 <snprintf@plt>
jmp    1395 <cvtstr+0x285>
jmp    139a <cvtstr+0x28a>
jmp    139f <cvtstr+0x28f>
jmp    13a4 <cvtstr+0x294>
jmp    13a9 <cvtstr+0x299>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cvtstr>:
movsd  0xee8(%rip),%xmm3
movapd %xmm0,%xmm1
mulsd  %xmm3,%xmm1
cvttpd2dq %xmm0,%xmm2
cvtdq2pd %xmm2,%xmm2
mulsd  %xmm3,%xmm2
ucomisd 0xed4(%rip),%xmm0
jae    1184 <cvtstr+0x74>
ucomisd 0xeda(%rip),%xmm0
jae    11ab <cvtstr+0x9b>
ucomisd 0xee0(%rip),%xmm0
jae    11d2 <cvtstr+0xc2>
ucomisd 0xee2(%rip),%xmm0
jae    11f9 <cvtstr+0xe9>
ucomisd 0xee4(%rip),%xmm0
jae    1220 <cvtstr+0x110>
ucomisd 0xee6(%rip),%xmm0
jae    1247 <cvtstr+0x137>
lea    0xf4f(%rip),%rdx
jmp    1030 <snprintf@plt>
ucomisd %xmm2,%xmm1
lea    0xee1(%rip),%rax
lea    0xed2(%rip),%rdx
cmovne %rax,%rdx
cmovp  %rax,%rdx
mulsd  0xe6a(%rip),%xmm0
jmp    1030 <snprintf@plt>
ucomisd %xmm2,%xmm1
lea    0xecb(%rip),%rax
lea    0xebc(%rip),%rdx
cmovne %rax,%rdx
cmovp  %rax,%rdx
mulsd  0xe53(%rip),%xmm0
jmp    1030 <snprintf@plt>
ucomisd %xmm2,%xmm1
lea    0xeb5(%rip),%rax
lea    0xea6(%rip),%rdx
cmovne %rax,%rdx
cmovp  %rax,%rdx
mulsd  0xe3c(%rip),%xmm0
jmp    1030 <snprintf@plt>
ucomisd %xmm2,%xmm1
lea    0xe9f(%rip),%rax
lea    0xe90(%rip),%rdx
cmovne %rax,%rdx
cmovp  %rax,%rdx
mulsd  0xe25(%rip),%xmm0
jmp    1030 <snprintf@plt>
ucomisd %xmm2,%xmm1
lea    0xe89(%rip),%rax
lea    0xe7a(%rip),%rdx
cmovne %rax,%rdx
cmovp  %rax,%rdx
mulsd  0xe0e(%rip),%xmm0
jmp    1030 <snprintf@plt>
ucomisd %xmm2,%xmm1
lea    0xe73(%rip),%rax
lea    0xe64(%rip),%rdx
cmovne %rax,%rdx
cmovp  %rax,%rdx
mulsd  0xdf7(%rip),%xmm0
jmp    1030 <snprintf@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"%.f EiB\00"
@.str.1 = [9 x i8] c"%.3f EiB\00"
@.str.2 = [8 x i8] c"%.f PiB\00"
@.str.3 = [9 x i8] c"%.3f PiB\00"
@.str.4 = [8 x i8] c"%.f TiB\00"
@.str.5 = [9 x i8] c"%.3f TiB\00"
@.str.6 = [8 x i8] c"%.f GiB\00"
@.str.7 = [9 x i8] c"%.3f GiB\00"
@.str.8 = [8 x i8] c"%.f MiB\00"
@.str.9 = [9 x i8] c"%.3f MiB\00"
@.str.10 = [8 x i8] c"%.f KiB\00"
@.str.11 = [9 x i8] c"%.3f KiB\00"
@.str.12 = [9 x i8] c"%f bytes\00"
define void @cvtstr(double %0, i8* %1, i64 %2) {
%4 = alloca double
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
store double %0, double* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load double, double* %4
%10 = fmul double %9, 1.000000e+03
%11 = load double, double* %4
%12 = fptosi double %11 to i32
%13 = sitofp i32 %12 to double
%14 = fmul double %13, 1.000000e+03
%15 = fcmp oeq double %10, %14
%16 = zext i1 %15 to i32
store i32 %16, i32* %8
%17 = load double, double* %4
%18 = fcmp oge double %17, 0x43B0000000000000
br i1 %18, label %19, label %30
19: ; preds = %3
%20 = load i32, i32* %8
%21 = icmp ne i32 %20, 0
%22 = zext i1 %21 to i64
%23 = select i1 %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0)
store i8* %23, i8** %7
%24 = load i8*, i8** %5
%25 = load i64, i64* %6
%26 = load i8*, i8** %7
%27 = load double, double* %4
%28 = fdiv double %27, 0x43B0000000000000
%29 = call i32 @snprintf(i8* %24, i64 %25, i8* %26, double %28)
br label %110
30: ; preds = %3
%31 = load double, double* %4
%32 = fcmp oge double %31, 0x4310000000000000
br i1 %32, label %33, label %44
33: ; preds = %30
%34 = load i32, i32* %8
%35 = icmp ne i32 %34, 0
%36 = zext i1 %35 to i64
%37 = select i1 %35, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0)
store i8* %37, i8** %7
%38 = load i8*, i8** %5
%39 = load i64, i64* %6
%40 = load i8*, i8** %7
%41 = load double, double* %4
%42 = fdiv double %41, 0x4310000000000000
%43 = call i32 @snprintf(i8* %38, i64 %39, i8* %40, double %42)
br label %109
44: ; preds = %30
%45 = load double, double* %4
%46 = fcmp oge double %45, 0x4270000000000000
br i1 %46, label %47, label %58
47: ; preds = %44
%48 = load i32, i32* %8
%49 = icmp ne i32 %48, 0
%50 = zext i1 %49 to i64
%51 = select i1 %49, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0)
store i8* %51, i8** %7
%52 = load i8*, i8** %5
%53 = load i64, i64* %6
%54 = load i8*, i8** %7
%55 = load double, double* %4
%56 = fdiv double %55, 0x4270000000000000
%57 = call i32 @snprintf(i8* %52, i64 %53, i8* %54, double %56)
br label %108
58: ; preds = %44
%59 = load double, double* %4
%60 = fcmp oge double %59, 0x41D0000000000000
br i1 %60, label %61, label %72
61: ; preds = %58
%62 = load i32, i32* %8
%63 = icmp ne i32 %62, 0
%64 = zext i1 %63 to i64
%65 = select i1 %63, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0)
store i8* %65, i8** %7
%66 = load i8*, i8** %5
%67 = load i64, i64* %6
%68 = load i8*, i8** %7
%69 = load double, double* %4
%70 = fdiv double %69, 0x41D0000000000000
%71 = call i32 @snprintf(i8* %66, i64 %67, i8* %68, double %70)
br label %107
72: ; preds = %58
%73 = load double, double* %4
%74 = fcmp oge double %73, 0x4130000000000000
br i1 %74, label %75, label %86
75: ; preds = %72
%76 = load i32, i32* %8
%77 = icmp ne i32 %76, 0
%78 = zext i1 %77 to i64
%79 = select i1 %77, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0)
store i8* %79, i8** %7
%80 = load i8*, i8** %5
%81 = load i64, i64* %6
%82 = load i8*, i8** %7
%83 = load double, double* %4
%84 = fdiv double %83, 0x4130000000000000
%85 = call i32 @snprintf(i8* %80, i64 %81, i8* %82, double %84)
br label %106
86: ; preds = %72
%87 = load double, double* %4
%88 = fcmp oge double %87, 1.024000e+03
br i1 %88, label %89, label %100
89: ; preds = %86
%90 = load i32, i32* %8
%91 = icmp ne i32 %90, 0
%92 = zext i1 %91 to i64
%93 = select i1 %91, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0)
store i8* %93, i8** %7
%94 = load i8*, i8** %5
%95 = load i64, i64* %6
%96 = load i8*, i8** %7
%97 = load double, double* %4
%98 = fdiv double %97, 1.024000e+03
%99 = call i32 @snprintf(i8* %94, i64 %95, i8* %96, double %98)
br label %105
100: ; preds = %86
%101 = load i8*, i8** %5
%102 = load i64, i64* %6
%103 = load double, double* %4
%104 = call i32 @snprintf(i8* %101, i64 %102, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), double %103)
br label %105
105: ; preds = %100, %89
br label %106
106: ; preds = %105, %75
br label %107
107: ; preds = %106, %61
br label %108
108: ; preds = %107, %47
br label %109
109: ; preds = %108, %33
br label %110
110: ; preds = %109, %19
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"%.f EiB\00"
@.str.1 = [9 x i8] c"%.3f EiB\00"
@.str.2 = [8 x i8] c"%.f PiB\00"
@.str.3 = [9 x i8] c"%.3f PiB\00"
@.str.4 = [8 x i8] c"%.f TiB\00"
@.str.5 = [9 x i8] c"%.3f TiB\00"
@.str.6 = [8 x i8] c"%.f GiB\00"
@.str.7 = [9 x i8] c"%.3f GiB\00"
@.str.8 = [8 x i8] c"%.f MiB\00"
@.str.9 = [9 x i8] c"%.3f MiB\00"
@.str.10 = [8 x i8] c"%.f KiB\00"
@.str.11 = [9 x i8] c"%.3f KiB\00"
@.str.12 = [9 x i8] c"%f bytes\00"
define void @cvtstr(double %0, i8* %1, i64 %2) {
%4 = fmul double %0, 1.000000e+03
%5 = fptosi double %0 to i32
%6 = sitofp i32 %5 to double
%7 = fmul double %6, 1.000000e+03
%8 = fcmp oeq double %4, %7
%9 = fcmp ult double %0, 0x43B0000000000000
br i1 %9, label %14, label %10
10: ; preds = %3
%11 = select i1 %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0)
%12 = fmul double %0, 0x3C30000000000000
%13 = tail call i32 @snprintf(i8* %1, i64 %2, i8* %11, double %12)
br label %46
14: ; preds = %3
%15 = fcmp ult double %0, 0x4310000000000000
br i1 %15, label %20, label %16
16: ; preds = %14
%17 = select i1 %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0)
%18 = fmul double %0, 0x3CD0000000000000
%19 = tail call i32 @snprintf(i8* %1, i64 %2, i8* %17, double %18)
br label %46
20: ; preds = %14
%21 = fcmp ult double %0, 0x4270000000000000
br i1 %21, label %26, label %22
22: ; preds = %20
%23 = select i1 %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0)
%24 = fmul double %0, 0x3D70000000000000
%25 = tail call i32 @snprintf(i8* %1, i64 %2, i8* %23, double %24)
br label %46
26: ; preds = %20
%27 = fcmp ult double %0, 0x41D0000000000000
br i1 %27, label %32, label %28
28: ; preds = %26
%29 = select i1 %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0)
%30 = fmul double %0, 0x3E10000000000000
%31 = tail call i32 @snprintf(i8* %1, i64 %2, i8* %29, double %30)
br label %46
32: ; preds = %26
%33 = fcmp ult double %0, 0x4130000000000000
br i1 %33, label %38, label %34
34: ; preds = %32
%35 = select i1 %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0)
%36 = fmul double %0, 0x3EB0000000000000
%37 = tail call i32 @snprintf(i8* %1, i64 %2, i8* %35, double %36)
br label %46
38: ; preds = %32
%39 = fcmp ult double %0, 1.024000e+03
br i1 %39, label %44, label %40
40: ; preds = %38
%41 = select i1 %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0)
%42 = fmul double %0, 0x3F50000000000000
%43 = tail call i32 @snprintf(i8* %1, i64 %2, i8* %41, double %42)
br label %46
44: ; preds = %38
%45 = tail call i32 @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), double %0)
br label %46
46: ; preds = %16, %28, %40, %44, %34, %22, %10
ret void
}