#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*/ sprintf(char *, char *, double);
char *format_bytes(char *sout, double x) {
  if (x > (1024. * 1024. * 1024.)) {
    sprintf(sout, "%8.2fb", x / (1024. * 1024. * 1024.));
  } else if (x > (1024. * 1024.)) {
    sprintf(sout, "%8.2fm", x / (1024. * 1024.));
  } else if (x > 1024.) {
    sprintf(sout, "%8.2fk", x / 1024.);
  } else {
    sprintf(sout, "%8.2f ", x);
  }
  return (sout);
}


x86 assembly (clang, -O0):
<format_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xed2(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    115e <format_bytes+0x4e>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
movsd  0xeb7(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xec4(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11f7 <format_bytes+0xe7>
movsd  -0x10(%rbp),%xmm0
movsd  0xe9d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    119b <format_bytes+0x8b>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
movsd  0xe82(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe8e(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11f2 <format_bytes+0xe2>
movsd  -0x10(%rbp),%xmm0
movsd  0xe68(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11d8 <format_bytes+0xc8>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
movsd  0xe4d(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe58(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11ed <format_bytes+0xdd>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
lea    0xe45(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11f2 <format_bytes+0xe2>
jmp    11f7 <format_bytes+0xe7>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_bytes>:
push   %rbx
mov    %rdi,%rbx
ucomisd 0xee4(%rip),%xmm0
jbe    112f <format_bytes+0x1f>
mulsd  0xf02(%rip),%xmm0
lea    0xf03(%rip),%rsi
jmp    116c <format_bytes+0x5c>
ucomisd 0xed1(%rip),%xmm0
jbe    114a <format_bytes+0x3a>
mulsd  0xedf(%rip),%xmm0
lea    0xeef(%rip),%rsi
jmp    116c <format_bytes+0x5c>
ucomisd 0xebe(%rip),%xmm0
jbe    1165 <format_bytes+0x55>
mulsd  0xebc(%rip),%xmm0
lea    0xedb(%rip),%rsi
jmp    116c <format_bytes+0x5c>
lea    0xed9(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%8.2fb\00"
@.str.1 = [7 x i8] c"%8.2fm\00"
@.str.2 = [7 x i8] c"%8.2fk\00"
@.str.3 = [7 x i8] c"%8.2f \00"
define i8* @format_bytes(i8* %0, double %1) {
%3 = alloca i8*
%4 = alloca double
store i8* %0, i8** %3
store double %1, double* %4
%5 = load double, double* %4
%6 = fcmp ogt double %5, 0x41D0000000000000
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i8*, i8** %3
%9 = load double, double* %4
%10 = fdiv double %9, 0x41D0000000000000
%11 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %10)
br label %34
12: ; preds = %2
%13 = load double, double* %4
%14 = fcmp ogt double %13, 0x4130000000000000
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i8*, i8** %3
%17 = load double, double* %4
%18 = fdiv double %17, 0x4130000000000000
%19 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %18)
br label %33
20: ; preds = %12
%21 = load double, double* %4
%22 = fcmp ogt double %21, 1.024000e+03
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = load i8*, i8** %3
%25 = load double, double* %4
%26 = fdiv double %25, 1.024000e+03
%27 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %26)
br label %32
28: ; preds = %20
%29 = load i8*, i8** %3
%30 = load double, double* %4
%31 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %30)
br label %32
32: ; preds = %28, %23
br label %33
33: ; preds = %32, %15
br label %34
34: ; preds = %33, %7
%35 = load i8*, i8** %3
ret i8* %35
}

LLVM IR (-O2):
@.str = [7 x i8] c"%8.2fb\00"
@.str.1 = [7 x i8] c"%8.2fm\00"
@.str.2 = [7 x i8] c"%8.2fk\00"
@.str.3 = [7 x i8] c"%8.2f \00"
define i8* @format_bytes(i8* returned writeonly %0, double %1) {
%3 = fcmp ogt double %1, 0x41D0000000000000
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = fmul double %1, 0x3E10000000000000
%6 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %5)
br label %19
7: ; preds = %2
%8 = fcmp ogt double %1, 0x4130000000000000
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = fmul double %1, 0x3EB0000000000000
%11 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %10)
br label %19
12: ; preds = %7
%13 = fcmp ogt double %1, 1.024000e+03
br i1 %13, label %14, label %17
14: ; preds = %12
%15 = fmul double %1, 0x3F50000000000000
%16 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %15)
br label %19
17: ; preds = %12
%18 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %1)
br label %19
19: ; preds = %9, %17, %14, %4
ret i8* %0
}