#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 long long uint64_t;

/* Variables and functions */
const char *format_size(uint64_t in, double *out) {
  double size = 0;
  const char *unit = "B";
  if (in >= 1024ll * 1024ll * 1024ll * 1024ll * 1024ll * 1024ll) {
    size = (double)in /
           (double)(1024ll * 1024ll * 1024ll * 1024ll * 1024ll * 1024ll);
    unit = "EB";
  } else if (in >= 1024ll * 1024ll * 1024ll * 1024ll * 1024ll) {
    size = (double)in / (double)(1024ll * 1024ll * 1024ll * 1024ll * 1024ll);
    unit = "PB";
  } else if (in >= 1024ll * 1024ll * 1024ll * 1024ll) {
    size = (double)in / (double)(1024ll * 1024ll * 1024ll * 1024ll);
    unit = "TB";
  } else if (in >= 1024ll * 1024ll * 1024ll) {
    size = (double)in / (double)(1024ll * 1024ll * 1024ll);
    unit = "GB";
  } else if (in >= 1024ll * 1024ll) {
    size = (double)in / (double)(1024ll * 1024ll);
    unit = "MB";
  } else if (in >= 1024ll) {
    size = (double)in / (double)1024ll;
    unit = "kB";
  } else {
    size = (double)in;
  }
  if (out)
    *out = size;
  return unit;
}


x86 assembly (clang, -O0):
<format_size>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
lea    0xf16(%rip),%rax
mov    %rax,-0x20(%rbp)
movabs $0x1000000000000000,%rax
cmp    %rax,-0x8(%rbp)
jl     115a <format_size+0x5a>
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  0xee7(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
lea    0xedf(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1293 <format_size+0x193>
movabs $0x4000000000000,%rax
cmp    %rax,-0x8(%rbp)
jl     1195 <format_size+0x95>
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  0xea4(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
lea    0xea7(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    128e <format_size+0x18e>
movabs $0x10000000000,%rax
cmp    %rax,-0x8(%rbp)
jl     11d0 <format_size+0xd0>
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  0xe61(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
lea    0xe6f(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1289 <format_size+0x189>
cmpq   $0x40000000,-0x8(%rbp)
40
jl     1205 <format_size+0x105>
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  0xe24(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
lea    0xe3d(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1284 <format_size+0x184>
cmpq   $0x100000,-0x8(%rbp)
jl     123a <format_size+0x13a>
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  0xde7(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
lea    0xe0b(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    127f <format_size+0x17f>
cmpq   $0x400,-0x8(%rbp)
jl     126f <format_size+0x16f>
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  0xdaa(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
lea    0xdd9(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    127a <format_size+0x17a>
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    127f <format_size+0x17f>
jmp    1284 <format_size+0x184>
jmp    1289 <format_size+0x189>
jmp    128e <format_size+0x18e>
jmp    1293 <format_size+0x193>
cmpq   $0x0,-0x10(%rbp)
je     12ab <format_size+0x1ab>
movsd  -0x18(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_size>:
movabs $0x1000000000000000,%rax
cmp    %rax,%rdi
jl     1128 <format_size+0x28>
cvtsi2sd %rdi,%xmm0
mulsd  0xf0c(%rip),%xmm0
lea    0xf0d(%rip),%rax
jmp    11d9 <format_size+0xd9>
movabs $0x4000000000000,%rax
cmp    %rax,%rdi
jl     1150 <format_size+0x50>
cvtsi2sd %rdi,%xmm0
mulsd  0xedc(%rip),%xmm0
lea    0xee8(%rip),%rax
jmp    11d9 <format_size+0xd9>
movabs $0x10000000000,%rax
cmp    %rax,%rdi
jl     1175 <format_size+0x75>
cvtsi2sd %rdi,%xmm0
mulsd  0xeac(%rip),%xmm0
lea    0xec3(%rip),%rax
jmp    11d9 <format_size+0xd9>
cmp    $0x40000000,%rdi
jl     1194 <format_size+0x94>
cvtsi2sd %rdi,%xmm0
mulsd  0xe85(%rip),%xmm0
lea    0xea7(%rip),%rax
jmp    11d9 <format_size+0xd9>
cmp    $0x100000,%rdi
jl     11b3 <format_size+0xb3>
cvtsi2sd %rdi,%xmm0
mulsd  0xe5e(%rip),%xmm0
lea    0xe8b(%rip),%rax
jmp    11d9 <format_size+0xd9>
cvtsi2sd %rdi,%xmm0
cmp    $0x400,%rdi
jl     11d2 <format_size+0xd2>
mulsd  0xe37(%rip),%xmm0
lea    0xe6f(%rip),%rax
jmp    11d9 <format_size+0xd9>
lea    0xe58(%rip),%rax
test   %rsi,%rsi
je     11e2 <format_size+0xe2>
movsd  %xmm0,(%rsi)
ret

LLVM IR (-O0):
@.str = [2 x i8] c"B\00"
@.str.1 = [3 x i8] c"EB\00"
@.str.2 = [3 x i8] c"PB\00"
@.str.3 = [3 x i8] c"TB\00"
@.str.4 = [3 x i8] c"GB\00"
@.str.5 = [3 x i8] c"MB\00"
@.str.6 = [3 x i8] c"kB\00"
define i8* @format_size(i64 %0, double* %1) {
%3 = alloca i64
%4 = alloca double*
%5 = alloca double
%6 = alloca i8*
store i64 %0, i64* %3
store double* %1, double** %4
store double 0.000000e+00, double* %5
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %6
%7 = load i64, i64* %3
%8 = icmp sge i64 %7, 1152921504606846976
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i64, i64* %3
%11 = sitofp i64 %10 to double
%12 = fdiv double %11, 0x43B0000000000000
store double %12, double* %5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %6
br label %56
13: ; preds = %2
%14 = load i64, i64* %3
%15 = icmp sge i64 %14, 1125899906842624
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i64, i64* %3
%18 = sitofp i64 %17 to double
%19 = fdiv double %18, 0x4310000000000000
store double %19, double* %5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %6
br label %55
20: ; preds = %13
%21 = load i64, i64* %3
%22 = icmp sge i64 %21, 1099511627776
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i64, i64* %3
%25 = sitofp i64 %24 to double
%26 = fdiv double %25, 0x4270000000000000
store double %26, double* %5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %6
br label %54
27: ; preds = %20
%28 = load i64, i64* %3
%29 = icmp sge i64 %28, 1073741824
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load i64, i64* %3
%32 = sitofp i64 %31 to double
%33 = fdiv double %32, 0x41D0000000000000
store double %33, double* %5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %6
br label %53
34: ; preds = %27
%35 = load i64, i64* %3
%36 = icmp sge i64 %35, 1048576
br i1 %36, label %37, label %41
37: ; preds = %34
%38 = load i64, i64* %3
%39 = sitofp i64 %38 to double
%40 = fdiv double %39, 0x4130000000000000
store double %40, double* %5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8** %6
br label %52
41: ; preds = %34
%42 = load i64, i64* %3
%43 = icmp sge i64 %42, 1024
br i1 %43, label %44, label %48
44: ; preds = %41
%45 = load i64, i64* %3
%46 = sitofp i64 %45 to double
%47 = fdiv double %46, 1.024000e+03
store double %47, double* %5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8** %6
br label %51
48: ; preds = %41
%49 = load i64, i64* %3
%50 = sitofp i64 %49 to double
store double %50, double* %5
br label %51
51: ; preds = %48, %44
br label %52
52: ; preds = %51, %37
br label %53
53: ; preds = %52, %30
br label %54
54: ; preds = %53, %23
br label %55
55: ; preds = %54, %16
br label %56
56: ; preds = %55, %9
%57 = load double*, double** %4
%58 = icmp ne double* %57, null
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load double, double* %5
%61 = load double*, double** %4
store double %60, double* %61
br label %62
62: ; preds = %59, %56
%63 = load i8*, i8** %6
ret i8* %63
}

LLVM IR (-O2):
@.str = [2 x i8] c"B\00"
@.str.1 = [3 x i8] c"EB\00"
@.str.2 = [3 x i8] c"PB\00"
@.str.3 = [3 x i8] c"TB\00"
@.str.4 = [3 x i8] c"GB\00"
@.str.5 = [3 x i8] c"MB\00"
@.str.6 = [3 x i8] c"kB\00"
define i8* @format_size(i64 %0, double* writeonly %1) {
%3 = icmp sgt i64 %0, 1152921504606846975
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = sitofp i64 %0 to double
%6 = fmul double %5, 0x3C30000000000000
br label %32
7: ; preds = %2
%8 = icmp sgt i64 %0, 1125899906842623
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = sitofp i64 %0 to double
%11 = fmul double %10, 0x3CD0000000000000
br label %32
12: ; preds = %7
%13 = icmp sgt i64 %0, 1099511627775
br i1 %13, label %14, label %17
14: ; preds = %12
%15 = sitofp i64 %0 to double
%16 = fmul double %15, 0x3D70000000000000
br label %32
17: ; preds = %12
%18 = icmp sgt i64 %0, 1073741823
br i1 %18, label %19, label %22
19: ; preds = %17
%20 = sitofp i64 %0 to double
%21 = fmul double %20, 0x3E10000000000000
br label %32
22: ; preds = %17
%23 = icmp sgt i64 %0, 1048575
br i1 %23, label %24, label %27
24: ; preds = %22
%25 = sitofp i64 %0 to double
%26 = fmul double %25, 0x3EB0000000000000
br label %32
27: ; preds = %22
%28 = icmp sgt i64 %0, 1023
%29 = sitofp i64 %0 to double
br i1 %28, label %30, label %32
30: ; preds = %27
%31 = fmul double %29, 0x3F50000000000000
br label %32
32: ; preds = %27, %9, %19, %30, %24, %14, %4
%33 = phi double [ %6, %4 ], [ %11, %9 ], [ %16, %14 ], [ %21, %19 ], [ %26, %24 ], [ %31, %30 ], [ %29, %27 ]
%34 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %4 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %9 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), %14 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), %19 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), %24 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), %30 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %27 ]
%35 = icmp eq double* %1, null
br i1 %35, label %37, label %36
36: ; preds = %32
store double %33, double* %1
br label %37
37: ; preds = %36, %32
ret i8* %34
}