#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*/ floor(int);
int fmin(int /*<<< orphan*/, int);
int log10(unsigned long long);
unsigned long long pow(int, int);
void format_size(unsigned long long value, double *result, int *suffix) {
  int e = 0.0;
  double n = 0.0;
  e = fmin(floor(log10(value) / 3), 5);
  n = value / pow(1000, e);
  *result = n;
  *suffix = e;
}


x86 assembly (clang, -O0):
<format_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <log10@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rax
shr    $0x3f,%rax
shr    $0x20,%rcx
mov    %ecx,%edi
add    %eax,%edi
call   1060 <floor@plt>
mov    %eax,%edi
mov    $0x5,%esi
call   1030 <fmin@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%esi
mov    $0x3e8,%edi
call   1040 <pow@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
xor    %edx,%edx
div    %rcx
movq   %rax,%xmm0
movaps 0xe3b(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xe3f(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_size>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1050 <log10@plt>
cltq
imul   $0x55555556,%rax,%rdi
mov    %rdi,%rax
shr    $0x3f,%rax
shr    $0x20,%rdi
add    %eax,%edi
call   1060 <floor@plt>
mov    %eax,%edi
mov    $0x5,%esi
call   1030 <fmin@plt>
mov    %eax,%ebp
mov    $0x3e8,%edi
mov    %eax,%esi
call   1040 <pow@plt>
mov    %rax,%rcx
or     %rbx,%rax
shr    $0x20,%rax
je     11a0 <format_size+0x60>
mov    %rbx,%rax
xor    %edx,%edx
div    %rcx
jmp    11a6 <format_size+0x66>
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
movq   %rax,%xmm0
punpckldq 0xe4d(%rip),%xmm0
subpd  0xe55(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%r15)
mov    %ebp,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @format_size(i64 %0, double* %1, i32* %2) {
%4 = alloca i64
%5 = alloca double*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca double
store i64 %0, i64* %4
store double* %1, double** %5
store i32* %2, i32** %6
store i32 0, i32* %7
store double 0.000000e+00, double* %8
%9 = load i64, i64* %4
%10 = call i32 @log10(i64 %9)
%11 = sdiv i32 %10, 3
%12 = call i32 @floor(i32 %11)
%13 = call i32 @fmin(i32 %12, i32 5)
store i32 %13, i32* %7
%14 = load i64, i64* %4
%15 = load i32, i32* %7
%16 = call i64 @pow(i32 1000, i32 %15)
%17 = udiv i64 %14, %16
%18 = uitofp i64 %17 to double
store double %18, double* %8
%19 = load double, double* %8
%20 = load double*, double** %5
store double %19, double* %20
%21 = load i32, i32* %7
%22 = load i32*, i32** %6
store i32 %21, i32* %22
ret void
}

LLVM IR (-O2):
define void @format_size(i64 %0, double* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = tail call i32 @log10(i64 %0)
%5 = sdiv i32 %4, 3
%6 = tail call i32 @floor(i32 %5)
%7 = tail call i32 @fmin(i32 %6, i32 5)
%8 = tail call i64 @pow(i32 1000, i32 %7)
%9 = udiv i64 %0, %8
%10 = uitofp i64 %9 to double
store double %10, double* %1
store i32 %7, i32* %2
ret void
}