#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 erf(double);
double erfc(double);
int /*<<< orphan*/ error(char *);
double normcdf(double x, double mu, double sig) {
  if (sig < 0)
    error("Parameter sig is smaller than 0.");
  if (x > 3 * sig)
    return 0.5 * erfc(-0.7071067811865475 * (x - mu) / sig);
  return 0.5 * (1 + erf(0.7071067811865475 * (x - mu) / sig));
}


x86 assembly (clang, -O0):
<normcdf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1161 <normcdf+0x31>
lea    0xec4(%rip),%rdi
call   1030 <error@plt>
movsd  -0x10(%rbp),%xmm0
movsd  0xe92(%rip),%xmm1
mulsd  -0x20(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    11b6 <normcdf+0x86>
movsd  -0x10(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movsd  0xe89(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x20(%rbp),%xmm0
call   1050 <erfc@plt>
movaps %xmm0,%xmm1
movsd  0xe60(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11ee <normcdf+0xbe>
movsd  -0x10(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movsd  0xe48(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x20(%rbp),%xmm0
call   1040 <erf@plt>
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe23(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normcdf>:
sub    $0x18,%rsp
xorpd  %xmm3,%xmm3
ucomisd %xmm2,%xmm3
jbe    116c <normcdf+0x3c>
lea    0xedb(%rip),%rdi
movsd  %xmm0,0x10(%rsp)
movsd  %xmm2,0x8(%rsp)
movsd  %xmm1,(%rsp)
call   1030 <error@plt>
movsd  (%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
movsd  0x10(%rsp),%xmm0
movsd  0xe8c(%rip),%xmm3
mulsd  %xmm2,%xmm3
ucomisd %xmm3,%xmm0
subsd  %xmm1,%xmm0
jbe    1195 <normcdf+0x65>
mulsd  0xe86(%rip),%xmm0
divsd  %xmm2,%xmm0
call   1050 <erfc@plt>
jmp    11b0 <normcdf+0x80>
mulsd  0xe6b(%rip),%xmm0
divsd  %xmm2,%xmm0
call   1040 <erf@plt>
add    $0x1,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe60(%rip),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Parameter sig is smaller than 0.\00"
define double @normcdf(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
%8 = load double, double* %7
%9 = fcmp olt double %8, 0.000000e+00
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = call i32 @error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %3
%13 = load double, double* %5
%14 = load double, double* %7
%15 = fmul double 3.000000e+00, %14
%16 = fcmp ogt double %13, %15
br i1 %16, label %17, label %26
17: ; preds = %12
%18 = load double, double* %5
%19 = load double, double* %6
%20 = fsub double %18, %19
%21 = fmul double 0xBFE6A09E667F3BCC, %20
%22 = load double, double* %7
%23 = fdiv double %21, %22
%24 = call double @erfc(double %23)
%25 = fmul double 5.000000e-01, %24
store double %25, double* %4
br label %37
26: ; preds = %12
%27 = load double, double* %5
%28 = load double, double* %6
%29 = fsub double %27, %28
%30 = fmul double 0x3FE6A09E667F3BCC, %29
%31 = load double, double* %7
%32 = fdiv double %30, %31
%33 = call i32 @erf(double %32)
%34 = add nsw i32 1, %33
%35 = sitofp i32 %34 to double
%36 = fmul double 5.000000e-01, %35
store double %36, double* %4
br label %37
37: ; preds = %26, %17
%38 = load double, double* %4
ret double %38
}

LLVM IR (-O2):
@.str = [33 x i8] c"Parameter sig is smaller than 0.\00"
define double @normcdf(double %0, double %1, double %2) {
%4 = fcmp olt double %2, 0.000000e+00
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %3
%8 = fmul double %2, 3.000000e+00
%9 = fcmp olt double %8, %0
%10 = fsub double %0, %1
br i1 %9, label %11, label %15
11: ; preds = %7
%12 = fmul double %10, 0xBFE6A09E667F3BCC
%13 = fdiv double %12, %2
%14 = tail call double @erfc(double %13)
br label %21
15: ; preds = %7
%16 = fmul double %10, 0x3FE6A09E667F3BCC
%17 = fdiv double %16, %2
%18 = tail call i32 @erf(double %17)
%19 = add nsw i32 %18, 1
%20 = sitofp i32 %19 to double
br label %21
21: ; preds = %15, %11
%22 = phi double [ %14, %11 ], [ %20, %15 ]
%23 = fmul double %22, 5.000000e-01
ret double %23
}