#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 unsigned long long uint64_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, double);
char *bytes(uint64_t b) {
  static char buf[1024];
  if (b < 1024ULL)
    snprintf(buf, sizeof(buf) - 1,
             "%u "
             "\x1b[36m"
             "B"
             "\x1b[0m",
             (unsigned)b);
  else if (b < 1024ULL * 1024ULL)
    snprintf(buf, sizeof(buf) - 1,
             "%.2f "
             "\x1b[36m"
             "KiB"
             "\x1b[0m",
             (double)b / 1024);
  else if (b < 1024ULL * 1024ULL * 1024ULL)
    snprintf(buf, sizeof(buf) - 1,
             "%.2f "
             "\x1b[36m"
             "MiB"
             "\x1b[0m",
             (double)b / (1024 * 1024));
  else if (b < 1024ULL * 1024ULL * 1024ULL * 1024ULL)
    snprintf(buf, sizeof(buf) - 1,
             "%.2f "
             "\x1b[36m"
             "GiB"
             "\x1b[0m",
             (double)b / (1024 * 1024 * 1024));
  else
    snprintf(buf, sizeof(buf) - 1,
             "%.2f "
             "\x1b[36m"
             "TiB"
             "\x1b[0m",
             (double)b / (1024 * 1024 * 1024) / 1024);
  return buf;
}


x86 assembly (clang, -O0):
<bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x400,-0x8(%rbp)
jae    114f <bytes+0x3f>
mov    -0x8(%rbp),%eax
cvtsi2sd %rax,%xmm0
lea    0x2f07(%rip),%rdi
mov    $0x3ff,%esi
lea    0xefb(%rip),%rdx
call   1030 <snprintf@plt>
jmp    12d5 <bytes+0x1c5>
cmpq   $0x100000,-0x8(%rbp)
jae    11ad <bytes+0x9d>
movaps 0xebc(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xebb(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe74(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0x2ea9(%rip),%rdi
mov    $0x3ff,%esi
lea    0xeab(%rip),%rdx
call   1030 <snprintf@plt>
jmp    12d0 <bytes+0x1c0>
cmpq   $0x40000000,-0x8(%rbp)
40
jae    120b <bytes+0xfb>
movaps 0xe5e(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe5d(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe26(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0x2e4b(%rip),%rdi
mov    $0x3ff,%esi
lea    0xe5f(%rip),%rdx
call   1030 <snprintf@plt>
jmp    12cb <bytes+0x1bb>
movabs $0x10000000000,%rax
cmp    %rax,-0x8(%rbp)
jae    126f <bytes+0x15f>
movaps 0xdfa(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xdf9(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xdba(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0x2de7(%rip),%rdi
mov    $0x3ff,%esi
lea    0xe0d(%rip),%rdx
call   1030 <snprintf@plt>
jmp    12c6 <bytes+0x1b6>
movaps 0xdaa(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xda9(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xd6a(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xd56(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0x2d8b(%rip),%rdi
mov    $0x3ff,%esi
lea    0xdc3(%rip),%rdx
call   1030 <snprintf@plt>
jmp    12cb <bytes+0x1bb>
jmp    12d0 <bytes+0x1c0>
jmp    12d5 <bytes+0x1c5>
lea    0x2d64(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bytes>:
push   %rax
cmp    $0x3ff,%rdi
ja     1134 <bytes+0x24>
mov    %edi,%eax
cvtsi2sd %rax,%xmm0
lea    0x2f18(%rip),%rdi
lea    0xf09(%rip),%rdx
jmp    1210 <bytes+0x100>
cmp    $0xfffff,%rdi
ja     1179 <bytes+0x69>
movq   %rdi,%xmm1
punpckldq 0xeb6(%rip),%xmm1
subpd  0xebe(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xec2(%rip),%xmm0
lea    0x2ed3(%rip),%rdi
lea    0xed2(%rip),%rdx
jmp    1210 <bytes+0x100>
cmp    $0x3fffffff,%rdi
ja     11bb <bytes+0xab>
movq   %rdi,%xmm1
punpckldq 0xe71(%rip),%xmm1
subpd  0xe79(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xe85(%rip),%xmm0
lea    0x2e8e(%rip),%rdi
lea    0xe9f(%rip),%rdx
jmp    1210 <bytes+0x100>
movq   %rdi,%xmm1
shr    $0x28,%rdi
punpckldq 0xe34(%rip),%xmm1
subpd  0xe3c(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xe38(%rip),%xmm0
jne    11fa <bytes+0xea>
lea    0x2e4f(%rip),%rdi
lea    0xe72(%rip),%rdx
jmp    1210 <bytes+0x100>
mulsd  0xe26(%rip),%xmm0
lea    0x2e37(%rip),%rdi
lea    0xe6c(%rip),%rdx
mov    $0x3ff,%esi
call   1030 <snprintf@plt>
lea    0x2e1f(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@bytes.buf = internal global [1024 x i8] zeroinitializer
@.str = [14 x i8] c"%u \1B[36mB\1B[0m\00"
@.str.1 = [18 x i8] c"%.2f \1B[36mKiB\1B[0m\00"
@.str.2 = [18 x i8] c"%.2f \1B[36mMiB\1B[0m\00"
@.str.3 = [18 x i8] c"%.2f \1B[36mGiB\1B[0m\00"
@.str.4 = [18 x i8] c"%.2f \1B[36mTiB\1B[0m\00"
define i8* @bytes(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = load i64, i64* %2
%4 = icmp ult i64 %3, 1024
br i1 %4, label %5, label %10
5: ; preds = %1
%6 = load i64, i64* %2
%7 = trunc i64 %6 to i32
%8 = uitofp i32 %7 to double
%9 = call i32 @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @bytes.buf, i64 0, i64 0), i32 1023, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), double %8)
br label %43
10: ; preds = %1
%11 = load i64, i64* %2
%12 = icmp ult i64 %11, 1048576
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = load i64, i64* %2
%15 = uitofp i64 %14 to double
%16 = fdiv double %15, 1.024000e+03
%17 = call i32 @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @bytes.buf, i64 0, i64 0), i32 1023, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), double %16)
br label %42
18: ; preds = %10
%19 = load i64, i64* %2
%20 = icmp ult i64 %19, 1073741824
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load i64, i64* %2
%23 = uitofp i64 %22 to double
%24 = fdiv double %23, 0x4130000000000000
%25 = call i32 @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @bytes.buf, i64 0, i64 0), i32 1023, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), double %24)
br label %41
26: ; preds = %18
%27 = load i64, i64* %2
%28 = icmp ult i64 %27, 1099511627776
br i1 %28, label %29, label %34
29: ; preds = %26
%30 = load i64, i64* %2
%31 = uitofp i64 %30 to double
%32 = fdiv double %31, 0x41D0000000000000
%33 = call i32 @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @bytes.buf, i64 0, i64 0), i32 1023, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), double %32)
br label %40
34: ; preds = %26
%35 = load i64, i64* %2
%36 = uitofp i64 %35 to double
%37 = fdiv double %36, 0x41D0000000000000
%38 = fdiv double %37, 1.024000e+03
%39 = call i32 @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @bytes.buf, i64 0, i64 0), i32 1023, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), double %38)
br label %40
40: ; preds = %34, %29
br label %41
41: ; preds = %40, %21
br label %42
42: ; preds = %41, %13
br label %43
43: ; preds = %42, %5
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @bytes.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@bytes.buf = internal global [1024 x i8] zeroinitializer
@.str = [14 x i8] c"%u \1B[36mB\1B[0m\00"
@.str.1 = [18 x i8] c"%.2f \1B[36mKiB\1B[0m\00"
@.str.2 = [18 x i8] c"%.2f \1B[36mMiB\1B[0m\00"
@.str.3 = [18 x i8] c"%.2f \1B[36mGiB\1B[0m\00"
@.str.4 = [18 x i8] c"%.2f \1B[36mTiB\1B[0m\00"
define i8* @bytes(i64 %0) {
%2 = icmp ult i64 %0, 1024
br i1 %2, label %3, label %7
3: ; preds = %1
%4 = trunc i64 %0 to i32
%5 = uitofp i32 %4 to double
%6 = tail call i32 @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @bytes.buf, i64 0, i64 0), i32 1023, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), double %5)
br label %28
7: ; preds = %1
%8 = icmp ult i64 %0, 1048576
br i1 %8, label %9, label %13
9: ; preds = %7
%10 = uitofp i64 %0 to double
%11 = fmul double %10, 0x3F50000000000000
%12 = tail call i32 @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @bytes.buf, i64 0, i64 0), i32 1023, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), double %11)
br label %28
13: ; preds = %7
%14 = icmp ult i64 %0, 1073741824
br i1 %14, label %15, label %19
15: ; preds = %13
%16 = uitofp i64 %0 to double
%17 = fmul double %16, 0x3EB0000000000000
%18 = tail call i32 @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @bytes.buf, i64 0, i64 0), i32 1023, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), double %17)
br label %28
19: ; preds = %13
%20 = icmp ult i64 %0, 1099511627776
%21 = uitofp i64 %0 to double
%22 = fmul double %21, 0x3E10000000000000
br i1 %20, label %23, label %25
23: ; preds = %19
%24 = tail call i32 @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @bytes.buf, i64 0, i64 0), i32 1023, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), double %22)
br label %28
25: ; preds = %19
%26 = fmul double %22, 0x3F50000000000000
%27 = tail call i32 @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @bytes.buf, i64 0, i64 0), i32 1023, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), double %26)
br label %28
28: ; preds = %9, %23, %25, %15, %3
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @bytes.buf, i64 0, i64 0)
}