#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 */
double exp(double);
double tanh(double x) {
  int sign;
  if (x > 27.0)
    return 1.0;
  else if (x < -27.0)
    return -1.0;
  if (x < 0.0)
    x = -x, sign = 1;
  else
    sign = 0;
  if (x > 0.549306144334054846) {
    x = exp(2.0 * x);
    x = 1.0 - 2.0 / (x + 1.0);
    if (sign)
      return -x;
    else
      return x;
  }
  if (x > 1.0e-10) {
    double y = x * x;
    y = (((-0.96437492777225469787e0 * y + -0.99225929672236083313e2) * y +
          -0.16134119023996228053e4) *
         y) /
        (((y + 0.11274474380534949335e3) * y + 0.22337720718962312926e4) * y +
         0.48402357071988688686e4);
    x = x + x * y;
  }
  if (sign)
    return -x;
  else
    return x;
}


x86 assembly (clang, -O0):
<tanh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xed6(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1146 <tanh+0x36>
movsd  0xf14(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    133c <tanh+0x22c>
movsd  0xeba(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    116b <tanh+0x5b>
movsd  0xeff(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    133c <tanh+0x22c>
jmp    1170 <tanh+0x60>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11ab <tanh+0x9b>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
jmp    11b2 <tanh+0xa2>
movl   $0x0,-0x14(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe51(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1249 <tanh+0x139>
movsd  0xe87(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
call   1030 <exp@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  0xe68(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  0xe63(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  0xe4f(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     123a <tanh+0x12a>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    133c <tanh+0x22c>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    133c <tanh+0x22c>
movsd  -0x10(%rbp),%xmm0
movsd  0xdc2(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1302 <tanh+0x1f2>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xdc4(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdc0(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd9b(%rip),%xmm1
addsd  %xmm1,%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  0xd82(%rip),%xmm1
addsd  -0x20(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xd64(%rip),%xmm2
addsd  %xmm2,%xmm1
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xd47(%rip),%xmm2
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1332 <tanh+0x222>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    133c <tanh+0x22c>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tanh>:
sub    $0x18,%rsp
ucomisd 0xeec(%rip),%xmm0
jbe    112b <tanh+0x1b>
movsd  0xeda(%rip),%xmm0
add    $0x18,%rsp
ret
movapd %xmm0,%xmm4
movsd  0xee1(%rip),%xmm0
ucomisd %xmm4,%xmm0
jbe    114a <tanh+0x3a>
movsd  0xecb(%rip),%xmm0
add    $0x18,%rsp
ret
movapd 0xf1e(%rip),%xmm1
xorpd  %xmm4,%xmm1
xorpd  %xmm2,%xmm2
movapd %xmm4,%xmm0
cmpltsd %xmm2,%xmm0
andpd  %xmm0,%xmm1
andnpd %xmm4,%xmm0
orpd   %xmm1,%xmm0
ucomisd 0xea9(%rip),%xmm0
jbe    11b4 <tanh+0xa4>
addsd  %xmm0,%xmm0
movapd %xmm4,(%rsp)
call   1030 <exp@plt>
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd (%rsp),%xmm0
movsd  0xe64(%rip),%xmm2
addsd  %xmm2,%xmm1
movsd  0xeb8(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
ja     1224 <tanh+0x114>
jmp    122c <tanh+0x11c>
ucomisd 0xe6c(%rip),%xmm0
jbe    121a <tanh+0x10a>
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movsd  0xe62(%rip),%xmm2
mulsd  %xmm1,%xmm2
addsd  0xe5e(%rip),%xmm2
mulsd  %xmm1,%xmm2
addsd  0xe5a(%rip),%xmm2
movsd  0xe5a(%rip),%xmm3
addsd  %xmm1,%xmm3
mulsd  %xmm1,%xmm3
addsd  0xe52(%rip),%xmm3
mulsd  %xmm1,%xmm3
addsd  0xe4e(%rip),%xmm3
mulsd  %xmm1,%xmm2
divsd  %xmm3,%xmm2
mulsd  %xmm0,%xmm2
addsd  %xmm2,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm4,%xmm1
jbe    122c <tanh+0x11c>
xorpd  0xe44(%rip),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @tanh(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca double
store double %0, double* %3
%6 = load double, double* %3
%7 = fcmp ogt double %6, 2.700000e+01
br i1 %7, label %8, label %9
8: ; preds = %1
store double 1.000000e+00, double* %2
br label %71
9: ; preds = %1
%10 = load double, double* %3
%11 = fcmp olt double %10, -2.700000e+01
br i1 %11, label %12, label %13
12: ; preds = %9
store double -1.000000e+00, double* %2
br label %71
13: ; preds = %9
br label %14
14: ; preds = %13
%15 = load double, double* %3
%16 = fcmp olt double %15, 0.000000e+00
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load double, double* %3
%19 = fneg double %18
store double %19, double* %3
store i32 1, i32* %4
br label %21
20: ; preds = %14
store i32 0, i32* %4
br label %21
21: ; preds = %20, %17
%22 = load double, double* %3
%23 = fcmp ogt double %22, 0x3FE193EA7AAD030B
br i1 %23, label %24, label %39
24: ; preds = %21
%25 = load double, double* %3
%26 = fmul double 2.000000e+00, %25
%27 = call double @exp(double %26)
store double %27, double* %3
%28 = load double, double* %3
%29 = fadd double %28, 1.000000e+00
%30 = fdiv double 2.000000e+00, %29
%31 = fsub double 1.000000e+00, %30
store double %31, double* %3
%32 = load i32, i32* %4
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %24
%35 = load double, double* %3
%36 = fneg double %35
store double %36, double* %2
br label %71
37: ; preds = %24
%38 = load double, double* %3
store double %38, double* %2
br label %71
39: ; preds = %21
%40 = load double, double* %3
%41 = fcmp ogt double %40, 1.000000e-10
br i1 %41, label %42, label %63
42: ; preds = %39
%43 = load double, double* %3
%44 = load double, double* %3
%45 = fmul double %43, %44
store double %45, double* %5
%46 = load double, double* %5
%47 = call double @llvm.fmuladd.f64(double 0xBFEEDC28CEFBA77F, double %46, double 0xC058CE75A1BA5CCC)
%48 = load double, double* %5
%49 = call double @llvm.fmuladd.f64(double %47, double %48, double 0xC09935A5C9BE1E18)
%50 = load double, double* %5
%51 = fmul double %49, %50
%52 = load double, double* %5
%53 = fadd double %52, 0x405C2FA9E1EBF7FA
%54 = load double, double* %5
%55 = call double @llvm.fmuladd.f64(double %53, double %54, double 0x40A1738B4D01F0F3)
%56 = load double, double* %5
%57 = call double @llvm.fmuladd.f64(double %55, double %56, double 0x40B2E83C574E9693)
%58 = fdiv double %51, %57
store double %58, double* %5
%59 = load double, double* %3
%60 = load double, double* %3
%61 = load double, double* %5
%62 = call double @llvm.fmuladd.f64(double %60, double %61, double %59)
store double %62, double* %3
br label %63
63: ; preds = %42, %39
%64 = load i32, i32* %4
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %63
%67 = load double, double* %3
%68 = fneg double %67
store double %68, double* %2
br label %71
69: ; preds = %63
%70 = load double, double* %3
store double %70, double* %2
br label %71
71: ; preds = %69, %66, %37, %34, %12, %8
%72 = load double, double* %2
ret double %72
}

LLVM IR (-O2):
define double @tanh(double %0) {
%2 = fcmp ogt double %0, 2.700000e+01
br i1 %2, label %34, label %3
3: ; preds = %1
%4 = fcmp olt double %0, -2.700000e+01
br i1 %4, label %34, label %5
5: ; preds = %3
%6 = fcmp olt double %0, 0.000000e+00
%7 = fneg double %0
%8 = select i1 %6, double %7, double %0
%9 = fcmp ogt double %8, 0x3FE193EA7AAD030B
br i1 %9, label %10, label %18
10: ; preds = %5
%11 = fmul double %8, 2.000000e+00
%12 = tail call double @exp(double %11)
%13 = fadd double %12, 1.000000e+00
%14 = fdiv double 2.000000e+00, %13
%15 = fsub double 1.000000e+00, %14
br i1 %6, label %16, label %34
16: ; preds = %10
%17 = fneg double %15
br label %34
18: ; preds = %5
%19 = fcmp ogt double %8, 1.000000e-10
br i1 %19, label %20, label %30
20: ; preds = %18
%21 = fmul double %8, %8
%22 = tail call double @llvm.fmuladd.f64(double %21, double 0xBFEEDC28CEFBA77F, double 0xC058CE75A1BA5CCC)
%23 = tail call double @llvm.fmuladd.f64(double %22, double %21, double 0xC09935A5C9BE1E18)
%24 = fmul double %21, %23
%25 = fadd double %21, 0x405C2FA9E1EBF7FA
%26 = tail call double @llvm.fmuladd.f64(double %25, double %21, double 0x40A1738B4D01F0F3)
%27 = tail call double @llvm.fmuladd.f64(double %26, double %21, double 0x40B2E83C574E9693)
%28 = fdiv double %24, %27
%29 = tail call double @llvm.fmuladd.f64(double %8, double %28, double %8)
br label %30
30: ; preds = %20, %18
%31 = phi double [ %29, %20 ], [ %8, %18 ]
br i1 %6, label %32, label %34
32: ; preds = %30
%33 = fneg double %31
br label %34
34: ; preds = %30, %10, %3, %1, %32, %16
%35 = phi double [ %17, %16 ], [ %33, %32 ], [ 1.000000e+00, %1 ], [ -1.000000e+00, %3 ], [ %15, %10 ], [ %31, %30 ]
ret double %35
}