#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 */
int /*<<< orphan*/ exit(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, double);
char *scale_bytes(double bytes) {
  char *string;
  if ((string = (char *)malloc(50 * sizeof(char))) == NULL) {
    printf("[Error  ]\tInsufficient physical memory");
    exit(-1);
  }
  if (bytes < 1024)
    sprintf(string, "%15.0f B", bytes);
  else if (bytes < 1024 * 1024)
    sprintf(string, "%15.2f KiB", bytes / 1024);
  else if (bytes < 1024 * 1024 * 1024)
    sprintf(string, "%15.2f MiB", bytes / 1024 / 1024);
  else
    sprintf(string, "%15.2f GiB", bytes / 1024 / 1024 / 1024);
  return string;
}


x86 assembly (clang, -O0):
<scale_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    $0x32,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    117b <scale_bytes+0x3b>
lea    0xeac(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
movsd  0xe7d(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11a8 <scale_bytes+0x68>
mov    -0x10(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
lea    0xea1(%rip),%rsi
call   1050 <sprintf@plt>
jmp    1269 <scale_bytes+0x129>
movsd  0xe58(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11e1 <scale_bytes+0xa1>
mov    -0x10(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
movsd  0xe34(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe71(%rip),%rsi
call   1050 <sprintf@plt>
jmp    1264 <scale_bytes+0x124>
movsd  0xe27(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1226 <scale_bytes+0xe6>
mov    -0x10(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
movsd  0xdfb(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xdef(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe37(%rip),%rsi
call   1050 <sprintf@plt>
jmp    125f <scale_bytes+0x11f>
mov    -0x10(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
movsd  0xdc9(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xdbd(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xdb1(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe04(%rip),%rsi
call   1050 <sprintf@plt>
jmp    1264 <scale_bytes+0x124>
jmp    1269 <scale_bytes+0x129>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scale_bytes>:
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,0x8(%rsp)
mov    $0x32,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     11e4 <scale_bytes+0xa4>
mov    %rax,%rbx
movsd  0xe97(%rip),%xmm1
movsd  0x8(%rsp),%xmm0
ucomisd %xmm0,%xmm1
jbe    117e <scale_bytes+0x3e>
lea    0xecb(%rip),%rsi
jmp    11d3 <scale_bytes+0x93>
movsd  0xe82(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    119d <scale_bytes+0x5d>
mulsd  0xe84(%rip),%xmm0
lea    0xeb5(%rip),%rsi
jmp    11d3 <scale_bytes+0x93>
movsd  0xe6b(%rip),%xmm1
ucomisd %xmm0,%xmm1
movsd  0xe67(%rip),%xmm1
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
jbe    11c4 <scale_bytes+0x84>
lea    0xe99(%rip),%rsi
jmp    11d3 <scale_bytes+0x93>
mulsd  0xe4c(%rip),%xmm0
lea    0xe93(%rip),%rsi
mov    %rbx,%rdi
call   1050 <sprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe35(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [39 x i8] c"[Error ]\09Insufficient physical memory\00"
@.str.1 = [9 x i8] c"%15.0f B\00"
@.str.2 = [11 x i8] c"%15.2f KiB\00"
@.str.3 = [11 x i8] c"%15.2f MiB\00"
@.str.4 = [11 x i8] c"%15.2f GiB\00"
define i8* @scale_bytes(double %0) {
%2 = alloca double
%3 = alloca i8*
store double %0, double* %2
%4 = call i64 @malloc(i32 50)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 -1)
unreachable
10: ; preds = %1
%11 = load double, double* %2
%12 = fcmp olt double %11, 1.024000e+03
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i8*, i8** %3
%15 = load double, double* %2
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %15)
br label %43
17: ; preds = %10
%18 = load double, double* %2
%19 = fcmp olt double %18, 0x4130000000000000
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i8*, i8** %3
%22 = load double, double* %2
%23 = fdiv double %22, 1.024000e+03
%24 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), double %23)
br label %42
25: ; preds = %17
%26 = load double, double* %2
%27 = fcmp olt double %26, 0x41D0000000000000
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = load i8*, i8** %3
%30 = load double, double* %2
%31 = fdiv double %30, 1.024000e+03
%32 = fdiv double %31, 1.024000e+03
%33 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), double %32)
br label %41
34: ; preds = %25
%35 = load i8*, i8** %3
%36 = load double, double* %2
%37 = fdiv double %36, 1.024000e+03
%38 = fdiv double %37, 1.024000e+03
%39 = fdiv double %38, 1.024000e+03
%40 = call i32 @sprintf(i8* %35, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), double %39)
br label %41
41: ; preds = %34, %28
br label %42
42: ; preds = %41, %20
br label %43
43: ; preds = %42, %13
%44 = load i8*, i8** %3
ret i8* %44
}

LLVM IR (-O2):
@.str = [39 x i8] c"[Error ]\09Insufficient physical memory\00"
@.str.1 = [9 x i8] c"%15.0f B\00"
@.str.2 = [11 x i8] c"%15.2f KiB\00"
@.str.3 = [11 x i8] c"%15.2f MiB\00"
@.str.4 = [11 x i8] c"%15.2f GiB\00"
define i8* @scale_bytes(double %0) {
%2 = tail call i64 @malloc(i32 50)
%3 = inttoptr i64 %2 to i8*
%4 = icmp eq i64 %2, 0
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %1
%9 = fcmp olt double %0, 1.024000e+03
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = tail call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %0)
br label %26
12: ; preds = %8
%13 = fcmp olt double %0, 0x4130000000000000
br i1 %13, label %14, label %17
14: ; preds = %12
%15 = fmul double %0, 0x3F50000000000000
%16 = tail call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), double %15)
br label %26
17: ; preds = %12
%18 = fcmp olt double %0, 0x41D0000000000000
%19 = fmul double %0, 0x3F50000000000000
%20 = fmul double %19, 0x3F50000000000000
br i1 %18, label %21, label %23
21: ; preds = %17
%22 = tail call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), double %20)
br label %26
23: ; preds = %17
%24 = fmul double %20, 0x3F50000000000000
%25 = tail call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), double %24)
br label %26
26: ; preds = %14, %23, %21, %10
ret i8* %3
}