#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 */
double const erf(double);
int exp(double);
int fabs(double);
int /*<<< orphan*/ log(int);
double sqrt(int /*<<< orphan*/);
double inverf(const double y) {
  double x, diff;
  const double erf_limit = .915;
  if (y < -erf_limit)
    return (-inverf(-y));
  else if (y > erf_limit)
    x = sqrt(-log(1. - y)) - .34;
  else
    x = y * (.8963 + y * y * (.0889 + .494 * y * y));
  do {
    const double dy = erf(x) - y;
    const double slope =
        (2. /
         1.7724538509055160272981674833411451827975494561223871282138077898529113) *
        exp(-x * x);
    diff = -dy / slope;
    diff = -dy / (slope + x * dy);
    x += diff;
  } while (fabs(diff) > 1e-14);
  return (x);
}


x86 assembly (clang, -O0):
<inverf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  0xe93(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe7e(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11cf <inverf+0x6f>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <inverf@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1359 <inverf+0x1f9>
movsd  -0x10(%rbp),%xmm0
movsd  0xe2c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    121b <inverf+0xbb>
movsd  0xe42(%rip),%xmm0
subsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1060 <log@plt>
xor    %edi,%edi
sub    %eax,%edi
call   1070 <sqrt@plt>
movsd  0xe1b(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1265 <inverf+0x105>
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
movsd  0xdee(%rip),%xmm2
mulsd  -0x10(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm3
mulsd  %xmm3,%xmm2
movsd  0xdd0(%rip),%xmm3
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm1
movsd  0xdb8(%rip),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    126a <inverf+0x10a>
jmp    126f <inverf+0x10f>
movsd  -0x18(%rbp),%xmm0
call   1080 <erf@plt>
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x18(%rbp),%xmm0
call   1050 <exp@plt>
cvtsi2sd %eax,%xmm1
movsd  0xd83(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  -0x38(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xcfb(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     126f <inverf+0x10f>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inverf>:
sub    $0x38,%rsp
movsd  0xe94(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1190 <inverf+0x30>
xorpd  0xec6(%rip),%xmm0
call   1030 <inverf@plt>
movapd %xmm0,%xmm2
xorpd  0xeb5(%rip),%xmm2
jmp    1287 <inverf+0x127>
ucomisd 0xe70(%rip),%xmm0
movapd %xmm0,0x10(%rsp)
jbe    11cc <inverf+0x6c>
movsd  0xe80(%rip),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
call   1060 <log@plt>
neg    %eax
mov    %eax,%edi
call   1070 <sqrt@plt>
movapd %xmm0,%xmm2
addsd  0xe66(%rip),%xmm2
jmp    1200 <inverf+0xa0>
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movsd  0xe34(%rip),%xmm2
mulsd  %xmm0,%xmm2
mulsd  %xmm0,%xmm2
addsd  0xe2c(%rip),%xmm2
mulsd  %xmm1,%xmm2
addsd  0xe28(%rip),%xmm2
mulsd  %xmm0,%xmm2
nopl   0x0(%rax)
movapd %xmm2,(%rsp)
movapd %xmm2,%xmm0
call   1080 <erf@plt>
subsd  0x10(%rsp),%xmm0
movapd %xmm0,0x20(%rsp)
movapd (%rsp),%xmm0
movapd 0xe19(%rip),%xmm1
xorpd  %xmm1,%xmm0
mulsd  (%rsp),%xmm0
call   1050 <exp@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xdf4(%rip),%xmm0
movapd (%rsp),%xmm1
movapd 0x20(%rsp),%xmm2
mulsd  %xmm2,%xmm1
xorpd  0xde5(%rip),%xmm2
addsd  %xmm0,%xmm1
divsd  %xmm1,%xmm2
movapd (%rsp),%xmm0
addsd  %xmm2,%xmm0
movapd %xmm0,(%rsp)
movapd %xmm2,%xmm0
call   1040 <fabs@plt>
movapd (%rsp),%xmm2
test   %eax,%eax
jg     1200 <inverf+0xa0>
movapd %xmm2,%xmm0
add    $0x38,%rsp
ret

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

LLVM IR (-O2):
define double @inverf(double %0) {
%2 = fcmp olt double %0, -9.150000e-01
br i1 %2, label %5, label %9
3: ; preds = %26, %5
%4 = phi double [ %8, %5 ], [ %38, %26 ]
ret double %4
5: ; preds = %1
%6 = fneg double %0
%7 = tail call double @inverf(double %6)
%8 = fneg double %7
br label %3
9: ; preds = %1
%10 = fcmp ogt double %0, 9.150000e-01
br i1 %10, label %11, label %18
11: ; preds = %9
%12 = fsub double 1.000000e+00, %0
%13 = fptosi double %12 to i32
%14 = tail call i32 @log(i32 %13)
%15 = sub nsw i32 0, %14
%16 = tail call double @sqrt(i32 %15)
%17 = fadd double %16, -3.400000e-01
br label %24
18: ; preds = %9
%19 = fmul double %0, %0
%20 = fmul double %0, 4.940000e-01
%21 = tail call double @llvm.fmuladd.f64(double %20, double %0, double 8.890000e-02)
%22 = tail call double @llvm.fmuladd.f64(double %19, double %21, double 8.963000e-01)
%23 = fmul double %22, %0
br label %24
24: ; preds = %11, %18
%25 = phi double [ %23, %18 ], [ %17, %11 ]
br label %26
26: ; preds = %24, %26
%27 = phi double [ %38, %26 ], [ %25, %24 ]
%28 = tail call double @erf(double %27)
%29 = fsub double %28, %0
%30 = fneg double %27
%31 = fmul double %27, %30
%32 = tail call i32 @exp(double %31)
%33 = sitofp i32 %32 to double
%34 = fmul double %33, 0x3FF20DD750429B6D
%35 = fneg double %29
%36 = tail call double @llvm.fmuladd.f64(double %27, double %29, double %34)
%37 = fdiv double %35, %36
%38 = fadd double %27, %37
%39 = tail call i32 @fabs(double %37)
%40 = icmp sgt i32 %39, 0
br i1 %40, label %26, label %3
}