#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*/ exit(int);
double fabs(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
double normal(double, char const *);
double normal_density(double);
int /*<<< orphan*/ stderr;
double normal_inv(double p, const char *prompt) {
  static double last_p = 0.5, last_x = 0;
  double x, xx;
  static const double eps = 1e-10;
  if (p <= 0 || p >= 1) {
    fprintf(stderr,
            "%s: IMPLEMENTATION ERROR! (Invalid argument in function "
            "\"normal_inv\")\n",
            prompt);
    exit(4);
  }
  if ((((p) != (p)) || ((last_p) != (last_p))
           ? (((p) != (p)) && ((last_p) != (last_p)) ? 1 : 0)
           : !(p < last_p || last_p < p)))
    return last_x;
  if ((((p) != (p)) || ((0.5) != (0.5))
           ? (((p) != (p)) && ((0.5) != (0.5)) ? 1 : 0)
           : !(p < 0.5 || 0.5 < p)))
    return 0;
  else if (p < 0.5)
    return -normal_inv(1 - p, prompt);
  else {
    x = 0;
    while (1) {
      xx = x - (normal(x, prompt) - p) / normal_density(x);
      if (fabs(xx - x) < x * eps)
        break;
      x = xx;
    }
    last_p = p;
    last_x = x;
    return x;
  }
}


x86 assembly (clang, -O0):
<normal_inv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jae    1186 <normal_inv+0x36>
movsd  -0x10(%rbp),%xmm0
movsd  0xe84(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11a9 <normal_inv+0x59>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe9e(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x4,%edi
call   1060 <exit@plt>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    11e0 <normal_inv+0x90>
jp     11e0 <normal_inv+0x90>
movsd  0x2e81(%rip),%xmm0
ucomisd 0x2e79(%rip),%xmm0
jne    11e0 <normal_inv+0x90>
jp     11e0 <normal_inv+0x90>
jmp    123a <normal_inv+0xea>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    11fb <normal_inv+0xab>
jp     11fb <normal_inv+0xab>
jmp    122b <normal_inv+0xdb>
movsd  0x2e45(%rip),%xmm0
ucomisd 0x2e3d(%rip),%xmm0
jne    121c <normal_inv+0xcc>
jp     121c <normal_inv+0xcc>
jmp    122b <normal_inv+0xdb>
mov    $0x1,%al
test   $0x1,%al
jne    1268 <normal_inv+0x118>
jmp    127a <normal_inv+0x12a>
xor    %eax,%eax
test   $0x1,%al
jne    1268 <normal_inv+0x118>
jmp    127a <normal_inv+0x12a>
movsd  -0x10(%rbp),%xmm1
movsd  0x2e01(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     127a <normal_inv+0x12a>
movsd  0x2def(%rip),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     127a <normal_inv+0x12a>
movsd  0x2de8(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1410 <normal_inv+0x2c0>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    1295 <normal_inv+0x145>
jp     1295 <normal_inv+0x145>
jmp    12dd <normal_inv+0x18d>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    12b0 <normal_inv+0x160>
jp     12b0 <normal_inv+0x160>
jmp    12ce <normal_inv+0x17e>
xor    %eax,%eax
test   $0x1,%al
jne    12bf <normal_inv+0x16f>
jmp    12ce <normal_inv+0x17e>
mov    $0x1,%al
test   $0x1,%al
jne    1307 <normal_inv+0x1b7>
jmp    1314 <normal_inv+0x1c4>
xor    %eax,%eax
test   $0x1,%al
jne    1307 <normal_inv+0x1b7>
jmp    1314 <normal_inv+0x1c4>
movsd  0xd23(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
ja     1314 <normal_inv+0x1c4>
movsd  -0x10(%rbp),%xmm0
movsd  0xd0b(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     1314 <normal_inv+0x1c4>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1410 <normal_inv+0x2c0>
movsd  0xcec(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    135e <normal_inv+0x20e>
movsd  0xcd1(%rip),%xmm0
subsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rdi
call   1070 <normal_inv@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1410 <normal_inv+0x2c0>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rdi
call   1050 <normal@plt>
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <normal_density@plt>
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
subsd  -0x20(%rbp),%xmm1
movaps 0xc63(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xc47(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    13dd <normal_inv+0x28d>
jmp    13ec <normal_inv+0x29c>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1366 <normal_inv+0x216>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,0x2c4f(%rip)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,0x2c52(%rip)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normal_inv>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jae    128b <normal_inv+0x13b>
ucomisd 0xe8e(%rip),%xmm1
jae    128b <normal_inv+0x13b>
ucomisd %xmm1,%xmm1
movsd  0x2ec4(%rip),%xmm0
jp     12ad <normal_inv+0x15d>
ucomisd %xmm0,%xmm0
jp     11a3 <normal_inv+0x53>
ucomisd %xmm1,%xmm0
jne    11a3 <normal_inv+0x53>
movsd  0x2eba(%rip),%xmm2
jmp    1281 <normal_inv+0x131>
ucomisd 0xe5d(%rip),%xmm1
je     11e0 <normal_inv+0x90>
movsd  0xe53(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11e9 <normal_inv+0x99>
movsd  0xe3d(%rip),%xmm0
subsd  %xmm1,%xmm0
mov    %rbx,%rdi
call   1070 <normal_inv@plt>
movapd %xmm0,%xmm2
xorpd  0xe55(%rip),%xmm2
jmp    1281 <normal_inv+0x131>
xorpd  %xmm2,%xmm2
jmp    1281 <normal_inv+0x131>
xorpd  %xmm3,%xmm3
movsd  %xmm1,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  %xmm3,0x18(%rsp)
movapd %xmm3,%xmm0
movapd %xmm3,0x20(%rsp)
mov    %rbx,%rdi
call   1050 <normal@plt>
subsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movapd 0x20(%rsp),%xmm0
call   1040 <normal_density@plt>
movsd  0x18(%rsp),%xmm3
movapd 0x20(%rsp),%xmm2
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
subsd  %xmm1,%xmm3
movapd %xmm3,%xmm0
subsd  %xmm2,%xmm0
andpd  0xdc7(%rip),%xmm0
movapd %xmm2,%xmm1
mulsd  0xdab(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1200 <normal_inv+0xb0>
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x2dcf(%rip)
movsd  %xmm2,0x2dd7(%rip)
movapd %xmm2,%xmm0
add    $0x30,%rsp
pop    %rbx
ret
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
lea    0xda5(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
mov    $0x4,%edi
call   1060 <exit@plt>
ucomisd %xmm0,%xmm0
jnp    11ad <normal_inv+0x5d>
jmp    1196 <normal_inv+0x46>

LLVM IR (-O0):
@normal_inv.last_p = internal global double 5.000000e-01
@normal_inv.last_x = internal global double 0.000000e+00
@normal_inv.eps = internal constant double 1.000000e-10
@stderr = global i32 0
@.str = [71 x i8] c"%s: IMPLEMENTATION ERROR! (Invalid argument in function \22normal_inv\22)\0A\00"
define double @normal_inv(double %0, i8* %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca i8*
%6 = alloca double
%7 = alloca double
store double %0, double* %4
store i8* %1, i8** %5
%8 = load double, double* %4
%9 = fcmp ole double %8, 0.000000e+00
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load double, double* %4
%12 = fcmp oge double %11, 1.000000e+00
br i1 %12, label %13, label %18
13: ; preds = %10, %2
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %5
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 4)
unreachable
18: ; preds = %10
%19 = load double, double* %4
%20 = load double, double* %4
%21 = fcmp une double %19, %20
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = load double, double* @normal_inv.last_p
%24 = load double, double* @normal_inv.last_p
%25 = fcmp une double %23, %24
br i1 %25, label %26, label %36
26: ; preds = %22, %18
%27 = load double, double* %4
%28 = load double, double* %4
%29 = fcmp une double %27, %28
br i1 %29, label %30, label %35
30: ; preds = %26
%31 = load double, double* @normal_inv.last_p
%32 = load double, double* @normal_inv.last_p
%33 = fcmp une double %31, %32
br i1 %33, label %34, label %35
34: ; preds = %30
br i1 true, label %44, label %46
35: ; preds = %30, %26
br i1 false, label %44, label %46
36: ; preds = %22
%37 = load double, double* %4
%38 = load double, double* @normal_inv.last_p
%39 = fcmp olt double %37, %38
br i1 %39, label %46, label %40
40: ; preds = %36
%41 = load double, double* @normal_inv.last_p
%42 = load double, double* %4
%43 = fcmp olt double %41, %42
br i1 %43, label %46, label %44
44: ; preds = %40, %35, %34
%45 = load double, double* @normal_inv.last_x
store double %45, double* %3
br label %99
46: ; preds = %40, %36, %35, %34
%47 = load double, double* %4
%48 = load double, double* %4
%49 = fcmp une double %47, %48
br i1 %49, label %50, label %57
50: ; preds = %46
%51 = load double, double* %4
%52 = load double, double* %4
%53 = fcmp une double %51, %52
br i1 %53, label %54, label %56
54: ; preds = %50
br i1 false, label %55, label %56
55: ; preds = %54
br i1 true, label %63, label %64
56: ; preds = %54, %50
br i1 false, label %63, label %64
57: ; preds = %46
%58 = load double, double* %4
%59 = fcmp olt double %58, 5.000000e-01
br i1 %59, label %64, label %60
60: ; preds = %57
%61 = load double, double* %4
%62 = fcmp olt double 5.000000e-01, %61
br i1 %62, label %64, label %63
63: ; preds = %60, %56, %55
store double 0.000000e+00, double* %3
br label %99
64: ; preds = %60, %57, %56, %55
%65 = load double, double* %4
%66 = fcmp olt double %65, 5.000000e-01
br i1 %66, label %67, label %73
67: ; preds = %64
%68 = load double, double* %4
%69 = fsub double 1.000000e+00, %68
%70 = load i8*, i8** %5
%71 = call double @normal_inv(double %69, i8* %70)
%72 = fneg double %71
store double %72, double* %3
br label %99
73: ; preds = %64
store double 0.000000e+00, double* %6
br label %74
74: ; preds = %73, %93
%75 = load double, double* %6
%76 = load double, double* %6
%77 = load i8*, i8** %5
%78 = call double @normal(double %76, i8* %77)
%79 = load double, double* %4
%80 = fsub double %78, %79
%81 = load double, double* %6
%82 = call double @normal_density(double %81)
%83 = fdiv double %80, %82
%84 = fsub double %75, %83
store double %84, double* %7
%85 = load double, double* %7
%86 = load double, double* %6
%87 = fsub double %85, %86
%88 = call double @llvm.fabs.f64(double %87)
%89 = load double, double* %6
%90 = fmul double %89, 1.000000e-10
%91 = fcmp olt double %88, %90
br i1 %91, label %92, label %93
92: ; preds = %74
br label %95
93: ; preds = %74
%94 = load double, double* %7
store double %94, double* %6
br label %74
95: ; preds = %92
%96 = load double, double* %4
store double %96, double* @normal_inv.last_p
%97 = load double, double* %6
store double %97, double* @normal_inv.last_x
%98 = load double, double* %6
store double %98, double* %3
br label %99
99: ; preds = %95, %67, %63, %44
%100 = load double, double* %3
ret double %100
}

LLVM IR (-O2):
@normal_inv.last_p = internal unnamed_addr global double 5.000000e-01
@normal_inv.last_x = internal unnamed_addr global double 0.000000e+00
@stderr = global i32 0
@.str = [71 x i8] c"%s: IMPLEMENTATION ERROR! (Invalid argument in function \22normal_inv\22)\0A\00"
define double @normal_inv(double %0, i8* %1) {
%3 = fcmp ole double %0, 0.000000e+00
%4 = fcmp oge double %0, 1.000000e+00
%5 = or i1 %3, %4
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0), i8* %1)
%9 = tail call i32 @exit(i32 4)
unreachable
10: ; preds = %2
%11 = fcmp uno double %0, 0.000000e+00
%12 = load double, double* @normal_inv.last_p
br i1 %11, label %17, label %13
13: ; preds = %10
%14 = fcmp ord double %12, 0.000000e+00
%15 = fcmp ueq double %12, %0
%16 = and i1 %14, %15
br i1 %16, label %19, label %21
17: ; preds = %10
%18 = fcmp uno double %12, 0.000000e+00
br i1 %18, label %19, label %23
19: ; preds = %13, %17
%20 = load double, double* @normal_inv.last_x
br label %25
21: ; preds = %13
%22 = fcmp ueq double %0, 5.000000e-01
br i1 %22, label %25, label %23
23: ; preds = %17, %21
%24 = fcmp olt double %0, 5.000000e-01
br i1 %24, label %27, label %31
25: ; preds = %19, %42, %21, %27
%26 = phi double [ %30, %27 ], [ %20, %19 ], [ %32, %42 ], [ 0.000000e+00, %21 ]
ret double %26
27: ; preds = %23
%28 = fsub double 1.000000e+00, %0
%29 = tail call double @normal_inv(double %28, i8* %1)
%30 = fneg double %29
br label %25
31: ; preds = %23, %31
%32 = phi double [ %37, %31 ], [ 0.000000e+00, %23 ]
%33 = tail call double @normal(double %32, i8* %1)
%34 = fsub double %33, %0
%35 = tail call double @normal_density(double %32)
%36 = fdiv double %34, %35
%37 = fsub double %32, %36
%38 = fsub double %37, %32
%39 = tail call double @llvm.fabs.f64(double %38)
%40 = fmul double %32, 1.000000e-10
%41 = fcmp olt double %39, %40
br i1 %41, label %42, label %31
42: ; preds = %31
store double %0, double* @normal_inv.last_p
store double %32, double* @normal_inv.last_x
br label %25
}