#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*/ EDOM;
int /*<<< orphan*/ ERANGE;
double INFINITY;
double __fast_log1p(double);
int /*<<< orphan*/ errno;
double fabs(double);
scalar_t__ isnan(double);
double nan(char *);
double atanh(double x) {
  double z;
  if (isnan(x))
    return x;
  z = fabs(x);
  if (z == 1.0) {
    errno = ERANGE;
    return (x > 0 ? INFINITY : -INFINITY);
  }
  if (z > 1.0) {
    errno = EDOM;
    return nan("");
  }
  z = 0.5 * __fast_log1p((z + z) / (1.0 - z));
  return x >= 0 ? z : -z;
}


x86 assembly (clang, -O0):
<atanh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <isnan@plt>
cmp    $0x0,%rax
je     1160 <atanh+0x30>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12c0 <atanh+0x190>
movsd  -0x10(%rbp),%xmm0
movaps 0xea4(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe7e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1201 <atanh+0xd1>
jp     1201 <atanh+0xd1>
mov    0x2e3f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e26(%rip),%rax
mov    %ecx,(%rax)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11cb <atanh+0x9b>
mov    0x2e2b(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11f2 <atanh+0xc2>
mov    0x2e16(%rip),%rax
movsd  (%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12c0 <atanh+0x190>
movsd  -0x18(%rbp),%xmm0
movsd  0xdf2(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1240 <atanh+0x110>
mov    0x2dc1(%rip),%rax
mov    (%rax),%ecx
mov    0x2da0(%rip),%rax
mov    %ecx,(%rax)
lea    0xdef(%rip),%rdi
call   1030 <nan@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    12c0 <atanh+0x190>
movsd  -0x18(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  0xdae(%rip),%xmm1
subsd  -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1050 <__fast_log1p@plt>
movaps %xmm0,%xmm1
movsd  0xd9d(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1295 <atanh+0x165>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    12b6 <atanh+0x186>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atanh>:
sub    $0x18,%rsp
movaps %xmm0,(%rsp)
call   1040 <isnan@plt>
test   %rax,%rax
je     114b <atanh+0x1b>
movaps (%rsp),%xmm0
add    $0x18,%rsp
ret
movapd 0xead(%rip),%xmm0
movapd (%rsp),%xmm3
andpd  %xmm3,%xmm0
ucomisd 0xebc(%rip),%xmm0
jne    119c <atanh+0x6c>
jp     119c <atanh+0x6c>
mov    0x2e69(%rip),%rax
mov    (%rax),%eax
mov    0x2e50(%rip),%rcx
mov    %eax,(%rcx)
mov    0x2e67(%rip),%rax
movsd  (%rax),%xmm0
movapd 0xe83(%rip),%xmm1
xorpd  %xmm0,%xmm1
xorpd  %xmm2,%xmm2
cmpltsd %xmm3,%xmm2
jmp    11ff <atanh+0xcf>
ucomisd 0xe7c(%rip),%xmm0
jbe    11c8 <atanh+0x98>
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    0x2e12(%rip),%rcx
mov    %eax,(%rcx)
lea    0xe71(%rip),%rdi
add    $0x18,%rsp
jmp    1030 <nan@plt>
movsd  0xe50(%rip),%xmm1
subsd  %xmm0,%xmm1
addsd  %xmm0,%xmm0
divsd  %xmm1,%xmm0
call   1050 <__fast_log1p@plt>
mulsd  0xe3f(%rip),%xmm0
movapd 0xe1f(%rip),%xmm1
xorpd  %xmm0,%xmm1
xorpd  %xmm2,%xmm2
cmplesd (%rsp),%xmm2
andpd  %xmm2,%xmm0
andnpd %xmm1,%xmm2
orpd   %xmm0,%xmm2
movapd %xmm2,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@ERANGE = global i32 0
@errno = global i32 0
@INFINITY = global double 0.000000e+00
@EDOM = global i32 0
@.str = [1 x i8] zeroinitializer
define double @atanh(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
store double %0, double* %3
%5 = load double, double* %3
%6 = call i64 @isnan(double %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = load double, double* %3
store double %9, double* %2
br label %50
10: ; preds = %1
%11 = load double, double* %3
%12 = call double @llvm.fabs.f64(double %11)
store double %12, double* %4
%13 = load double, double* %4
%14 = fcmp oeq double %13, 1.000000e+00
br i1 %14, label %15, label %26
15: ; preds = %10
%16 = load i32, i32* @ERANGE
store i32 %16, i32* @errno
%17 = load double, double* %3
%18 = fcmp ogt double %17, 0.000000e+00
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = load double, double* @INFINITY
br label %24
21: ; preds = %15
%22 = load double, double* @INFINITY
%23 = fneg double %22
br label %24
24: ; preds = %21, %19
%25 = phi double [ %20, %19 ], [ %23, %21 ]
store double %25, double* %2
br label %50
26: ; preds = %10
%27 = load double, double* %4
%28 = fcmp ogt double %27, 1.000000e+00
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i32, i32* @EDOM
store i32 %30, i32* @errno
%31 = call double @nan(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store double %31, double* %2
br label %50
32: ; preds = %26
%33 = load double, double* %4
%34 = load double, double* %4
%35 = fadd double %33, %34
%36 = load double, double* %4
%37 = fsub double 1.000000e+00, %36
%38 = fdiv double %35, %37
%39 = call double @__fast_log1p(double %38)
%40 = fmul double 5.000000e-01, %39
store double %40, double* %4
%41 = load double, double* %3
%42 = fcmp oge double %41, 0.000000e+00
br i1 %42, label %43, label %45
43: ; preds = %32
%44 = load double, double* %4
br label %48
45: ; preds = %32
%46 = load double, double* %4
%47 = fneg double %46
br label %48
48: ; preds = %45, %43
%49 = phi double [ %44, %43 ], [ %47, %45 ]
store double %49, double* %2
br label %50
50: ; preds = %48, %29, %24, %8
%51 = load double, double* %2
ret double %51
}

LLVM IR (-O2):
@ERANGE = global i32 0
@errno = global i32 0
@INFINITY = global double 0.000000e+00
@EDOM = global i32 0
@.str = [1 x i8] zeroinitializer
define double @atanh(double %0) {
%2 = tail call i64 @isnan(double %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %27
4: ; preds = %1
%5 = tail call double @llvm.fabs.f64(double %0)
%6 = fcmp oeq double %5, 1.000000e+00
br i1 %6, label %7, label %13
7: ; preds = %4
%8 = load i32, i32* @ERANGE
store i32 %8, i32* @errno
%9 = fcmp ogt double %0, 0.000000e+00
%10 = load double, double* @INFINITY
%11 = fneg double %10
%12 = select i1 %9, double %10, double %11
br label %27
13: ; preds = %4
%14 = fcmp ogt double %5, 1.000000e+00
br i1 %14, label %15, label %18
15: ; preds = %13
%16 = load i32, i32* @EDOM
store i32 %16, i32* @errno
%17 = tail call double @nan(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %27
18: ; preds = %13
%19 = fadd double %5, %5
%20 = fsub double 1.000000e+00, %5
%21 = fdiv double %19, %20
%22 = tail call double @__fast_log1p(double %21)
%23 = fmul double %22, 5.000000e-01
%24 = fcmp oge double %0, 0.000000e+00
%25 = fneg double %23
%26 = select i1 %24, double %23, double %25
br label %27
27: ; preds = %1, %18, %15, %7
%28 = phi double [ %12, %7 ], [ %17, %15 ], [ %26, %18 ], [ %0, %1 ]
ret double %28
}