#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*/ finite(double);
scalar_t__ isnan(double);
double p_gamma(double, double, double);
double erf(double x) {
  if (!finite(x)) {
    if (isnan(x))
      return x;
    return (x > 0 ? 1.0 : -1.0);
  }
  if (x >= 0)
    return p_gamma(0.5, x * x, 0.572364942924700087071713675675);
  else
    return -p_gamma(0.5, x * x, 0.572364942924700087071713675675);
}


x86 assembly (clang, -O0):
<erf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xef7(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xebb(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11a8 <erf+0x88>
movsd  -0x10(%rbp),%xmm0
call   1040 <isnan@plt>
cmp    $0x0,%rax
je     1172 <erf+0x52>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    121e <erf+0xfe>
movsd  -0x10(%rbp),%xmm1
movsd  0xe89(%rip),%xmm3
movsd  0xe89(%rip),%xmm2
xorps  %xmm0,%xmm0
cmpltsd %xmm1,%xmm0
movaps %xmm0,%xmm1
andpd  %xmm3,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    121e <erf+0xfe>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11e3 <erf+0xc3>
movsd  -0x10(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
movsd  0xe4c(%rip),%xmm0
movsd  0xe4c(%rip),%xmm2
call   1030 <p_gamma@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    121e <erf+0xfe>
movsd  -0x10(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
movsd  0xe23(%rip),%xmm0
movsd  0xe23(%rip),%xmm2
call   1030 <p_gamma@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<erf>:
sub    $0x18,%rsp
movapd 0xed4(%rip),%xmm1
andpd  %xmm0,%xmm1
ucomisd 0xef8(%rip),%xmm1
movapd %xmm0,(%rsp)
je     1177 <erf+0x57>
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movsd  0xee9(%rip),%xmm0
movsd  0xee9(%rip),%xmm2
call   1030 <p_gamma@plt>
xorpd  %xmm1,%xmm1
movapd (%rsp),%xmm2
ucomisd %xmm1,%xmm2
jae    1172 <erf+0x52>
xorps  0xe9e(%rip),%xmm0
add    $0x18,%rsp
ret
call   1040 <isnan@plt>
test   %rax,%rax
je     118a <erf+0x6a>
movaps (%rsp),%xmm0
add    $0x18,%rsp
ret
xorpd  %xmm0,%xmm0
xor    %eax,%eax
movapd (%rsp),%xmm1
ucomisd %xmm0,%xmm1
seta   %al
lea    0xe7d(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @erf(double %0) {
%2 = alloca double
%3 = alloca double
store double %0, double* %3
%4 = load double, double* %3
%5 = call double @llvm.fabs.f64(double %4)
%6 = fcmp one double %5, 0x7FF0000000000000
br i1 %6, label %18, label %7
7: ; preds = %1
%8 = load double, double* %3
%9 = call i64 @isnan(double %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = load double, double* %3
store double %12, double* %2
br label %32
13: ; preds = %7
%14 = load double, double* %3
%15 = fcmp ogt double %14, 0.000000e+00
%16 = zext i1 %15 to i64
%17 = select i1 %15, double 1.000000e+00, double -1.000000e+00
store double %17, double* %2
br label %32
18: ; preds = %1
%19 = load double, double* %3
%20 = fcmp oge double %19, 0.000000e+00
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load double, double* %3
%23 = load double, double* %3
%24 = fmul double %22, %23
%25 = call double @p_gamma(double 5.000000e-01, double %24, double 0x3FE250D048E7A1BD)
store double %25, double* %2
br label %32
26: ; preds = %18
%27 = load double, double* %3
%28 = load double, double* %3
%29 = fmul double %27, %28
%30 = call double @p_gamma(double 5.000000e-01, double %29, double 0x3FE250D048E7A1BD)
%31 = fneg double %30
store double %31, double* %2
br label %32
32: ; preds = %26, %21, %13, %11
%33 = load double, double* %2
ret double %33
}

LLVM IR (-O2):
define double @erf(double %0) {
%2 = tail call double @llvm.fabs.f64(double %0)
%3 = fcmp ueq double %2, 0x7FF0000000000000
br i1 %3, label %4, label %10
4: ; preds = %1
%5 = tail call i64 @isnan(double %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %16
7: ; preds = %4
%8 = fcmp ogt double %0, 0.000000e+00
%9 = select i1 %8, double 1.000000e+00, double -1.000000e+00
br label %16
10: ; preds = %1
%11 = fcmp ult double %0, 0.000000e+00
%12 = fmul double %0, %0
%13 = tail call double @p_gamma(double 5.000000e-01, double %12, double 0x3FE250D048E7A1BD)
br i1 %11, label %14, label %16
14: ; preds = %10
%15 = fneg double %13
br label %16
16: ; preds = %10, %4, %14, %7
%17 = phi double [ %15, %14 ], [ %9, %7 ], [ %0, %4 ], [ %13, %10 ]
ret double %17
}