#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 *, double);
int /*<<< orphan*/ strcat(char *, char *);
void get_format_size(unsigned long size, char *buf) {
  double size_d = size;
  if (size_d <= 0) {
    buf = (char *)"0B";
  } else {
    if (size <= 1024) {
      sprintf(buf, "%.0lf", size_d);
      strcat(buf, "B");
    } else {
      size_d /= 1024;
      if (size_d <= 1024) {
        sprintf(buf, "%.0lf", size_d);
        strcat(buf, "KB");
      } else {
        size_d /= 1024;
        if (size_d <= 1024) {
          sprintf(buf, "%.2lf", size_d);
          strcat(buf, "MB");
        } else {
          size_d /= 1024;
          if (size_d <= 1024) {
            sprintf(buf, "%.2lf", size_d);
            strcat(buf, "GB");
          } else {
            size_d /= 1024;
            if (size_d <= 1024) {
              sprintf(buf, "%.2lf", size_d);
              strcat(buf, "TB");
            } else {
              sprintf(buf, "%.0lf", size_d);
              strcat(buf, ">TB");
            }
          }
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<get_format_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movaps 0xec9(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xec8(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     117a <get_format_size+0x5a>
lea    0xeb7(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    133c <get_format_size+0x21c>
cmpq   $0x400,-0x8(%rbp)
ja     11b2 <get_format_size+0x92>
mov    -0x10(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
lea    0xe93(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1030 <strcat@plt>
jmp    1337 <get_format_size+0x217>
movsd  -0x18(%rbp),%xmm0
movsd  0xe61(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe50(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     1205 <get_format_size+0xe5>
mov    -0x10(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
lea    0xe40(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe36(%rip),%rsi
call   1030 <strcat@plt>
jmp    1332 <get_format_size+0x212>
movsd  -0x18(%rbp),%xmm0
movsd  0xe0e(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xdfd(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     1258 <get_format_size+0x138>
mov    -0x10(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
lea    0xdf6(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xdec(%rip),%rsi
call   1030 <strcat@plt>
jmp    132d <get_format_size+0x20d>
movsd  -0x18(%rbp),%xmm0
movsd  0xdbb(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xdaa(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     12ab <get_format_size+0x18b>
mov    -0x10(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
lea    0xda3(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xd9c(%rip),%rsi
call   1030 <strcat@plt>
jmp    1328 <get_format_size+0x208>
movsd  -0x18(%rbp),%xmm0
movsd  0xd68(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xd57(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     12fe <get_format_size+0x1de>
mov    -0x10(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
lea    0xd50(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xd4d(%rip),%rsi
call   1030 <strcat@plt>
jmp    1323 <get_format_size+0x203>
mov    -0x10(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
lea    0xd1d(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xd22(%rip),%rsi
call   1030 <strcat@plt>
jmp    1328 <get_format_size+0x208>
jmp    132d <get_format_size+0x20d>
jmp    1332 <get_format_size+0x212>
jmp    1337 <get_format_size+0x217>
jmp    133c <get_format_size+0x21c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_format_size>:
test   %rdi,%rdi
je     116e <get_format_size+0x4e>
push   %rbx
mov    %rsi,%rbx
movq   %rdi,%xmm1
punpckldq 0xeca(%rip),%xmm1
subpd  0xed2(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
cmp    $0x400,%rdi
ja     116f <get_format_size+0x4f>
lea    0xed6(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sprintf@plt>
lea    0xeda(%rip),%rsi
jmp    1225 <get_format_size+0x105>
ret
mulsd  0xea9(%rip),%xmm0
movsd  0xea9(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    11c7 <get_format_size+0xa7>
mulsd  0xe93(%rip),%xmm0
ucomisd %xmm0,%xmm1
jae    11df <get_format_size+0xbf>
mulsd  0xe85(%rip),%xmm0
ucomisd %xmm0,%xmm1
jae    11f7 <get_format_size+0xd7>
mulsd  0xe77(%rip),%xmm0
ucomisd %xmm0,%xmm1
jae    120f <get_format_size+0xef>
lea    0xe7a(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sprintf@plt>
lea    0xe80(%rip),%rsi
jmp    1225 <get_format_size+0x105>
lea    0xe62(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sprintf@plt>
lea    0xe59(%rip),%rsi
jmp    1225 <get_format_size+0x105>
lea    0xe53(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sprintf@plt>
lea    0xe4a(%rip),%rsi
jmp    1225 <get_format_size+0x105>
lea    0xe3b(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sprintf@plt>
lea    0xe35(%rip),%rsi
jmp    1225 <get_format_size+0x105>
lea    0xe23(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sprintf@plt>
lea    0xe21(%rip),%rsi
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <strcat@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"0B\00"
@.str.1 = [6 x i8] c"%.0lf\00"
@.str.2 = [2 x i8] c"B\00"
@.str.3 = [3 x i8] c"KB\00"
@.str.4 = [6 x i8] c"%.2lf\00"
@.str.5 = [3 x i8] c"MB\00"
@.str.6 = [3 x i8] c"GB\00"
@.str.7 = [3 x i8] c"TB\00"
@.str.8 = [4 x i8] c">TB\00"
define void @get_format_size(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca double
store i64 %0, i64* %3
store i8* %1, i8** %4
%6 = load i64, i64* %3
%7 = uitofp i64 %6 to double
store double %7, double* %5
%8 = load double, double* %5
%9 = fcmp ole double %8, 0.000000e+00
br i1 %9, label %10, label %11
10: ; preds = %2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %4
br label %75
11: ; preds = %2
%12 = load i64, i64* %3
%13 = icmp ule i64 %12, 1024
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i8*, i8** %4
%16 = load double, double* %5
%17 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double %16)
%18 = load i8*, i8** %4
%19 = call i32 @strcat(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %74
20: ; preds = %11
%21 = load double, double* %5
%22 = fdiv double %21, 1.024000e+03
store double %22, double* %5
%23 = load double, double* %5
%24 = fcmp ole double %23, 1.024000e+03
br i1 %24, label %25, label %31
25: ; preds = %20
%26 = load i8*, i8** %4
%27 = load double, double* %5
%28 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double %27)
%29 = load i8*, i8** %4
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %73
31: ; preds = %20
%32 = load double, double* %5
%33 = fdiv double %32, 1.024000e+03
store double %33, double* %5
%34 = load double, double* %5
%35 = fcmp ole double %34, 1.024000e+03
br i1 %35, label %36, label %42
36: ; preds = %31
%37 = load i8*, i8** %4
%38 = load double, double* %5
%39 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), double %38)
%40 = load i8*, i8** %4
%41 = call i32 @strcat(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %72
42: ; preds = %31
%43 = load double, double* %5
%44 = fdiv double %43, 1.024000e+03
store double %44, double* %5
%45 = load double, double* %5
%46 = fcmp ole double %45, 1.024000e+03
br i1 %46, label %47, label %53
47: ; preds = %42
%48 = load i8*, i8** %4
%49 = load double, double* %5
%50 = call i32 @sprintf(i8* %48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), double %49)
%51 = load i8*, i8** %4
%52 = call i32 @strcat(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %71
53: ; preds = %42
%54 = load double, double* %5
%55 = fdiv double %54, 1.024000e+03
store double %55, double* %5
%56 = load double, double* %5
%57 = fcmp ole double %56, 1.024000e+03
br i1 %57, label %58, label %64
58: ; preds = %53
%59 = load i8*, i8** %4
%60 = load double, double* %5
%61 = call i32 @sprintf(i8* %59, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), double %60)
%62 = load i8*, i8** %4
%63 = call i32 @strcat(i8* %62, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
br label %70
64: ; preds = %53
%65 = load i8*, i8** %4
%66 = load double, double* %5
%67 = call i32 @sprintf(i8* %65, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double %66)
%68 = load i8*, i8** %4
%69 = call i32 @strcat(i8* %68, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
br label %70
70: ; preds = %64, %58
br label %71
71: ; preds = %70, %47
br label %72
72: ; preds = %71, %36
br label %73
73: ; preds = %72, %25
br label %74
74: ; preds = %73, %14
br label %75
75: ; preds = %74, %10
ret void
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"%.0lf\00"
@.str.2 = [2 x i8] c"B\00"
@.str.3 = [3 x i8] c"KB\00"
@.str.4 = [6 x i8] c"%.2lf\00"
@.str.5 = [3 x i8] c"MB\00"
@.str.6 = [3 x i8] c"GB\00"
@.str.7 = [3 x i8] c"TB\00"
@.str.8 = [4 x i8] c">TB\00"
define void @get_format_size(i64 %0, i8* %1) {
%3 = uitofp i64 %0 to double
%4 = icmp eq i64 %0, 0
br i1 %4, label %34, label %5
5: ; preds = %2
%6 = icmp ult i64 %0, 1025
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double %3)
br label %31
9: ; preds = %5
%10 = fmul double %3, 0x3F50000000000000
%11 = fcmp ugt double %10, 1.024000e+03
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double %10)
br label %31
14: ; preds = %9
%15 = fmul double %10, 0x3F50000000000000
%16 = fcmp ugt double %15, 1.024000e+03
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), double %15)
br label %31
19: ; preds = %14
%20 = fmul double %15, 0x3F50000000000000
%21 = fcmp ugt double %20, 1.024000e+03
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), double %20)
br label %31
24: ; preds = %19
%25 = fmul double %20, 0x3F50000000000000
%26 = fcmp ugt double %25, 1.024000e+03
br i1 %26, label %29, label %27
27: ; preds = %24
%28 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), double %25)
br label %31
29: ; preds = %24
%30 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double %25)
br label %31
31: ; preds = %12, %22, %29, %27, %17, %7
%32 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), %7 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), %17 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), %27 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), %29 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), %22 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), %12 ]
%33 = tail call i32 @strcat(i8* %1, i8* %32)
br label %34
34: ; preds = %31, %2
ret void
}