#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*/ res;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int, double, int);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int io_get_size_double(double size, int prec, char *sizestr, int maxlen) {
  char res[64] = {0};
  int len, div = 1, unit = ' ';
  if (size > (double)(1 << 30)) {
    div = (1 << 30);
    unit = 'G';
  } else if (size > (double)(1 << 20)) {
    div = (1 << 20);
    unit = 'M';
  } else if (size > (double)(1 << 10)) {
    div = (1 << 10);
    unit = 'k';
  } else
    div = 1;
  snprintf(res, sizeof(res), "%.*f %cB", prec, (double)size / div, unit);
  len = strlen(res);
  if (len > maxlen)
    len = maxlen;
  memset(sizestr, 0, maxlen);
  strncpy(sizestr, res, len);
  return len;
}


x86 assembly (clang, -O0):
<io_get_size_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1060 <memset@plt>
movl   $0x1,-0x68(%rbp)
movl   $0x20,-0x6c(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe7e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    119f <io_get_size_double+0x5f>
movl   $0x40000000,-0x68(%rbp)
movl   $0x47,-0x6c(%rbp)
jmp    1204 <io_get_size_double+0xc4>
movsd  -0x8(%rbp),%xmm0
movsd  0xe5c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11c9 <io_get_size_double+0x89>
movl   $0x100000,-0x68(%rbp)
movl   $0x4d,-0x6c(%rbp)
jmp    11ff <io_get_size_double+0xbf>
movsd  -0x8(%rbp),%xmm0
movsd  0xe3a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11f3 <io_get_size_double+0xb3>
movl   $0x400,-0x68(%rbp)
movl   $0x6b,-0x6c(%rbp)
jmp    11fa <io_get_size_double+0xba>
movl   $0x1,-0x68(%rbp)
jmp    11ff <io_get_size_double+0xbf>
jmp    1204 <io_get_size_double+0xc4>
lea    -0x60(%rbp),%rdi
mov    -0xc(%rbp),%ecx
movsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0x68(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x6c(%rbp),%r8d
mov    $0x40,%esi
lea    0xdef(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    124c <io_get_size_double+0x10c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x18(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    -0x64(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x64(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<io_get_size_double>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
mov    %edi,%ecx
xorps  %xmm1,%xmm1
movaps %xmm1,0x30(%rsp)
movaps %xmm1,0x20(%rsp)
movaps %xmm1,0x10(%rsp)
movaps %xmm1,(%rsp)
mov    $0x47,%r8d
movsd  0xe8b(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     11b7 <io_get_size_double+0x77>
mov    $0x4d,%r8d
movsd  0xe7f(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     11b7 <io_get_size_double+0x77>
xor    %eax,%eax
ucomisd 0xe77(%rip),%xmm0
seta   %al
lea    0xe75(%rip),%rdx
movsd  (%rdx,%rax,8),%xmm1
mov    $0x6b,%eax
mov    $0x20,%r8d
cmova  %eax,%r8d
divsd  %xmm1,%xmm0
lea    0xe66(%rip),%rdx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x40,%esi
call   1050 <snprintf@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
cmp    %ebp,%eax
cmovg  %ebp,%ebx
mov    %r14,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1060 <memset@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%.*f %cB\00"
define i32 @io_get_size_double(double %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca double
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [64 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store double %0, double* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%13 = bitcast [64 x i8]* %9 to i8*
store i32 1, i32* %11
store i32 32, i32* %12
%14 = load double, double* %5
%15 = fcmp ogt double %14, 0x41D0000000000000
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 1073741824, i32* %11
store i32 71, i32* %12
br label %28
17: ; preds = %4
%18 = load double, double* %5
%19 = fcmp ogt double %18, 0x4130000000000000
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 1048576, i32* %11
store i32 77, i32* %12
br label %27
21: ; preds = %17
%22 = load double, double* %5
%23 = fcmp ogt double %22, 1.024000e+03
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 1024, i32* %11
store i32 107, i32* %12
br label %26
25: ; preds = %21
store i32 1, i32* %11
br label %26
26: ; preds = %25, %24
br label %27
27: ; preds = %26, %20
br label %28
28: ; preds = %27, %16
%29 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%30 = load i32, i32* %6
%31 = load double, double* %5
%32 = load i32, i32* %11
%33 = sitofp i32 %32 to double
%34 = fdiv double %31, %33
%35 = load i32, i32* %12
%36 = call i32 @snprintf(i8* %29, i32 64, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %30, double %34, i32 %35)
%37 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%38 = call i32 @strlen(i8* %37)
store i32 %38, i32* %10
%39 = load i32, i32* %10
%40 = load i32, i32* %8
%41 = icmp sgt i32 %39, %40
br i1 %41, label %42, label %44
42: ; preds = %28
%43 = load i32, i32* %8
store i32 %43, i32* %10
br label %44
44: ; preds = %42, %28
%45 = load i8*, i8** %7
%46 = load i32, i32* %8
%47 = call i32 @memset(i8* %45, i32 0, i32 %46)
%48 = load i8*, i8** %7
%49 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%50 = load i32, i32* %10
%51 = call i32 @strncpy(i8* %48, i8* %49, i32 %50)
%52 = load i32, i32* %10
ret i32 %52
}

LLVM IR (-O2):
@.str = [9 x i8] c"%.*f %cB\00"
define i32 @io_get_size_double(double %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca [64 x i8]
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%7 = fcmp ogt double %0, 0x41D0000000000000
br i1 %7, label %14, label %8
8: ; preds = %4
%9 = fcmp ogt double %0, 0x4130000000000000
br i1 %9, label %14, label %10
10: ; preds = %8
%11 = fcmp ogt double %0, 1.024000e+03
%12 = select i1 %11, double 1.024000e+03, double 1.000000e+00
%13 = select i1 %11, i32 107, i32 32
br label %14
14: ; preds = %10, %8, %4
%15 = phi double [ 0x41D0000000000000, %4 ], [ 0x4130000000000000, %8 ], [ %12, %10 ]
%16 = phi i32 [ 71, %4 ], [ 77, %8 ], [ %13, %10 ]
%17 = fdiv double %0, %15
%18 = call i32 @snprintf(i8* %6, i32 64, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %1, double %17, i32 %16)
%19 = call i32 @strlen(i8* %6)
%20 = icmp sgt i32 %19, %3
%21 = select i1 %20, i32 %3, i32 %19
%22 = call i32 @memset(i8* %2, i32 0, i32 %3)
%23 = call i32 @strncpy(i8* %2, i8* %6, i32 %21)
ret i32 %21
}