#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
char *malloc(int);
scalar_t__ sfd_files_filesize(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, double, char *);
char *sfd_files_ffilesize(FILE *file) {
  double size = (double)sfd_files_filesize(file);
  char *s = malloc(13), *u;
  fseek(file, 0, SEEK_END);
  if (size >= 1073741824) {
    u = "GB";
    size /= 1073741824.0;
  } else if (size >= 1048576) {
    u = "MB";
    size /= 1048576.0;
  } else if (size >= 1024) {
    u = "KB";
    size /= 1024.0;
  } else
    u = "B ";
  sprintf(s, "%8.2f %s", size, u);
  return s;
}


x86 assembly (clang, -O0):
<sfd_files_ffilesize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <sfd_files_filesize@plt>
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    $0xd,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e70(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <fseek@plt>
movsd  -0x10(%rbp),%xmm0
movsd  0xe72(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11be <sfd_files_ffilesize+0x7e>
lea    0xe79(%rip),%rax
mov    %rax,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe50(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    124d <sfd_files_ffilesize+0x10d>
movsd  -0x10(%rbp),%xmm0
movsd  0xe3d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11fb <sfd_files_ffilesize+0xbb>
lea    0xe3f(%rip),%rax
mov    %rax,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe1b(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1248 <sfd_files_ffilesize+0x108>
movsd  -0x10(%rbp),%xmm0
movsd  0xe08(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1238 <sfd_files_ffilesize+0xf8>
lea    0xe05(%rip),%rax
mov    %rax,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xde6(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1243 <sfd_files_ffilesize+0x103>
lea    0xde2(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1248 <sfd_files_ffilesize+0x108>
jmp    124d <sfd_files_ffilesize+0x10d>
mov    -0x18(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
mov    -0x20(%rbp),%rdx
lea    0xdc3(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sfd_files_ffilesize>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
call   1060 <sfd_files_filesize@plt>
mov    %rax,%rbx
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0xd,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
mov    0x2e75(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <fseek@plt>
cmp    $0x40000000,%rbx
jl     119f <sfd_files_ffilesize+0x5f>
movsd  0x8(%rsp),%xmm0
mulsd  0xe7a(%rip),%xmm0
lea    0xe7b(%rip),%rdx
jmp    11e0 <sfd_files_ffilesize+0xa0>
movsd  0x8(%rsp),%xmm0
cmp    $0x100000,%rbx
jl     11bf <sfd_files_ffilesize+0x7f>
mulsd  0xe52(%rip),%xmm0
lea    0xe5e(%rip),%rdx
jmp    11e0 <sfd_files_ffilesize+0xa0>
cmp    $0x400,%rbx
jl     11d9 <sfd_files_ffilesize+0x99>
mulsd  0xe30(%rip),%xmm0
lea    0xe47(%rip),%rdx
jmp    11e0 <sfd_files_ffilesize+0xa0>
lea    0xe41(%rip),%rdx
lea    0xe3d(%rip),%rsi
mov    %r14,%rdi
call   1050 <sprintf@plt>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@.str = [3 x i8] c"GB\00"
@.str.1 = [3 x i8] c"MB\00"
@.str.2 = [3 x i8] c"KB\00"
@.str.3 = [3 x i8] c"B \00"
@.str.4 = [9 x i8] c"%8.2f %s\00"
define i8* @sfd_files_ffilesize(i32* %0) {
%2 = alloca i32*
%3 = alloca double
%4 = alloca i8*
%5 = alloca i8*
store i32* %0, i32** %2
%6 = load i32*, i32** %2
%7 = call i64 @sfd_files_filesize(i32* %6)
%8 = sitofp i64 %7 to double
store double %8, double* %3
%9 = call i8* @malloc(i32 13)
store i8* %9, i8** %4
%10 = load i32*, i32** %2
%11 = load i32, i32* @SEEK_END
%12 = call i32 @fseek(i32* %10, i32 0, i32 %11)
%13 = load double, double* %3
%14 = fcmp oge double %13, 0x41D0000000000000
br i1 %14, label %15, label %18
15: ; preds = %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %5
%16 = load double, double* %3
%17 = fdiv double %16, 0x41D0000000000000
store double %17, double* %3
br label %33
18: ; preds = %1
%19 = load double, double* %3
%20 = fcmp oge double %19, 0x4130000000000000
br i1 %20, label %21, label %24
21: ; preds = %18
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %5
%22 = load double, double* %3
%23 = fdiv double %22, 0x4130000000000000
store double %23, double* %3
br label %32
24: ; preds = %18
%25 = load double, double* %3
%26 = fcmp oge double %25, 1.024000e+03
br i1 %26, label %27, label %30
27: ; preds = %24
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %5
%28 = load double, double* %3
%29 = fdiv double %28, 1.024000e+03
store double %29, double* %3
br label %31
30: ; preds = %24
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %5
br label %31
31: ; preds = %30, %27
br label %32
32: ; preds = %31, %21
br label %33
33: ; preds = %32, %15
%34 = load i8*, i8** %4
%35 = load double, double* %3
%36 = load i8*, i8** %5
%37 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), double %35, i8* %36)
%38 = load i8*, i8** %4
ret i8* %38
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@.str = [3 x i8] c"GB\00"
@.str.1 = [3 x i8] c"MB\00"
@.str.2 = [3 x i8] c"KB\00"
@.str.3 = [3 x i8] c"B \00"
@.str.4 = [9 x i8] c"%8.2f %s\00"
define noalias i8* @sfd_files_ffilesize(i32* %0) {
%2 = tail call i64 @sfd_files_filesize(i32* %0)
%3 = sitofp i64 %2 to double
%4 = tail call dereferenceable_or_null(13) i8* @malloc(i32 13)
%5 = load i32, i32* @SEEK_END
%6 = tail call i32 @fseek(i32* %0, i32 0, i32 %5)
%7 = icmp sgt i64 %2, 1073741823
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = fmul double %3, 0x3E10000000000000
br label %18
10: ; preds = %1
%11 = icmp sgt i64 %2, 1048575
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = fmul double %3, 0x3EB0000000000000
br label %18
14: ; preds = %10
%15 = icmp sgt i64 %2, 1023
br i1 %15, label %16, label %18
16: ; preds = %14
%17 = fmul double %3, 0x3F50000000000000
br label %18
18: ; preds = %14, %12, %16, %8
%19 = phi double [ %9, %8 ], [ %13, %12 ], [ %17, %16 ], [ %3, %14 ]
%20 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %8 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %12 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %16 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), %14 ]
%21 = tail call i32 @sprintf(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), double %19, i8* %20)
ret i8* %4
}