#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*/ add_deps(char *);
int /*<<< orphan*/ free(char *);
int get_filesize(char *);
char *process_text(char *);
int /*<<< orphan*/ sprintf(char *, char *, float, ...);
char *strdup(char *);
char *tag_file_size(int argc, char *argv[]) {
  if (argc >= 1) {
    char *filename = process_text(argv[0]);
    int size = get_filesize(filename);
    char format[256];
    if (size >= 0)
      add_deps(filename);
    if (size < 0)
      sprintf(format, "%d", size);
    else if (size < 1024)
      sprintf(format, "%d byte%c", size, size == 1 ? 0 : 's');
    else if (size < 1024 * 1024)
      sprintf(format, "%0.1f KB", (float)size / 1024.0);
    else if (size < 1024 * 1024 * 1024)
      sprintf(format, "%0.2f MB", (float)size / 1024.0 / 1024.0);
    else
      sprintf(format, "%0.2f GB", (float)size / 1024.0 / 1024.0 / 1024.0);
    free(filename);
    return strdup(format);
  } else
    return 0;
}


x86 assembly (clang, -O0):
<tag_file_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
cmpl   $0x1,-0xc(%rbp)
jl     130f <tag_file_size+0x1af>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1050 <process_text@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <get_filesize@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     11ab <tag_file_size+0x4b>
mov    -0x20(%rbp),%rdi
call   1040 <add_deps@plt>
cmpl   $0x0,-0x24(%rbp)
jge    11d4 <tag_file_size+0x74>
lea    -0x130(%rbp),%rdi
cvtsi2ssl -0x24(%rbp),%xmm0
lea    0xe40(%rip),%rsi
mov    $0x1,%al
call   1060 <sprintf@plt>
jmp    12f1 <tag_file_size+0x191>
cmpl   $0x400,-0x24(%rbp)
jge    1210 <tag_file_size+0xb0>
lea    -0x130(%rbp),%rdi
cvtsi2ssl -0x24(%rbp),%xmm0
mov    -0x24(%rbp),%ecx
mov    $0x73,%edx
xor    %eax,%eax
cmp    $0x1,%ecx
cmove  %eax,%edx
lea    0xe07(%rip),%rsi
mov    $0x1,%al
call   1060 <sprintf@plt>
jmp    12ec <tag_file_size+0x18c>
cmpl   $0x100000,-0x24(%rbp)
jge    1250 <tag_file_size+0xf0>
lea    -0x130(%rbp),%rdi
cvtsi2ssl -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdcb(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
lea    0xdd1(%rip),%rsi
mov    $0x1,%al
call   1060 <sprintf@plt>
jmp    12e7 <tag_file_size+0x187>
cmpl   $0x40000000,-0x24(%rbp)
jge    129c <tag_file_size+0x13c>
lea    -0x130(%rbp),%rdi
cvtsi2ssl -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd8b(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xd7f(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
lea    0xd8e(%rip),%rsi
mov    $0x1,%al
call   1060 <sprintf@plt>
jmp    12e2 <tag_file_size+0x182>
lea    -0x130(%rbp),%rdi
cvtsi2ssl -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd4c(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xd40(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xd34(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
lea    0xd4c(%rip),%rsi
mov    $0x1,%al
call   1060 <sprintf@plt>
jmp    12e7 <tag_file_size+0x187>
jmp    12ec <tag_file_size+0x18c>
jmp    12f1 <tag_file_size+0x191>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
lea    -0x130(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1317 <tag_file_size+0x1b7>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tag_file_size>:
test   %edi,%edi
jle    11ba <tag_file_size+0x5a>
push   %rbp
push   %rbx
sub    $0x108,%rsp
mov    (%rsi),%rdi
call   1050 <process_text@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <get_filesize@plt>
mov    %eax,%ebp
test   %eax,%eax
js     11bd <tag_file_size+0x5d>
mov    %rbx,%rdi
call   1040 <add_deps@plt>
cmp    $0x3ff,%ebp
ja     11ca <tag_file_size+0x6a>
cvtsi2ss %ebp,%xmm0
xor    %eax,%eax
cmp    $0x1,%ebp
mov    $0x73,%edx
cmove  %eax,%edx
lea    0xe61(%rip),%rsi
mov    %rsp,%rdi
mov    $0x1,%al
call   1060 <sprintf@plt>
jmp    1231 <tag_file_size+0xd1>
xor    %eax,%eax
ret
cvtsi2ss %ebp,%xmm0
lea    0xe44(%rip),%rsi
jmp    1227 <tag_file_size+0xc7>
cmp    $0xfffff,%ebp
ja     11e7 <tag_file_size+0x87>
cvtsi2ss %ebp,%xmm0
mulss  0xe2a(%rip),%xmm0
lea    0xe34(%rip),%rsi
jmp    1227 <tag_file_size+0xc7>
cvtsi2ss %ebp,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe09(%rip),%xmm1
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
cmp    $0x3fffffff,%ebp
ja     1214 <tag_file_size+0xb4>
cvtsd2ss %xmm0,%xmm0
lea    0xe10(%rip),%rsi
jmp    1227 <tag_file_size+0xc7>
mulsd  0xde4(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
lea    0xe04(%rip),%rsi
mov    %rsp,%rdi
mov    $0x1,%al
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rsp,%rdi
call   1080 <strdup@plt>
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [10 x i8] c"%d byte%c\00"
@.str.2 = [9 x i8] c"%0.1f KB\00"
@.str.3 = [9 x i8] c"%0.2f MB\00"
@.str.4 = [9 x i8] c"%0.2f GB\00"
define i8* @tag_file_size(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [256 x i8]
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp sge i32 %9, 1
br i1 %10, label %11, label %84
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i8* @process_text(i8* %14)
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = call i32 @get_filesize(i8* %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %11
%21 = load i8*, i8** %6
%22 = call i32 @add_deps(i8* %21)
br label %23
23: ; preds = %20, %11
%24 = load i32, i32* %7
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%28 = load i32, i32* %7
%29 = sitofp i32 %28 to float
%30 = call i32 (i8*, i8*, float, ...) @sprintf(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), float %29)
br label %79
31: ; preds = %23
%32 = load i32, i32* %7
%33 = icmp slt i32 %32, 1024
br i1 %33, label %34, label %43
34: ; preds = %31
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%36 = load i32, i32* %7
%37 = sitofp i32 %36 to float
%38 = load i32, i32* %7
%39 = icmp eq i32 %38, 1
%40 = zext i1 %39 to i64
%41 = select i1 %39, i32 0, i32 115
%42 = call i32 (i8*, i8*, float, ...) @sprintf(i8* %35, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), float %37, i32 %41)
br label %78
43: ; preds = %31
%44 = load i32, i32* %7
%45 = icmp slt i32 %44, 1048576
br i1 %45, label %46, label %54
46: ; preds = %43
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%48 = load i32, i32* %7
%49 = sitofp i32 %48 to float
%50 = fpext float %49 to double
%51 = fdiv double %50, 1.024000e+03
%52 = fptrunc double %51 to float
%53 = call i32 (i8*, i8*, float, ...) @sprintf(i8* %47, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), float %52)
br label %77
54: ; preds = %43
%55 = load i32, i32* %7
%56 = icmp slt i32 %55, 1073741824
br i1 %56, label %57, label %66
57: ; preds = %54
%58 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%59 = load i32, i32* %7
%60 = sitofp i32 %59 to float
%61 = fpext float %60 to double
%62 = fdiv double %61, 1.024000e+03
%63 = fdiv double %62, 1.024000e+03
%64 = fptrunc double %63 to float
%65 = call i32 (i8*, i8*, float, ...) @sprintf(i8* %58, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), float %64)
br label %76
66: ; preds = %54
%67 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%68 = load i32, i32* %7
%69 = sitofp i32 %68 to float
%70 = fpext float %69 to double
%71 = fdiv double %70, 1.024000e+03
%72 = fdiv double %71, 1.024000e+03
%73 = fdiv double %72, 1.024000e+03
%74 = fptrunc double %73 to float
%75 = call i32 (i8*, i8*, float, ...) @sprintf(i8* %67, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), float %74)
br label %76
76: ; preds = %66, %57
br label %77
77: ; preds = %76, %46
br label %78
78: ; preds = %77, %34
br label %79
79: ; preds = %78, %26
%80 = load i8*, i8** %6
%81 = call i32 @free(i8* %80)
%82 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%83 = call i8* @strdup(i8* %82)
store i8* %83, i8** %3
br label %85
84: ; preds = %2
store i8* null, i8** %3
br label %85
85: ; preds = %84, %79
%86 = load i8*, i8** %3
ret i8* %86
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [10 x i8] c"%d byte%c\00"
@.str.2 = [9 x i8] c"%0.1f KB\00"
@.str.3 = [9 x i8] c"%0.2f MB\00"
@.str.4 = [9 x i8] c"%0.2f GB\00"
define noalias i8* @tag_file_size(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %44
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i8* @process_text(i8* %6)
%8 = tail call i32 @get_filesize(i8* %7)
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%10 = icmp sgt i32 %8, -1
br i1 %10, label %14, label %11
11: ; preds = %5
%12 = sitofp i32 %8 to float
%13 = call i32 (i8*, i8*, float, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), float %12)
br label %41
14: ; preds = %5
%15 = tail call i32 @add_deps(i8* %7)
%16 = icmp ult i32 %8, 1024
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = sitofp i32 %8 to float
%19 = icmp eq i32 %8, 1
%20 = select i1 %19, i32 0, i32 115
%21 = call i32 (i8*, i8*, float, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), float %18, i32 %20)
br label %41
22: ; preds = %14
%23 = icmp ult i32 %8, 1048576
br i1 %23, label %24, label %28
24: ; preds = %22
%25 = sitofp i32 %8 to float
%26 = fmul float %25, 0x3F50000000000000
%27 = call i32 (i8*, i8*, float, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), float %26)
br label %41
28: ; preds = %22
%29 = icmp ult i32 %8, 1073741824
%30 = sitofp i32 %8 to float
%31 = fpext float %30 to double
%32 = fmul double %31, 0x3F50000000000000
%33 = fmul double %32, 0x3F50000000000000
br i1 %29, label %34, label %37
34: ; preds = %28
%35 = fptrunc double %33 to float
%36 = call i32 (i8*, i8*, float, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), float %35)
br label %41
37: ; preds = %28
%38 = fmul double %33, 0x3F50000000000000
%39 = fptrunc double %38 to float
%40 = call i32 (i8*, i8*, float, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), float %39)
br label %41
41: ; preds = %17, %34, %37, %24, %11
%42 = tail call i32 @free(i8* %7)
%43 = call i8* @strdup(i8* %9)
br label %44
44: ; preds = %2, %41
%45 = phi i8* [ %43, %41 ], [ null, %2 ]
ret i8* %45
}