#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*/ erfc(double const);
double exp(double const);
double const log(int /*<<< orphan*/);
double peirce_func(const int rayleigh, const double x, const double a,
                   const double b, const double log_P, const int n) {
  const double sqrt_2 =
      1.414213562373095048801688724209698078569671875376948073176679737;
  const double log_R = (rayleigh ? -(x * x + 1.) / 2.
                                 : (x * x - 1.) / 2. + log(erfc(x / sqrt_2)));
  const double tval = exp(b * (log_P - (double)n * log_R));
  const double func = 1. + a * (1. - tval) - x * x;
  return (func);
}


x86 assembly (clang, -O0):
<peirce_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
mov    %esi,-0x2c(%rbp)
movsd  0xea6(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11b0 <peirce_func+0x80>
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe99(%rip),%xmm1
addsd  %xmm1,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe66(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    1209 <peirce_func+0xd9>
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe4a(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xe36(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe18(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <erfc@plt>
mov    %eax,%edi
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
cvtsi2sdl -0x2c(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm3
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
call   1030 <exp@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  0xdb7(%rip),%xmm0
subsd  -0x48(%rbp),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xda6(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<peirce_func>:
push   %rbx
sub    $0x30,%rsp
mov    %esi,%ebx
movsd  %xmm1,0x28(%rsp)
test   %edi,%edi
movsd  %xmm0,0x20(%rsp)
je     115d <peirce_func+0x2d>
mulsd  %xmm0,%xmm0
addsd  0xead(%rip),%xmm0
mulsd  0xead(%rip),%xmm0
jmp    11ad <peirce_func+0x7d>
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
addsd  0xea3(%rip),%xmm1
mulsd  0xea3(%rip),%xmm1
movsd  %xmm1,0x8(%rsp)
divsd  0xe9d(%rip),%xmm0
movsd  %xmm3,0x18(%rsp)
movsd  %xmm2,0x10(%rsp)
call   1050 <erfc@plt>
mov    %eax,%edi
call   1040 <log@plt>
movsd  0x10(%rsp),%xmm2
movsd  0x18(%rsp),%xmm3
addsd  0x8(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
mulsd  %xmm0,%xmm1
subsd  %xmm1,%xmm3
mulsd  %xmm2,%xmm3
movapd %xmm3,%xmm0
call   1030 <exp@plt>
movsd  0xe2f(%rip),%xmm1
movapd %xmm1,%xmm2
subsd  %xmm0,%xmm2
movsd  0x28(%rsp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0x20(%rsp),%xmm1
mulsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @peirce_func(i32 %0, double %1, double %2, double %3, double %4, i32 %5) {
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca i32
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
store i32 %0, i32* %7
store double %1, double* %8
store double %2, double* %9
store double %3, double* %10
store double %4, double* %11
store i32 %5, i32* %12
store double 0x3FF6A09E667F3BCD, double* %13
%17 = load i32, i32* %7
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %6
%20 = load double, double* %8
%21 = load double, double* %8
%22 = call double @llvm.fmuladd.f64(double %20, double %21, double 1.000000e+00)
%23 = fneg double %22
%24 = fdiv double %23, 2.000000e+00
br label %35
25: ; preds = %6
%26 = load double, double* %8
%27 = load double, double* %8
%28 = call double @llvm.fmuladd.f64(double %26, double %27, double -1.000000e+00)
%29 = fdiv double %28, 2.000000e+00
%30 = load double, double* %8
%31 = fdiv double %30, 0x3FF6A09E667F3BCD
%32 = call i32 @erfc(double %31)
%33 = call double @log(i32 %32)
%34 = fadd double %29, %33
br label %35
35: ; preds = %25, %19
%36 = phi double [ %24, %19 ], [ %34, %25 ]
store double %36, double* %14
%37 = load double, double* %10
%38 = load double, double* %11
%39 = load i32, i32* %12
%40 = sitofp i32 %39 to double
%41 = load double, double* %14
%42 = fneg double %40
%43 = call double @llvm.fmuladd.f64(double %42, double %41, double %38)
%44 = fmul double %37, %43
%45 = call double @exp(double %44)
store double %45, double* %15
%46 = load double, double* %9
%47 = load double, double* %15
%48 = fsub double 1.000000e+00, %47
%49 = call double @llvm.fmuladd.f64(double %46, double %48, double 1.000000e+00)
%50 = load double, double* %8
%51 = load double, double* %8
%52 = fneg double %50
%53 = call double @llvm.fmuladd.f64(double %52, double %51, double %49)
store double %53, double* %16
%54 = load double, double* %16
ret double %54
}

LLVM IR (-O2):
define double @peirce_func(i32 %0, double %1, double %2, double %3, double %4, i32 %5) {
%7 = icmp eq i32 %0, 0
br i1 %7, label %11, label %8
8: ; preds = %6
%9 = tail call double @llvm.fmuladd.f64(double %1, double %1, double 1.000000e+00)
%10 = fmul double %9, -5.000000e-01
br label %18
11: ; preds = %6
%12 = tail call double @llvm.fmuladd.f64(double %1, double %1, double -1.000000e+00)
%13 = fmul double %12, 5.000000e-01
%14 = fdiv double %1, 0x3FF6A09E667F3BCD
%15 = tail call i32 @erfc(double %14)
%16 = tail call double @log(i32 %15)
%17 = fadd double %13, %16
br label %18
18: ; preds = %11, %8
%19 = phi double [ %10, %8 ], [ %17, %11 ]
%20 = sitofp i32 %5 to double
%21 = fneg double %20
%22 = tail call double @llvm.fmuladd.f64(double %21, double %19, double %4)
%23 = fmul double %22, %3
%24 = tail call double @exp(double %23)
%25 = fsub double 1.000000e+00, %24
%26 = tail call double @llvm.fmuladd.f64(double %2, double %25, double 1.000000e+00)
%27 = fneg double %1
%28 = tail call double @llvm.fmuladd.f64(double %27, double %1, double %26)
ret double %28
}