#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) {
  if (x > 50)
    return 1;
  else if (x < -50)
    return -1;
  else {
    const double ebig = exp(x);
    const double esmall = 1.0 / ebig;
    return (ebig - esmall) / (ebig + esmall);
  }
}


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  0xed4(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11a9 <tanh+0x99>
movsd  0xeba(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    116b <tanh+0x5b>
movsd  0xeb7(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11a9 <tanh+0x99>
movsd  -0x10(%rbp),%xmm0
call   1030 <exp@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  0xe8e(%rip),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
addsd  -0x20(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tanh>:
push   %rax
ucomisd 0xeef(%rip),%xmm0
jbe    1125 <tanh+0x15>
movsd  0xedd(%rip),%xmm0
pop    %rax
ret
movsd  0xeeb(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    113d <tanh+0x2d>
movsd  0xed5(%rip),%xmm0
pop    %rax
ret
call   1030 <exp@plt>
movapd %xmm0,%xmm1
movsd  0xeb2(%rip),%xmm2
divsd  %xmm0,%xmm2
subsd  %xmm2,%xmm0
addsd  %xmm1,%xmm2
divsd  %xmm2,%xmm0
pop    %rax
ret

LLVM IR (-O0):
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 = fcmp ogt double %6, 5.000000e+01
br i1 %7, label %8, label %9
8: ; preds = %1
store double 1.000000e+00, double* %2
br label %25
9: ; preds = %1
%10 = load double, double* %3
%11 = fcmp olt double %10, -5.000000e+01
br i1 %11, label %12, label %13
12: ; preds = %9
store double -1.000000e+00, double* %2
br label %25
13: ; preds = %9
%14 = load double, double* %3
%15 = call double @exp(double %14)
store double %15, double* %4
%16 = load double, double* %4
%17 = fdiv double 1.000000e+00, %16
store double %17, double* %5
%18 = load double, double* %4
%19 = load double, double* %5
%20 = fsub double %18, %19
%21 = load double, double* %4
%22 = load double, double* %5
%23 = fadd double %21, %22
%24 = fdiv double %20, %23
store double %24, double* %2
br label %25
25: ; preds = %13, %12, %8
%26 = load double, double* %2
ret double %26
}

LLVM IR (-O2):
define double @tanh(double %0) {
%2 = fcmp ogt double %0, 5.000000e+01
br i1 %2, label %11, label %3
3: ; preds = %1
%4 = fcmp olt double %0, -5.000000e+01
br i1 %4, label %11, label %5
5: ; preds = %3
%6 = tail call double @exp(double %0)
%7 = fdiv double 1.000000e+00, %6
%8 = fsub double %6, %7
%9 = fadd double %6, %7
%10 = fdiv double %8, %9
br label %11
11: ; preds = %3, %1, %5
%12 = phi double [ %10, %5 ], [ 1.000000e+00, %1 ], [ -1.000000e+00, %3 ]
ret double %12
}