#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*/ sprintf(char *, char *, int, char);
int /*<<< orphan*/ systemlog(int, char *);
int filesize(int fsize) {
  int size = 0;
  int kilo = 0;
  char atribute;
  char string[4];
  systemlog(4, "filesize");
  size = fsize;
  while (size >= 1000) {
    size /= 1000;
    kilo++;
  }
  switch (kilo) {
  case 1:
    atribute = 'k';
    break;
  case 2:
    atribute = 'M';
    break;
  case 3:
    atribute = 'G';
    break;
  case 4:
    atribute = 'T';
    break;
  case 5:
    atribute = 'Y';
    break;
  default:
    atribute = ' ';
    break;
  }
  if (499 < ((fsize - size * kilo) / (kilo - 1)))
    size++;
  sprintf(string, "%i%c", size, atribute);
  return size;
}


x86 assembly (clang, -O0):
<filesize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x4,%edi
lea    0xecf(%rip),%rsi
call   1030 <systemlog@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jl     1179 <filesize+0x59>
mov    -0x8(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1150 <filesize+0x30>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x4,%eax
ja     11cf <filesize+0xaf>
mov    -0x20(%rbp),%rax
lea    0xe67(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0x6b,-0xd(%rbp)
jmp    11d3 <filesize+0xb3>
movb   $0x4d,-0xd(%rbp)
jmp    11d3 <filesize+0xb3>
movb   $0x47,-0xd(%rbp)
jmp    11d3 <filesize+0xb3>
movb   $0x54,-0xd(%rbp)
jmp    11d3 <filesize+0xb3>
movb   $0x59,-0xd(%rbp)
jmp    11d3 <filesize+0xb3>
movb   $0x20,-0xd(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
imul   -0xc(%rbp),%ecx
sub    %ecx,%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    $0x1f3,%eax
cmp    %ecx,%eax
jge    1200 <filesize+0xe0>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
lea    -0x11(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe0f(%rip),%rsi
movsbl -0xd(%rbp),%ecx
call   1040 <sprintf@plt>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filesize>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xee6(%rip),%rsi
mov    $0x4,%edi
call   1030 <systemlog@plt>
mov    $0x20,%cl
xor    %edi,%edi
cmp    $0x3e8,%ebx
jl     1191 <filesize+0x71>
mov    $0xffffffff,%eax
mov    %ebx,%esi
nopl   0x0(%rax,%rax,1)
mov    %esi,%edx
mov    %esi,%esi
imul   $0x10624dd3,%rsi,%rsi
shr    $0x26,%rsi
add    $0x1,%eax
cmp    $0xf423f,%edx
ja     1150 <filesize+0x30>
cmp    $0x4,%eax
ja     11cc <filesize+0xac>
mov    $0x6b,%cl
mov    $0x1,%edi
mov    %eax,%eax
lea    0xe81(%rip),%rdx
movslq (%rdx,%rax,4),%rax
add    %rdx,%rax
jmp    *%rax
mov    $0x4d,%cl
mov    $0x2,%edi
jmp    1193 <filesize+0x73>
mov    %ebx,%esi
mov    %edi,%eax
imul   %esi,%eax
sub    %eax,%ebx
add    $0xffffffff,%edi
mov    %ebx,%eax
cltd
idiv   %edi
xor    %ebx,%ebx
cmp    $0x1f4,%eax
setge  %bl
add    %esi,%ebx
movzbl %cl,%ecx
lea    0xe65(%rip),%rsi
lea    0xc(%rsp),%rdi
mov    %ebx,%edx
call   1040 <sprintf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
add    $0x1,%eax
mov    %eax,%edi
jmp    1193 <filesize+0x73>
mov    $0x47,%cl
mov    $0x3,%edi
jmp    1193 <filesize+0x73>
mov    $0x54,%cl
mov    $0x4,%edi
jmp    1193 <filesize+0x73>
mov    $0x59,%cl
mov    $0x5,%edi
jmp    1193 <filesize+0x73>

LLVM IR (-O0):
@.str = [9 x i8] c"filesize\00"
@.str.1 = [5 x i8] c"%i%c\00"
define i32 @filesize(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca [4 x i8]
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
%7 = call i32 @systemlog(i32 4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* %2
store i32 %8, i32* %3
br label %9
9: ; preds = %12, %1
%10 = load i32, i32* %3
%11 = icmp sge i32 %10, 1000
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load i32, i32* %3
%14 = sdiv i32 %13, 1000
store i32 %14, i32* %3
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
br label %9
17: ; preds = %9
%18 = load i32, i32* %4
switch i32 %18, label %24 [
i32 1, label %19
i32 2, label %20
i32 3, label %21
i32 4, label %22
i32 5, label %23
]
19: ; preds = %17
store i8 107, i8* %5
br label %25
20: ; preds = %17
store i8 77, i8* %5
br label %25
21: ; preds = %17
store i8 71, i8* %5
br label %25
22: ; preds = %17
store i8 84, i8* %5
br label %25
23: ; preds = %17
store i8 89, i8* %5
br label %25
24: ; preds = %17
store i8 32, i8* %5
br label %25
25: ; preds = %24, %23, %22, %21, %20, %19
%26 = load i32, i32* %2
%27 = load i32, i32* %3
%28 = load i32, i32* %4
%29 = mul nsw i32 %27, %28
%30 = sub nsw i32 %26, %29
%31 = load i32, i32* %4
%32 = sub nsw i32 %31, 1
%33 = sdiv i32 %30, %32
%34 = icmp slt i32 499, %33
br i1 %34, label %35, label %38
35: ; preds = %25
%36 = load i32, i32* %3
%37 = add nsw i32 %36, 1
store i32 %37, i32* %3
br label %38
38: ; preds = %35, %25
%39 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%40 = load i32, i32* %3
%41 = load i8, i8* %5
%42 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %40, i8 signext %41)
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [9 x i8] c"filesize\00"
@.str.1 = [5 x i8] c"%i%c\00"
define i32 @filesize(i32 %0) {
%2 = alloca [4 x i8]
%3 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @systemlog(i32 4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%5 = icmp sgt i32 %0, 999
br i1 %5, label %6, label %17
6: ; preds = %1, %6
%7 = phi i32 [ %10, %6 ], [ 0, %1 ]
%8 = phi i32 [ %9, %6 ], [ %0, %1 ]
%9 = udiv i32 %8, 1000
%10 = add nuw nsw i32 %7, 1
%11 = icmp ugt i32 %8, 999999
br i1 %11, label %6, label %12
12: ; preds = %6
switch i32 %7, label %17 [
i32 0, label %20
i32 1, label %13
i32 2, label %14
i32 3, label %15
i32 4, label %16
]
13: ; preds = %12
br label %20
14: ; preds = %12
br label %20
15: ; preds = %12
br label %20
16: ; preds = %12
br label %20
17: ; preds = %1, %12
%18 = phi i32 [ %10, %12 ], [ 0, %1 ]
%19 = phi i32 [ %9, %12 ], [ %0, %1 ]
br label %20
20: ; preds = %12, %17, %16, %15, %14, %13
%21 = phi i32 [ %18, %17 ], [ 5, %16 ], [ 4, %15 ], [ 3, %14 ], [ 2, %13 ], [ 1, %12 ]
%22 = phi i32 [ %19, %17 ], [ %9, %16 ], [ %9, %15 ], [ %9, %14 ], [ %9, %13 ], [ %9, %12 ]
%23 = phi i8 [ 32, %17 ], [ 89, %16 ], [ 84, %15 ], [ 71, %14 ], [ 77, %13 ], [ 107, %12 ]
%24 = mul nsw i32 %21, %22
%25 = sub nsw i32 %0, %24
%26 = add nsw i32 %21, -1
%27 = sdiv i32 %25, %26
%28 = icmp sgt i32 %27, 499
%29 = zext i1 %28 to i32
%30 = add nsw i32 %22, %29
%31 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %30, i8 signext %23)
ret i32 %30
}