#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*/ assert(int);
double log(int);
double rational_approx(int /*<<< orphan*/);
int /*<<< orphan*/ sqrt(double);
double inverse_normalCDF(double p) {
  assert(p <= 0.0 || p >= 1.0);
  if (p < 0.5) {
    return -rational_approx(sqrt(-2.0 * log(p)));
  } else {
    return rational_approx(sqrt(-2.0 * log(1 - p)));
  }
}


x86 assembly (clang, -O0):
<inverse_normalCDF>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    $0x1,%al
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
mov    %al,-0x11(%rbp)
jae    1177 <inverse_normalCDF+0x37>
movsd  -0x10(%rbp),%xmm0
movsd  0xe93(%rip),%xmm1
ucomisd %xmm1,%xmm0
setae  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movsd  0xe7c(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11dd <inverse_normalCDF+0x9d>
cvttsd2si -0x10(%rbp),%edi
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe64(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
mov    %eax,%edi
call   1040 <rational_approx@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1213 <inverse_normalCDF+0xd3>
movsd  0xe1b(%rip),%xmm0
subsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe12(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
mov    %eax,%edi
call   1040 <rational_approx@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inverse_normalCDF>:
push   %rax
movsd  %xmm0,(%rsp)
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
setae  %al
ucomisd 0xea7(%rip),%xmm0
setae  %cl
or     %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
movsd  (%rsp),%xmm1
movsd  0xe95(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11a0 <inverse_normalCDF+0x60>
cvttsd2si %xmm1,%edi
call   1050 <log@plt>
mulsd  0xe86(%rip),%xmm0
call   1060 <sqrt@plt>
mov    %eax,%edi
call   1040 <rational_approx@plt>
xorpd  0xe82(%rip),%xmm0
pop    %rax
ret
movsd  0xe58(%rip),%xmm0
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <log@plt>
mulsd  0xe53(%rip),%xmm0
call   1060 <sqrt@plt>
mov    %eax,%edi
pop    %rax
jmp    1040 <rational_approx@plt>

LLVM IR (-O0):
define double @inverse_normalCDF(double %0) {
%2 = alloca double
%3 = alloca double
store double %0, double* %3
%4 = load double, double* %3
%5 = fcmp ole double %4, 0.000000e+00
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = load double, double* %3
%8 = fcmp oge double %7, 1.000000e+00
br label %9
9: ; preds = %6, %1
%10 = phi i1 [ true, %1 ], [ %8, %6 ]
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load double, double* %3
%14 = fcmp olt double %13, 5.000000e-01
br i1 %14, label %15, label %23
15: ; preds = %9
%16 = load double, double* %3
%17 = fptosi double %16 to i32
%18 = call double @log(i32 %17)
%19 = fmul double -2.000000e+00, %18
%20 = call i32 @sqrt(double %19)
%21 = call double @rational_approx(i32 %20)
%22 = fneg double %21
store double %22, double* %2
br label %31
23: ; preds = %9
%24 = load double, double* %3
%25 = fsub double 1.000000e+00, %24
%26 = fptosi double %25 to i32
%27 = call double @log(i32 %26)
%28 = fmul double -2.000000e+00, %27
%29 = call i32 @sqrt(double %28)
%30 = call double @rational_approx(i32 %29)
store double %30, double* %2
br label %31
31: ; preds = %23, %15
%32 = load double, double* %2
ret double %32
}

LLVM IR (-O2):
define double @inverse_normalCDF(double %0) {
%2 = fcmp ole double %0, 0.000000e+00
%3 = fcmp oge double %0, 1.000000e+00
%4 = or i1 %2, %3
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = fcmp olt double %0, 5.000000e-01
br i1 %7, label %8, label %15
8: ; preds = %1
%9 = fptosi double %0 to i32
%10 = tail call double @log(i32 %9)
%11 = fmul double %10, -2.000000e+00
%12 = tail call i32 @sqrt(double %11)
%13 = tail call double @rational_approx(i32 %12)
%14 = fneg double %13
br label %22
15: ; preds = %1
%16 = fsub double 1.000000e+00, %0
%17 = fptosi double %16 to i32
%18 = tail call double @log(i32 %17)
%19 = fmul double %18, -2.000000e+00
%20 = tail call i32 @sqrt(double %19)
%21 = tail call double @rational_approx(i32 %20)
br label %22
22: ; preds = %15, %8
%23 = phi double [ %14, %8 ], [ %21, %15 ]
ret double %23
}