double atanh(x)
double x;
{
  int neg = x < 0;
  double z = fabs(x);
  if (z < (1.0 / (1 << (53 / 3))))
    return x;
  z = log(z > 1 ? -1 : (1 + z) / (1 - z)) / 2;
  if (neg)
    z = -z;
  return z;
}


x86 assembly (clang, -O0):
<atanh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xee4(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xeb3(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1167 <atanh+0x57>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1203 <atanh+0xf3>
movsd  -0x20(%rbp),%xmm0
movsd  0xe94(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1190 <atanh+0x80>
movsd  0xe8a(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11b3 <atanh+0xa3>
movsd  0xe70(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  0xe63(%rip),%xmm1
subsd  -0x20(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <log@plt>
movsd  0xe53(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11f9 <atanh+0xe9>
movsd  -0x20(%rbp),%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)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atanh>:
sub    $0x18,%rsp
movapd %xmm0,%xmm3
movapd 0xee0(%rip),%xmm1
andpd  %xmm0,%xmm1
movsd  0xef4(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     119a <atanh+0x8a>
ucomisd 0xef6(%rip),%xmm1
movapd %xmm3,(%rsp)
jbe    114b <atanh+0x3b>
movsd  0xedf(%rip),%xmm0
jmp    1163 <atanh+0x53>
movsd  0xedd(%rip),%xmm2
movapd %xmm1,%xmm0
addsd  %xmm2,%xmm0
subsd  %xmm1,%xmm2
divsd  %xmm2,%xmm0
call   1030 <log@plt>
mulsd  0xec8(%rip),%xmm0
movapd 0xe98(%rip),%xmm1
xorpd  %xmm0,%xmm1
xorpd  %xmm2,%xmm2
movapd (%rsp),%xmm3
cmpltsd %xmm2,%xmm3
movapd %xmm3,%xmm2
andnpd %xmm0,%xmm2
andpd  %xmm1,%xmm3
orpd   %xmm2,%xmm3
movapd %xmm3,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @atanh(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 olt double %6, 0.000000e+00
%8 = zext i1 %7 to i32
store i32 %8, i32* %4
%9 = load double, double* %3
%10 = call double @llvm.fabs.f64(double %9)
store double %10, double* %5
%11 = load double, double* %5
%12 = fcmp olt double %11, 0x3EE0000000000000
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = load double, double* %3
store double %14, double* %2
br label %36
15: ; preds = %1
%16 = load double, double* %5
%17 = fcmp ogt double %16, 1.000000e+00
br i1 %17, label %18, label %19
18: ; preds = %15
br label %25
19: ; preds = %15
%20 = load double, double* %5
%21 = fadd double 1.000000e+00, %20
%22 = load double, double* %5
%23 = fsub double 1.000000e+00, %22
%24 = fdiv double %21, %23
br label %25
25: ; preds = %19, %18
%26 = phi double [ -1.000000e+00, %18 ], [ %24, %19 ]
%27 = call double @log(double %26)
%28 = fdiv double %27, 2.000000e+00
store double %28, double* %5
%29 = load i32, i32* %4
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = load double, double* %5
%33 = fneg double %32
store double %33, double* %5
br label %34
34: ; preds = %31, %25
%35 = load double, double* %5
store double %35, double* %2
br label %36
36: ; preds = %34, %13
%37 = load double, double* %2
ret double %37
}

LLVM IR (-O2):
define double @atanh(double %0) {
%2 = fcmp olt double %0, 0.000000e+00
%3 = tail call double @llvm.fabs.f64(double %0)
%4 = fcmp olt double %3, 0x3EE0000000000000
br i1 %4, label %17, label %5
5: ; preds = %1
%6 = fcmp ogt double %3, 1.000000e+00
br i1 %6, label %11, label %7
7: ; preds = %5
%8 = fadd double %3, 1.000000e+00
%9 = fsub double 1.000000e+00, %3
%10 = fdiv double %8, %9
br label %11
11: ; preds = %5, %7
%12 = phi double [ %10, %7 ], [ -1.000000e+00, %5 ]
%13 = tail call double @log(double %12)
%14 = fmul double %13, 5.000000e-01
%15 = fneg double %14
%16 = select i1 %2, double %15, double %14
br label %17
17: ; preds = %1, %11
%18 = phi double [ %16, %11 ], [ %0, %1 ]
ret double %18
}