#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, double);
const char *prettysize(unsigned long long size) {
  static char buf[256];
  if (size < (1 << 20))
    snprintf(buf, sizeof(buf), "%llu KB", size >> 10);
  else if (size < (1 << 30))
    snprintf(buf, sizeof(buf), "%llu MB", size >> 20);
  else
    snprintf(buf, sizeof(buf), "%.2f GB", ((double)size) / (1 << 30));
  return buf;
}


x86 assembly (clang, -O0):
<prettysize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x100000,-0x8(%rbp)
jae    1154 <prettysize+0x44>
mov    -0x8(%rbp),%rax
shr    $0xa,%rax
cvtsi2sd %rax,%xmm0
lea    0x2f02(%rip),%rdi
mov    $0x100,%esi
lea    0xee6(%rip),%rdx
call   1030 <snprintf@plt>
jmp    11dc <prettysize+0xcc>
cmpq   $0x40000000,-0x8(%rbp)
40
jae    118c <prettysize+0x7c>
mov    -0x8(%rbp),%rax
shr    $0x14,%rax
cvtsi2sd %rax,%xmm0
lea    0x2eca(%rip),%rdi
mov    $0x100,%esi
lea    0xeb6(%rip),%rdx
call   1030 <snprintf@plt>
jmp    11d7 <prettysize+0xc7>
movaps 0xe7d(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe7c(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe45(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0x2e7a(%rip),%rdi
mov    $0x100,%esi
lea    0xe6e(%rip),%rdx
call   1030 <snprintf@plt>
jmp    11dc <prettysize+0xcc>
lea    0x2e5d(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prettysize>:
push   %rax
cmp    $0xfffff,%rdi
ja     1133 <prettysize+0x23>
shr    $0xa,%rdi
cvtsi2sd %rdi,%xmm0
lea    0x2f16(%rip),%rdi
lea    0xef7(%rip),%rdx
jmp    118c <prettysize+0x7c>
cmp    $0x3fffffff,%rdi
ja     1155 <prettysize+0x45>
shr    $0x14,%rdi
cvtsi2sd %rdi,%xmm0
lea    0x2ef4(%rip),%rdi
lea    0xedd(%rip),%rdx
jmp    118c <prettysize+0x7c>
movq   %rdi,%xmm1
punpckldq 0xe9e(%rip),%xmm1
subpd  0xea6(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xea2(%rip),%xmm0
lea    0x2ebb(%rip),%rdi
lea    0xeac(%rip),%rdx
mov    $0x100,%esi
call   1030 <snprintf@plt>
lea    0x2ea3(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@prettysize.buf = internal global [256 x i8] zeroinitializer
@.str = [8 x i8] c"%llu KB\00"
@.str.1 = [8 x i8] c"%llu MB\00"
@.str.2 = [8 x i8] c"%.2f GB\00"
define i8* @prettysize(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = load i64, i64* %2
%4 = icmp ult i64 %3, 1048576
br i1 %4, label %5, label %10
5: ; preds = %1
%6 = load i64, i64* %2
%7 = lshr i64 %6, 10
%8 = uitofp i64 %7 to double
%9 = call i32 @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @prettysize.buf, i64 0, i64 0), i32 256, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %8)
br label %24
10: ; preds = %1
%11 = load i64, i64* %2
%12 = icmp ult i64 %11, 1073741824
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = load i64, i64* %2
%15 = lshr i64 %14, 20
%16 = uitofp i64 %15 to double
%17 = call i32 @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @prettysize.buf, i64 0, i64 0), i32 256, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double %16)
br label %23
18: ; preds = %10
%19 = load i64, i64* %2
%20 = uitofp i64 %19 to double
%21 = fdiv double %20, 0x41D0000000000000
%22 = call i32 @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @prettysize.buf, i64 0, i64 0), i32 256, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %21)
br label %23
23: ; preds = %18, %13
br label %24
24: ; preds = %23, %5
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @prettysize.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@prettysize.buf = internal global [256 x i8] zeroinitializer
@.str = [8 x i8] c"%llu KB\00"
@.str.1 = [8 x i8] c"%llu MB\00"
@.str.2 = [8 x i8] c"%.2f GB\00"
define i8* @prettysize(i64 %0) {
%2 = icmp ult i64 %0, 1048576
br i1 %2, label %3, label %7
3: ; preds = %1
%4 = lshr i64 %0, 10
%5 = uitofp i64 %4 to double
%6 = tail call i32 @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @prettysize.buf, i64 0, i64 0), i32 256, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %5)
br label %17
7: ; preds = %1
%8 = icmp ult i64 %0, 1073741824
br i1 %8, label %9, label %13
9: ; preds = %7
%10 = lshr i64 %0, 20
%11 = uitofp i64 %10 to double
%12 = tail call i32 @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @prettysize.buf, i64 0, i64 0), i32 256, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double %11)
br label %17
13: ; preds = %7
%14 = uitofp i64 %0 to double
%15 = fmul double %14, 0x3E10000000000000
%16 = tail call i32 @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @prettysize.buf, i64 0, i64 0), i32 256, i8* 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 ([256 x i8], [256 x i8]* @prettysize.buf, i64 0, i64 0)
}