#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*/ memset(char *, char, int);
int /*<<< orphan*/ sprintf(char *, char *, float);
int /*<<< orphan*/ strcat(char *, char *);
void url_filesize(char *format_string, long long int size) {
  int unit;
  float value;
  memset(format_string, '\0', 24);
  if (size < 1) {
    strcat(format_string, "N/A");
    return;
  }
  if (0 < size && size < 1000)
    unit = 1;
  if (1000 <= size && size < 1000000)
    unit = 1000;
  if (1000000 <= size && size < 1000000000)
    unit = 1000000;
  if (size >= 1000000000)
    unit = 1000000000;
  value = ((float)size / (float)unit);
  sprintf(format_string, "%.1f ", value);
  switch (unit) {
  case 1:
    strcat(format_string, " B");
    break;
  case 1000:
    strcat(format_string, " KB");
    break;
  case 1000000:
    strcat(format_string, " MB");
    break;
  case 1000000000:
    strcat(format_string, " GB");
    break;
  }
}


x86 assembly (clang, -O0):
<url_filesize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
cmpq   $0x1,-0x10(%rbp)
jge    1170 <url_filesize+0x40>
mov    -0x8(%rbp),%rdi
lea    0xe9a(%rip),%rsi
call   1040 <strcat@plt>
jmp    12b3 <url_filesize+0x183>
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jge    1191 <url_filesize+0x61>
cmpq   $0x3e8,-0x10(%rbp)
jge    1191 <url_filesize+0x61>
movl   $0x1,-0x14(%rbp)
mov    $0x3e8,%eax
cmp    -0x10(%rbp),%rax
jg     11b5 <url_filesize+0x85>
cmpq   $0xf4240,-0x10(%rbp)
jge    11b5 <url_filesize+0x85>
movl   $0x3e8,-0x14(%rbp)
mov    $0xf4240,%eax
cmp    -0x10(%rbp),%rax
jg     11d9 <url_filesize+0xa9>
cmpq   $0x3b9aca00,-0x10(%rbp)
3b
jge    11d9 <url_filesize+0xa9>
movl   $0xf4240,-0x14(%rbp)
cmpq   $0x3b9aca00,-0x10(%rbp)
3b
jl     11ee <url_filesize+0xbe>
movl   $0x3b9aca00,-0x14(%rbp)
cvtsi2ssq -0x10(%rbp),%xmm0
cvtsi2ssl -0x14(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
movss  -0x18(%rbp),%xmm0
lea    0xdf2(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x1,%eax
je     1264 <url_filesize+0x134>
jmp    122b <url_filesize+0xfb>
mov    -0x1c(%rbp),%eax
sub    $0x3e8,%eax
je     1279 <url_filesize+0x149>
jmp    123e <url_filesize+0x10e>
mov    -0x1c(%rbp),%eax
sub    $0xf4240,%eax
je     128e <url_filesize+0x15e>
jmp    1251 <url_filesize+0x121>
mov    -0x1c(%rbp),%eax
sub    $0x3b9aca00,%eax
je     12a3 <url_filesize+0x173>
jmp    12b3 <url_filesize+0x183>
mov    -0x8(%rbp),%rdi
lea    0xd9b(%rip),%rsi
call   1040 <strcat@plt>
jmp    12b3 <url_filesize+0x183>
mov    -0x8(%rbp),%rdi
lea    0xd89(%rip),%rsi
call   1040 <strcat@plt>
jmp    12b3 <url_filesize+0x183>
mov    -0x8(%rbp),%rdi
lea    0xd78(%rip),%rsi
call   1040 <strcat@plt>
jmp    12b3 <url_filesize+0x183>
mov    -0x8(%rbp),%rdi
lea    0xd67(%rip),%rsi
call   1040 <strcat@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<url_filesize>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
test   %rbx,%rbx
jle    11c3 <url_filesize+0x93>
lea    -0x3e8(%rbx),%rax
cmp    $0xf3e58,%rax
mov    $0x3e8,%eax
mov    $0x1,%ecx
cmovb  %eax,%ecx
lea    -0xf4240(%rbx),%rax
cmp    $0x3b8b87c0,%rax
mov    $0xf4240,%eax
cmovae %ecx,%eax
cmp    $0x3b9aca00,%rbx
mov    $0x3b9aca00,%ebp
cmovb  %eax,%ebp
cvtsi2ss %rbx,%xmm0
cvtsi2ss %ebp,%xmm1
divss  %xmm1,%xmm0
lea    0xe67(%rip),%rsi
mov    %r14,%rdi
call   1050 <sprintf@plt>
cmp    $0xf423f,%ebp
jg     11cc <url_filesize+0x9c>
cmp    $0x1,%ebp
je     11ea <url_filesize+0xba>
cmp    $0x3e8,%ebp
jne    11e5 <url_filesize+0xb5>
lea    0xe4c(%rip),%rsi
jmp    11fa <url_filesize+0xca>
lea    0xe36(%rip),%rsi
jmp    11fa <url_filesize+0xca>
cmp    $0xf4240,%ebp
je     11f3 <url_filesize+0xc3>
cmp    $0x3b9aca00,%ebp
jne    11e5 <url_filesize+0xb5>
lea    0xe32(%rip),%rsi
jmp    11fa <url_filesize+0xca>
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe19(%rip),%rsi
jmp    11fa <url_filesize+0xca>
lea    0xe17(%rip),%rsi
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <strcat@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"N/A\00"
@.str.1 = [6 x i8] c"%.1f \00"
@.str.2 = [3 x i8] c" B\00"
@.str.3 = [4 x i8] c" KB\00"
@.str.4 = [4 x i8] c" MB\00"
@.str.5 = [4 x i8] c" GB\00"
define void @url_filesize(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca float
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = load i8*, i8** %3
%8 = call i32 @memset(i8* %7, i8 signext 0, i32 24)
%9 = load i64, i64* %4
%10 = icmp slt i64 %9, 1
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %61
14: ; preds = %2
%15 = load i64, i64* %4
%16 = icmp slt i64 0, %15
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i64, i64* %4
%19 = icmp slt i64 %18, 1000
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 1, i32* %5
br label %21
21: ; preds = %20, %17, %14
%22 = load i64, i64* %4
%23 = icmp sle i64 1000, %22
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i64, i64* %4
%26 = icmp slt i64 %25, 1000000
br i1 %26, label %27, label %28
27: ; preds = %24
store i32 1000, i32* %5
br label %28
28: ; preds = %27, %24, %21
%29 = load i64, i64* %4
%30 = icmp sle i64 1000000, %29
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = load i64, i64* %4
%33 = icmp slt i64 %32, 1000000000
br i1 %33, label %34, label %35
34: ; preds = %31
store i32 1000000, i32* %5
br label %35
35: ; preds = %34, %31, %28
%36 = load i64, i64* %4
%37 = icmp sge i64 %36, 1000000000
br i1 %37, label %38, label %39
38: ; preds = %35
store i32 1000000000, i32* %5
br label %39
39: ; preds = %38, %35
%40 = load i64, i64* %4
%41 = sitofp i64 %40 to float
%42 = load i32, i32* %5
%43 = sitofp i32 %42 to float
%44 = fdiv float %41, %43
store float %44, float* %6
%45 = load i8*, i8** %3
%46 = load float, float* %6
%47 = call i32 @sprintf(i8* %45, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), float %46)
%48 = load i32, i32* %5
switch i32 %48, label %61 [
i32 1, label %49
i32 1000, label %52
i32 1000000, label %55
i32 1000000000, label %58
]
49: ; preds = %39
%50 = load i8*, i8** %3
%51 = call i32 @strcat(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %61
52: ; preds = %39
%53 = load i8*, i8** %3
%54 = call i32 @strcat(i8* %53, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %61
55: ; preds = %39
%56 = load i8*, i8** %3
%57 = call i32 @strcat(i8* %56, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %61
58: ; preds = %39
%59 = load i8*, i8** %3
%60 = call i32 @strcat(i8* %59, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %61
61: ; preds = %11, %39, %58, %55, %52, %49
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"N/A\00"
@.str.1 = [6 x i8] c"%.1f \00"
@.str.2 = [3 x i8] c" B\00"
@.str.3 = [4 x i8] c" KB\00"
@.str.4 = [4 x i8] c" MB\00"
@.str.5 = [4 x i8] c" GB\00"
define void @url_filesize(i8* %0, i64 %1) {
%3 = tail call i32 @memset(i8* %0, i8 signext 0, i32 24)
%4 = icmp slt i64 %1, 1
br i1 %4, label %21, label %5
5: ; preds = %2
%6 = add nsw i64 %1, -1000
%7 = icmp ult i64 %6, 999000
%8 = select i1 %7, i32 1000, i32 1
%9 = add nsw i64 %1, -1000000
%10 = icmp ult i64 %9, 999000000
%11 = select i1 %10, i32 1000000, i32 %8
%12 = icmp ugt i64 %1, 999999999
%13 = select i1 %12, i32 1000000000, i32 %11
%14 = sitofp i64 %1 to float
%15 = sitofp i32 %13 to float
%16 = fdiv float %14, %15
%17 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), float %16)
switch i32 %13, label %24 [
i32 1, label %21
i32 1000, label %18
i32 1000000, label %19
i32 1000000000, label %20
]
18: ; preds = %5
br label %21
19: ; preds = %5
br label %21
20: ; preds = %5
br label %21
21: ; preds = %5, %2, %20, %19, %18
%22 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), %18 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), %19 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), %20 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %5 ]
%23 = tail call i32 @strcat(i8* %0, i8* %22)
br label %24
24: ; preds = %21, %5
ret void
}