#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 *malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, double, char *);
char *uireadablebytes(unsigned int bytes) {
  char *result = malloc(10);
  if (result == NULL) {
  }
  char *resultsufix = NULL;
  double resultnumber = 0;
  if (bytes > 1000.0) {
    if (bytes > 1000000.0) {
      if (bytes > 1000000000.0) {
        resultnumber = bytes / 1073741824.0;
        resultsufix = "GB";
      } else {
        resultnumber = bytes / 1048576.0;
        resultsufix = "MB";
      }
    } else {
      resultnumber = bytes / 1024.0;
      resultsufix = "KB";
    }
  } else {
    resultnumber = bytes;
    resultsufix = "  ";
  }
  snprintf(result, 10, "%3.2f%s", resultnumber, resultsufix);
  return result;
}


x86 assembly (clang, -O0):
<uireadablebytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0xa,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1149 <uireadablebytes+0x29>
jmp    1149 <uireadablebytes+0x29>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x4(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  0xe97(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1222 <uireadablebytes+0x102>
mov    -0x4(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  0xe85(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11f9 <uireadablebytes+0xd9>
mov    -0x4(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  0xe7b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11d0 <uireadablebytes+0xb0>
mov    -0x4(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  0xe71(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
lea    0xe69(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11f4 <uireadablebytes+0xd4>
mov    -0x4(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  0xe40(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
lea    0xe43(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    121d <uireadablebytes+0xfd>
mov    -0x4(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  0xe07(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
lea    0xe1d(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    123a <uireadablebytes+0x11a>
mov    -0x4(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
lea    0xe03(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
movsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rcx
mov    $0xa,%esi
lea    0xde9(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uireadablebytes>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0xa,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %ebp,%eax
cvtsi2sd %rax,%xmm0
cmp    $0x3e9,%ebp
jb     1162 <uireadablebytes+0x42>
cmp    $0xf4241,%ebp
jb     116b <uireadablebytes+0x4b>
cmp    $0x3b9aca01,%ebp
jb     117c <uireadablebytes+0x5c>
mulsd  0xeb7(%rip),%xmm0
lea    0xeb8(%rip),%rcx
jmp    118b <uireadablebytes+0x6b>
lea    0xeb8(%rip),%rcx
jmp    118b <uireadablebytes+0x6b>
mulsd  0xe8d(%rip),%xmm0
lea    0xea4(%rip),%rcx
jmp    118b <uireadablebytes+0x6b>
mulsd  0xe84(%rip),%xmm0
lea    0xe90(%rip),%rcx
lea    0xe92(%rip),%rdx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <snprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"GB\00"
@.str.1 = [3 x i8] c"MB\00"
@.str.2 = [3 x i8] c"KB\00"
@.str.3 = [3 x i8] c" \00"
@.str.4 = [8 x i8] c"%3.2f%s\00"
define i8* @uireadablebytes(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca double
store i32 %0, i32* %2
%6 = call i8* @malloc(i32 10)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
br label %10
10: ; preds = %9, %1
store i8* null, i8** %4
store double 0.000000e+00, double* %5
%11 = load i32, i32* %2
%12 = uitofp i32 %11 to double
%13 = fcmp ogt double %12, 1.000000e+03
br i1 %13, label %14, label %36
14: ; preds = %10
%15 = load i32, i32* %2
%16 = uitofp i32 %15 to double
%17 = fcmp ogt double %16, 1.000000e+06
br i1 %17, label %18, label %31
18: ; preds = %14
%19 = load i32, i32* %2
%20 = uitofp i32 %19 to double
%21 = fcmp ogt double %20, 1.000000e+09
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i32, i32* %2
%24 = uitofp i32 %23 to double
%25 = fdiv double %24, 0x41D0000000000000
store double %25, double* %5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %4
br label %30
26: ; preds = %18
%27 = load i32, i32* %2
%28 = uitofp i32 %27 to double
%29 = fdiv double %28, 0x4130000000000000
store double %29, double* %5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %4
br label %30
30: ; preds = %26, %22
br label %35
31: ; preds = %14
%32 = load i32, i32* %2
%33 = uitofp i32 %32 to double
%34 = fdiv double %33, 1.024000e+03
store double %34, double* %5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %4
br label %35
35: ; preds = %31, %30
br label %39
36: ; preds = %10
%37 = load i32, i32* %2
%38 = uitofp i32 %37 to double
store double %38, double* %5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %4
br label %39
39: ; preds = %36, %35
%40 = load i8*, i8** %3
%41 = load double, double* %5
%42 = load i8*, i8** %4
%43 = call i32 @snprintf(i8* %40, i32 10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), double %41, i8* %42)
%44 = load i8*, i8** %3
ret i8* %44
}

LLVM IR (-O2):
@.str = [3 x i8] c"GB\00"
@.str.1 = [3 x i8] c"MB\00"
@.str.2 = [3 x i8] c"KB\00"
@.str.3 = [3 x i8] c" \00"
@.str.4 = [8 x i8] c"%3.2f%s\00"
define i8* @uireadablebytes(i32 %0) {
%2 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%3 = uitofp i32 %0 to double
%4 = icmp ugt i32 %0, 1000
br i1 %4, label %5, label %15
5: ; preds = %1
%6 = icmp ugt i32 %0, 1000000
br i1 %6, label %7, label %13
7: ; preds = %5
%8 = icmp ugt i32 %0, 1000000000
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = fmul double %3, 0x3E10000000000000
br label %15
11: ; preds = %7
%12 = fmul double %3, 0x3EB0000000000000
br label %15
13: ; preds = %5
%14 = fmul double %3, 0x3F50000000000000
br label %15
15: ; preds = %1, %13, %11, %9
%16 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %9 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %11 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %13 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), %1 ]
%17 = phi double [ %10, %9 ], [ %12, %11 ], [ %14, %13 ], [ %3, %1 ]
%18 = tail call i32 @snprintf(i8* %2, i32 10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), double %17, i8* %16)
ret i8* %2
}