#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 exp(double);
double fabs(double);
double GaussianIntegral(double x) {
  int swap = 0, steps = 1;
  double vals[2] = {-2, -2};
  if (x > 0) {
    x = -x;
    swap = 1;
  }
  do {
    double C, v = 0.5;
    int i;
    steps *= 2;
    C = fabs(x / steps) * (0.39894228040143270 / 6);
    for (i = 0; i < steps; i++) {
      double a = x * i / steps;
      double b = x * (i + 1) / steps;
      double m = (a + b) / 2;
      v -= C * (exp(a * a * -0.5) + 4 * exp(m * m * -0.5) + exp(b * b * -0.5));
    }
    vals[0] = vals[1];
    vals[1] = v;
  } while (fabs(vals[1] - vals[0]) > 0.00000001 && steps < 1000);
  if (vals[1] < 0)
    vals[1] = 0;
  if (swap)
    vals[1] = 1.0 - vals[1];
  return vals[1];
}


x86 assembly (clang, -O0):
<GaussianIntegral>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    0xf0e(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xf0b(%rip),%rax
mov    %rax,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    117b <GaussianIntegral+0x6b>
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
jmp    1180 <GaussianIntegral+0x70>
movsd  0xe80(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movaps 0xe85(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xe49(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    12dd <GaussianIntegral+0x1cd>
movsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0x34(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    -0x34(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  0xe06(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x40(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  0xdd9(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1030 <exp@plt>
mov    %eax,-0x64(%rbp)
movsd  -0x50(%rbp),%xmm0
mulsd  -0x50(%rbp),%xmm0
movsd  0xdbb(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1030 <exp@plt>
mov    %eax,%ecx
mov    -0x64(%rbp),%eax
shl    $0x2,%ecx
add    %ecx,%eax
mov    %eax,-0x54(%rbp)
movsd  -0x48(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  0xd93(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1030 <exp@plt>
movsd  -0x60(%rbp),%xmm0
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
add    %ecx,%eax
cvtsi2sd %eax,%xmm2
movsd  -0x30(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11c7 <GaussianIntegral+0xb7>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movaps 0xd2e(%rip),%xmm1
pand   %xmm1,%xmm0
xor    %eax,%eax
movsd  0xd00(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x65(%rbp)
jbe    132a <GaussianIntegral+0x21a>
cmpl   $0x3e8,-0x10(%rbp)
setl   %al
mov    %al,-0x65(%rbp)
mov    -0x65(%rbp),%al
test   $0x1,%al
jne    1180 <GaussianIntegral+0x70>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    134b <GaussianIntegral+0x23b>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1367 <GaussianIntegral+0x257>
movsd  0xcbb(%rip),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GaussianIntegral>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
movapd 0xedb(%rip),%xmm1
xorpd  %xmm0,%xmm1
xorpd  %xmm2,%xmm2
cmpltsd %xmm0,%xmm2
andpd  %xmm2,%xmm1
movapd %xmm0,0x10(%rsp)
andnpd %xmm0,%xmm2
orpd   %xmm1,%xmm2
movapd %xmm2,0x20(%rsp)
unpcklpd %xmm2,%xmm2
mov    $0x1,%r14d
movsd  0xec4(%rip),%xmm0
movapd 0xeac(%rip),%xmm1
movsd  0xec4(%rip),%xmm3
movsd  0xec4(%rip),%xmm4
movapd %xmm2,0x30(%rsp)
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
lea    (%r14,%r14,1),%r15d
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
movapd 0x20(%rsp),%xmm5
divsd  %xmm0,%xmm5
andpd  %xmm1,%xmm5
mulsd  0xe81(%rip),%xmm5
movapd %xmm5,0x40(%rsp)
unpcklpd %xmm0,%xmm0
movapd %xmm0,0x50(%rsp)
xor    %ebp,%ebp
movapd %xmm3,%xmm5
nopl   (%rax)
movsd  %xmm5,0x8(%rsp)
movd   %ebp,%xmm0
add    $0x1,%ebp
movd   %ebp,%xmm1
punpckldq %xmm1,%xmm0
cvtdq2pd %xmm0,%xmm0
mulpd  %xmm2,%xmm0
divpd  0x50(%rsp),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
movapd %xmm1,0x70(%rsp)
movapd %xmm0,%xmm2
addsd  %xmm1,%xmm2
mulsd  %xmm3,%xmm2
movapd %xmm2,0x60(%rsp)
mulsd  %xmm0,%xmm0
mulsd  %xmm4,%xmm0
call   1030 <exp@plt>
mov    %eax,%ebx
movapd 0x60(%rsp),%xmm0
mulsd  %xmm0,%xmm0
mulsd  0xe14(%rip),%xmm0
call   1030 <exp@plt>
lea    (%rbx,%rax,4),%ebx
movapd 0x70(%rsp),%xmm0
mulsd  %xmm0,%xmm0
mulsd  0xdfa(%rip),%xmm0
call   1030 <exp@plt>
movsd  0x8(%rsp),%xmm5
movsd  0xde7(%rip),%xmm4
movsd  0xdd7(%rip),%xmm3
movapd 0x30(%rsp),%xmm2
add    %ebx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x40(%rsp),%xmm0
addsd  %xmm0,%xmm5
cmp    %ebp,%r15d
jne    11c0 <GaussianIntegral+0xb0>
movapd %xmm5,%xmm0
subsd  (%rsp),%xmm0
movapd 0xd84(%rip),%xmm1
andpd  %xmm1,%xmm0
ucomisd 0xda8(%rip),%xmm0
jbe    12ae <GaussianIntegral+0x19e>
movapd %xmm5,%xmm0
cmp    $0x1f4,%r14d
mov    %r15d,%r14d
jb     1180 <GaussianIntegral+0x70>
xorpd  %xmm0,%xmm0
xorpd  %xmm1,%xmm1
maxsd  %xmm5,%xmm1
movsd  0xd86(%rip),%xmm2
subsd  %xmm1,%xmm2
cmpltsd 0x10(%rsp),%xmm0
movapd %xmm0,%xmm3
andnpd %xmm1,%xmm3
andpd  %xmm2,%xmm0
orpd   %xmm3,%xmm0
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.GaussianIntegral.vals = [2 x double] [double -2.000000e+00, double -2.000000e+00]
define double @GaussianIntegral(double %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca i32
%5 = alloca [2 x double]
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
store double %0, double* %2
store i32 0, i32* %3
store i32 1, i32* %4
%12 = bitcast [2 x double]* %5 to i8*
%13 = load double, double* %2
%14 = fcmp ogt double %13, 0.000000e+00
br i1 %14, label %15, label %18
15: ; preds = %1
%16 = load double, double* %2
%17 = fneg double %16
store double %17, double* %2
store i32 1, i32* %3
br label %18
18: ; preds = %15, %1
br label %19
19: ; preds = %95, %18
store double 5.000000e-01, double* %7
%20 = load i32, i32* %4
%21 = mul nsw i32 %20, 2
store i32 %21, i32* %4
%22 = load double, double* %2
%23 = load i32, i32* %4
%24 = sitofp i32 %23 to double
%25 = fdiv double %22, %24
%26 = call double @llvm.fabs.f64(double %25)
%27 = fmul double %26, 0x3FB1058377E2CEE1
store double %27, double* %6
store i32 0, i32* %8
br label %28
28: ; preds = %75, %19
%29 = load i32, i32* %8
%30 = load i32, i32* %4
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %78
32: ; preds = %28
%33 = load double, double* %2
%34 = load i32, i32* %8
%35 = sitofp i32 %34 to double
%36 = fmul double %33, %35
%37 = load i32, i32* %4
%38 = sitofp i32 %37 to double
%39 = fdiv double %36, %38
store double %39, double* %9
%40 = load double, double* %2
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
%43 = sitofp i32 %42 to double
%44 = fmul double %40, %43
%45 = load i32, i32* %4
%46 = sitofp i32 %45 to double
%47 = fdiv double %44, %46
store double %47, double* %10
%48 = load double, double* %9
%49 = load double, double* %10
%50 = fadd double %48, %49
%51 = fdiv double %50, 2.000000e+00
store double %51, double* %11
%52 = load double, double* %6
%53 = load double, double* %9
%54 = load double, double* %9
%55 = fmul double %53, %54
%56 = fmul double %55, -5.000000e-01
%57 = call i32 @exp(double %56)
%58 = load double, double* %11
%59 = load double, double* %11
%60 = fmul double %58, %59
%61 = fmul double %60, -5.000000e-01
%62 = call i32 @exp(double %61)
%63 = mul nsw i32 4, %62
%64 = add nsw i32 %57, %63
%65 = load double, double* %10
%66 = load double, double* %10
%67 = fmul double %65, %66
%68 = fmul double %67, -5.000000e-01
%69 = call i32 @exp(double %68)
%70 = add nsw i32 %64, %69
%71 = sitofp i32 %70 to double
%72 = load double, double* %7
%73 = fneg double %52
%74 = call double @llvm.fmuladd.f64(double %73, double %71, double %72)
store double %74, double* %7
br label %75
75: ; preds = %32
%76 = load i32, i32* %8
%77 = add nsw i32 %76, 1
store i32 %77, i32* %8
br label %28
78: ; preds = %28
%79 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 1
%80 = load double, double* %79
%81 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
store double %80, double* %81
%82 = load double, double* %7
%83 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 1
store double %82, double* %83
br label %84
84: ; preds = %78
%85 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 1
%86 = load double, double* %85
%87 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
%88 = load double, double* %87
%89 = fsub double %86, %88
%90 = call double @llvm.fabs.f64(double %89)
%91 = fcmp ogt double %90, 1.000000e-08
br i1 %91, label %92, label %95
92: ; preds = %84
%93 = load i32, i32* %4
%94 = icmp slt i32 %93, 1000
br label %95
95: ; preds = %92, %84
%96 = phi i1 [ false, %84 ], [ %94, %92 ]
br i1 %96, label %19, label %97
97: ; preds = %95
%98 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 1
%99 = load double, double* %98
%100 = fcmp olt double %99, 0.000000e+00
br i1 %100, label %101, label %103
101: ; preds = %97
%102 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 1
store double 0.000000e+00, double* %102
br label %103
103: ; preds = %101, %97
%104 = load i32, i32* %3
%105 = icmp ne i32 %104, 0
br i1 %105, label %106, label %111
106: ; preds = %103
%107 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 1
%108 = load double, double* %107
%109 = fsub double 1.000000e+00, %108
%110 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 1
store double %109, double* %110
br label %111
111: ; preds = %106, %103
%112 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 1
%113 = load double, double* %112
ret double %113
}

LLVM IR (-O2):
define double @GaussianIntegral(double %0) {
%2 = fcmp ogt double %0, 0.000000e+00
%3 = fneg double %0
%4 = select i1 %2, double %3, double %0
%5 = insertelement <2 x double> poison, double %4, i64 0
%6 = shufflevector <2 x double> %5, <2 x double> poison, <2 x i32> zeroinitializer
br label %7
7: ; preds = %1, %46
%8 = phi double [ -2.000000e+00, %1 ], [ %44, %46 ]
%9 = phi i32 [ 1, %1 ], [ %10, %46 ]
%10 = shl i32 %9, 1
%11 = sitofp i32 %10 to double
%12 = fdiv double %4, %11
%13 = tail call double @llvm.fabs.f64(double %12)
%14 = fmul double %13, 0xBFB1058377E2CEE1
%15 = insertelement <2 x double> poison, double %11, i64 0
%16 = shufflevector <2 x double> %15, <2 x double> poison, <2 x i32> zeroinitializer
br label %17
17: ; preds = %7, %17
%18 = phi i32 [ 0, %7 ], [ %20, %17 ]
%19 = phi double [ 5.000000e-01, %7 ], [ %44, %17 ]
%20 = add nuw nsw i32 %18, 1
%21 = insertelement <2 x i32> poison, i32 %18, i64 0
%22 = insertelement <2 x i32> %21, i32 %20, i64 1
%23 = sitofp <2 x i32> %22 to <2 x double>
%24 = fmul <2 x double> %6, %23
%25 = fdiv <2 x double> %24, %16
%26 = extractelement <2 x double> %25, i64 0
%27 = extractelement <2 x double> %25, i64 1
%28 = fadd double %26, %27
%29 = fmul double %28, 5.000000e-01
%30 = fmul <2 x double> %25, %25
%31 = extractelement <2 x double> %30, i64 0
%32 = fmul double %31, -5.000000e-01
%33 = tail call i32 @exp(double %32)
%34 = fmul double %29, %29
%35 = fmul double %34, -5.000000e-01
%36 = tail call i32 @exp(double %35)
%37 = shl nsw i32 %36, 2
%38 = add nsw i32 %37, %33
%39 = fmul double %27, %27
%40 = fmul double %39, -5.000000e-01
%41 = tail call i32 @exp(double %40)
%42 = add nsw i32 %38, %41
%43 = sitofp i32 %42 to double
%44 = tail call double @llvm.fmuladd.f64(double %14, double %43, double %19)
%45 = icmp eq i32 %20, %10
br i1 %45, label %46, label %17
46: ; preds = %17
%47 = fsub double %44, %8
%48 = tail call double @llvm.fabs.f64(double %47)
%49 = fcmp ogt double %48, 1.000000e-08
%50 = icmp ult i32 %9, 500
%51 = select i1 %49, i1 %50, i1 false
br i1 %51, label %7, label %52
52: ; preds = %46
%53 = fcmp olt double %44, 0.000000e+00
%54 = select i1 %53, double 0.000000e+00, double %44
%55 = fsub double 1.000000e+00, %54
%56 = select i1 %2, double %55, double %54
ret double %56
}