#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*/ snprintf(char *, int, char *, double);
int /*<<< orphan*/ strcpy(char *, char *);
const char *print_decimal(double number) {
  static char buf[32];
  double n = number >= 0 ? number : -number;
  if (n >= 9.95)
    snprintf(buf, sizeof buf, "%.0f", number);
  else if (n >= 0.95)
    snprintf(buf, sizeof buf, "%.1f", number);
  else if (n >= 0.001)
    snprintf(buf, sizeof buf, "%.1g", number);
  else if (n >= 0.0005)
    snprintf(buf, sizeof buf, "%.3f", number);
  else
    strcpy(buf, "0");
  return buf;
}


x86 assembly (clang, -O0):
<print_decimal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     114e <print_decimal+0x2e>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    116f <print_decimal+0x4f>
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe7a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11b2 <print_decimal+0x92>
movsd  -0x8(%rbp),%xmm0
lea    0x2ea4(%rip),%rdi
mov    $0x20,%esi
lea    0xe78(%rip),%rdx
call   1040 <snprintf@plt>
jmp    127f <print_decimal+0x15f>
movsd  -0x10(%rbp),%xmm0
movsd  0xe49(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11eb <print_decimal+0xcb>
movsd  -0x8(%rbp),%xmm0
lea    0x2e6b(%rip),%rdi
mov    $0x20,%esi
lea    0xe44(%rip),%rdx
call   1040 <snprintf@plt>
jmp    127a <print_decimal+0x15a>
movsd  -0x10(%rbp),%xmm0
movsd  0xe18(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1224 <print_decimal+0x104>
movsd  -0x8(%rbp),%xmm0
lea    0x2e32(%rip),%rdi
mov    $0x20,%esi
lea    0xe10(%rip),%rdx
call   1040 <snprintf@plt>
jmp    1275 <print_decimal+0x155>
movsd  -0x10(%rbp),%xmm0
movsd  0xde7(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     125d <print_decimal+0x13d>
movsd  -0x8(%rbp),%xmm0
lea    0x2df9(%rip),%rdi
mov    $0x20,%esi
lea    0xddc(%rip),%rdx
call   1040 <snprintf@plt>
jmp    1270 <print_decimal+0x150>
lea    0x2ddc(%rip),%rdi
lea    0xdc9(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1275 <print_decimal+0x155>
jmp    127a <print_decimal+0x15a>
jmp    127f <print_decimal+0x15f>
lea    0x2dba(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_decimal>:
push   %rax
movapd 0xed7(%rip),%xmm2
xorpd  %xmm0,%xmm2
xorpd  %xmm1,%xmm1
cmplesd %xmm0,%xmm1
movapd %xmm1,%xmm3
andpd  %xmm0,%xmm3
andnpd %xmm2,%xmm1
orpd   %xmm3,%xmm1
lea    0x2ef3(%rip),%rdi
ucomisd 0xebb(%rip),%xmm1
jae    1183 <print_decimal+0x63>
ucomisd 0xeb9(%rip),%xmm1
jae    118c <print_decimal+0x6c>
ucomisd 0xeb7(%rip),%xmm1
jae    1195 <print_decimal+0x75>
ucomisd 0xeb5(%rip),%xmm1
jae    119e <print_decimal+0x7e>
lea    0xec8(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11af <print_decimal+0x8f>
lea    0xea6(%rip),%rdx
jmp    11a5 <print_decimal+0x85>
lea    0xea2(%rip),%rdx
jmp    11a5 <print_decimal+0x85>
lea    0xe9e(%rip),%rdx
jmp    11a5 <print_decimal+0x85>
lea    0xe9a(%rip),%rdx
mov    $0x20,%esi
call   1040 <snprintf@plt>
lea    0x2e8a(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@print_decimal.buf = internal global [32 x i8] zeroinitializer
@.str = [5 x i8] c"%.0f\00"
@.str.1 = [5 x i8] c"%.1f\00"
@.str.2 = [5 x i8] c"%.1g\00"
@.str.3 = [5 x i8] c"%.3f\00"
@.str.4 = [2 x i8] c"0\00"
define i8* @print_decimal(double %0) {
%2 = alloca double
%3 = alloca double
store double %0, double* %2
%4 = load double, double* %2
%5 = fcmp oge double %4, 0.000000e+00
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = load double, double* %2
br label %11
8: ; preds = %1
%9 = load double, double* %2
%10 = fneg double %9
br label %11
11: ; preds = %8, %6
%12 = phi double [ %7, %6 ], [ %10, %8 ]
store double %12, double* %3
%13 = load double, double* %3
%14 = fcmp oge double %13, 0x4023E66666666666
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load double, double* %2
%17 = call i32 @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @print_decimal.buf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %16)
br label %41
18: ; preds = %11
%19 = load double, double* %3
%20 = fcmp oge double %19, 0x3FEE666666666666
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load double, double* %2
%23 = call i32 @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @print_decimal.buf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %22)
br label %40
24: ; preds = %18
%25 = load double, double* %3
%26 = fcmp oge double %25, 1.000000e-03
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load double, double* %2
%29 = call i32 @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @print_decimal.buf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %28)
br label %39
30: ; preds = %24
%31 = load double, double* %3
%32 = fcmp oge double %31, 5.000000e-04
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load double, double* %2
%35 = call i32 @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @print_decimal.buf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), double %34)
br label %38
36: ; preds = %30
%37 = call i32 @strcpy(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @print_decimal.buf, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %38
38: ; preds = %36, %33
br label %39
39: ; preds = %38, %27
br label %40
40: ; preds = %39, %21
br label %41
41: ; preds = %40, %15
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @print_decimal.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@print_decimal.buf = internal global [32 x i8] zeroinitializer
@.str = [5 x i8] c"%.0f\00"
@.str.1 = [5 x i8] c"%.1f\00"
@.str.2 = [5 x i8] c"%.1g\00"
@.str.3 = [5 x i8] c"%.3f\00"
@.str.4 = [2 x i8] c"0\00"
define i8* @print_decimal(double %0) {
%2 = fcmp oge double %0, 0.000000e+00
%3 = fneg double %0
%4 = select i1 %2, double %0, double %3
%5 = fcmp ult double %4, 0x4023E66666666666
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = tail call i32 @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @print_decimal.buf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %0)
br label %22
8: ; preds = %1
%9 = fcmp ult double %4, 0x3FEE666666666666
br i1 %9, label %12, label %10
10: ; preds = %8
%11 = tail call i32 @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @print_decimal.buf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %0)
br label %22
12: ; preds = %8
%13 = fcmp ult double %4, 1.000000e-03
br i1 %13, label %16, label %14
14: ; preds = %12
%15 = tail call i32 @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @print_decimal.buf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %0)
br label %22
16: ; preds = %12
%17 = fcmp ult double %4, 5.000000e-04
br i1 %17, label %20, label %18
18: ; preds = %16
%19 = tail call i32 @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @print_decimal.buf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), double %0)
br label %22
20: ; preds = %16
%21 = tail call i32 @strcpy(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @print_decimal.buf, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %22
22: ; preds = %10, %18, %20, %14, %6
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @print_decimal.buf, i64 0, i64 0)
}