#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 *, int, char *, ...);
char *size2str(unsigned long long size, char *str, int len) {
  float n = (float)size / 1024;
  if (n >= 1000ULL * 1024 * 1024 * 1024)
    snprintf(str, len, "%.1fP", n / (1024ULL * 1024 * 1024 * 1024));
  else if (n >= 1000 * 1024 * 1024)
    snprintf(str, len, "%.1fT", n / (1024 * 1024 * 1024));
  else if (n >= 1000 * 1024)
    snprintf(str, len, "%.1fG", n / (1024 * 1024));
  else if (n >= 1000)
    snprintf(str, len, "%.1fM", n / 1024);
  else if (n > 0)
    snprintf(str, len, "%.1fK", n);
  else
    snprintf(str, len, "-0-");
  return str;
}


x86 assembly (clang, -O0):
<size2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x20(%rbp)
test   %rax,%rax
movss  %xmm0,-0x1c(%rbp)
js     1160 <size2str+0x50>
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  0xe97(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
movss  0xe7d(%rip),%xmm1
ucomiss %xmm1,%xmm0
jb     11bb <size2str+0xab>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
movss  -0x18(%rbp),%xmm0
movss  0xe7c(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe71(%rip),%rdx
mov    $0x1,%al
call   1030 <snprintf@plt>
jmp    12e7 <size2str+0x1d7>
movss  -0x18(%rbp),%xmm0
movss  0xe40(%rip),%xmm1
ucomiss %xmm1,%xmm0
jb     1200 <size2str+0xf0>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
movss  -0x18(%rbp),%xmm0
movss  0xe33(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe32(%rip),%rdx
mov    $0x1,%al
call   1030 <snprintf@plt>
jmp    12e2 <size2str+0x1d2>
movss  -0x18(%rbp),%xmm0
movss  0xdff(%rip),%xmm1
ucomiss %xmm1,%xmm0
jb     1245 <size2str+0x135>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
movss  -0x18(%rbp),%xmm0
movss  0xdea(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdf3(%rip),%rdx
mov    $0x1,%al
call   1030 <snprintf@plt>
jmp    12dd <size2str+0x1cd>
movss  -0x18(%rbp),%xmm0
movss  0xdbe(%rip),%xmm1
ucomiss %xmm1,%xmm0
jb     128a <size2str+0x17a>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
movss  -0x18(%rbp),%xmm0
movss  0xd95(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdb4(%rip),%rdx
mov    $0x1,%al
call   1030 <snprintf@plt>
jmp    12d8 <size2str+0x1c8>
movss  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    12be <size2str+0x1ae>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd86(%rip),%rdx
mov    $0x1,%al
call   1030 <snprintf@plt>
jmp    12d3 <size2str+0x1c3>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xd72(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    12d8 <size2str+0x1c8>
jmp    12dd <size2str+0x1cd>
jmp    12e2 <size2str+0x1d2>
jmp    12e7 <size2str+0x1d7>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<size2str>:
push   %rbx
mov    %rsi,%rbx
test   %rdi,%rdi
js     1120 <size2str+0x10>
cvtsi2ss %rdi,%xmm0
jmp    1135 <size2str+0x25>
mov    %rdi,%rax
shr    %rax
and    $0x1,%edi
or     %rax,%rdi
cvtsi2ss %rdi,%xmm0
addss  %xmm0,%xmm0
mulss  0xec3(%rip),%xmm0
ucomiss 0xec0(%rip),%xmm0
jae    1176 <size2str+0x66>
ucomiss 0xebf(%rip),%xmm0
jae    118b <size2str+0x7b>
ucomiss 0xebe(%rip),%xmm0
jae    11a0 <size2str+0x90>
ucomiss 0xebd(%rip),%xmm0
jae    11b5 <size2str+0xa5>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    11dc <size2str+0xcc>
cvtss2sd %xmm0,%xmm0
lea    0xec4(%rip),%rax
jmp    11c8 <size2str+0xb8>
mulss  0xe8a(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe97(%rip),%rax
jmp    11c8 <size2str+0xb8>
mulss  0xe7d(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe88(%rip),%rax
jmp    11c8 <size2str+0xb8>
mulss  0xe70(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe79(%rip),%rax
jmp    11c8 <size2str+0xb8>
mulss  0xe43(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe6a(%rip),%rax
mov    %rbx,%rdi
mov    %edx,%esi
mov    %rax,%rdx
mov    $0x1,%al
call   1030 <snprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret
lea    0xe5b(%rip),%rax
mov    %rbx,%rdi
mov    %edx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    11d7 <size2str+0xc7>

LLVM IR (-O0):
@.str = [6 x i8] c"%.1fP\00"
@.str.1 = [6 x i8] c"%.1fT\00"
@.str.2 = [6 x i8] c"%.1fG\00"
@.str.3 = [6 x i8] c"%.1fM\00"
@.str.4 = [6 x i8] c"%.1fK\00"
@.str.5 = [4 x i8] c"-0-\00"
define i8* @size2str(i64 %0, i8* %1, i32 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
%7 = alloca float
store i64 %0, i64* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i64, i64* %4
%9 = uitofp i64 %8 to float
%10 = fdiv float %9, 1.024000e+03
store float %10, float* %7
%11 = load float, float* %7
%12 = fcmp oge float %11, 0x426F400000000000
br i1 %12, label %13, label %20
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = load i32, i32* %6
%16 = load float, float* %7
%17 = fdiv float %16, 0x4270000000000000
%18 = fpext float %17 to double
%19 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %14, i32 %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %18)
br label %67
20: ; preds = %3
%21 = load float, float* %7
%22 = fcmp oge float %21, 0x41CF400000000000
br i1 %22, label %23, label %30
23: ; preds = %20
%24 = load i8*, i8** %5
%25 = load i32, i32* %6
%26 = load float, float* %7
%27 = fdiv float %26, 0x41D0000000000000
%28 = fpext float %27 to double
%29 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %24, i32 %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double %28)
br label %66
30: ; preds = %20
%31 = load float, float* %7
%32 = fcmp oge float %31, 1.024000e+06
br i1 %32, label %33, label %40
33: ; preds = %30
%34 = load i8*, i8** %5
%35 = load i32, i32* %6
%36 = load float, float* %7
%37 = fdiv float %36, 0x4130000000000000
%38 = fpext float %37 to double
%39 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %34, i32 %35, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %38)
br label %65
40: ; preds = %30
%41 = load float, float* %7
%42 = fcmp oge float %41, 1.000000e+03
br i1 %42, label %43, label %50
43: ; preds = %40
%44 = load i8*, i8** %5
%45 = load i32, i32* %6
%46 = load float, float* %7
%47 = fdiv float %46, 1.024000e+03
%48 = fpext float %47 to double
%49 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %44, i32 %45, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %48)
br label %64
50: ; preds = %40
%51 = load float, float* %7
%52 = fcmp ogt float %51, 0.000000e+00
br i1 %52, label %53, label %59
53: ; preds = %50
%54 = load i8*, i8** %5
%55 = load i32, i32* %6
%56 = load float, float* %7
%57 = fpext float %56 to double
%58 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %54, i32 %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), double %57)
br label %63
59: ; preds = %50
%60 = load i8*, i8** %5
%61 = load i32, i32* %6
%62 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %60, i32 %61, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %63
63: ; preds = %59, %53
br label %64
64: ; preds = %63, %43
br label %65
65: ; preds = %64, %33
br label %66
66: ; preds = %65, %23
br label %67
67: ; preds = %66, %13
%68 = load i8*, i8** %5
ret i8* %68
}

LLVM IR (-O2):
@.str = [6 x i8] c"%.1fP\00"
@.str.1 = [6 x i8] c"%.1fT\00"
@.str.2 = [6 x i8] c"%.1fG\00"
@.str.3 = [6 x i8] c"%.1fM\00"
@.str.4 = [6 x i8] c"%.1fK\00"
@.str.5 = [4 x i8] c"-0-\00"
define i8* @size2str(i64 %0, i8* returned %1, i32 %2) {
%4 = uitofp i64 %0 to float
%5 = fmul float %4, 0x3F50000000000000
%6 = fcmp ult float %5, 0x426F400000000000
br i1 %6, label %11, label %7
7: ; preds = %3
%8 = fmul float %5, 0x3D70000000000000
%9 = fpext float %8 to double
%10 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %9)
br label %36
11: ; preds = %3
%12 = fcmp ult float %5, 0x41CF400000000000
br i1 %12, label %17, label %13
13: ; preds = %11
%14 = fmul float %5, 0x3E10000000000000
%15 = fpext float %14 to double
%16 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double %15)
br label %36
17: ; preds = %11
%18 = fcmp ult float %5, 1.024000e+06
br i1 %18, label %23, label %19
19: ; preds = %17
%20 = fmul float %5, 0x3EB0000000000000
%21 = fpext float %20 to double
%22 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %21)
br label %36
23: ; preds = %17
%24 = fcmp ult float %5, 1.000000e+03
br i1 %24, label %29, label %25
25: ; preds = %23
%26 = fmul float %5, 0x3F50000000000000
%27 = fpext float %26 to double
%28 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %27)
br label %36
29: ; preds = %23
%30 = fcmp ogt float %5, 0.000000e+00
br i1 %30, label %31, label %34
31: ; preds = %29
%32 = fpext float %5 to double
%33 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), double %32)
br label %36
34: ; preds = %29
%35 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %36
36: ; preds = %13, %25, %34, %31, %19, %7
ret i8* %1
}