#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 normal(double x) {
  double arg, result, sqrt2 = 1.414213562373095048801688724209698078569672;
  if (x > 0) {
    arg = x / sqrt2;
    result = 0.5 * (1 + erf(arg));
  } else {
    arg = -x / sqrt2;
    result = 0.5 * (1 - erf(arg));
  }
  return (result);
}


x86 assembly (clang, -O0):
<normal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  0xedb(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1172 <normal+0x62>
movsd  -0x8(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <erf@plt>
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xea4(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11c0 <normal+0xb0>
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <erf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe51(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normal>:
push   %rax
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    112d <normal+0x1d>
divsd  0xee5(%rip),%xmm0
call   1030 <erf@plt>
add    $0x1,%eax
jmp    1143 <normal+0x33>
divsd  0xecb(%rip),%xmm0
call   1030 <erf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
sub    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xebe(%rip),%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @normal(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %2
store double 0x3FF6A09E667F3BCD, double* %5
%6 = load double, double* %2
%7 = fcmp ogt double %6, 0.000000e+00
br i1 %7, label %8, label %17
8: ; preds = %1
%9 = load double, double* %2
%10 = load double, double* %5
%11 = fdiv double %9, %10
store double %11, double* %3
%12 = load double, double* %3
%13 = call i32 @erf(double %12)
%14 = add nsw i32 1, %13
%15 = sitofp i32 %14 to double
%16 = fmul double 5.000000e-01, %15
store double %16, double* %4
br label %27
17: ; preds = %1
%18 = load double, double* %2
%19 = fneg double %18
%20 = load double, double* %5
%21 = fdiv double %19, %20
store double %21, double* %3
%22 = load double, double* %3
%23 = call i32 @erf(double %22)
%24 = sub nsw i32 1, %23
%25 = sitofp i32 %24 to double
%26 = fmul double 5.000000e-01, %25
store double %26, double* %4
br label %27
27: ; preds = %17, %8
%28 = load double, double* %4
ret double %28
}

LLVM IR (-O2):
define double @normal(double %0) {
%2 = fcmp ogt double %0, 0.000000e+00
br i1 %2, label %3, label %7
3: ; preds = %1
%4 = fdiv double %0, 0x3FF6A09E667F3BCD
%5 = tail call i32 @erf(double %4)
%6 = add nsw i32 %5, 1
br label %11
7: ; preds = %1
%8 = fdiv double %0, 0xBFF6A09E667F3BCD
%9 = tail call i32 @erf(double %8)
%10 = sub nsw i32 1, %9
br label %11
11: ; preds = %7, %3
%12 = phi i32 [ %6, %3 ], [ %10, %7 ]
%13 = sitofp i32 %12 to double
%14 = fmul double %13, 5.000000e-01
ret double %14
}