#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 off_t;

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, int);
void format_pretty_size(off_t amount, char *out) {
  if (amount >= (1024 * (1024 * (1024LL))))
    sprintf(out, "%.2f GiB", ((double)amount) / (1024 * (1024 * (1024LL))));
  else if (amount >= (1024 * (1024LL)))
    sprintf(out, "%.2f MiB", ((double)amount) / (1024 * (1024LL)));
  else if (amount >= (1024LL))
    sprintf(out, "%d KiB", (int)(amount / (1024LL)));
  else
    sprintf(out, "%d bytes", (int)amount);
}


x86 assembly (clang, -O0):
<format_pretty_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movslq -0x4(%rbp),%rax
cmp    $0x40000000,%rax
jl     1159 <format_pretty_size+0x49>
mov    -0x10(%rbp),%rdi
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  0xec8(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
lea    0xec1(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11e5 <format_pretty_size+0xd5>
movslq -0x4(%rbp),%rax
cmp    $0x100000,%rax
jl     1193 <format_pretty_size+0x83>
mov    -0x10(%rbp),%rdi
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  0xe86(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
lea    0xe90(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11e0 <format_pretty_size+0xd0>
movslq -0x4(%rbp),%rax
cmp    $0x400,%rax
jl     11c8 <format_pretty_size+0xb8>
mov    -0x10(%rbp),%rdi
movslq -0x4(%rbp),%rax
mov    $0x400,%ecx
cqto
idiv   %rcx
mov    %eax,%edx
lea    0xe64(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11db <format_pretty_size+0xcb>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe53(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11e0 <format_pretty_size+0xd0>
jmp    11e5 <format_pretty_size+0xd5>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_pretty_size>:
mov    %rsi,%rax
mov    %edi,%edx
cmp    $0x40000000,%edi
jl     113c <format_pretty_size+0x2c>
cvtsi2sd %edx,%xmm0
mulsd  0xedf(%rip),%xmm0
cvttsd2si %xmm0,%edx
lea    0xedc(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <sprintf@plt>
cmp    $0x100000,%edx
jl     1163 <format_pretty_size+0x53>
cvtsi2sd %edx,%xmm0
mulsd  0xeb0(%rip),%xmm0
cvttsd2si %xmm0,%edx
lea    0xebe(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <sprintf@plt>
cmp    $0x400,%edx
jl     117d <format_pretty_size+0x6d>
shr    $0xa,%edx
lea    0xead(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <sprintf@plt>
lea    0xea5(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"%.2f GiB\00"
@.str.1 = [9 x i8] c"%.2f MiB\00"
@.str.2 = [7 x i8] c"%d KiB\00"
@.str.3 = [9 x i8] c"%d bytes\00"
define void @format_pretty_size(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i32, i32* %3
%6 = sext i32 %5 to i64
%7 = icmp sge i64 %6, 1073741824
br i1 %7, label %8, label %15
8: ; preds = %2
%9 = load i8*, i8** %4
%10 = load i32, i32* %3
%11 = sitofp i32 %10 to double
%12 = fdiv double %11, 0x41D0000000000000
%13 = fptosi double %12 to i32
%14 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %43
15: ; preds = %2
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = icmp sge i64 %17, 1048576
br i1 %18, label %19, label %26
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = load i32, i32* %3
%22 = sitofp i32 %21 to double
%23 = fdiv double %22, 0x4130000000000000
%24 = fptosi double %23 to i32
%25 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %42
26: ; preds = %15
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = icmp sge i64 %28, 1024
br i1 %29, label %30, label %37
30: ; preds = %26
%31 = load i8*, i8** %4
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = sdiv i64 %33, 1024
%35 = trunc i64 %34 to i32
%36 = call i32 @sprintf(i8* %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %35)
br label %41
37: ; preds = %26
%38 = load i8*, i8** %4
%39 = load i32, i32* %3
%40 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %37, %30
br label %42
42: ; preds = %41, %19
br label %43
43: ; preds = %42, %8
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"%.2f GiB\00"
@.str.1 = [9 x i8] c"%.2f MiB\00"
@.str.2 = [7 x i8] c"%d KiB\00"
@.str.3 = [9 x i8] c"%d bytes\00"
define void @format_pretty_size(i32 %0, i8* nocapture writeonly %1) {
%3 = icmp sgt i32 %0, 1073741823
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = sitofp i32 %0 to double
%6 = fmul double %5, 0x3E10000000000000
%7 = fptosi double %6 to i32
%8 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %23
9: ; preds = %2
%10 = icmp sgt i32 %0, 1048575
br i1 %10, label %11, label %16
11: ; preds = %9
%12 = sitofp i32 %0 to double
%13 = fmul double %12, 0x3EB0000000000000
%14 = fptosi double %13 to i32
%15 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %23
16: ; preds = %9
%17 = icmp sgt i32 %0, 1023
br i1 %17, label %18, label %21
18: ; preds = %16
%19 = lshr i32 %0, 10
%20 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %19)
br label %23
21: ; preds = %16
%22 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %0)
br label %23
23: ; preds = %11, %21, %18, %4
ret void
}