#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*/ pv__si_prefix(long double *, char *, long double, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
void pv__sizestr(char *buffer, int bufsize, char *format, long double amount,
                 char *suffix_basic, char *suffix_bytes, int is_bytes) {
  char sizestr_buffer[256];
  char si_prefix[8] = " ";
  long double divider;
  long double display_amount;
  char *suffix;
  if (is_bytes) {
    suffix = suffix_bytes;
    divider = 1024.0;
  } else {
    suffix = suffix_basic;
    divider = 1000.0;
  }
  display_amount = amount;
  pv__si_prefix(&display_amount, si_prefix, divider, is_bytes);
  if (display_amount > 100000)
    display_amount = 100000;
  if (display_amount > 99.9) {
    sprintf(sizestr_buffer, "%4ld%.2s%.16s", (long)display_amount, si_prefix,
            suffix);
  } else {
    char str_disp[64];
    sprintf(str_disp, "%4.3Lg", display_amount);
    sprintf(sizestr_buffer, "%s%.2s%.16s", str_disp, si_prefix, suffix);
  }
  snprintf(buffer, bufsize, format, sizestr_buffer);
}


x86 assembly (clang, -O0):
<pv__sizestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f0,%rsp
fldt   0x10(%rbp)
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
fstpt  -0x30(%rbp)
mov    %rcx,-0x38(%rbp)
mov    %r8,-0x40(%rbp)
mov    %r9d,-0x44(%rbp)
mov    0xeb9(%rip),%rax
mov    %rax,-0x158(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     118c <pv__sizestr+0x5c>
mov    -0x40(%rbp),%rax
mov    %rax,-0x188(%rbp)
flds   0xe83(%rip)
fstpt  -0x170(%rbp)
jmp    11a3 <pv__sizestr+0x73>
mov    -0x38(%rbp),%rax
mov    %rax,-0x188(%rbp)
flds   0xe63(%rip)
fstpt  -0x170(%rbp)
fldt   -0x30(%rbp)
fstpt  -0x180(%rbp)
fldt   -0x170(%rbp)
mov    -0x44(%rbp),%edx
mov    %rsp,%rax
fstpt  (%rax)
lea    -0x180(%rbp),%rdi
lea    -0x158(%rbp),%rsi
call   1040 <pv__si_prefix@plt>
fldt   -0x180(%rbp)
flds   0xe2f(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jbe    11f6 <pv__sizestr+0xc6>
jmp    11ea <pv__sizestr+0xba>
flds   0xe18(%rip)
fstpt  -0x180(%rbp)
fldt   -0x180(%rbp)
fldl   0xe0e(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jbe    1273 <pv__sizestr+0x143>
jmp    1213 <pv__sizestr+0xe3>
lea    -0x150(%rbp),%rdi
fldt   -0x180(%rbp)
fnstcw -0x1da(%rbp)
movzwl -0x1da(%rbp),%eax
or     $0xc00,%eax
mov    %ax,-0x1dc(%rbp)
fldcw  -0x1dc(%rbp)
fistpll -0x1d8(%rbp)
fldcw  -0x1da(%rbp)
mov    -0x1d8(%rbp),%rdx
lea    -0x158(%rbp),%rcx
mov    -0x188(%rbp),%r8
lea    0xdb9(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    12bd <pv__sizestr+0x18d>
lea    -0x1d0(%rbp),%rdi
fldt   -0x180(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
lea    0xda2(%rip),%rsi
xor    %eax,%eax
call   1050 <sprintf@plt>
lea    -0x150(%rbp),%rdi
lea    -0x1d0(%rbp),%rdx
lea    -0x158(%rbp),%rcx
mov    -0x188(%rbp),%r8
lea    0xd7f(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    -0x150(%rbp),%rcx
call   1030 <snprintf@plt>
add    $0x1f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pv__sizestr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x180,%rsp
mov    %rcx,%rbp
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbx
fldt   0x1b0(%rsp)
movq   $0x20,0x18(%rsp)
xor    %eax,%eax
test   %r9d,%r9d
sete   %al
cmovne %r8,%rbp
shl    $0x4,%rax
lea    0xe8e(%rip),%rcx
fldt   (%rax,%rcx,1)
fxch   %st(1)
fstpt  0x20(%rsp)
fstpt  (%rsp)
lea    0x20(%rsp),%rdi
lea    0x18(%rsp),%rsi
mov    %r9d,%edx
call   1040 <pv__si_prefix@plt>
fldt   0x20(%rsp)
flds   0xe86(%rip)
fxch   %st(1)
fucomi %st(1),%st
jbe    11aa <pv__sizestr+0x7a>
fstp   %st(0)
fld    %st(0)
fstpt  0x20(%rsp)
jmp    11ba <pv__sizestr+0x8a>
fstp   %st(1)
fldl   0xe76(%rip)
fxch   %st(1)
fucomi %st(1),%st
fstp   %st(1)
jbe    11f4 <pv__sizestr+0xc4>
fnstcw 0x14(%rsp)
movzwl 0x14(%rsp),%eax
or     $0xc00,%eax
mov    %ax,0x16(%rsp)
fldcw  0x16(%rsp)
fistpll 0x38(%rsp)
fldcw  0x14(%rsp)
mov    0x38(%rsp),%rdx
lea    0xe4b(%rip),%rsi
lea    0x80(%rsp),%rdi
lea    0x18(%rsp),%rcx
jmp    1224 <pv__sizestr+0xf4>
fstpt  (%rsp)
lea    0xe40(%rip),%rsi
lea    0x40(%rsp),%r12
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <sprintf@plt>
lea    0xe31(%rip),%rsi
lea    0x80(%rsp),%rdi
lea    0x18(%rsp),%rcx
mov    %r12,%rdx
mov    %rbp,%r8
xor    %eax,%eax
call   1050 <sprintf@plt>
lea    0x80(%rsp),%rcx
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14,%rdx
call   1030 <snprintf@plt>
add    $0x180,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.pv__sizestr.si_prefix = [8 x i8] c" \00\00\00\00\00\00\00"
@.str = [14 x i8] c"%4ld%.2s%.16s\00"
@.str.1 = [7 x i8] c"%4.3Lg\00"
@.str.2 = [12 x i8] c"%s%.2s%.16s\00"
define void @pv__sizestr(i8* %0, i32 %1, i8* %2, x86_fp80 %3, i8* %4, i8* %5, i32 %6) {
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca x86_fp80
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca [256 x i8]
%16 = alloca [8 x i8]
%17 = alloca x86_fp80
%18 = alloca x86_fp80
%19 = alloca i8*
%20 = alloca [64 x i8]
store i8* %0, i8** %8
store i32 %1, i32* %9
store i8* %2, i8** %10
store x86_fp80 %3, x86_fp80* %11
store i8* %4, i8** %12
store i8* %5, i8** %13
store i32 %6, i32* %14
%21 = bitcast [8 x i8]* %16 to i8*
%22 = load i32, i32* %14
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %7
%25 = load i8*, i8** %13
store i8* %25, i8** %19
store x86_fp80 0xK40098000000000000000, x86_fp80* %17
br label %28
26: ; preds = %7
%27 = load i8*, i8** %12
store i8* %27, i8** %19
store x86_fp80 0xK4008FA00000000000000, x86_fp80* %17
br label %28
28: ; preds = %26, %24
%29 = load x86_fp80, x86_fp80* %11
store x86_fp80 %29, x86_fp80* %18
%30 = getelementptr inbounds [8 x i8], [8 x i8]* %16, i64 0, i64 0
%31 = load x86_fp80, x86_fp80* %17
%32 = load i32, i32* %14
%33 = call i32 @pv__si_prefix(x86_fp80* %18, i8* %30, x86_fp80 %31, i32 %32)
%34 = load x86_fp80, x86_fp80* %18
%35 = fcmp ogt x86_fp80 %34, 0xK400FC350000000000000
br i1 %35, label %36, label %37
36: ; preds = %28
store x86_fp80 0xK400FC350000000000000, x86_fp80* %18
br label %37
37: ; preds = %36, %28
%38 = load x86_fp80, x86_fp80* %18
%39 = fcmp ogt x86_fp80 %38, 0xK4005C7CCCCCCCCCCD000
br i1 %39, label %40, label %47
40: ; preds = %37
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%42 = load x86_fp80, x86_fp80* %18
%43 = fptosi x86_fp80 %42 to i64
%44 = getelementptr inbounds [8 x i8], [8 x i8]* %16, i64 0, i64 0
%45 = load i8*, i8** %19
%46 = call i32 (i8*, i8*, ...) @sprintf(i8* %41, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64 %43, i8* %44, i8* %45)
br label %56
47: ; preds = %37
%48 = getelementptr inbounds [64 x i8], [64 x i8]* %20, i64 0, i64 0
%49 = load x86_fp80, x86_fp80* %18
%50 = call i32 (i8*, i8*, ...) @sprintf(i8* %48, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), x86_fp80 %49)
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%52 = getelementptr inbounds [64 x i8], [64 x i8]* %20, i64 0, i64 0
%53 = getelementptr inbounds [8 x i8], [8 x i8]* %16, i64 0, i64 0
%54 = load i8*, i8** %19
%55 = call i32 (i8*, i8*, ...) @sprintf(i8* %51, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %52, i8* %53, i8* %54)
br label %56
56: ; preds = %47, %40
%57 = load i8*, i8** %8
%58 = load i32, i32* %9
%59 = load i8*, i8** %10
%60 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%61 = call i32 @snprintf(i8* %57, i32 %58, i8* %59, i8* %60)
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"%4ld%.2s%.16s\00"
@.str.1 = [7 x i8] c"%4.3Lg\00"
@.str.2 = [12 x i8] c"%s%.2s%.16s\00"
define void @pv__sizestr(i8* %0, i32 %1, i8* %2, x86_fp80 %3, i8* %4, i8* %5, i32 %6) {
%8 = alloca [256 x i8]
%9 = alloca i64
%10 = alloca x86_fp80
%11 = alloca [64 x i8]
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%13 = bitcast i64* %9 to i8*
store i64 32, i64* %9
%14 = bitcast x86_fp80* %10 to i8*
%15 = icmp eq i32 %6, 0
%16 = select i1 %15, x86_fp80 0xK4008FA00000000000000, x86_fp80 0xK40098000000000000000
%17 = select i1 %15, i8* %4, i8* %5
store x86_fp80 %3, x86_fp80* %10
%18 = call i32 @pv__si_prefix(x86_fp80* %10, i8* %13, x86_fp80 %16, i32 %6)
%19 = load x86_fp80, x86_fp80* %10
%20 = fcmp ogt x86_fp80 %19, 0xK400FC350000000000000
br i1 %20, label %21, label %22
21: ; preds = %7
store x86_fp80 0xK400FC350000000000000, x86_fp80* %10
br label %24
22: ; preds = %7
%23 = fcmp ogt x86_fp80 %19, 0xK4005C7CCCCCCCCCCD000
br i1 %23, label %24, label %28
24: ; preds = %21, %22
%25 = phi x86_fp80 [ 0xK400FC350000000000000, %21 ], [ %19, %22 ]
%26 = fptosi x86_fp80 %25 to i64
%27 = call i32 (i8*, i8*, ...) @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64 %26, i64* %9, i8* %17)
br label %32
28: ; preds = %22
%29 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 0
%30 = call i32 (i8*, i8*, ...) @sprintf(i8* %29, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), x86_fp80 %19)
%31 = call i32 (i8*, i8*, ...) @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %29, i64* %9, i8* %17)
br label %32
32: ; preds = %28, %24
%33 = call i32 @snprintf(i8* %0, i32 %1, i8* %2, i8* %12)
ret void
}