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

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, int);
char *makeHumanReadableSize(char *result, uint64_t size) {
  if (size >= (1024 * 1024 * 1024)) {
    sprintf(result, "%.3f Gb",
            (float)((float)size / (float)(1024 * 1024 * 1024)));
  } else if (size >= (1024 * 1024)) {
    sprintf(result, "%d Mb", (int)(size / (1024 * 1024)));
  } else if (size >= 1024) {
    sprintf(result, "%d Kb", (int)(size / 1024));
  } else {
    sprintf(result, "%d b", (int)size);
  }
  return result;
}


x86 assembly (clang, -O0):
<makeHumanReadableSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x40000000,-0xc(%rbp)
jl     1156 <makeHumanReadableSize+0x46>
mov    -0x8(%rbp),%rdi
cvtsi2ssl -0xc(%rbp),%xmm0
movss  0xec3(%rip),%xmm1
divss  %xmm1,%xmm0
cvttss2si %xmm0,%edx
lea    0xeb8(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11d1 <makeHumanReadableSize+0xc1>
cmpl   $0x100000,-0xc(%rbp)
jl     1185 <makeHumanReadableSize+0x75>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    $0x100000,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
lea    0xe91(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11cc <makeHumanReadableSize+0xbc>
cmpl   $0x400,-0xc(%rbp)
jl     11b4 <makeHumanReadableSize+0xa4>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
lea    0xe68(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11c7 <makeHumanReadableSize+0xb7>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe56(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11cc <makeHumanReadableSize+0xbc>
jmp    11d1 <makeHumanReadableSize+0xc1>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeHumanReadableSize>:
push   %rbx
mov    %esi,%edx
mov    %rdi,%rbx
cmp    $0x40000000,%esi
jl     1137 <makeHumanReadableSize+0x27>
cvtsi2ss %edx,%xmm0
mulss  0xed6(%rip),%xmm0
cvttss2si %xmm0,%edx
lea    0xecf(%rip),%rsi
jmp    1166 <makeHumanReadableSize+0x56>
cmp    $0x100000,%edx
jl     114b <makeHumanReadableSize+0x3b>
shr    $0x14,%edx
lea    0xec3(%rip),%rsi
jmp    1166 <makeHumanReadableSize+0x56>
cmp    $0x400,%edx
jl     115f <makeHumanReadableSize+0x4f>
shr    $0xa,%edx
lea    0xeb5(%rip),%rsi
jmp    1166 <makeHumanReadableSize+0x56>
lea    0xeb2(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

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

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