#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 fabs(double);
int monte_fact(long);
int pow(double, int);
double sqrt(long double);
double monte_errf(double x) {
  long i;
  double y = 0.0;
  long num = 60;
  if (x < -5.0) {
    return (0.0);
  }
  if (x > 5.0) {
    return (1.0);
  }
  if (fabs(x) <= 1.5) {
    num = 12;
  }
  if (fabs(x) <= 1.8) {
    num = 20;
  }
  if (fabs(x) <= 3.0) {
    num = 40;
  }
  for (i = 0; i <= num; i++) {
    y += (pow((-1.0), i) * pow(x, 2 * i + 1)) / (monte_fact(i) * (2 * i + 1));
  }
  y = 0.5 + 0.5 * (2.0 / sqrt(3.1415926535897932384626433832795029L)) * y;
  return (y);
}


x86 assembly (clang, -O0):
<monte_errf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movq   $0x3c,-0x28(%rbp)
movsd  0xeab(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    116d <monte_errf+0x3d>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12f9 <monte_errf+0x1c9>
movsd  -0x10(%rbp),%xmm0
movsd  0xe8e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1196 <monte_errf+0x66>
movsd  0xeb4(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12f9 <monte_errf+0x1c9>
movsd  -0x10(%rbp),%xmm1
movaps 0xeae(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe62(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     11c0 <monte_errf+0x90>
movq   $0xc,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm1
movaps 0xe84(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe40(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     11ea <monte_errf+0xba>
movq   $0x14,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm1
movaps 0xe5a(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe1e(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     1214 <monte_errf+0xe4>
movq   $0x28,-0x28(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jg     12ad <monte_errf+0x17d>
mov    -0x18(%rbp),%rax
mov    %eax,%edi
movsd  0xe00(%rip),%xmm0
call   1040 <pow@plt>
mov    %eax,-0x34(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1040 <pow@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
imul   %ecx,%eax
cltq
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <monte_fact@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
mov    -0x18(%rbp),%rdx
shl    $0x1,%rdx
add    $0x1,%rdx
imul   %rdx,%rcx
cqto
idiv   %rcx
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    121c <monte_errf+0xec>
mov    %rsp,%rax
fldt   0xdaa(%rip)
fstpt  (%rax)
call   1050 <sqrt@plt>
movsd  0xd6b(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  0xd57(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd42(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<monte_errf>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
movsd  0xeb4(%rip),%xmm1
ucomisd %xmm2,%xmm1
ja     128c <monte_errf+0x15c>
ucomisd 0xeb2(%rip),%xmm2
jbe    116d <monte_errf+0x3d>
movsd  0xea0(%rip),%xmm0
jmp    128c <monte_errf+0x15c>
movapd 0xedb(%rip),%xmm0
movapd %xmm2,0x20(%rsp)
andpd  %xmm2,%xmm0
movsd  0xe91(%rip),%xmm1
ucomisd %xmm0,%xmm1
mov    $0x3d,%eax
mov    $0xd,%ecx
cmovb  %rax,%rcx
movsd  0xe7f(%rip),%xmm1
ucomisd %xmm0,%xmm1
mov    $0x15,%eax
cmovb  %rcx,%rax
movsd  0xe72(%rip),%xmm1
ucomisd %xmm0,%xmm1
mov    $0x29,%r12d
cmovb  %rax,%r12
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x18(%rsp)
mov    $0x1,%r14d
xor    %ebx,%ebx
jmp    120d <monte_errf+0xdd>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rax
cqto
idiv   %rcx
movsd  0x18(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
add    $0x1,%rbx
add    $0x2,%r14
cmp    %rbx,%r12
je     1258 <monte_errf+0x128>
movsd  0xe1b(%rip),%xmm0
mov    %ebx,%edi
call   1040 <pow@plt>
mov    %eax,%r15d
movaps 0x20(%rsp),%xmm0
mov    %r14d,%edi
call   1040 <pow@plt>
mov    %eax,%ebp
imul   %r15d,%ebp
movslq %ebp,%r15
mov    %rbx,%rdi
call   1030 <monte_fact@plt>
movslq %eax,%rcx
imul   %r14,%rcx
mov    %r15,%rax
or     %rcx,%rax
shr    $0x20,%rax
jne    11e0 <monte_errf+0xb0>
mov    %ebp,%eax
xor    %edx,%edx
div    %ecx
jmp    11e8 <monte_errf+0xb8>
fldt   0xe02(%rip)
fstpt  (%rsp)
call   1050 <sqrt@plt>
movsd  0xdca(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  0xdc6(%rip),%xmm0
mulsd  %xmm0,%xmm1
mulsd  0x18(%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @monte_errf(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i64
%5 = alloca double
%6 = alloca i64
store double %0, double* %3
store double 0.000000e+00, double* %5
store i64 60, i64* %6
%7 = load double, double* %3
%8 = fcmp olt double %7, -5.000000e+00
br i1 %8, label %9, label %10
9: ; preds = %1
store double 0.000000e+00, double* %2
br label %67
10: ; preds = %1
%11 = load double, double* %3
%12 = fcmp ogt double %11, 5.000000e+00
br i1 %12, label %13, label %14
13: ; preds = %10
store double 1.000000e+00, double* %2
br label %67
14: ; preds = %10
%15 = load double, double* %3
%16 = call double @llvm.fabs.f64(double %15)
%17 = fcmp ole double %16, 1.500000e+00
br i1 %17, label %18, label %19
18: ; preds = %14
store i64 12, i64* %6
br label %19
19: ; preds = %18, %14
%20 = load double, double* %3
%21 = call double @llvm.fabs.f64(double %20)
%22 = fcmp ole double %21, 1.800000e+00
br i1 %22, label %23, label %24
23: ; preds = %19
store i64 20, i64* %6
br label %24
24: ; preds = %23, %19
%25 = load double, double* %3
%26 = call double @llvm.fabs.f64(double %25)
%27 = fcmp ole double %26, 3.000000e+00
br i1 %27, label %28, label %29
28: ; preds = %24
store i64 40, i64* %6
br label %29
29: ; preds = %28, %24
store i64 0, i64* %4
br label %30
30: ; preds = %57, %29
%31 = load i64, i64* %4
%32 = load i64, i64* %6
%33 = icmp sle i64 %31, %32
br i1 %33, label %34, label %60
34: ; preds = %30
%35 = load i64, i64* %4
%36 = trunc i64 %35 to i32
%37 = call i32 @pow(double -1.000000e+00, i32 %36)
%38 = load double, double* %3
%39 = load i64, i64* %4
%40 = mul nsw i64 2, %39
%41 = add nsw i64 %40, 1
%42 = trunc i64 %41 to i32
%43 = call i32 @pow(double %38, i32 %42)
%44 = mul nsw i32 %37, %43
%45 = sext i32 %44 to i64
%46 = load i64, i64* %4
%47 = call i32 @monte_fact(i64 %46)
%48 = sext i32 %47 to i64
%49 = load i64, i64* %4
%50 = mul nsw i64 2, %49
%51 = add nsw i64 %50, 1
%52 = mul nsw i64 %48, %51
%53 = sdiv i64 %45, %52
%54 = sitofp i64 %53 to double
%55 = load double, double* %5
%56 = fadd double %55, %54
store double %56, double* %5
br label %57
57: ; preds = %34
%58 = load i64, i64* %4
%59 = add nsw i64 %58, 1
store i64 %59, i64* %4
br label %30
60: ; preds = %30
%61 = call double @sqrt(x86_fp80 0xK4000C90FDAA22168C235)
%62 = fdiv double 2.000000e+00, %61
%63 = fmul double 5.000000e-01, %62
%64 = load double, double* %5
%65 = call double @llvm.fmuladd.f64(double %63, double %64, double 5.000000e-01)
store double %65, double* %5
%66 = load double, double* %5
store double %66, double* %2
br label %67
67: ; preds = %60, %13, %9
%68 = load double, double* %2
ret double %68
}

LLVM IR (-O2):
define double @monte_errf(double %0) {
%2 = fcmp olt double %0, -5.000000e+00
br i1 %2, label %37, label %3
3: ; preds = %1
%4 = fcmp ogt double %0, 5.000000e+00
br i1 %4, label %37, label %5
5: ; preds = %3
%6 = tail call double @llvm.fabs.f64(double %0)
%7 = fcmp ugt double %6, 1.500000e+00
%8 = fcmp ugt double %6, 1.800000e+00
%9 = fcmp ugt double %6, 3.000000e+00
%10 = select i1 %7, i64 61, i64 13
%11 = select i1 %8, i64 %10, i64 21
%12 = select i1 %9, i64 %11, i64 41
br label %13
13: ; preds = %5, %13
%14 = phi double [ 0.000000e+00, %5 ], [ %29, %13 ]
%15 = phi i64 [ 0, %5 ], [ %30, %13 ]
%16 = trunc i64 %15 to i32
%17 = tail call i32 @pow(double -1.000000e+00, i32 %16)
%18 = shl nuw nsw i64 %15, 1
%19 = or i64 %18, 1
%20 = trunc i64 %19 to i32
%21 = tail call i32 @pow(double %0, i32 %20)
%22 = mul nsw i32 %21, %17
%23 = sext i32 %22 to i64
%24 = tail call i32 @monte_fact(i64 %15)
%25 = sext i32 %24 to i64
%26 = mul nsw i64 %19, %25
%27 = sdiv i64 %23, %26
%28 = sitofp i64 %27 to double
%29 = fadd double %14, %28
%30 = add nuw nsw i64 %15, 1
%31 = icmp eq i64 %30, %12
br i1 %31, label %32, label %13
32: ; preds = %13
%33 = tail call double @sqrt(x86_fp80 0xK4000C90FDAA22168C235)
%34 = fdiv double 2.000000e+00, %33
%35 = fmul double %34, 5.000000e-01
%36 = tail call double @llvm.fmuladd.f64(double %35, double %29, double 5.000000e-01)
br label %37
37: ; preds = %3, %1, %32
%38 = phi double [ %36, %32 ], [ 0.000000e+00, %1 ], [ 1.000000e+00, %3 ]
ret double %38
}