#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 erfinv(double);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
double sqrt(double);
double normalinv(double p, double mu, double sigma) {
  double oup, t;
  if (sigma < 0.) {
    printf("Standard Deviation (Sigma) must be non-negative");
    exit(1);
  }
  if (p < 0. || p > 1.0) {
    printf("Probablity Values can only take values between 0.0 and 1.0");
    exit(1);
  }
  t = sqrt(2.0) * erfinv(2.0 * p - 1.0);
  oup = t * sigma + mu;
  return oup;
}


x86 assembly (clang, -O0):
<normalinv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    117b <normalinv+0x3b>
lea    0xeac(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
ja     11a0 <normalinv+0x60>
movsd  -0x8(%rbp),%xmm0
movsd  0xe6a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11b6 <normalinv+0x76>
lea    0xea1(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movsd  0xe52(%rip),%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe2f(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1030 <erfinv@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalinv>:
sub    $0x18,%rsp
xorpd  %xmm3,%xmm3
ucomisd %xmm2,%xmm3
ja     1184 <normalinv+0x54>
movsd  %xmm2,0x8(%rsp)
movsd  %xmm1,0x10(%rsp)
ucomisd %xmm0,%xmm3
ja     118d <normalinv+0x5d>
ucomisd 0xea8(%rip),%xmm0
ja     118d <normalinv+0x5d>
addsd  %xmm0,%xmm0
addsd  0xea2(%rip),%xmm0
call   1030 <erfinv@plt>
mulsd  0xe9d(%rip),%xmm0
mulsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
add    $0x18,%rsp
ret
lea    0xe8d(%rip),%rdi
jmp    1194 <normalinv+0x64>
lea    0xeb4(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [48 x i8] c"Standard Deviation (Sigma) must be non-negative\00"
@.str.1 = [59 x i8] c"Probablity Values can only take values between 0.0 and 1.0\00"
define double @normalinv(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double %0, double* %4
store double %1, double* %5
store double %2, double* %6
%9 = load double, double* %6
%10 = fcmp olt double %9, 0.000000e+00
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %3
%15 = load double, double* %4
%16 = fcmp olt double %15, 0.000000e+00
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load double, double* %4
%19 = fcmp ogt double %18, 1.000000e+00
br i1 %19, label %20, label %23
20: ; preds = %17, %14
%21 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %17
%24 = call double @sqrt(double 2.000000e+00)
%25 = load double, double* %4
%26 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %25, double -1.000000e+00)
%27 = call double @erfinv(double %26)
%28 = fmul double %24, %27
store double %28, double* %8
%29 = load double, double* %8
%30 = load double, double* %6
%31 = load double, double* %5
%32 = call double @llvm.fmuladd.f64(double %29, double %30, double %31)
store double %32, double* %7
%33 = load double, double* %7
ret double %33
}

LLVM IR (-O2):
@.str = [48 x i8] c"Standard Deviation (Sigma) must be non-negative\00"
@.str.1 = [59 x i8] c"Probablity Values can only take values between 0.0 and 1.0\00"
define double @normalinv(double %0, double %1, double %2) {
%4 = fcmp olt double %2, 0.000000e+00
br i1 %4, label %5, label %8
5: ; preds = %3
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %3
%9 = fcmp olt double %0, 0.000000e+00
%10 = fcmp ogt double %0, 1.000000e+00
%11 = or i1 %9, %10
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %8
%16 = tail call double @llvm.fmuladd.f64(double %0, double 2.000000e+00, double -1.000000e+00)
%17 = tail call double @erfinv(double %16)
%18 = fmul double %17, 0x3FF6A09E667F3BCD
%19 = tail call double @llvm.fmuladd.f64(double %18, double %2, double %1)
ret double %19
}