#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 */
scalar_t__ asprintf(char **, char *, double, char const *);
int /*<<< orphan*/ die(char *);
char *human_readable(unsigned long size) {
  const char *suffixes[] = {"B", "K", "M", "G", "T"};
  const int len = sizeof suffixes / sizeof suffixes[0];
  double s = size;
  int factor = 1;
  char *out;
  while (s >= 1024.0 && factor < len) {
    s /= 1024.0;
    factor++;
  }
  if (asprintf(&out, "%.2lf%s", s, suffixes[factor - 1]) < 0)
    die("Memory allocation failed");
  return out;
}


x86 assembly (clang, -O0):
<human_readable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
xorps  %xmm0,%xmm0
movaps %xmm0,-0x20(%rbp)
movaps %xmm0,-0x30(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xee2(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xed9(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xed0(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xec7(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xebe(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x5,-0x34(%rbp)
movaps 0xe7c(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe7b(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x1,-0x44(%rbp)
movsd  -0x40(%rbp),%xmm0
xor    %eax,%eax
movsd  0xe61(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x51(%rbp)
jb     11d6 <human_readable+0xb6>
cmpl   $0x5,-0x44(%rbp)
setl   %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    11e6 <human_readable+0xc6>
jmp    120a <human_readable+0xea>
movsd  -0x40(%rbp),%xmm0
movsd  0xe2d(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11b0 <human_readable+0x90>
movsd  -0x40(%rbp),%xmm0
mov    -0x44(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x30(%rbp,%rax,8),%rdx
lea    -0x50(%rbp),%rdi
lea    0xe0b(%rip),%rsi
call   1030 <asprintf@plt>
cmp    $0x0,%rax
jge    1242 <human_readable+0x122>
lea    0xdfd(%rip),%rdi
call   1040 <die@plt>
mov    -0x50(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<human_readable>:
sub    $0x38,%rsp
lea    0xf05(%rip),%rdx
mov    %rdx,0x10(%rsp)
lea    0xefb(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xef1(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xee7(%rip),%rax
mov    %rax,0x28(%rsp)
lea    0xedd(%rip),%rax
movq   %rdi,%xmm1
punpckldq 0xe98(%rip),%xmm1
subpd  0xea0(%rip),%xmm1
mov    %rax,0x30(%rsp)
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
cmp    $0x400,%rdi
jb     11e1 <human_readable+0xc1>
mulsd  0xe8e(%rip),%xmm0
mov    $0x1,%eax
ucomisd 0xe89(%rip),%xmm0
jb     11dc <human_readable+0xbc>
mulsd  0xe77(%rip),%xmm0
mov    $0x2,%eax
ucomisd 0xe72(%rip),%xmm0
jb     11dc <human_readable+0xbc>
mulsd  0xe60(%rip),%xmm0
mov    $0x3,%eax
ucomisd 0xe5b(%rip),%xmm0
jb     11dc <human_readable+0xbc>
mulsd  0xe49(%rip),%xmm0
mov    $0x4,%eax
mov    0x10(%rsp,%rax,8),%rdx
lea    0xe52(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1030 <asprintf@plt>
test   %rax,%rax
jns    1203 <human_readable+0xe3>
lea    0xe44(%rip),%rdi
call   1040 <die@plt>
mov    0x8(%rsp),%rax
add    $0x38,%rsp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"B\00"
@.str.1 = [2 x i8] c"K\00"
@.str.2 = [2 x i8] c"M\00"
@.str.3 = [2 x i8] c"G\00"
@.str.4 = [2 x i8] c"T\00"
@.str.5 = [8 x i8] c"%.2lf%s\00"
@.str.6 = [25 x i8] c"Memory allocation failed\00"
define i8* @human_readable(i64 %0) {
%2 = alloca i64
%3 = alloca [5 x i8*]
%4 = alloca i32
%5 = alloca double
%6 = alloca i32
%7 = alloca i8*
store i64 %0, i64* %2
%8 = bitcast [5 x i8*]* %3 to i8*
%9 = bitcast i8* %8 to [5 x i8*]*
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %9, i32 0, i32 0
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0), i8** %10
%11 = getelementptr inbounds [5 x i8*], [5 x i8*]* %9, i32 0, i32 1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i32 0, i32 0), i8** %11
%12 = getelementptr inbounds [5 x i8*], [5 x i8*]* %9, i32 0, i32 2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8** %12
%13 = getelementptr inbounds [5 x i8*], [5 x i8*]* %9, i32 0, i32 3
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i32 0, i32 0), i8** %13
%14 = getelementptr inbounds [5 x i8*], [5 x i8*]* %9, i32 0, i32 4
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i32 0, i32 0), i8** %14
store i32 5, i32* %4
%15 = load i64, i64* %2
%16 = uitofp i64 %15 to double
store double %16, double* %5
store i32 1, i32* %6
br label %17
17: ; preds = %25, %1
%18 = load double, double* %5
%19 = fcmp oge double %18, 1.024000e+03
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* %6
%22 = icmp slt i32 %21, 5
br label %23
23: ; preds = %20, %17
%24 = phi i1 [ false, %17 ], [ %22, %20 ]
br i1 %24, label %25, label %30
25: ; preds = %23
%26 = load double, double* %5
%27 = fdiv double %26, 1.024000e+03
store double %27, double* %5
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
br label %17
30: ; preds = %23
%31 = load double, double* %5
%32 = load i32, i32* %6
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 %34
%36 = load i8*, i8** %35
%37 = call i64 @asprintf(i8** %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), double %31, i8* %36)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %30
%40 = call i32 @die(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
br label %41
41: ; preds = %39, %30
%42 = load i8*, i8** %7
ret i8* %42
}

LLVM IR (-O2):
@.str = [2 x i8] c"B\00"
@.str.1 = [2 x i8] c"K\00"
@.str.2 = [2 x i8] c"M\00"
@.str.3 = [2 x i8] c"G\00"
@.str.4 = [2 x i8] c"T\00"
@.str.5 = [8 x i8] c"%.2lf%s\00"
@.str.6 = [25 x i8] c"Memory allocation failed\00"
define i8* @human_readable(i64 %0) {
%2 = alloca [5 x i8*]
%3 = alloca i8*
%4 = bitcast [5 x i8*]* %2 to i8*
%5 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 0
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %5
%6 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 3
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 4
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8** %9
%10 = uitofp i64 %0 to double
%11 = bitcast i8** %3 to i8*
%12 = icmp ugt i64 %0, 1023
br i1 %12, label %13, label %29
13: ; preds = %1
%14 = fmul double %10, 0x3F50000000000000
%15 = fcmp ult double %14, 1.024000e+03
br i1 %15, label %24, label %16
16: ; preds = %13
%17 = fmul double %14, 0x3F50000000000000
%18 = fcmp ult double %17, 1.024000e+03
br i1 %18, label %24, label %19
19: ; preds = %16
%20 = fmul double %17, 0x3F50000000000000
%21 = fcmp ult double %20, 1.024000e+03
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = fmul double %20, 0x3F50000000000000
br label %24
24: ; preds = %22, %19, %16, %13
%25 = phi i64 [ 1, %13 ], [ 2, %16 ], [ 3, %19 ], [ 4, %22 ]
%26 = phi double [ %14, %13 ], [ %17, %16 ], [ %20, %19 ], [ %23, %22 ]
%27 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 %25
%28 = load i8*, i8** %27
br label %29
29: ; preds = %24, %1
%30 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %1 ], [ %28, %24 ]
%31 = phi double [ %10, %1 ], [ %26, %24 ]
%32 = call i64 @asprintf(i8** %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), double %31, i8* %30)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = call i32 @die(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
br label %36
36: ; preds = %34, %29
%37 = load i8*, i8** %3
ret i8* %37
}