#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 copysign(double const, double const);
double const expm1(double);
scalar_t__ finite(double);
double tanh(double x) {
  static double const one = 1.0;
  static double const two = 2.0;
  static double const small = 1.0e-10;
  static double const big = 1.0e10;
  double t;
  double sign;
  if (x != x)
    return (x);
  sign = copysign(one, x);
  x = copysign(x, one);
  if (x < 22.0)
    if (x > one)
      return (copysign(one - two / (expm1(x + x) + two), sign));
    else if (x > small) {
      t = -expm1(-(x + x));
      return (copysign(t / (two - t), sign));
    } else {
      (void volatile)(big + x);
      return (copysign(x, sign));
    }
  else if (finite(x))
    return (sign + 1.0E-37);
  else
    return (sign);
}


x86 assembly (clang, -O0):
<tanh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    1148 <tanh+0x28>
jp     1148 <tanh+0x28>
jmp    1157 <tanh+0x37>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    130d <tanh+0x1ed>
movsd  -0x10(%rbp),%xmm0
movaps 0xedd(%rip),%xmm1
pand   %xmm1,%xmm0
movaps 0xee2(%rip),%xmm1
por    %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xead(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe6c(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    12d8 <tanh+0x1b8>
movsd  -0x10(%rbp),%xmm0
movsd  0xe64(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1212 <tanh+0xf2>
movsd  -0x10(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
call   1030 <expm1@plt>
movsd  0xe53(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xe47(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  0xe2b(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
movaps 0xe4b(%rip),%xmm2
pand   %xmm2,%xmm1
movaps 0xe30(%rip),%xmm2
pand   %xmm2,%xmm0
por    %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    130d <tanh+0x1ed>
movsd  -0x10(%rbp),%xmm0
movsd  0xdf9(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12aa <tanh+0x18a>
movsd  -0x10(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <expm1@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xda8(%rip),%xmm1
subsd  -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
movaps 0xdb3(%rip),%xmm2
pand   %xmm2,%xmm1
movaps 0xd98(%rip),%xmm2
pand   %xmm2,%xmm0
por    %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    130d <tanh+0x1ed>
movsd  -0x10(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movaps 0xd85(%rip),%xmm2
pand   %xmm2,%xmm1
movaps 0xd6a(%rip),%xmm2
pand   %xmm2,%xmm0
por    %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    130d <tanh+0x1ed>
movsd  -0x10(%rbp),%xmm0
call   1040 <finite@plt>
cmp    $0x0,%rax
je     1303 <tanh+0x1e3>
movsd  0xd14(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    130d <tanh+0x1ed>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tanh>:
sub    $0x18,%rsp
movapd %xmm0,%xmm3
ucomisd %xmm0,%xmm0
jp     1216 <tanh+0xf6>
movapd 0xec6(%rip),%xmm2
andpd  %xmm3,%xmm2
movapd 0xeda(%rip),%xmm0
andpd  %xmm3,%xmm0
movsd  0xede(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    119e <tanh+0x7e>
ucomisd 0xee0(%rip),%xmm0
jbe    11c4 <tanh+0xa4>
addsd  %xmm0,%xmm0
movapd %xmm2,(%rsp)
call   1030 <expm1@plt>
movsd  0xed8(%rip),%xmm1
addsd  %xmm1,%xmm0
divsd  %xmm0,%xmm1
movsd  0xeb8(%rip),%xmm0
subsd  %xmm1,%xmm0
andpd  0xe8c(%rip),%xmm0
orpd   (%rsp),%xmm0
add    $0x18,%rsp
ret
orpd   0xe6a(%rip),%xmm2
movapd %xmm2,(%rsp)
call   1040 <finite@plt>
movapd (%rsp),%xmm3
test   %rax,%rax
je     1216 <tanh+0xf6>
addsd  0xe76(%rip),%xmm3
jmp    1216 <tanh+0xf6>
ucomisd 0xe7c(%rip),%xmm0
jbe    1216 <tanh+0xf6>
addsd  %xmm0,%xmm0
xorpd  0xe26(%rip),%xmm0
movapd %xmm3,(%rsp)
call   1030 <expm1@plt>
movapd 0xe14(%rip),%xmm1
xorpd  %xmm0,%xmm1
addsd  0xe58(%rip),%xmm0
divsd  %xmm0,%xmm1
movapd 0xe1c(%rip),%xmm0
andpd  %xmm0,%xmm1
andnpd (%rsp),%xmm0
orpd   %xmm1,%xmm0
add    $0x18,%rsp
ret
movapd %xmm3,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@tanh.one = internal constant double 1.000000e+00
@tanh.two = internal constant double 2.000000e+00
@tanh.small = internal constant double 1.000000e-10
@tanh.big = internal constant double 1.000000e+10
define double @tanh(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %3
%6 = load double, double* %3
%7 = load double, double* %3
%8 = fcmp une double %6, %7
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = load double, double* %3
store double %10, double* %2
br label %62
11: ; preds = %1
%12 = load double, double* %3
%13 = call double @llvm.copysign.f64(double 1.000000e+00, double %12)
store double %13, double* %5
%14 = load double, double* %3
%15 = call double @llvm.copysign.f64(double %14, double 1.000000e+00)
store double %15, double* %3
%16 = load double, double* %3
%17 = fcmp olt double %16, 2.200000e+01
br i1 %17, label %18, label %53
18: ; preds = %11
%19 = load double, double* %3
%20 = fcmp ogt double %19, 1.000000e+00
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = load double, double* %3
%23 = load double, double* %3
%24 = fadd double %22, %23
%25 = call double @expm1(double %24)
%26 = fadd double %25, 2.000000e+00
%27 = fdiv double 2.000000e+00, %26
%28 = fsub double 1.000000e+00, %27
%29 = load double, double* %5
%30 = call double @llvm.copysign.f64(double %28, double %29)
store double %30, double* %2
br label %62
31: ; preds = %18
%32 = load double, double* %3
%33 = fcmp ogt double %32, 1.000000e-10
br i1 %33, label %34, label %47
34: ; preds = %31
%35 = load double, double* %3
%36 = load double, double* %3
%37 = fadd double %35, %36
%38 = fneg double %37
%39 = call double @expm1(double %38)
%40 = fneg double %39
store double %40, double* %4
%41 = load double, double* %4
%42 = load double, double* %4
%43 = fsub double 2.000000e+00, %42
%44 = fdiv double %41, %43
%45 = load double, double* %5
%46 = call double @llvm.copysign.f64(double %44, double %45)
store double %46, double* %2
br label %62
47: ; preds = %31
%48 = load double, double* %3
%49 = fadd double 1.000000e+10, %48
%50 = load double, double* %3
%51 = load double, double* %5
%52 = call double @llvm.copysign.f64(double %50, double %51)
store double %52, double* %2
br label %62
53: ; preds = %11
%54 = load double, double* %3
%55 = call i64 @finite(double %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %53
%58 = load double, double* %5
%59 = fadd double %58, 1.000000e-37
store double %59, double* %2
br label %62
60: ; preds = %53
%61 = load double, double* %5
store double %61, double* %2
br label %62
62: ; preds = %60, %57, %47, %34, %21, %9
%63 = load double, double* %2
ret double %63
}

LLVM IR (-O2):
define double @tanh(double %0) {
%2 = fcmp uno double %0, 0.000000e+00
br i1 %2, label %31, label %3
3: ; preds = %1
%4 = tail call double @llvm.copysign.f64(double 1.000000e+00, double %0)
%5 = tail call double @llvm.fabs.f64(double %0)
%6 = fcmp olt double %5, 2.200000e+01
br i1 %6, label %7, label %26
7: ; preds = %3
%8 = fcmp ogt double %5, 1.000000e+00
br i1 %8, label %9, label %16
9: ; preds = %7
%10 = fadd double %5, %5
%11 = tail call double @expm1(double %10)
%12 = fadd double %11, 2.000000e+00
%13 = fdiv double 2.000000e+00, %12
%14 = fsub double 1.000000e+00, %13
%15 = tail call double @llvm.copysign.f64(double %14, double %0)
br label %31
16: ; preds = %7
%17 = fcmp ogt double %5, 1.000000e-10
br i1 %17, label %18, label %31
18: ; preds = %16
%19 = fadd double %5, %5
%20 = fneg double %19
%21 = tail call double @expm1(double %20)
%22 = fneg double %21
%23 = fadd double %21, 2.000000e+00
%24 = fdiv double %22, %23
%25 = tail call double @llvm.copysign.f64(double %24, double %0)
br label %31
26: ; preds = %3
%27 = tail call i64 @finite(double %5)
%28 = icmp eq i64 %27, 0
%29 = fadd double %4, 1.000000e-37
%30 = select i1 %28, double %4, double %29
br label %31
31: ; preds = %26, %16, %1, %18, %9
%32 = phi double [ %15, %9 ], [ %25, %18 ], [ %0, %1 ], [ %0, %16 ], [ %30, %26 ]
ret double %32
}