#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*/ SQR(double);
double erfc(double);
double exp(int /*<<< orphan*/);
int log(double);
double sqrt(int);
double inverfc(const double p) {
  double x, err, t, pp;
  if (p >= 2.0)
    return -100.;
  if (p <= 0.0)
    return 100.;
  pp = (p < 1.0) ? p : 2. - p;
  t = sqrt(-2. * log(pp / 2.));
  x = -0.70711 *
      ((2.30753 + t * 0.27061) / (1. + t * (0.99229 + t * 0.04481)) - t);
  for (int j = 0; j < 2; j++) {
    err = erfc(x) - pp;
    x += err / (1.12837916709551257 * exp(-SQR(x)) - x * err);
  }
  return (p < 1.0 ? x : -x);
}


x86 assembly (clang, -O0):
<inverfc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe96(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1186 <inverfc+0x36>
movsd  0xed4(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1365 <inverfc+0x215>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     11a6 <inverfc+0x56>
movsd  0xeac(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1365 <inverfc+0x215>
movsd  0xe5a(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11c8 <inverfc+0x78>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    11da <inverfc+0x8a>
movsd  0xe30(%rip),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe0f(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <log@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe32(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1060 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  0xe03(%rip),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xdff(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  0xdd1(%rip),%xmm3
mulsd  %xmm3,%xmm2
movsd  0xdcd(%rip),%xmm3
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
movsd  0xda5(%rip),%xmm2
addsd  %xmm2,%xmm0
divsd  %xmm0,%xmm1
subsd  -0x28(%rbp),%xmm1
movsd  0xd98(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x2,-0x34(%rbp)
jge    1318 <inverfc+0x1c8>
movsd  -0x18(%rbp),%xmm0
call   1070 <erfc@plt>
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <SQR@plt>
xor    %edi,%edi
sub    %eax,%edi
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
mulsd  -0x20(%rbp),%xmm2
movq   %xmm2,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm2
movsd  0xd4c(%rip),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1288 <inverfc+0x138>
movsd  0xce8(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    133a <inverfc+0x1ea>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    135b <inverfc+0x20b>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inverfc>:
sub    $0x48,%rsp
ucomisd 0xeac(%rip),%xmm0
jae    12df <inverfc+0x18f>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jae    12ec <inverfc+0x19c>
movsd  0xe90(%rip),%xmm2
subsd  %xmm0,%xmm2
movapd %xmm0,%xmm3
cmpltsd 0xe8f(%rip),%xmm3
movapd %xmm0,0x30(%rsp)
movapd %xmm3,%xmm1
andnpd %xmm2,%xmm1
andpd  %xmm0,%xmm3
orpd   %xmm1,%xmm3
movapd %xmm3,0x20(%rsp)
movsd  0xe73(%rip),%xmm0
mulsd  %xmm3,%xmm0
call   1050 <log@plt>
lea    (%rax,%rax,1),%edi
neg    %edi
call   1060 <sqrt@plt>
movsd  0xe60(%rip),%xmm1
mulsd  %xmm0,%xmm1
addsd  0xe5c(%rip),%xmm1
movapd %xmm0,%xmm2
unpcklpd %xmm0,%xmm2
movapd 0xe6c(%rip),%xmm3
unpcklpd %xmm1,%xmm3
mulpd  %xmm2,%xmm3
addpd  0xe6c(%rip),%xmm3
movapd %xmm3,%xmm1
unpckhpd %xmm3,%xmm1
divsd  %xmm1,%xmm3
subsd  %xmm0,%xmm3
mulsd  0xe2c(%rip),%xmm3
movapd %xmm3,0x10(%rsp)
movapd %xmm3,%xmm0
call   1070 <erfc@plt>
subsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movapd 0x10(%rsp),%xmm0
call   1030 <SQR@plt>
neg    %eax
mov    %eax,%edi
call   1040 <exp@plt>
movsd  0x8(%rsp),%xmm3
movapd %xmm3,%xmm1
movapd 0x10(%rsp),%xmm2
mulsd  %xmm2,%xmm1
mulsd  0xde9(%rip),%xmm0
subsd  %xmm1,%xmm0
movapd %xmm3,%xmm1
divsd  %xmm0,%xmm1
addsd  %xmm2,%xmm1
movsd  %xmm1,0x8(%rsp)
movapd %xmm1,%xmm0
call   1070 <erfc@plt>
movapd %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <SQR@plt>
neg    %eax
mov    %eax,%edi
call   1040 <exp@plt>
movsd  0xd80(%rip),%xmm1
ucomisd 0x30(%rsp),%xmm1
movapd 0x10(%rsp),%xmm3
subsd  0x20(%rsp),%xmm3
movapd %xmm3,%xmm1
movsd  0x8(%rsp),%xmm2
mulsd  %xmm2,%xmm1
mulsd  0xd80(%rip),%xmm0
subsd  %xmm1,%xmm0
divsd  %xmm0,%xmm3
movapd %xmm3,%xmm0
addsd  %xmm2,%xmm0
ja     12da <inverfc+0x18a>
xorpd  0xd96(%rip),%xmm0
add    $0x48,%rsp
ret
movsd  0xd19(%rip),%xmm0
add    $0x48,%rsp
ret
movsd  0xd1c(%rip),%xmm0
add    $0x48,%rsp
ret

LLVM IR (-O0):
define double @inverfc(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
store double %0, double* %3
%9 = load double, double* %3
%10 = fcmp oge double %9, 2.000000e+00
br i1 %10, label %11, label %12
11: ; preds = %1
store double -1.000000e+02, double* %2
br label %77
12: ; preds = %1
%13 = load double, double* %3
%14 = fcmp ole double %13, 0.000000e+00
br i1 %14, label %15, label %16
15: ; preds = %12
store double 1.000000e+02, double* %2
br label %77
16: ; preds = %12
%17 = load double, double* %3
%18 = fcmp olt double %17, 1.000000e+00
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = load double, double* %3
br label %24
21: ; preds = %16
%22 = load double, double* %3
%23 = fsub double 2.000000e+00, %22
br label %24
24: ; preds = %21, %19
%25 = phi double [ %20, %19 ], [ %23, %21 ]
store double %25, double* %7
%26 = load double, double* %7
%27 = fdiv double %26, 2.000000e+00
%28 = call i32 @log(double %27)
%29 = sitofp i32 %28 to double
%30 = fmul double -2.000000e+00, %29
%31 = fptosi double %30 to i32
%32 = call double @sqrt(i32 %31)
store double %32, double* %6
%33 = load double, double* %6
%34 = call double @llvm.fmuladd.f64(double %33, double 2.706100e-01, double 2.307530e+00)
%35 = load double, double* %6
%36 = load double, double* %6
%37 = call double @llvm.fmuladd.f64(double %36, double 4.481000e-02, double 9.922900e-01)
%38 = call double @llvm.fmuladd.f64(double %35, double %37, double 1.000000e+00)
%39 = fdiv double %34, %38
%40 = load double, double* %6
%41 = fsub double %39, %40
%42 = fmul double -7.071100e-01, %41
store double %42, double* %4
store i32 0, i32* %8
br label %43
43: ; preds = %64, %24
%44 = load i32, i32* %8
%45 = icmp slt i32 %44, 2
br i1 %45, label %46, label %67
46: ; preds = %43
%47 = load double, double* %4
%48 = call double @erfc(double %47)
%49 = load double, double* %7
%50 = fsub double %48, %49
store double %50, double* %5
%51 = load double, double* %5
%52 = load double, double* %4
%53 = call i32 @SQR(double %52)
%54 = sub nsw i32 0, %53
%55 = call double @exp(i32 %54)
%56 = load double, double* %4
%57 = load double, double* %5
%58 = fmul double %56, %57
%59 = fneg double %58
%60 = call double @llvm.fmuladd.f64(double 0x3FF20DD750429B6D, double %55, double %59)
%61 = fdiv double %51, %60
%62 = load double, double* %4
%63 = fadd double %62, %61
store double %63, double* %4
br label %64
64: ; preds = %46
%65 = load i32, i32* %8
%66 = add nsw i32 %65, 1
store i32 %66, i32* %8
br label %43
67: ; preds = %43
%68 = load double, double* %3
%69 = fcmp olt double %68, 1.000000e+00
br i1 %69, label %70, label %72
70: ; preds = %67
%71 = load double, double* %4
br label %75
72: ; preds = %67
%73 = load double, double* %4
%74 = fneg double %73
br label %75
75: ; preds = %72, %70
%76 = phi double [ %71, %70 ], [ %74, %72 ]
store double %76, double* %2
br label %77
77: ; preds = %75, %15, %11
%78 = load double, double* %2
ret double %78
}

LLVM IR (-O2):
define double @inverfc(double %0) {
%2 = fcmp ult double %0, 2.000000e+00
br i1 %2, label %3, label %45
3: ; preds = %1
%4 = fcmp ugt double %0, 0.000000e+00
br i1 %4, label %5, label %45
5: ; preds = %3
%6 = fcmp olt double %0, 1.000000e+00
%7 = fsub double 2.000000e+00, %0
%8 = select i1 %6, double %0, double %7
%9 = fmul double %8, 5.000000e-01
%10 = tail call i32 @log(double %9)
%11 = mul i32 %10, -2
%12 = tail call double @sqrt(i32 %11)
%13 = tail call double @llvm.fmuladd.f64(double %12, double 4.481000e-02, double 9.922900e-01)
%14 = insertelement <2 x double> poison, double %12, i64 0
%15 = shufflevector <2 x double> %14, <2 x double> poison, <2 x i32> zeroinitializer
%16 = insertelement <2 x double> <double 2.706100e-01, double poison>, double %13, i64 1
%17 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %15, <2 x double> %16, <2 x double> <double 2.307530e+00, double 1.000000e+00>)
%18 = extractelement <2 x double> %17, i64 0
%19 = extractelement <2 x double> %17, i64 1
%20 = fdiv double %18, %19
%21 = fsub double %20, %12
%22 = fmul double %21, -7.071100e-01
%23 = tail call double @erfc(double %22)
%24 = fsub double %23, %8
%25 = tail call i32 @SQR(double %22)
%26 = sub nsw i32 0, %25
%27 = tail call double @exp(i32 %26)
%28 = fneg double %22
%29 = fmul double %24, %28
%30 = tail call double @llvm.fmuladd.f64(double %27, double 0x3FF20DD750429B6D, double %29)
%31 = fdiv double %24, %30
%32 = fadd double %22, %31
%33 = tail call double @erfc(double %32)
%34 = fsub double %33, %8
%35 = tail call i32 @SQR(double %32)
%36 = sub nsw i32 0, %35
%37 = tail call double @exp(i32 %36)
%38 = fneg double %32
%39 = fmul double %34, %38
%40 = tail call double @llvm.fmuladd.f64(double %37, double 0x3FF20DD750429B6D, double %39)
%41 = fdiv double %34, %40
%42 = fadd double %32, %41
%43 = fneg double %42
%44 = select i1 %6, double %42, double %43
br label %45
45: ; preds = %3, %1, %5
%46 = phi double [ %44, %5 ], [ -1.000000e+02, %1 ], [ 1.000000e+02, %3 ]
ret double %46
}