#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 */
typedef int /*<<< orphan*/ str;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, double);
char *file_size(long long size, char *str) {
  if (size < 1024) {
    snprintf(str, sizeof(str), "%luB", (unsigned long)size);
  } else if (size < 0x100000) {
    snprintf(str, sizeof(str), "%.1fK", (double)size / 1024.0);
  } else if (size < 0x40000000) {
    snprintf(str, sizeof(str), "%.1fM", (double)size / 1048576);
  } else {
    snprintf(str, sizeof(str), "%.1fG", (double)size / 1073741824);
  }
  return str;
}


x86 assembly (clang, -O0):
<file_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x400,-0x8(%rbp)
jge    116f <file_size+0x5f>
mov    -0x10(%rbp),%rdi
movaps 0xee7(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xee6(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
mov    $0x8,%esi
lea    0xedb(%rip),%rdx
call   1030 <snprintf@plt>
jmp    1214 <file_size+0x104>
cmpq   $0x100000,-0x8(%rbp)
jge    11a9 <file_size+0x99>
mov    -0x10(%rbp),%rdi
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  0xe81(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    $0x8,%esi
lea    0xea6(%rip),%rdx
call   1030 <snprintf@plt>
jmp    120f <file_size+0xff>
cmpq   $0x40000000,-0x8(%rbp)
40
jge    11e3 <file_size+0xd3>
mov    -0x10(%rbp),%rdi
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  0xe3f(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    $0x8,%esi
lea    0xe72(%rip),%rdx
call   1030 <snprintf@plt>
jmp    120a <file_size+0xfa>
mov    -0x10(%rbp),%rdi
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  0xe0b(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    $0x8,%esi
lea    0xe4c(%rip),%rdx
call   1030 <snprintf@plt>
jmp    120f <file_size+0xff>
jmp    1214 <file_size+0x104>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_size>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x3ff,%rdi
jg     1147 <file_size+0x37>
movq   %rdi,%xmm1
punpckldq 0xef6(%rip),%xmm1
subpd  0xefe(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
lea    0xefb(%rip),%rdx
jmp    1194 <file_size+0x84>
cmp    $0xfffff,%rdi
ja     1166 <file_size+0x56>
cvtsi2sd %rdi,%xmm0
mulsd  0xeb3(%rip),%xmm0
lea    0xee1(%rip),%rdx
jmp    1194 <file_size+0x84>
cvtsi2sd %rdi,%xmm0
cmp    $0x3fffffff,%rdi
ja     1185 <file_size+0x75>
mulsd  0xe8c(%rip),%xmm0
lea    0xec8(%rip),%rdx
jmp    1194 <file_size+0x84>
mulsd  0xe73(%rip),%xmm0
lea    0xebd(%rip),%rdx
mov    %rbx,%rdi
mov    $0x8,%esi
call   1030 <snprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%luB\00"
@.str.1 = [6 x i8] c"%.1fK\00"
@.str.2 = [6 x i8] c"%.1fM\00"
@.str.3 = [6 x i8] c"%.1fG\00"
define i8* @file_size(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
store i64 %0, i64* %3
store i8* %1, i8** %4
%5 = load i64, i64* %3
%6 = icmp slt i64 %5, 1024
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i8*, i8** %4
%9 = load i64, i64* %3
%10 = uitofp i64 %9 to double
%11 = call i32 @snprintf(i8* %8, i32 8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %10)
br label %38
12: ; preds = %2
%13 = load i64, i64* %3
%14 = icmp slt i64 %13, 1048576
br i1 %14, label %15, label %21
15: ; preds = %12
%16 = load i8*, i8** %4
%17 = load i64, i64* %3
%18 = sitofp i64 %17 to double
%19 = fdiv double %18, 1.024000e+03
%20 = call i32 @snprintf(i8* %16, i32 8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double %19)
br label %37
21: ; preds = %12
%22 = load i64, i64* %3
%23 = icmp slt i64 %22, 1073741824
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = load i8*, i8** %4
%26 = load i64, i64* %3
%27 = sitofp i64 %26 to double
%28 = fdiv double %27, 0x4130000000000000
%29 = call i32 @snprintf(i8* %25, i32 8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %28)
br label %36
30: ; preds = %21
%31 = load i8*, i8** %4
%32 = load i64, i64* %3
%33 = sitofp i64 %32 to double
%34 = fdiv double %33, 0x41D0000000000000
%35 = call i32 @snprintf(i8* %31, i32 8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %34)
br label %36
36: ; preds = %30, %24
br label %37
37: ; preds = %36, %15
br label %38
38: ; preds = %37, %7
%39 = load i8*, i8** %4
ret i8* %39
}

LLVM IR (-O2):
@.str = [5 x i8] c"%luB\00"
@.str.1 = [6 x i8] c"%.1fK\00"
@.str.2 = [6 x i8] c"%.1fM\00"
@.str.3 = [6 x i8] c"%.1fG\00"
define i8* @file_size(i64 %0, i8* returned %1) {
%3 = icmp slt i64 %0, 1024
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = uitofp i64 %0 to double
%6 = tail call i32 @snprintf(i8* %1, i32 8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %5)
br label %22
7: ; preds = %2
%8 = icmp ult i64 %0, 1048576
br i1 %8, label %9, label %13
9: ; preds = %7
%10 = sitofp i64 %0 to double
%11 = fmul double %10, 0x3F50000000000000
%12 = tail call i32 @snprintf(i8* %1, i32 8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double %11)
br label %22
13: ; preds = %7
%14 = icmp ult i64 %0, 1073741824
%15 = sitofp i64 %0 to double
br i1 %14, label %16, label %19
16: ; preds = %13
%17 = fmul double %15, 0x3EB0000000000000
%18 = tail call i32 @snprintf(i8* %1, i32 8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %17)
br label %22
19: ; preds = %13
%20 = fmul double %15, 0x3E10000000000000
%21 = tail call i32 @snprintf(i8* %1, i32 8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %20)
br label %22
22: ; preds = %9, %19, %16, %4
ret i8* %1
}