#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 */
char *mp_malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, float);
int /*<<< orphan*/ strcat(char *, char *);
char *mp_human_size(float size) {
  char *out;
  int exp;
  for (exp = 0; exp < 5 && size > 1024; exp++) {
    size /= 1024;
  }
  out = mp_malloc(14);
  sprintf(out, "%.2f ", size);
  switch (exp) {
  case 1:
    strcat(out, "KiB");
    break;
  case 2:
    strcat(out, "MiB");
    break;
  case 3:
    strcat(out, "GiB");
    break;
  case 4:
    strcat(out, "TiB");
    break;
  }
  return out;
}


x86 assembly (clang, -O0):
<mp_human_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x5,-0x14(%rbp)
mov    %al,-0x15(%rbp)
jge    1169 <mp_human_size+0x39>
movss  -0x4(%rbp),%xmm0
movss  0xea0(%rip),%xmm1
ucomiss %xmm1,%xmm0
seta   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1179 <mp_human_size+0x49>
jmp    119d <mp_human_size+0x6d>
movss  -0x4(%rbp),%xmm0
movss  0xe7a(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1144 <mp_human_size+0x14>
mov    $0xe,%edi
call   1050 <mp_malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
movss  -0x4(%rbp),%xmm0
lea    0xe59(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x3,%eax
ja     1238 <mp_human_size+0x108>
mov    -0x20(%rbp),%rax
lea    0xe24(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
lea    0xe26(%rip),%rsi
call   1030 <strcat@plt>
jmp    1238 <mp_human_size+0x108>
mov    -0x10(%rbp),%rdi
lea    0xe15(%rip),%rsi
call   1030 <strcat@plt>
jmp    1238 <mp_human_size+0x108>
mov    -0x10(%rbp),%rdi
lea    0xe04(%rip),%rsi
call   1030 <strcat@plt>
jmp    1238 <mp_human_size+0x108>
mov    -0x10(%rbp),%rdi
lea    0xdf3(%rip),%rsi
call   1030 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mp_human_size>:
push   %rbp
push   %rbx
push   %rax
ucomiss 0xec6(%rip),%xmm0
jbe    11aa <mp_human_size+0x7a>
mulss  0xec0(%rip),%xmm0
xor    %ebp,%ebp
ucomiss 0xeb3(%rip),%xmm0
jbe    11d4 <mp_human_size+0xa4>
mulss  0xea9(%rip),%xmm0
mov    $0x1,%ebp
ucomiss 0xe99(%rip),%xmm0
jbe    11d4 <mp_human_size+0xa4>
mulss  0xe93(%rip),%xmm0
mov    $0x2,%ebp
ucomiss 0xe83(%rip),%xmm0
jbe    11d4 <mp_human_size+0xa4>
mulss  0xe7d(%rip),%xmm0
mov    $0x3,%ebp
ucomiss 0xe6d(%rip),%xmm0
jbe    11d4 <mp_human_size+0xa4>
mulss  0xe67(%rip),%xmm0
movss  %xmm0,0x4(%rsp)
mov    $0x4,%ebp
jmp    11da <mp_human_size+0xaa>
mov    $0xe,%edi
movss  %xmm0,0x4(%rsp)
call   1050 <mp_malloc@plt>
mov    %rax,%rbx
lea    0xe54(%rip),%rsi
mov    %rax,%rdi
movss  0x4(%rsp),%xmm0
call   1040 <sprintf@plt>
jmp    123d <mp_human_size+0x10d>
movss  %xmm0,0x4(%rsp)
mov    $0xe,%edi
call   1050 <mp_malloc@plt>
mov    %rax,%rbx
lea    0xe2a(%rip),%rsi
mov    %rax,%rdi
movss  0x4(%rsp),%xmm0
call   1040 <sprintf@plt>
cmp    $0x3,%ebp
ja     123d <mp_human_size+0x10d>
mov    %ebp,%eax
lea    0xdfe(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe04(%rip),%rsi
jmp    1235 <mp_human_size+0x105>
lea    0xdff(%rip),%rsi
jmp    1235 <mp_human_size+0x105>
lea    0xdfa(%rip),%rsi
jmp    1235 <mp_human_size+0x105>
lea    0xdf5(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcat@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%.2f \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"
@.str.4 = [4 x i8] c"TiB\00"
define i8* @mp_human_size(float %0) {
%2 = alloca float
%3 = alloca i8*
%4 = alloca i32
store float %0, float* %2
store i32 0, i32* %4
br label %5
5: ; preds = %16, %1
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 5
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = load float, float* %2
%10 = fcmp ogt float %9, 1.024000e+03
br label %11
11: ; preds = %8, %5
%12 = phi i1 [ false, %5 ], [ %10, %8 ]
br i1 %12, label %13, label %19
13: ; preds = %11
%14 = load float, float* %2
%15 = fdiv float %14, 1.024000e+03
store float %15, float* %2
br label %16
16: ; preds = %13
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %5
19: ; preds = %11
%20 = call i8* @mp_malloc(i32 14)
store i8* %20, i8** %3
%21 = load i8*, i8** %3
%22 = load float, float* %2
%23 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), float %22)
%24 = load i32, i32* %4
switch i32 %24, label %37 [
i32 1, label %25
i32 2, label %28
i32 3, label %31
i32 4, label %34
]
25: ; preds = %19
%26 = load i8*, i8** %3
%27 = call i32 @strcat(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %37
28: ; preds = %19
%29 = load i8*, i8** %3
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %37
31: ; preds = %19
%32 = load i8*, i8** %3
%33 = call i32 @strcat(i8* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %37
34: ; preds = %19
%35 = load i8*, i8** %3
%36 = call i32 @strcat(i8* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %37
37: ; preds = %19, %34, %31, %28, %25
%38 = load i8*, i8** %3
ret i8* %38
}

LLVM IR (-O2):
@.str = [6 x i8] c"%.2f \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"
@.str.4 = [4 x i8] c"TiB\00"
define i8* @mp_human_size(float %0) {
%2 = fcmp ogt float %0, 1.024000e+03
br i1 %2, label %6, label %3
3: ; preds = %1
%4 = tail call i8* @mp_malloc(i32 14)
%5 = tail call i32 @sprintf(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), float %0)
br label %33
6: ; preds = %1
%7 = fmul float %0, 0x3F50000000000000
%8 = fcmp ogt float %7, 1.024000e+03
br i1 %8, label %9, label %20
9: ; preds = %6
%10 = fmul float %7, 0x3F50000000000000
%11 = fcmp ogt float %10, 1.024000e+03
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = fmul float %10, 0x3F50000000000000
%14 = fcmp ogt float %13, 1.024000e+03
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = fmul float %13, 0x3F50000000000000
%17 = fcmp ogt float %16, 1.024000e+03
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = fmul float %16, 0x3F50000000000000
br label %20
20: ; preds = %18, %15, %12, %9, %6
%21 = phi i32 [ 0, %6 ], [ 1, %9 ], [ 2, %12 ], [ 3, %15 ], [ 4, %18 ]
%22 = phi float [ %7, %6 ], [ %10, %9 ], [ %13, %12 ], [ %16, %15 ], [ %19, %18 ]
%23 = tail call i8* @mp_malloc(i32 14)
%24 = tail call i32 @sprintf(i8* dereferenceable(1) %23, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), float %22)
switch i32 %21, label %33 [
i32 0, label %25
i32 1, label %27
i32 2, label %29
i32 3, label %31
]
25: ; preds = %20
%26 = tail call i32 @strcat(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %33
27: ; preds = %20
%28 = tail call i32 @strcat(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %33
29: ; preds = %20
%30 = tail call i32 @strcat(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %33
31: ; preds = %20
%32 = tail call i32 @strcat(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %33
33: ; preds = %3, %20, %31, %29, %27, %25
%34 = phi i8* [ %4, %3 ], [ %23, %20 ], [ %23, %31 ], [ %23, %29 ], [ %23, %27 ], [ %23, %25 ]
ret i8* %34
}