#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 long uint64_t;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *const, int, char *, double, char const);
char *get_estimated_filesize(char *const restrict buffer,
                             const double fs_size) {
  const char fs_units[6] = {'B', 'K', 'M', 'G', 'T', 'P'};
  const uint64_t data_denom[6] = {
      1L,
      1024L,
      ((uint64_t)(1024L * 1024L)),
      ((uint64_t)(((uint64_t)(1024L * 1024L)) * 1024L)),
      ((uint64_t)(((uint64_t)(((uint64_t)(1024L * 1024L)) * 1024L)) * 1024L)),
      ((uint64_t)(((uint64_t)(((uint64_t)(((uint64_t)(1024L * 1024L)) *
                                          1024L)) *
                              1024L)) *
                  1024L))};
  double reduced_fs;
  for (int i = 6 - 1; i > -1; i--) {
    reduced_fs = fs_size / data_denom[i];
    if (reduced_fs > 1) {
      snprintf(buffer, 6 + 1, "%.1f%c", reduced_fs, fs_units[i]);
      return buffer;
    }
  }
  return "0B";
}


x86 assembly (clang, -O0):
<get_estimated_filesize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    0xed1(%rip),%eax
mov    %eax,-0x1e(%rbp)
mov    0xecb(%rip),%ax
mov    %ax,-0x1a(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
movq   $0x1,-0x50(%rbp)
movq   $0x400,-0x48(%rbp)
movq   $0x100000,-0x40(%rbp)
movq   $0x40000000,-0x38(%rbp)
40
movabs $0x10000000000,%rax
mov    %rax,-0x30(%rbp)
movabs $0x4000000000000,%rax
mov    %rax,-0x28(%rbp)
movl   $0x5,-0x5c(%rbp)
cmpl   $0xffffffff,-0x5c(%rbp)
jle    1215 <get_estimated_filesize+0xf5>
movsd  -0x18(%rbp),%xmm0
movslq -0x5c(%rbp),%rax
cvtsi2sdq -0x50(%rbp,%rax,8),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  0xe38(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1202 <get_estimated_filesize+0xe2>
mov    -0x10(%rbp),%rdi
movsd  -0x58(%rbp),%xmm0
movslq -0x5c(%rbp),%rax
mov    $0x7,%esi
lea    0xe23(%rip),%rdx
movsbl -0x1e(%rbp,%rax,1),%ecx
call   1030 <snprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1220 <get_estimated_filesize+0x100>
jmp    1207 <get_estimated_filesize+0xe7>
mov    -0x5c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x5c(%rbp)
jmp    1198 <get_estimated_filesize+0x78>
lea    0xdf9(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_estimated_filesize>:
push   %rbx
mov    %rdi,%rbx
movsd  0xee4(%rip),%xmm1
mulsd  %xmm0,%xmm1
mov    $0x5,%eax
ucomisd 0xedb(%rip),%xmm1
ja     11ab <get_estimated_filesize+0x9b>
movsd  0xed9(%rip),%xmm1
mulsd  %xmm0,%xmm1
mov    $0x4,%eax
ucomisd 0xec0(%rip),%xmm1
ja     11ab <get_estimated_filesize+0x9b>
movsd  0xec6(%rip),%xmm1
mulsd  %xmm0,%xmm1
mov    $0x3,%eax
ucomisd 0xea5(%rip),%xmm1
ja     11ab <get_estimated_filesize+0x9b>
movsd  0xeb3(%rip),%xmm1
mulsd  %xmm0,%xmm1
mov    $0x2,%eax
ucomisd 0xe8a(%rip),%xmm1
ja     11ab <get_estimated_filesize+0x9b>
movsd  0xea0(%rip),%xmm1
mulsd  %xmm0,%xmm1
mov    $0x1,%eax
ucomisd 0xe6f(%rip),%xmm1
ja     11ab <get_estimated_filesize+0x9b>
ucomisd 0xe65(%rip),%xmm0
jbe    11d3 <get_estimated_filesize+0xc3>
xor    %eax,%eax
movapd %xmm0,%xmm1
lea    0xe7e(%rip),%rcx
movsbl (%rax,%rcx,1),%ecx
lea    0xe79(%rip),%rdx
mov    %rbx,%rdi
mov    $0x7,%esi
movapd %xmm1,%xmm0
call   1030 <snprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret
lea    0xe63(%rip),%rbx
jmp    11ce <get_estimated_filesize+0xbe>

LLVM IR (-O0):
@__const.get_estimated_filesize.fs_units = [6 x i8] c"BKMGTP"
@.str = [7 x i8] c"%.1f%c\00"
@.str.1 = [3 x i8] c"0B\00"
define i8* @get_estimated_filesize(i8* noalias %0, double %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca double
%6 = alloca [6 x i8]
%7 = alloca [6 x i64]
%8 = alloca double
%9 = alloca i32
store i8* %0, i8** %4
store double %1, double* %5
%10 = bitcast [6 x i8]* %6 to i8*
%11 = bitcast [6 x i64]* %7 to i8*
%12 = bitcast i8* %11 to [6 x i64]*
%13 = getelementptr inbounds [6 x i64], [6 x i64]* %12, i32 0, i32 0
store i64 1, i64* %13
%14 = getelementptr inbounds [6 x i64], [6 x i64]* %12, i32 0, i32 1
store i64 1024, i64* %14
%15 = getelementptr inbounds [6 x i64], [6 x i64]* %12, i32 0, i32 2
store i64 1048576, i64* %15
%16 = getelementptr inbounds [6 x i64], [6 x i64]* %12, i32 0, i32 3
store i64 1073741824, i64* %16
%17 = getelementptr inbounds [6 x i64], [6 x i64]* %12, i32 0, i32 4
store i64 1099511627776, i64* %17
%18 = getelementptr inbounds [6 x i64], [6 x i64]* %12, i32 0, i32 5
store i64 1125899906842624, i64* %18
store i32 5, i32* %9
br label %19
19: ; preds = %42, %2
%20 = load i32, i32* %9
%21 = icmp sgt i32 %20, -1
br i1 %21, label %22, label %45
22: ; preds = %19
%23 = load double, double* %5
%24 = load i32, i32* %9
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [6 x i64], [6 x i64]* %7, i64 0, i64 %25
%27 = load i64, i64* %26
%28 = sitofp i64 %27 to double
%29 = fdiv double %23, %28
store double %29, double* %8
%30 = load double, double* %8
%31 = fcmp ogt double %30, 1.000000e+00
br i1 %31, label %32, label %41
32: ; preds = %22
%33 = load i8*, i8** %4
%34 = load double, double* %8
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = call i32 @snprintf(i8* %33, i32 7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %34, i8 signext %38)
%40 = load i8*, i8** %4
store i8* %40, i8** %3
br label %46
41: ; preds = %22
br label %42
42: ; preds = %41
%43 = load i32, i32* %9
%44 = add nsw i32 %43, -1
store i32 %44, i32* %9
br label %19
45: ; preds = %19
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %46
46: ; preds = %45, %32
%47 = load i8*, i8** %3
ret i8* %47
}

LLVM IR (-O2):
@__const.get_estimated_filesize.fs_units = [6 x i8] c"BKMGTP"
@.str = [7 x i8] c"%.1f%c\00"
@.str.1 = [3 x i8] c"0B\00"
define i8* @get_estimated_filesize(i8* noalias %0, double %1) {
%3 = fmul double %1, 0x3CD0000000000000
%4 = fcmp ogt double %3, 1.000000e+00
br i1 %4, label %5, label %11
5: ; preds = %23, %20, %17, %14, %11, %2
%6 = phi i64 [ 5, %2 ], [ 4, %11 ], [ 3, %14 ], [ 2, %17 ], [ 1, %20 ], [ 0, %23 ]
%7 = phi double [ %3, %2 ], [ %12, %11 ], [ %15, %14 ], [ %18, %17 ], [ %21, %20 ], [ %1, %23 ]
%8 = getelementptr inbounds [6 x i8], [6 x i8]* @__const.get_estimated_filesize.fs_units, i64 0, i64 %6
%9 = load i8, i8* %8
%10 = tail call i32 @snprintf(i8* %0, i32 7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %7, i8 signext %9)
br label %25
11: ; preds = %2
%12 = fmul double %1, 0x3D70000000000000
%13 = fcmp ogt double %12, 1.000000e+00
br i1 %13, label %5, label %14
14: ; preds = %11
%15 = fmul double %1, 0x3E10000000000000
%16 = fcmp ogt double %15, 1.000000e+00
br i1 %16, label %5, label %17
17: ; preds = %14
%18 = fmul double %1, 0x3EB0000000000000
%19 = fcmp ogt double %18, 1.000000e+00
br i1 %19, label %5, label %20
20: ; preds = %17
%21 = fmul double %1, 0x3F50000000000000
%22 = fcmp ogt double %21, 1.000000e+00
br i1 %22, label %5, label %23
23: ; preds = %20
%24 = fcmp ogt double %1, 1.000000e+00
br i1 %24, label %5, label %25
25: ; preds = %23, %5
%26 = phi i8* [ %0, %5 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %23 ]
ret i8* %26
}