#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 const);
char *byte_units(const double bytes) {
  static char result[0x100];
  if (bytes >= 1 << 30)
    sprintf(result, "%0.2lf GiB", bytes / (1 << 30));
  else if (bytes >= 1 << 20)
    sprintf(result, "%0.2lf MiB", bytes / (1 << 20));
  else if (bytes >= 1 << 10)
    sprintf(result, "%0.2lf KiB", bytes / (1 << 10));
  else
    sprintf(result, "%.0lf B", bytes);
  return result;
}


x86 assembly (clang, -O0):
<byte_units>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xed6(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     115d <byte_units+0x4d>
movsd  -0x8(%rbp),%xmm0
movsd  0xebf(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0x2ef4(%rip),%rdi
lea    0xec5(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11ff <byte_units+0xef>
movsd  -0x8(%rbp),%xmm0
movsd  0xe9e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     119d <byte_units+0x8d>
movsd  -0x8(%rbp),%xmm0
movsd  0xe87(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0x2eb4(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11fa <byte_units+0xea>
movsd  -0x8(%rbp),%xmm0
movsd  0xe66(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11dd <byte_units+0xcd>
movsd  -0x8(%rbp),%xmm0
movsd  0xe4f(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0x2e74(%rip),%rdi
lea    0xe5b(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11f5 <byte_units+0xe5>
movsd  -0x8(%rbp),%xmm0
lea    0x2e57(%rip),%rdi
lea    0xe49(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11fa <byte_units+0xea>
jmp    11ff <byte_units+0xef>
lea    0x2e3a(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<byte_units>:
push   %rax
ucomisd 0xee7(%rip),%xmm0
jae    113f <byte_units+0x2f>
ucomisd 0xeed(%rip),%xmm0
jae    1157 <byte_units+0x47>
ucomisd 0xef3(%rip),%xmm0
jae    116f <byte_units+0x5f>
lea    0x2f0a(%rip),%rdi
lea    0xf14(%rip),%rsi
jmp    1185 <byte_units+0x75>
mulsd  0xec1(%rip),%xmm0
lea    0x2ef2(%rip),%rdi
lea    0xedb(%rip),%rsi
jmp    1185 <byte_units+0x75>
mulsd  0xeb9(%rip),%xmm0
lea    0x2eda(%rip),%rdi
lea    0xece(%rip),%rsi
jmp    1185 <byte_units+0x75>
mulsd  0xeb1(%rip),%xmm0
lea    0x2ec2(%rip),%rdi
lea    0xec1(%rip),%rsi
call   1030 <sprintf@plt>
lea    0x2eaf(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@byte_units.result = internal global [256 x i8] zeroinitializer
@.str = [11 x i8] c"%0.2lf GiB\00"
@.str.1 = [11 x i8] c"%0.2lf MiB\00"
@.str.2 = [11 x i8] c"%0.2lf KiB\00"
@.str.3 = [8 x i8] c"%.0lf B\00"
define i8* @byte_units(double %0) {
%2 = alloca double
store double %0, double* %2
%3 = load double, double* %2
%4 = fcmp oge double %3, 0x41D0000000000000
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = load double, double* %2
%7 = fdiv double %6, 0x41D0000000000000
%8 = call i32 @sprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @byte_units.result, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), double %7)
br label %28
9: ; preds = %1
%10 = load double, double* %2
%11 = fcmp oge double %10, 0x4130000000000000
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load double, double* %2
%14 = fdiv double %13, 0x4130000000000000
%15 = call i32 @sprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @byte_units.result, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double %14)
br label %27
16: ; preds = %9
%17 = load double, double* %2
%18 = fcmp oge double %17, 1.024000e+03
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load double, double* %2
%21 = fdiv double %20, 1.024000e+03
%22 = call i32 @sprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @byte_units.result, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), double %21)
br label %26
23: ; preds = %16
%24 = load double, double* %2
%25 = call i32 @sprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @byte_units.result, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), double %24)
br label %26
26: ; preds = %23, %19
br label %27
27: ; preds = %26, %12
br label %28
28: ; preds = %27, %5
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @byte_units.result, i64 0, i64 0)
}

LLVM IR (-O2):
@byte_units.result = internal global [256 x i8] zeroinitializer
@.str = [11 x i8] c"%0.2lf GiB\00"
@.str.1 = [11 x i8] c"%0.2lf MiB\00"
@.str.2 = [11 x i8] c"%0.2lf KiB\00"
@.str.3 = [8 x i8] c"%.0lf B\00"
define i8* @byte_units(double %0) {
%2 = fcmp ult double %0, 0x41D0000000000000
br i1 %2, label %6, label %3
3: ; preds = %1
%4 = fmul double %0, 0x3E10000000000000
%5 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([256 x i8], [256 x i8]* @byte_units.result, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), double %4)
br label %18
6: ; preds = %1
%7 = fcmp ult double %0, 0x4130000000000000
br i1 %7, label %11, label %8
8: ; preds = %6
%9 = fmul double %0, 0x3EB0000000000000
%10 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([256 x i8], [256 x i8]* @byte_units.result, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double %9)
br label %18
11: ; preds = %6
%12 = fcmp ult double %0, 1.024000e+03
br i1 %12, label %16, label %13
13: ; preds = %11
%14 = fmul double %0, 0x3F50000000000000
%15 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([256 x i8], [256 x i8]* @byte_units.result, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), double %14)
br label %18
16: ; preds = %11
%17 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([256 x i8], [256 x i8]* @byte_units.result, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), double %0)
br label %18
18: ; preds = %8, %16, %13, %3
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @byte_units.result, i64 0, i64 0)
}