#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 *readable(double w, int slot) {
  static char slots[4][30];
  char *buff;
  buff = slots[slot];
  if (w < 0.0) {
    w = 0.0;
  }
  if (w < 1000.0) {
    sprintf(buff, "%.2lf", w);
    return buff;
  }
  w *= 0.001;
  if (w < 1000.0) {
    sprintf(buff, "%.2lfk", w);
    return buff;
  }
  w *= 0.001;
  if (w < 1000.0) {
    sprintf(buff, "%.2lfM", w);
    return buff;
  }
  w *= 0.001;
  if (w < 1000.0) {
    sprintf(buff, "%.2lfG", w);
    return buff;
  }
  w *= 0.001;
  if (w < 1000.0) {
    sprintf(buff, "%.2lfT", w);
    return buff;
  }
  sprintf(buff, "%lgT", w);
  return buff;
}


x86 assembly (clang, -O0):
<readable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
movslq -0x14(%rbp),%rcx
lea    0x2f15(%rip),%rax
imul   $0x1e,%rcx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    114c <readable+0x3c>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xeac(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1181 <readable+0x71>
mov    -0x20(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
lea    0xea1(%rip),%rsi
call   1030 <sprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <readable+0x1aa>
movsd  0xe7f(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe65(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11c8 <readable+0xb8>
mov    -0x20(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
lea    0xe60(%rip),%rsi
call   1030 <sprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <readable+0x1aa>
movsd  0xe38(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe1e(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    120f <readable+0xff>
mov    -0x20(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
lea    0xe20(%rip),%rsi
call   1030 <sprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <readable+0x1aa>
movsd  0xdf1(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xdd7(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1256 <readable+0x146>
mov    -0x20(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
lea    0xde0(%rip),%rsi
call   1030 <sprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <readable+0x1aa>
movsd  0xdaa(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xd90(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    129d <readable+0x18d>
mov    -0x20(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
lea    0xda0(%rip),%rsi
call   1030 <sprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12ba <readable+0x1aa>
mov    -0x20(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
lea    0xd85(%rip),%rsi
call   1030 <sprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readable>:
push   %rbx
movapd %xmm0,%xmm1
movslq %edi,%rax
mov    %rax,%rcx
shl    $0x5,%rcx
sub    %rax,%rcx
sub    %rax,%rcx
lea    0x2f14(%rip),%rbx
add    %rcx,%rbx
xorpd  %xmm0,%xmm0
maxsd  %xmm1,%xmm0
movsd  0xec1(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    114e <readable+0x3e>
lea    0xec4(%rip),%rsi
jmp    11b1 <readable+0xa1>
mulsd  0xeb2(%rip),%xmm0
ucomisd %xmm0,%xmm1
jbe    1165 <readable+0x55>
lea    0xeb3(%rip),%rsi
jmp    11b1 <readable+0xa1>
mulsd  0xe9b(%rip),%xmm0
ucomisd %xmm0,%xmm1
jbe    117c <readable+0x6c>
lea    0xea3(%rip),%rsi
jmp    11b1 <readable+0xa1>
mulsd  0xe84(%rip),%xmm0
ucomisd %xmm0,%xmm1
jbe    1193 <readable+0x83>
lea    0xe93(%rip),%rsi
jmp    11b1 <readable+0xa1>
mulsd  0xe6d(%rip),%xmm0
ucomisd %xmm0,%xmm1
jbe    11aa <readable+0x9a>
lea    0xe83(%rip),%rsi
jmp    11b1 <readable+0xa1>
lea    0xe81(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@readable.slots = internal global [4 x [30 x i8]] zeroinitializer
@.str = [6 x i8] c"%.2lf\00"
@.str.1 = [7 x i8] c"%.2lfk\00"
@.str.2 = [7 x i8] c"%.2lfM\00"
@.str.3 = [7 x i8] c"%.2lfG\00"
@.str.4 = [7 x i8] c"%.2lfT\00"
@.str.5 = [5 x i8] c"%lgT\00"
define i8* @readable(double %0, i32 %1) {
%3 = alloca i8*
%4 = alloca double
%5 = alloca i32
%6 = alloca i8*
store double %0, double* %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [4 x [30 x i8]], [4 x [30 x i8]]* @readable.slots, i64 0, i64 %8
%10 = getelementptr inbounds [30 x i8], [30 x i8]* %9, i64 0, i64 0
store i8* %10, i8** %6
%11 = load double, double* %4
%12 = fcmp olt double %11, 0.000000e+00
br i1 %12, label %13, label %14
13: ; preds = %2
store double 0.000000e+00, double* %4
br label %14
14: ; preds = %13, %2
%15 = load double, double* %4
%16 = fcmp olt double %15, 1.000000e+03
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = load i8*, i8** %6
%19 = load double, double* %4
%20 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %19)
%21 = load i8*, i8** %6
store i8* %21, i8** %3
br label %67
22: ; preds = %14
%23 = load double, double* %4
%24 = fmul double %23, 1.000000e-03
store double %24, double* %4
%25 = load double, double* %4
%26 = fcmp olt double %25, 1.000000e+03
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i8*, i8** %6
%29 = load double, double* %4
%30 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %29)
%31 = load i8*, i8** %6
store i8* %31, i8** %3
br label %67
32: ; preds = %22
%33 = load double, double* %4
%34 = fmul double %33, 1.000000e-03
store double %34, double* %4
%35 = load double, double* %4
%36 = fcmp olt double %35, 1.000000e+03
br i1 %36, label %37, label %42
37: ; preds = %32
%38 = load i8*, i8** %6
%39 = load double, double* %4
%40 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %39)
%41 = load i8*, i8** %6
store i8* %41, i8** %3
br label %67
42: ; preds = %32
%43 = load double, double* %4
%44 = fmul double %43, 1.000000e-03
store double %44, double* %4
%45 = load double, double* %4
%46 = fcmp olt double %45, 1.000000e+03
br i1 %46, label %47, label %52
47: ; preds = %42
%48 = load i8*, i8** %6
%49 = load double, double* %4
%50 = call i32 @sprintf(i8* %48, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %49)
%51 = load i8*, i8** %6
store i8* %51, i8** %3
br label %67
52: ; preds = %42
%53 = load double, double* %4
%54 = fmul double %53, 1.000000e-03
store double %54, double* %4
%55 = load double, double* %4
%56 = fcmp olt double %55, 1.000000e+03
br i1 %56, label %57, label %62
57: ; preds = %52
%58 = load i8*, i8** %6
%59 = load double, double* %4
%60 = call i32 @sprintf(i8* %58, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %59)
%61 = load i8*, i8** %6
store i8* %61, i8** %3
br label %67
62: ; preds = %52
%63 = load i8*, i8** %6
%64 = load double, double* %4
%65 = call i32 @sprintf(i8* %63, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), double %64)
%66 = load i8*, i8** %6
store i8* %66, i8** %3
br label %67
67: ; preds = %62, %57, %47, %37, %27, %17
%68 = load i8*, i8** %3
ret i8* %68
}

LLVM IR (-O2):
@readable.slots = internal global [4 x [30 x i8]] zeroinitializer
@.str = [6 x i8] c"%.2lf\00"
@.str.1 = [7 x i8] c"%.2lfk\00"
@.str.2 = [7 x i8] c"%.2lfM\00"
@.str.3 = [7 x i8] c"%.2lfG\00"
@.str.4 = [7 x i8] c"%.2lfT\00"
@.str.5 = [5 x i8] c"%lgT\00"
define i8* @readable(double %0, i32 %1) {
%3 = sext i32 %1 to i64
%4 = getelementptr inbounds [4 x [30 x i8]], [4 x [30 x i8]]* @readable.slots, i64 0, i64 %3, i64 0
%5 = fcmp olt double %0, 0.000000e+00
%6 = select i1 %5, double 0.000000e+00, double %0
%7 = fcmp olt double %6, 1.000000e+03
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %6)
br label %32
10: ; preds = %2
%11 = fmul double %6, 1.000000e-03
%12 = fcmp olt double %11, 1.000000e+03
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %11)
br label %32
15: ; preds = %10
%16 = fmul double %11, 1.000000e-03
%17 = fcmp olt double %16, 1.000000e+03
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %16)
br label %32
20: ; preds = %15
%21 = fmul double %16, 1.000000e-03
%22 = fcmp olt double %21, 1.000000e+03
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = tail call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %21)
br label %32
25: ; preds = %20
%26 = fmul double %21, 1.000000e-03
%27 = fcmp olt double %26, 1.000000e+03
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = tail call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %26)
br label %32
30: ; preds = %25
%31 = tail call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), double %26)
br label %32
32: ; preds = %30, %28, %23, %18, %13, %8
ret i8* %4
}