#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*/ sprintf(char *, char *, float, char const *);
const char *fsize_str(size_t sz) {
  static char str[128];
  static const char *units[] = {"bytes", "kb", "mb", "gb", "tb", "pb", 0};
  int i = 0;
  float fsz = (float)sz;
  while (units[i + 1] && fsz > 1024.0) {
    i++;
    fsz /= 1024.0;
  }
  sprintf(str, "%.2f %s", fsz, units[i]);
  return str;
}


x86 assembly (clang, -O0):
<fsize_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%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,-0x18(%rbp)
test   %rax,%rax
movss  %xmm0,-0x14(%rbp)
js     1160 <fsize_str+0x50>
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rdx
xor    %eax,%eax
lea    0x2eb4(%rip),%rcx
cmpq   $0x0,(%rcx,%rdx,8)
mov    %al,-0x19(%rbp)
je     11a5 <fsize_str+0x95>
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe65(%rip),%xmm1
ucomisd %xmm1,%xmm0
seta   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11b5 <fsize_str+0xa5>
jmp    11e1 <fsize_str+0xd1>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe31(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
jmp    116a <fsize_str+0x5a>
movss  -0x10(%rbp),%xmm0
movslq -0xc(%rbp),%rcx
lea    0x2e3f(%rip),%rax
mov    (%rax,%rcx,8),%rdx
lea    0x2e84(%rip),%rdi
lea    0xe1a(%rip),%rsi
call   1030 <sprintf@plt>
lea    0x2e71(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsize_str>:
test   %rdi,%rdi
js     111c <fsize_str+0xc>
cvtsi2ss %rdi,%xmm0
jmp    1133 <fsize_str+0x23>
mov    %rdi,%rax
shr    %rax
mov    %edi,%ecx
and    $0x1,%ecx
or     %rax,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
push   %rbx
cmp    $0x401,%rdi
jb     11a4 <fsize_str+0x94>
mulss  0xebb(%rip),%xmm0
mov    $0x1,%eax
ucomiss 0xeb3(%rip),%xmm0
jbe    11a6 <fsize_str+0x96>
mulss  0xea5(%rip),%xmm0
mov    $0x2,%eax
ucomiss 0xe9d(%rip),%xmm0
jbe    11a6 <fsize_str+0x96>
mulss  0xe8f(%rip),%xmm0
mov    $0x3,%eax
ucomiss 0xe87(%rip),%xmm0
jbe    11a6 <fsize_str+0x96>
mulss  0xe79(%rip),%xmm0
mov    $0x4,%eax
ucomiss 0xe71(%rip),%xmm0
jbe    11a6 <fsize_str+0x96>
mulss  0xe63(%rip),%xmm0
mov    $0x5,%eax
jmp    11a6 <fsize_str+0x96>
xor    %eax,%eax
lea    0x2c33(%rip),%rcx
mov    (%rcx,%rax,8),%rdx
lea    0x2e88(%rip),%rbx
lea    0xe5e(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@fsize_str.str = internal global [128 x i8] zeroinitializer
@fsize_str.units = internal global [7 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i32 0, i32 0), i8* null]
@.str = [6 x i8] c"bytes\00"
@.str.1 = [3 x i8] c"kb\00"
@.str.2 = [3 x i8] c"mb\00"
@.str.3 = [3 x i8] c"gb\00"
@.str.4 = [3 x i8] c"tb\00"
@.str.5 = [3 x i8] c"pb\00"
@.str.6 = [8 x i8] c"%.2f %s\00"
define i8* @fsize_str(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca float
store i64 %0, i64* %2
store i32 0, i32* %3
%5 = load i64, i64* %2
%6 = uitofp i64 %5 to float
store float %6, float* %4
br label %7
7: ; preds = %20, %1
%8 = load i32, i32* %3
%9 = add nsw i32 %8, 1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [7 x i8*], [7 x i8*]* @fsize_str.units, i64 0, i64 %10
%12 = load i8*, i8** %11
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %7
%15 = load float, float* %4
%16 = fpext float %15 to double
%17 = fcmp ogt double %16, 1.024000e+03
br label %18
18: ; preds = %14, %7
%19 = phi i1 [ false, %7 ], [ %17, %14 ]
br i1 %19, label %20, label %27
20: ; preds = %18
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
%23 = load float, float* %4
%24 = fpext float %23 to double
%25 = fdiv double %24, 1.024000e+03
%26 = fptrunc double %25 to float
store float %26, float* %4
br label %7
27: ; preds = %18
%28 = load float, float* %4
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [7 x i8*], [7 x i8*]* @fsize_str.units, i64 0, i64 %30
%32 = load i8*, i8** %31
%33 = call i32 @sprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @fsize_str.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), float %28, i8* %32)
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @fsize_str.str, i64 0, i64 0)
}

LLVM IR (-O2):
@fsize_str.str = internal global [128 x i8] zeroinitializer
@fsize_str.units = internal unnamed_addr constant [7 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i32 0, i32 0), i8* null]
@.str = [6 x i8] c"bytes\00"
@.str.1 = [3 x i8] c"kb\00"
@.str.2 = [3 x i8] c"mb\00"
@.str.3 = [3 x i8] c"gb\00"
@.str.4 = [3 x i8] c"tb\00"
@.str.5 = [3 x i8] c"pb\00"
@.str.6 = [8 x i8] c"%.2f %s\00"
define i8* @fsize_str(i64 %0) {
%2 = uitofp i64 %0 to float
%3 = icmp ugt i64 %0, 1024
br i1 %3, label %4, label %18
4: ; preds = %1
%5 = fmul float %2, 0x3F50000000000000
%6 = fcmp ogt float %5, 1.024000e+03
br i1 %6, label %7, label %18
7: ; preds = %4
%8 = fmul float %5, 0x3F50000000000000
%9 = fcmp ogt float %8, 1.024000e+03
br i1 %9, label %10, label %18
10: ; preds = %7
%11 = fmul float %8, 0x3F50000000000000
%12 = fcmp ogt float %11, 1.024000e+03
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = fmul float %11, 0x3F50000000000000
%15 = fcmp ogt float %14, 1.024000e+03
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = fmul float %14, 0x3F50000000000000
br label %18
18: ; preds = %4, %7, %10, %13, %16, %1
%19 = phi i64 [ 0, %1 ], [ 1, %4 ], [ 2, %7 ], [ 3, %10 ], [ 4, %13 ], [ 5, %16 ]
%20 = phi float [ %2, %1 ], [ %5, %4 ], [ %8, %7 ], [ %11, %10 ], [ %14, %13 ], [ %17, %16 ]
%21 = and i64 %19, 4294967295
%22 = getelementptr inbounds [7 x i8*], [7 x i8*]* @fsize_str.units, i64 0, i64 %21
%23 = load i8*, i8** %22
%24 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([128 x i8], [128 x i8]* @fsize_str.str, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), float %20, i8* %23)
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @fsize_str.str, i64 0, i64 0)
}