#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*/ printf(char *, ...);
void ubiutils_print_bytes(long long bytes, int bracket) {
  const char *p;
  if (bracket)
    p = " (";
  else
    p = ", ";
  printf("%lld bytes", bytes);
  if (bytes > 1024 * 1024 * 1024)
    printf("%s%.1f GiB", p, (double)bytes / (1024 * 1024 * 1024));
  else if (bytes > 1024 * 1024)
    printf("%s%.1f MiB", p, (double)bytes / (1024 * 1024));
  else if (bytes > 1024 && bytes != 0)
    printf("%s%.1f KiB", p, (double)bytes / 1024);
  else
    return;
  if (bracket)
    printf(")");
}


x86 assembly (clang, -O0):
<ubiutils_print_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1139 <ubiutils_print_bytes+0x29>
lea    0xee8(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1144 <ubiutils_print_bytes+0x34>
lea    0xedb(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xecf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x40000000,-0x8(%rbp)
40
jle    118d <ubiutils_print_bytes+0x7d>
mov    -0x18(%rbp),%rsi
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  0xe9a(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xea8(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1215 <ubiutils_print_bytes+0x105>
cmpq   $0x100000,-0x8(%rbp)
jle    11c4 <ubiutils_print_bytes+0xb4>
mov    -0x18(%rbp),%rsi
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  0xe5b(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe7c(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1210 <ubiutils_print_bytes+0x100>
cmpq   $0x400,-0x8(%rbp)
jle    1206 <ubiutils_print_bytes+0xf6>
cmpq   $0x0,-0x8(%rbp)
je     1206 <ubiutils_print_bytes+0xf6>
mov    -0x18(%rbp),%rsi
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  0xe11(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe45(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    120b <ubiutils_print_bytes+0xfb>
jmp    122d <ubiutils_print_bytes+0x11d>
jmp    1210 <ubiutils_print_bytes+0x100>
jmp    1215 <ubiutils_print_bytes+0x105>
cmpl   $0x0,-0xc(%rbp)
je     122d <ubiutils_print_bytes+0x11d>
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ubiutils_print_bytes>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbp
test   %esi,%esi
lea    0xee8(%rip),%rax
lea    0xede(%rip),%rbx
cmove  %rax,%rbx
lea    0xed9(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x40000000,%rbp
jle    1169 <ubiutils_print_bytes+0x49>
lea    0xeca(%rip),%rdi
movsd  0xe99(%rip),%xmm1
jmp    119b <ubiutils_print_bytes+0x7b>
cmp    $0x100000,%rbp
jle    1183 <ubiutils_print_bytes+0x63>
lea    0xebb(%rip),%rdi
movsd  0xe87(%rip),%xmm1
jmp    119b <ubiutils_print_bytes+0x7b>
cmp    $0x401,%rbp
jl     11c1 <ubiutils_print_bytes+0xa1>
lea    0xeac(%rip),%rdi
movsd  0xe75(%rip),%xmm1
cvtsi2sd %rbp,%xmm0
mulsd  %xmm1,%xmm0
mov    %rbx,%rsi
mov    $0x1,%al
call   1040 <printf@plt>
test   %r14d,%r14d
je     11c1 <ubiutils_print_bytes+0xa1>
mov    $0x29,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c" (\00"
@.str.1 = [3 x i8] c", \00"
@.str.2 = [11 x i8] c"%lld bytes\00"
@.str.3 = [11 x i8] c"%s%.1f GiB\00"
@.str.4 = [11 x i8] c"%s%.1f MiB\00"
@.str.5 = [11 x i8] c"%s%.1f KiB\00"
@.str.6 = [2 x i8] c")\00"
define void @ubiutils_print_bytes(i64 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i8*
store i64 %0, i64* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %5
br label %10
9: ; preds = %2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %5
br label %10
10: ; preds = %9, %8
%11 = load i64, i64* %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %11)
%13 = load i64, i64* %3
%14 = icmp sgt i64 %13, 1073741824
br i1 %14, label %15, label %21
15: ; preds = %10
%16 = load i8*, i8** %5
%17 = load i64, i64* %3
%18 = sitofp i64 %17 to double
%19 = fdiv double %18, 0x41D0000000000000
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %16, double %19)
br label %45
21: ; preds = %10
%22 = load i64, i64* %3
%23 = icmp sgt i64 %22, 1048576
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = load i8*, i8** %5
%26 = load i64, i64* %3
%27 = sitofp i64 %26 to double
%28 = fdiv double %27, 0x4130000000000000
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %25, double %28)
br label %44
30: ; preds = %21
%31 = load i64, i64* %3
%32 = icmp sgt i64 %31, 1024
br i1 %32, label %33, label %42
33: ; preds = %30
%34 = load i64, i64* %3
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %33
%37 = load i8*, i8** %5
%38 = load i64, i64* %3
%39 = sitofp i64 %38 to double
%40 = fdiv double %39, 1.024000e+03
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %37, double %40)
br label %43
42: ; preds = %33, %30
br label %50
43: ; preds = %36
br label %44
44: ; preds = %43, %24
br label %45
45: ; preds = %44, %15
%46 = load i32, i32* %4
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %50
50: ; preds = %42, %48, %45
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c" (\00"
@.str.1 = [3 x i8] c", \00"
@.str.2 = [11 x i8] c"%lld bytes\00"
@.str.3 = [11 x i8] c"%s%.1f GiB\00"
@.str.4 = [11 x i8] c"%s%.1f MiB\00"
@.str.5 = [11 x i8] c"%s%.1f KiB\00"
define void @ubiutils_print_bytes(i64 %0, i32 %1) {
%3 = icmp eq i32 %1, 0
%4 = select i1 %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %0)
%6 = icmp sgt i64 %0, 1073741824
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = icmp sgt i64 %0, 1048576
br i1 %8, label %11, label %9
9: ; preds = %7
%10 = icmp sgt i64 %0, 1024
br i1 %10, label %11, label %19
11: ; preds = %9, %7, %2
%12 = phi double [ 0x3E10000000000000, %2 ], [ 0x3EB0000000000000, %7 ], [ 0x3F50000000000000, %9 ]
%13 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), %2 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), %7 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), %9 ]
%14 = sitofp i64 %0 to double
%15 = fmul double %12, %14
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %13, i8* %4, double %15)
br i1 %3, label %19, label %17
17: ; preds = %11
%18 = tail call i32 @putchar(i32 41)
br label %19
19: ; preds = %11, %17, %9
ret void
}