#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 log(double);
double atanh(double r1) {
  double r2 = r1 < 0 ? -r1 : r1;
  double r3 = log((r2 / (1.0 - r2) * 2) + 1) / 2;
  return r1 < 0 ? -r3 : r3;
}


x86 assembly (clang, -O0):
<atanh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1151 <atanh+0x41>
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    115b <atanh+0x4b>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe8e(%rip),%xmm1
subsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
addsd  %xmm0,%xmm0
movsd  0xe79(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1030 <log@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11d5 <atanh+0xc5>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11df <atanh+0xcf>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atanh>:
sub    $0x18,%rsp
movapd %xmm0,%xmm2
movapd %xmm0,(%rsp)
movapd %xmm0,%xmm1
xorpd  0xed7(%rip),%xmm1
xorpd  %xmm3,%xmm3
cmpltsd %xmm3,%xmm0
andpd  %xmm0,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
movsd  0xeca(%rip),%xmm1
movapd %xmm1,%xmm2
subsd  %xmm0,%xmm2
divsd  %xmm2,%xmm0
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
call   1030 <log@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
xorpd  %xmm0,%xmm0
ucomisd (%rsp),%xmm0
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
jbe    1182 <atanh+0x72>
xorpd  0xe7e(%rip),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @atanh(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
store double %0, double* %2
%5 = load double, double* %2
%6 = fcmp olt double %5, 0.000000e+00
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load double, double* %2
%9 = fneg double %8
br label %12
10: ; preds = %1
%11 = load double, double* %2
br label %12
12: ; preds = %10, %7
%13 = phi double [ %9, %7 ], [ %11, %10 ]
store double %13, double* %3
%14 = load double, double* %3
%15 = load double, double* %3
%16 = fsub double 1.000000e+00, %15
%17 = fdiv double %14, %16
%18 = call double @llvm.fmuladd.f64(double %17, double 2.000000e+00, double 1.000000e+00)
%19 = call i32 @log(double %18)
%20 = sdiv i32 %19, 2
%21 = sitofp i32 %20 to double
store double %21, double* %4
%22 = load double, double* %2
%23 = fcmp olt double %22, 0.000000e+00
br i1 %23, label %24, label %27
24: ; preds = %12
%25 = load double, double* %4
%26 = fneg double %25
br label %29
27: ; preds = %12
%28 = load double, double* %4
br label %29
29: ; preds = %27, %24
%30 = phi double [ %26, %24 ], [ %28, %27 ]
ret double %30
}

LLVM IR (-O2):
define double @atanh(double %0) {
%2 = fcmp olt double %0, 0.000000e+00
%3 = fneg double %0
%4 = select i1 %2, double %3, double %0
%5 = fsub double 1.000000e+00, %4
%6 = fdiv double %4, %5
%7 = tail call double @llvm.fmuladd.f64(double %6, double 2.000000e+00, double 1.000000e+00)
%8 = tail call i32 @log(double %7)
%9 = sdiv i32 %8, 2
%10 = sitofp i32 %9 to double
%11 = fneg double %10
%12 = select i1 %2, double %11, double %10
ret double %12
}