#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 M_PI;
int det(double **, int);
double dot(double *, double *, int);
double exp(double);
int /*<<< orphan*/ free_matrix2(double **);
int /*<<< orphan*/ inv(double **, double **, int);
int /*<<< orphan*/ matrix_vec_mult(double *, double **, double *, int, int);
double **new_matrix2(int, int);
int pow(int, int);
double sqrt(int);
int /*<<< orphan*/ sub(double *, double *, double *, int);
double mvnpdf(double *x, double *mu, double **S, int d) {
  double **S_inv = new_matrix2(d, d);
  inv(S_inv, S, d);
  double dx[d];
  sub(dx, x, mu, d);
  double S_inv_dx[d];
  matrix_vec_mult(S_inv_dx, S_inv, dx, d, d);
  double dm = dot(dx, S_inv_dx, d);
  double p = exp(-.5 * dm) / sqrt(pow(2 * M_PI, d) * det(S, d));
  free_matrix2(S_inv);
  return p;
}


x86 assembly (clang, -O0):
<mvnpdf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
mov    %esi,%edi
call   1070 <new_matrix2@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <inv@plt>
mov    -0x1c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x70(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   10c0 <sub@plt>
mov    -0x70(%rbp),%rdx
mov    -0x1c(%rbp),%eax
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x68(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   10b0 <matrix_vec_mult@plt>
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <dot@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  0xda3(%rip),%xmm0
mulsd  -0x48(%rbp),%xmm0
call   1060 <exp@plt>
movsd  %xmm0,-0x58(%rbp)
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
shl    $0x1,%edi
mov    -0x1c(%rbp),%esi
call   1080 <pow@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1090 <det@plt>
mov    -0x5c(%rbp),%edi
imul   %eax,%edi
call   10a0 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <free_matrix2@plt>
movsd  -0x50(%rbp),%xmm0
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mvnpdf>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r12d
mov    %rdx,%rbx
mov    %rdx,-0x40(%rbp)
mov    %rsi,-0x30(%rbp)
mov    %rdi,%r13
mov    %ecx,%edi
mov    %ecx,%esi
call   1070 <new_matrix2@plt>
mov    %rax,-0x38(%rbp)
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1050 <inv@plt>
mov    %r12d,%eax
mov    %rsp,%r15
lea    0xf(,%rax,8),%r14
and    $0xfffffffffffffff0,%r14
sub    %r14,%r15
mov    %r15,%rsp
mov    %r15,%rdi
mov    %r13,%rsi
mov    -0x30(%rbp),%rdx
mov    %r12d,%ecx
call   10c0 <sub@plt>
mov    %rsp,%rbx
sub    %r14,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    -0x38(%rbp),%r14
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12d,%ecx
mov    %r12d,%r8d
call   10b0 <matrix_vec_mult@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1030 <dot@plt>
mulsd  0xdc2(%rip),%xmm0
call   1060 <exp@plt>
movsd  %xmm0,-0x30(%rbp)
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
add    %edi,%edi
mov    %r12d,%esi
call   1080 <pow@plt>
mov    %eax,%ebx
mov    -0x40(%rbp),%rdi
mov    %r12d,%esi
call   1090 <det@plt>
imul   %eax,%ebx
mov    %ebx,%edi
call   10a0 <sqrt@plt>
movsd  -0x30(%rbp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,-0x30(%rbp)
mov    %r14,%rdi
call   1040 <free_matrix2@plt>
movsd  -0x30(%rbp),%xmm0
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@M_PI = global i32 0
define double @mvnpdf(double* %0, double* %1, double** %2, i32 %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double**
%8 = alloca i32
%9 = alloca double**
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
%13 = alloca double
%14 = alloca double
store double* %0, double** %5
store double* %1, double** %6
store double** %2, double*** %7
store i32 %3, i32* %8
%15 = load i32, i32* %8
%16 = load i32, i32* %8
%17 = call double** @new_matrix2(i32 %15, i32 %16)
store double** %17, double*** %9
%18 = load double**, double*** %9
%19 = load double**, double*** %7
%20 = load i32, i32* %8
%21 = call i32 @inv(double** %18, double** %19, i32 %20)
%22 = load i32, i32* %8
%23 = zext i32 %22 to i64
%24 = call i8* @llvm.stacksave()
store i8* %24, i8** %10
%25 = alloca double, i64 %23
store i64 %23, i64* %11
%26 = load double*, double** %5
%27 = load double*, double** %6
%28 = load i32, i32* %8
%29 = call i32 @sub(double* %25, double* %26, double* %27, i32 %28)
%30 = load i32, i32* %8
%31 = zext i32 %30 to i64
%32 = alloca double, i64 %31
store i64 %31, i64* %12
%33 = load double**, double*** %9
%34 = load i32, i32* %8
%35 = load i32, i32* %8
%36 = call i32 @matrix_vec_mult(double* %32, double** %33, double* %25, i32 %34, i32 %35)
%37 = load i32, i32* %8
%38 = call double @dot(double* %25, double* %32, i32 %37)
store double %38, double* %13
%39 = load double, double* %13
%40 = fmul double -5.000000e-01, %39
%41 = call double @exp(double %40)
%42 = load i32, i32* @M_PI
%43 = mul nsw i32 2, %42
%44 = load i32, i32* %8
%45 = call i32 @pow(i32 %43, i32 %44)
%46 = load double**, double*** %7
%47 = load i32, i32* %8
%48 = call i32 @det(double** %46, i32 %47)
%49 = mul nsw i32 %45, %48
%50 = call double @sqrt(i32 %49)
%51 = fdiv double %41, %50
store double %51, double* %14
%52 = load double**, double*** %9
%53 = call i32 @free_matrix2(double** %52)
%54 = load double, double* %14
%55 = load i8*, i8** %10
ret double %54
}

LLVM IR (-O2):
@M_PI = global i32 0
define double @mvnpdf(double* %0, double* %1, double** %2, i32 %3) {
%5 = tail call double** @new_matrix2(i32 %3, i32 %3)
%6 = tail call i32 @inv(double** %5, double** %2, i32 %3)
%7 = zext i32 %3 to i64
%8 = alloca double, i64 %7
%9 = call i32 @sub(double* %8, double* %0, double* %1, i32 %3)
%10 = alloca double, i64 %7
%11 = call i32 @matrix_vec_mult(double* %10, double** %5, double* %8, i32 %3, i32 %3)
%12 = call double @dot(double* %8, double* %10, i32 %3)
%13 = fmul double %12, -5.000000e-01
%14 = call double @exp(double %13)
%15 = load i32, i32* @M_PI
%16 = shl nsw i32 %15, 1
%17 = call i32 @pow(i32 %16, i32 %3)
%18 = call i32 @det(double** %2, i32 %3)
%19 = mul nsw i32 %18, %17
%20 = call double @sqrt(i32 %19)
%21 = fdiv double %14, %20
%22 = call i32 @free_matrix2(double** %5)
ret double %21
}