#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);
scalar_t__ xmalloc(int);
char *filesize_str(unsigned long long log_size) {
  char *size = (char *)xmalloc(sizeof(char) * 12);
  if (log_size >= ((1024 * 1024) * 1024))
    snprintf(size, 12, "%.2f GiB", (double)(log_size) / ((1024 * 1024) * 1024));
  else if (log_size >= (1024 * 1024))
    snprintf(size, 12, "%.2f MiB", (double)(log_size) / (1024 * 1024));
  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)
cmpq   $0x40000000,-0x8(%rbp)
40
jb     1195 <filesize_str+0x75>
mov    -0x10(%rbp),%rdi
movaps 0xead(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xeac(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xeb5(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    $0xc,%esi
lea    0xead(%rip),%rdx
call   1030 <snprintf@plt>
jmp    1291 <filesize_str+0x171>
cmpq   $0x100000,-0x8(%rbp)
jb     11f0 <filesize_str+0xd0>
mov    -0x10(%rbp),%rdi
movaps 0xe52(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe51(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe52(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    $0xc,%esi
lea    0xe5b(%rip),%rdx
call   1030 <snprintf@plt>
jmp    128c <filesize_str+0x16c>
cmpq   $0x400,-0x8(%rbp)
jb     124b <filesize_str+0x12b>
mov    -0x10(%rbp),%rdi
movaps 0xdf7(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xdf6(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xdef(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    $0xc,%esi
lea    0xe09(%rip),%rdx
call   1030 <snprintf@plt>
jmp    1287 <filesize_str+0x167>
mov    -0x10(%rbp),%rdi
movaps 0xdaa(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xda9(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
mov    $0xc,%esi
lea    0xdd1(%rip),%rdx
call   1030 <snprintf@plt>
jmp    128c <filesize_str+0x16c>
jmp    1291 <filesize_str+0x171>
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
cmp    $0x40000000,%rbx
jb     116f <filesize_str+0x4f>
movq   %rbx,%xmm1
punpckldq 0xeb6(%rip),%xmm1
subpd  0xebe(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xeca(%rip),%xmm0
lea    0xecb(%rip),%rdx
jmp    11ec <filesize_str+0xcc>
cmp    $0x100000,%rbx
jb     11aa <filesize_str+0x8a>
movq   %rbx,%xmm1
punpckldq 0xe7b(%rip),%xmm1
subpd  0xe83(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xe87(%rip),%xmm0
lea    0xe99(%rip),%rdx
jmp    11ec <filesize_str+0xcc>
movq   %rbx,%xmm1
punpckldq 0xe49(%rip),%xmm1
subpd  0xe51(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
cmp    $0x400,%rbx
jb     11e5 <filesize_str+0xc5>
mulsd  0xe44(%rip),%xmm0
lea    0xe67(%rip),%rdx
jmp    11ec <filesize_str+0xcc>
lea    0xe67(%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 GiB\00"
@.str.1 = [9 x i8] c"%.2f MiB\00"
@.str.2 = [9 x i8] c"%.2f KiB\00"
@.str.3 = [8 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 i64 @xmalloc(i32 12)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %3
%6 = load i64, i64* %2
%7 = icmp uge i64 %6, 1073741824
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = load i64, i64* %2
%11 = uitofp i64 %10 to double
%12 = fdiv double %11, 0x41D0000000000000
%13 = call i32 @snprintf(i8* %9, i32 12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double %12)
br label %39
14: ; preds = %1
%15 = load i64, i64* %2
%16 = icmp uge i64 %15, 1048576
br i1 %16, label %17, label %23
17: ; preds = %14
%18 = load i8*, i8** %3
%19 = load i64, i64* %2
%20 = uitofp i64 %19 to double
%21 = fdiv double %20, 0x4130000000000000
%22 = call i32 @snprintf(i8* %18, i32 12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %21)
br label %38
23: ; preds = %14
%24 = load i64, i64* %2
%25 = icmp uge i64 %24, 1024
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i8*, i8** %3
%28 = load i64, i64* %2
%29 = uitofp i64 %28 to double
%30 = fdiv double %29, 1.024000e+03
%31 = call i32 @snprintf(i8* %27, i32 12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %30)
br label %37
32: ; preds = %23
%33 = load i8*, i8** %3
%34 = load i64, i64* %2
%35 = uitofp i64 %34 to double
%36 = call i32 @snprintf(i8* %33, i32 12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), double %35)
br label %37
37: ; preds = %32, %26
br label %38
38: ; preds = %37, %17
br label %39
39: ; preds = %38, %8
%40 = load i8*, i8** %3
ret i8* %40
}

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