#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);
char *bytestr(size_t sz) {
  static char str[64];
  if (sz < 1024)
    sprintf(str, "%ub", (unsigned int)sz);
  else if (sz < 1024 * 1024)
    sprintf(str, "%.2fkb", (double)sz / 1024.0f);
  else if (sz < 1024 * 1024 * 1024)
    sprintf(str, "%.2fmb", (double)sz / 1024.0f / 1024.0f);
  return (str);
}


x86 assembly (clang, -O0):
<bytestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x400,-0x8(%rbp)
jae    114a <bytestr+0x3a>
mov    -0x8(%rbp),%eax
cvtsi2sd %rax,%xmm0
lea    0x2f07(%rip),%rdi
lea    0xef0(%rip),%rsi
call   1030 <sprintf@plt>
jmp    120d <bytestr+0xfd>
cmpq   $0x100000,-0x8(%rbp)
jae    11a3 <bytestr+0x93>
movaps 0xeb1(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xeb0(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe79(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0x2eae(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1030 <sprintf@plt>
jmp    1208 <bytestr+0xf8>
cmpq   $0x40000000,-0x8(%rbp)
40
jae    1203 <bytestr+0xf3>
movaps 0xe58(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe57(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe20(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe14(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0x2e49(%rip),%rdi
lea    0xe3d(%rip),%rsi
call   1030 <sprintf@plt>
jmp    1208 <bytestr+0xf8>
jmp    120d <bytestr+0xfd>
lea    0x2e2c(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bytestr>:
push   %rax
cmp    $0x3ff,%rdi
ja     1134 <bytestr+0x24>
mov    %edi,%eax
cvtsi2sd %rax,%xmm0
lea    0x2f18(%rip),%rdi
lea    0xef9(%rip),%rsi
jmp    11be <bytestr+0xae>
cmp    $0xfffff,%rdi
ja     1176 <bytestr+0x66>
movq   %rdi,%xmm1
punpckldq 0xeb6(%rip),%xmm1
subpd  0xebe(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xeba(%rip),%xmm0
lea    0x2ed3(%rip),%rdi
lea    0xeb8(%rip),%rsi
jmp    11be <bytestr+0xae>
cmp    $0x3fffffff,%rdi
ja     11c3 <bytestr+0xb3>
movq   %rdi,%xmm1
punpckldq 0xe74(%rip),%xmm1
subpd  0xe7c(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe78(%rip),%xmm1
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
lea    0x2e89(%rip),%rdi
lea    0xe75(%rip),%rsi
call   1030 <sprintf@plt>
lea    0x2e76(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@bytestr.str = internal global [64 x i8] zeroinitializer
@.str = [4 x i8] c"%ub\00"
@.str.1 = [7 x i8] c"%.2fkb\00"
@.str.2 = [7 x i8] c"%.2fmb\00"
define i8* @bytestr(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 @sprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @bytestr.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %8)
br label %29
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 @sprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @bytestr.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %16)
br label %28
18: ; preds = %10
%19 = load i64, i64* %2
%20 = icmp ult i64 %19, 1073741824
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i64, i64* %2
%23 = uitofp i64 %22 to double
%24 = fdiv double %23, 1.024000e+03
%25 = fdiv double %24, 1.024000e+03
%26 = call i32 @sprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @bytestr.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %25)
br label %27
27: ; preds = %21, %18
br label %28
28: ; preds = %27, %13
br label %29
29: ; preds = %28, %5
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @bytestr.str, i64 0, i64 0)
}

LLVM IR (-O2):
@bytestr.str = internal global [64 x i8] zeroinitializer
@.str = [4 x i8] c"%ub\00"
@.str.1 = [7 x i8] c"%.2fkb\00"
@.str.2 = [7 x i8] c"%.2fmb\00"
define i8* @bytestr(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 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @bytestr.str, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %5)
br label %20
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 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @bytestr.str, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %11)
br label %20
13: ; preds = %7
%14 = icmp ult i64 %0, 1073741824
br i1 %14, label %15, label %20
15: ; preds = %13
%16 = uitofp i64 %0 to double
%17 = fmul double %16, 0x3F50000000000000
%18 = fmul double %17, 0x3F50000000000000
%19 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @bytestr.str, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %18)
br label %20
20: ; preds = %9, %15, %13, %3
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @bytestr.str, i64 0, i64 0)
}