#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*/ plural(long);
int /*<<< orphan*/ sprintf(char *, char *, double, ...);
const char *byte_print(long numbytes) {
  static char byte_string[64];
  if (numbytes < 1024)
    sprintf(byte_string, "%li byte%s", numbytes, plural(numbytes));
  else if (numbytes < (1024 * 1024))
    sprintf(byte_string, "%li KB", numbytes / 1024);
  else
    sprintf(byte_string, "%.1f MB", (double)numbytes / (1024 * 1024));
  return byte_string;
}


x86 assembly (clang, -O0):
<byte_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x400,-0x8(%rbp)
jge    116f <byte_print+0x4f>
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <plural@plt>
movsd  -0x10(%rbp),%xmm0
mov    %eax,%edx
lea    0x2ee4(%rip),%rdi
lea    0xea5(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    11d6 <byte_print+0xb6>
cmpq   $0x100000,-0x8(%rbp)
jge    11aa <byte_print+0x8a>
mov    -0x8(%rbp),%rax
mov    $0x400,%ecx
cqto
idiv   %rcx
cvtsi2sd %rax,%xmm0
lea    0x2ea9(%rip),%rdi
lea    0xe75(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    11d1 <byte_print+0xb1>
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  0xe48(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0x2e7d(%rip),%rdi
lea    0xe50(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    11d6 <byte_print+0xb6>
lea    0x2e63(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<byte_print>:
push   %rax
cmp    $0x3ff,%rdi
jg     1157 <byte_print+0x37>
cvtsi2sd %rdi,%xmm0
movsd  %xmm0,(%rsp)
call   1040 <plural@plt>
lea    0x2f00(%rip),%rdi
lea    0xec1(%rip),%rsi
movsd  (%rsp),%xmm0
mov    %eax,%edx
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    119b <byte_print+0x7b>
cmp    $0xfffff,%rdi
ja     1179 <byte_print+0x59>
shr    $0xa,%rdi
cvtsi2sd %rdi,%xmm0
lea    0x2ed0(%rip),%rdi
lea    0xe9c(%rip),%rsi
jmp    1194 <byte_print+0x74>
cvtsi2sd %rdi,%xmm0
mulsd  0xe7a(%rip),%xmm0
lea    0x2eb3(%rip),%rdi
lea    0xe86(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
lea    0x2e9e(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@byte_print.byte_string = internal global [64 x i8] zeroinitializer
@.str = [11 x i8] c"%li byte%s\00"
@.str.1 = [7 x i8] c"%li KB\00"
@.str.2 = [8 x i8] c"%.1f MB\00"
define i8* @byte_print(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = load i64, i64* %2
%4 = icmp slt i64 %3, 1024
br i1 %4, label %5, label %11
5: ; preds = %1
%6 = load i64, i64* %2
%7 = sitofp i64 %6 to double
%8 = load i64, i64* %2
%9 = call i32 @plural(i64 %8)
%10 = call i32 (i8*, i8*, double, ...) @sprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @byte_print.byte_string, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), double %7, i32 %9)
br label %25
11: ; preds = %1
%12 = load i64, i64* %2
%13 = icmp slt i64 %12, 1048576
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i64, i64* %2
%16 = sdiv i64 %15, 1024
%17 = sitofp i64 %16 to double
%18 = call i32 (i8*, i8*, double, ...) @sprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @byte_print.byte_string, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %17)
br label %24
19: ; preds = %11
%20 = load i64, i64* %2
%21 = sitofp i64 %20 to double
%22 = fdiv double %21, 0x4130000000000000
%23 = call i32 (i8*, i8*, double, ...) @sprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @byte_print.byte_string, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %22)
br label %24
24: ; preds = %19, %14
br label %25
25: ; preds = %24, %5
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @byte_print.byte_string, i64 0, i64 0)
}

LLVM IR (-O2):
@byte_print.byte_string = internal global [64 x i8] zeroinitializer
@.str = [11 x i8] c"%li byte%s\00"
@.str.1 = [7 x i8] c"%li KB\00"
@.str.2 = [8 x i8] c"%.1f MB\00"
define i8* @byte_print(i64 %0) {
%2 = icmp slt i64 %0, 1024
br i1 %2, label %3, label %7
3: ; preds = %1
%4 = sitofp i64 %0 to double
%5 = tail call i32 @plural(i64 %0)
%6 = tail call i32 (i8*, i8*, double, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @byte_print.byte_string, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), double %4, i32 %5)
br label %17
7: ; preds = %1
%8 = icmp ult i64 %0, 1048576
br i1 %8, label %9, label %13
9: ; preds = %7
%10 = lshr i64 %0, 10
%11 = sitofp i64 %10 to double
%12 = tail call i32 (i8*, i8*, double, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @byte_print.byte_string, 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 %17
13: ; preds = %7
%14 = sitofp i64 %0 to double
%15 = fmul double %14, 0x3EB0000000000000
%16 = tail call i32 (i8*, i8*, double, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @byte_print.byte_string, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %15)
br label %17
17: ; preds = %9, %13, %3
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @byte_print.byte_string, i64 0, i64 0)
}