#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 *, double);
char *xmalloc(int);
char *filesize_str(unsigned long long log_size) {
  char *size = xmalloc(sizeof(char) * 12);
  if (log_size >= 1099511627776LL)
    snprintf(size, 12, "%.2f TiB", (double)(log_size) / 1099511627776LL);
  else if (log_size >= 1073741824)
    snprintf(size, 12, "%.2f GiB", (double)(log_size) / 1073741824);
  else if (log_size >= 1048576)
    snprintf(size, 12, "%.2f MiB", (double)(log_size) / 1048576);
  else if (log_size >= 1024)
    snprintf(size, 12, "%.2f KiB", (double)(log_size) / 1024);
  else
    snprintf(size, 12, "%.1f   B", (double)(log_size));
  return size;
}


x86 assembly (clang, -O0):
<filesize_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0xc,%edi
call   1040 <xmalloc@plt>
mov    %rax,-0x10(%rbp)
movabs $0x10000000000,%rax
cmp    %rax,-0x8(%rbp)
jb     119b <filesize_str+0x7b>
mov    -0x10(%rbp),%rdi
movaps 0xea7(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xea6(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xeb7(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    $0xc,%esi
lea    0xeaf(%rip),%rdx
call   1030 <snprintf@plt>
jmp    12f7 <filesize_str+0x1d7>
cmpq   $0x40000000,-0x8(%rbp)
40
jb     11f6 <filesize_str+0xd6>
mov    -0x10(%rbp),%rdi
movaps 0xe4c(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe4b(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe54(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    $0xc,%esi
lea    0xe5d(%rip),%rdx
call   1030 <snprintf@plt>
jmp    12f2 <filesize_str+0x1d2>
cmpq   $0x100000,-0x8(%rbp)
jb     1251 <filesize_str+0x131>
mov    -0x10(%rbp),%rdi
movaps 0xdf1(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xdf0(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xdf1(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    $0xc,%esi
lea    0xe0b(%rip),%rdx
call   1030 <snprintf@plt>
jmp    12ed <filesize_str+0x1cd>
cmpq   $0x400,-0x8(%rbp)
jb     12ac <filesize_str+0x18c>
mov    -0x10(%rbp),%rdi
movaps 0xd96(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xd95(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xd8e(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    $0xc,%esi
lea    0xdb9(%rip),%rdx
call   1030 <snprintf@plt>
jmp    12e8 <filesize_str+0x1c8>
mov    -0x10(%rbp),%rdi
movaps 0xd49(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xd48(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
mov    $0xc,%esi
lea    0xd81(%rip),%rdx
call   1030 <snprintf@plt>
jmp    12ed <filesize_str+0x1cd>
jmp    12f2 <filesize_str+0x1d2>
jmp    12f7 <filesize_str+0x1d7>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filesize_str>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0xc,%edi
call   1040 <xmalloc@plt>
mov    %rax,%r14
mov    %rbx,%rax
shr    $0x28,%rax
je     1172 <filesize_str+0x52>
movq   %rbx,%xmm1
punpckldq 0xeb6(%rip),%xmm1
subpd  0xebe(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xed2(%rip),%xmm0
lea    0xed3(%rip),%rdx
jmp    122a <filesize_str+0x10a>
cmp    $0x40000000,%rbx
jb     11ad <filesize_str+0x8d>
movq   %rbx,%xmm1
punpckldq 0xe78(%rip),%xmm1
subpd  0xe80(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xe8c(%rip),%xmm0
lea    0xe9e(%rip),%rdx
jmp    122a <filesize_str+0x10a>
cmp    $0x100000,%rbx
jb     11e8 <filesize_str+0xc8>
movq   %rbx,%xmm1
punpckldq 0xe3d(%rip),%xmm1
subpd  0xe45(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xe49(%rip),%xmm0
lea    0xe6c(%rip),%rdx
jmp    122a <filesize_str+0x10a>
movq   %rbx,%xmm1
punpckldq 0xe0b(%rip),%xmm1
subpd  0xe13(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
cmp    $0x400,%rbx
jb     1223 <filesize_str+0x103>
mulsd  0xe06(%rip),%xmm0
lea    0xe3a(%rip),%rdx
jmp    122a <filesize_str+0x10a>
lea    0xe3a(%rip),%rdx
mov    %r14,%rdi
mov    $0xc,%esi
call   1030 <snprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%.2f TiB\00"
@.str.1 = [9 x i8] c"%.2f GiB\00"
@.str.2 = [9 x i8] c"%.2f MiB\00"
@.str.3 = [9 x i8] c"%.2f KiB\00"
@.str.4 = [9 x i8] c"%.1f B\00"
define i8* @filesize_str(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
store i64 %0, i64* %2
%4 = call i8* @xmalloc(i32 12)
store i8* %4, i8** %3
%5 = load i64, i64* %2
%6 = icmp uge i64 %5, 1099511627776
br i1 %6, label %7, label %13
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = load i64, i64* %2
%10 = uitofp i64 %9 to double
%11 = fdiv double %10, 0x4270000000000000
%12 = call i32 @snprintf(i8* %8, i32 12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double %11)
br label %48
13: ; preds = %1
%14 = load i64, i64* %2
%15 = icmp uge i64 %14, 1073741824
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = load i8*, i8** %3
%18 = load i64, i64* %2
%19 = uitofp i64 %18 to double
%20 = fdiv double %19, 0x41D0000000000000
%21 = call i32 @snprintf(i8* %17, i32 12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %20)
br label %47
22: ; preds = %13
%23 = load i64, i64* %2
%24 = icmp uge i64 %23, 1048576
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = load i8*, i8** %3
%27 = load i64, i64* %2
%28 = uitofp i64 %27 to double
%29 = fdiv double %28, 0x4130000000000000
%30 = call i32 @snprintf(i8* %26, i32 12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %29)
br label %46
31: ; preds = %22
%32 = load i64, i64* %2
%33 = icmp uge i64 %32, 1024
br i1 %33, label %34, label %40
34: ; preds = %31
%35 = load i8*, i8** %3
%36 = load i64, i64* %2
%37 = uitofp i64 %36 to double
%38 = fdiv double %37, 1.024000e+03
%39 = call i32 @snprintf(i8* %35, i32 12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), double %38)
br label %45
40: ; preds = %31
%41 = load i8*, i8** %3
%42 = load i64, i64* %2
%43 = uitofp i64 %42 to double
%44 = call i32 @snprintf(i8* %41, i32 12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), double %43)
br label %45
45: ; preds = %40, %34
br label %46
46: ; preds = %45, %25
br label %47
47: ; preds = %46, %16
br label %48
48: ; preds = %47, %7
%49 = load i8*, i8** %3
ret i8* %49
}

LLVM IR (-O2):
@.str = [9 x i8] c"%.2f TiB\00"
@.str.1 = [9 x i8] c"%.2f GiB\00"
@.str.2 = [9 x i8] c"%.2f MiB\00"
@.str.3 = [9 x i8] c"%.2f KiB\00"
@.str.4 = [9 x i8] c"%.1f B\00"
define i8* @filesize_str(i64 %0) {
%2 = tail call i8* @xmalloc(i32 12)
%3 = icmp ugt i64 %0, 1099511627775
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = uitofp i64 %0 to double
%6 = fmul double %5, 0x3D70000000000000
%7 = tail call i32 @snprintf(i8* %2, i32 12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double %6)
br label %28
8: ; preds = %1
%9 = icmp ugt i64 %0, 1073741823
br i1 %9, label %10, label %14
10: ; preds = %8
%11 = uitofp i64 %0 to double
%12 = fmul double %11, 0x3E10000000000000
%13 = tail call i32 @snprintf(i8* %2, i32 12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %12)
br label %28
14: ; preds = %8
%15 = icmp ugt i64 %0, 1048575
br i1 %15, label %16, label %20
16: ; preds = %14
%17 = uitofp i64 %0 to double
%18 = fmul double %17, 0x3EB0000000000000
%19 = tail call i32 @snprintf(i8* %2, i32 12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %18)
br label %28
20: ; preds = %14
%21 = icmp ugt i64 %0, 1023
%22 = uitofp i64 %0 to double
br i1 %21, label %23, label %26
23: ; preds = %20
%24 = fmul double %22, 0x3F50000000000000
%25 = tail call i32 @snprintf(i8* %2, i32 12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), double %24)
br label %28
26: ; preds = %20
%27 = tail call i32 @snprintf(i8* %2, i32 12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), double %22)
br label %28
28: ; preds = %10, %23, %26, %16, %4
ret i8* %2
}