#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 int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, double, char const *);
char *pretty_print_size(unsigned long bytes) {
  static const char *suffixes[] = {"B", "KiB", "MiB", "GiB"};
  static char buffer[32];
  int unit = 0;
  double count = bytes;
  while (count > 1024 && unit < 3) {
    unit++;
    count /= 1024.0;
  }
  snprintf(buffer, sizeof(buffer), "%.1f%s", count, suffixes[unit]);
  return buffer;
}


x86 assembly (clang, -O0):
<pretty_print_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movaps 0xed6(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xed5(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xor    %eax,%eax
movsd  0xec2(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x19(%rbp)
jbe    1175 <pretty_print_size+0x65>
cmpl   $0x3,-0xc(%rbp)
setl   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1185 <pretty_print_size+0x75>
jmp    11a9 <pretty_print_size+0x99>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe85(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    114f <pretty_print_size+0x3f>
movsd  -0x18(%rbp),%xmm0
movslq -0xc(%rbp),%rcx
lea    0x2e77(%rip),%rax
mov    (%rax,%rcx,8),%rcx
lea    0x2e9c(%rip),%rdi
mov    $0x20,%esi
lea    0xe64(%rip),%rdx
call   1030 <snprintf@plt>
lea    0x2e84(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pretty_print_size>:
push   %rbx
movq   %rdi,%xmm1
punpckldq 0xee2(%rip),%xmm1
subpd  0xeea(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
cmp    $0x401,%rdi
jb     1178 <pretty_print_size+0x68>
mulsd  0xedd(%rip),%xmm0
mov    $0x1,%eax
ucomisd 0xed8(%rip),%xmm0
jbe    117a <pretty_print_size+0x6a>
mulsd  0xec6(%rip),%xmm0
mov    $0x2,%eax
ucomisd 0xec1(%rip),%xmm0
jbe    117a <pretty_print_size+0x6a>
mulsd  0xeaf(%rip),%xmm0
mov    $0x3,%eax
jmp    117a <pretty_print_size+0x6a>
xor    %eax,%eax
lea    0xeaf(%rip),%rdx
movslq (%rdx,%rax,4),%rcx
add    %rdx,%rcx
lea    0x2eb1(%rip),%rbx
lea    0xeb6(%rip),%rdx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1030 <snprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@pretty_print_size.suffixes = internal global [4 x i8*] [i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0)]
@.str = [2 x i8] c"B\00"
@.str.1 = [4 x i8] c"KiB\00"
@.str.2 = [4 x i8] c"MiB\00"
@.str.3 = [4 x i8] c"GiB\00"
@pretty_print_size.buffer = internal global [32 x i8] zeroinitializer
@.str.4 = [7 x i8] c"%.1f%s\00"
define i8* @pretty_print_size(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca double
store i64 %0, i64* %2
store i32 0, i32* %3
%5 = load i64, i64* %2
%6 = uitofp i64 %5 to double
store double %6, double* %4
br label %7
7: ; preds = %15, %1
%8 = load double, double* %4
%9 = fcmp ogt double %8, 1.024000e+03
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 3
br label %13
13: ; preds = %10, %7
%14 = phi i1 [ false, %7 ], [ %12, %10 ]
br i1 %14, label %15, label %20
15: ; preds = %13
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
%18 = load double, double* %4
%19 = fdiv double %18, 1.024000e+03
store double %19, double* %4
br label %7
20: ; preds = %13
%21 = load double, double* %4
%22 = load i32, i32* %3
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [4 x i8*], [4 x i8*]* @pretty_print_size.suffixes, i64 0, i64 %23
%25 = load i8*, i8** %24
%26 = call i32 @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @pretty_print_size.buffer, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %21, i8* %25)
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @pretty_print_size.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
@reltable.pretty_print_size = internal unnamed_addr constant [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([2 x i8]* @.str to i64), i64 ptrtoint ([4 x i32]* @reltable.pretty_print_size to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.1 to i64), i64 ptrtoint ([4 x i32]* @reltable.pretty_print_size to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @reltable.pretty_print_size to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @reltable.pretty_print_size to i64)) to i32)]
@.str = [2 x i8] c"B\00"
@.str.1 = [4 x i8] c"KiB\00"
@.str.2 = [4 x i8] c"MiB\00"
@.str.3 = [4 x i8] c"GiB\00"
@pretty_print_size.buffer = internal global [32 x i8] zeroinitializer
@.str.4 = [7 x i8] c"%.1f%s\00"
define i8* @pretty_print_size(i64 %0) {
%2 = uitofp i64 %0 to double
%3 = icmp ugt i64 %0, 1024
br i1 %3, label %4, label %12
4: ; preds = %1
%5 = fmul double %2, 0x3F50000000000000
%6 = fcmp ogt double %5, 1.024000e+03
br i1 %6, label %7, label %12
7: ; preds = %4
%8 = fmul double %5, 0x3F50000000000000
%9 = fcmp ogt double %8, 1.024000e+03
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = fmul double %8, 0x3F50000000000000
br label %12
12: ; preds = %4, %7, %10, %1
%13 = phi i64 [ 0, %1 ], [ 1, %4 ], [ 2, %7 ], [ 3, %10 ]
%14 = phi double [ %2, %1 ], [ %5, %4 ], [ %8, %7 ], [ %11, %10 ]
%15 = shl i64 %13, 2
%16 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.pretty_print_size to i8*), i64 %15)
%17 = tail call i32 @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @pretty_print_size.buffer, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %14, i8* %16)
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @pretty_print_size.buffer, i64 0, i64 0)
}