#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 cvtDoubleToExpString(double, char *, unsigned short);
int cvtDoubleToString(double, char *, unsigned short);
int cvtDoubleToCompactString(double f_value, char *pstr_value,
                             unsigned short f_precision) {
  if ((f_value < 1.e4 && f_value > 1.e-4) ||
      (f_value > -1.e4 && f_value < -1.e-4) || f_value == 0.0) {
    return (cvtDoubleToString(f_value, pstr_value, f_precision));
  } else {
    return (cvtDoubleToExpString(f_value, pstr_value, f_precision));
  }
}


x86 assembly (clang, -O0):
<cvtDoubleToCompactString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %ax,-0x1a(%rbp)
movsd  0xec0(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1162 <cvtDoubleToCompactString+0x42>
movsd  -0x10(%rbp),%xmm0
movsd  0xeb0(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     11a4 <cvtDoubleToCompactString+0x84>
movsd  -0x10(%rbp),%xmm0
movsd  0xea1(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    118c <cvtDoubleToCompactString+0x6c>
movsd  0xe97(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
ja     11a4 <cvtDoubleToCompactString+0x84>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11be <cvtDoubleToCompactString+0x9e>
jp     11be <cvtDoubleToCompactString+0x9e>
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rdi
movzwl -0x1a(%rbp),%esi
call   1040 <cvtDoubleToString@plt>
mov    %eax,-0x4(%rbp)
jmp    11d3 <cvtDoubleToCompactString+0xb3>
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rdi
movzwl -0x1a(%rbp),%esi
call   1030 <cvtDoubleToExpString@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cvtDoubleToCompactString>:
movsd  0xed8(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1138 <cvtDoubleToCompactString+0x18>
ucomisd 0xed2(%rip),%xmm0
ja     116a <cvtDoubleToCompactString+0x4a>
ucomisd 0xed0(%rip),%xmm0
seta   %al
movsd  0xecd(%rip),%xmm1
ucomisd %xmm0,%xmm1
seta   %cl
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    115e <cvtDoubleToCompactString+0x3e>
jnp    116a <cvtDoubleToCompactString+0x4a>
and    %cl,%al
jne    116a <cvtDoubleToCompactString+0x4a>
movzwl %si,%esi
jmp    1030 <cvtDoubleToExpString@plt>
movzwl %si,%esi
jmp    1040 <cvtDoubleToString@plt>

LLVM IR (-O0):
define i32 @cvtDoubleToCompactString(double %0, i8* %1, i16 zeroext %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca i8*
%7 = alloca i16
store double %0, double* %5
store i8* %1, i8** %6
store i16 %2, i16* %7
%8 = load double, double* %5
%9 = fcmp olt double %8, 1.000000e+04
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load double, double* %5
%12 = fcmp ogt double %11, 1.000000e-04
br i1 %12, label %22, label %13
13: ; preds = %10, %3
%14 = load double, double* %5
%15 = fcmp ogt double %14, -1.000000e+04
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load double, double* %5
%18 = fcmp olt double %17, -1.000000e-04
br i1 %18, label %22, label %19
19: ; preds = %16, %13
%20 = load double, double* %5
%21 = fcmp oeq double %20, 0.000000e+00
br i1 %21, label %22, label %27
22: ; preds = %19, %16, %10
%23 = load double, double* %5
%24 = load i8*, i8** %6
%25 = load i16, i16* %7
%26 = call i32 @cvtDoubleToString(double %23, i8* %24, i16 zeroext %25)
store i32 %26, i32* %4
br label %32
27: ; preds = %19
%28 = load double, double* %5
%29 = load i8*, i8** %6
%30 = load i16, i16* %7
%31 = call i32 @cvtDoubleToExpString(double %28, i8* %29, i16 zeroext %30)
store i32 %31, i32* %4
br label %32
32: ; preds = %27, %22
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
define i32 @cvtDoubleToCompactString(double %0, i8* %1, i16 zeroext %2) {
%4 = fcmp olt double %0, 1.000000e+04
%5 = fcmp ogt double %0, 1.000000e-04
%6 = and i1 %4, %5
br i1 %6, label %13, label %7
7: ; preds = %3
%8 = fcmp ogt double %0, -1.000000e+04
%9 = fcmp olt double %0, -1.000000e-04
%10 = and i1 %8, %9
%11 = fcmp oeq double %0, 0.000000e+00
%12 = or i1 %11, %10
br i1 %12, label %13, label %15
13: ; preds = %7, %3
%14 = tail call i32 @cvtDoubleToString(double %0, i8* %1, i16 zeroext %2)
br label %17
15: ; preds = %7
%16 = tail call i32 @cvtDoubleToExpString(double %0, i8* %1, i16 zeroext %2)
br label %17
17: ; preds = %15, %13
%18 = phi i32 [ %14, %13 ], [ %16, %15 ]
ret i32 %18
}