#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;
double dot(double *, double *, int);
double exp(double);
int log(int);
int prod(double *, int);
int /*<<< orphan*/ sub(double *, double *, double *, int);
double mvnpdf_pcs(double *x, double *mu, double *z, double **V, int d) {
  int i;
  double xv, dx[d];
  sub(dx, x, mu, d);
  double logp = -(d / 2) * log(2 * M_PI) - log(prod(z, d));
  for (i = 0; i < d; i++) {
    xv = dot(dx, V[i], d) / z[i];
    logp -= 0.5 * xv * xv;
  }
  return exp(logp);
}


x86 assembly (clang, -O0):
<mvnpdf_pcs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x58(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1070 <sub@plt>
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x50(%rbp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
shl    $0x1,%edi
call   1050 <log@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1060 <prod@plt>
mov    %eax,%edi
call   1050 <log@plt>
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    127c <mvnpdf_pcs+0x12c>
mov    -0x58(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x24(%rbp),%edx
call   1030 <dot@plt>
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
divsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xdc5(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11fd <mvnpdf_pcs+0xad>
movsd  -0x48(%rbp),%xmm0
call   1040 <exp@plt>
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mvnpdf_pcs>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,%r12d
mov    %rcx,-0x38(%rbp)
mov    %rdx,%r13
mov    %rsi,%rdx
mov    %rdi,%rsi
mov    %r8d,%eax
mov    %rsp,%rbx
mov    %rax,-0x30(%rbp)
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r8d,%ecx
call   1070 <sub@plt>
mov    %r12d,%r14d
shr    $0x1f,%r14d
add    %r12d,%r14d
sar    %r14d
neg    %r14d
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
add    %edi,%edi
call   1050 <log@plt>
mov    %eax,%r15d
imul   %r14d,%r15d
mov    %r13,-0x40(%rbp)
mov    %r13,%rdi
mov    %r12d,%esi
call   1060 <prod@plt>
mov    %eax,%edi
call   1050 <log@plt>
sub    %eax,%r15d
cvtsi2sd %r15d,%xmm0
test   %r12d,%r12d
jle    1230 <mvnpdf_pcs+0xe0>
xor    %r14d,%r14d
mov    -0x30(%rbp),%r13
mov    -0x38(%rbp),%r15
nopl   (%rax)
movsd  %xmm0,-0x48(%rbp)
mov    (%r15,%r14,8),%rsi
mov    %rbx,%rdi
mov    %r12d,%edx
call   1030 <dot@plt>
mov    -0x40(%rbp),%rax
divsd  (%rax,%r14,8),%xmm0
movapd %xmm0,%xmm1
mulsd  0xde6(%rip),%xmm1
mulsd  %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
addsd  %xmm1,%xmm0
add    $0x1,%r14
cmp    %r14,%r13
jne    11f0 <mvnpdf_pcs+0xa0>
call   1040 <exp@plt>
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_pcs(double* %0, double* %1, double* %2, double** %3, i32 %4) {
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca double**
%10 = alloca i32
%11 = alloca i32
%12 = alloca double
%13 = alloca i8*
%14 = alloca i64
%15 = alloca double
store double* %0, double** %6
store double* %1, double** %7
store double* %2, double** %8
store double** %3, double*** %9
store i32 %4, i32* %10
%16 = load i32, i32* %10
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %13
%19 = alloca double, i64 %17
store i64 %17, i64* %14
%20 = load double*, double** %6
%21 = load double*, double** %7
%22 = load i32, i32* %10
%23 = call i32 @sub(double* %19, double* %20, double* %21, i32 %22)
%24 = load i32, i32* %10
%25 = sdiv i32 %24, 2
%26 = sub nsw i32 0, %25
%27 = load i32, i32* @M_PI
%28 = mul nsw i32 2, %27
%29 = call i32 @log(i32 %28)
%30 = mul nsw i32 %26, %29
%31 = load double*, double** %8
%32 = load i32, i32* %10
%33 = call i32 @prod(double* %31, i32 %32)
%34 = call i32 @log(i32 %33)
%35 = sub nsw i32 %30, %34
%36 = sitofp i32 %35 to double
store double %36, double* %15
store i32 0, i32* %11
br label %37
37: ; preds = %61, %5
%38 = load i32, i32* %11
%39 = load i32, i32* %10
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %64
41: ; preds = %37
%42 = load double**, double*** %9
%43 = load i32, i32* %11
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double*, double** %42, i64 %44
%46 = load double*, double** %45
%47 = load i32, i32* %10
%48 = call double @dot(double* %19, double* %46, i32 %47)
%49 = load double*, double** %8
%50 = load i32, i32* %11
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %49, i64 %51
%53 = load double, double* %52
%54 = fdiv double %48, %53
store double %54, double* %12
%55 = load double, double* %12
%56 = fmul double 5.000000e-01, %55
%57 = load double, double* %12
%58 = load double, double* %15
%59 = fneg double %56
%60 = call double @llvm.fmuladd.f64(double %59, double %57, double %58)
store double %60, double* %15
br label %61
61: ; preds = %41
%62 = load i32, i32* %11
%63 = add nsw i32 %62, 1
store i32 %63, i32* %11
br label %37
64: ; preds = %37
%65 = load double, double* %15
%66 = call double @exp(double %65)
%67 = load i8*, i8** %13
ret double %66
}

LLVM IR (-O2):
@M_PI = global i32 0
define double @mvnpdf_pcs(double* %0, double* %1, double* %2, double** nocapture %3, i32 %4) {
%6 = zext i32 %4 to i64
%7 = alloca double, i64 %6
%8 = call i32 @sub(double* %7, double* %0, double* %1, i32 %4)
%9 = sdiv i32 %4, -2
%10 = load i32, i32* @M_PI
%11 = shl nsw i32 %10, 1
%12 = call i32 @log(i32 %11)
%13 = mul nsw i32 %12, %9
%14 = call i32 @prod(double* %2, i32 %4)
%15 = call i32 @log(i32 %14)
%16 = sub nsw i32 %13, %15
%17 = sitofp i32 %16 to double
%18 = icmp sgt i32 %4, 0
br i1 %18, label %19, label %32
19: ; preds = %5, %19
%20 = phi i64 [ %30, %19 ], [ 0, %5 ]
%21 = phi double [ %29, %19 ], [ %17, %5 ]
%22 = getelementptr inbounds double*, double** %3, i64 %20
%23 = load double*, double** %22
%24 = call double @dot(double* %7, double* %23, i32 %4)
%25 = getelementptr inbounds double, double* %2, i64 %20
%26 = load double, double* %25
%27 = fdiv double %24, %26
%28 = fmul double %27, -5.000000e-01
%29 = call double @llvm.fmuladd.f64(double %28, double %27, double %21)
%30 = add nuw nsw i64 %20, 1
%31 = icmp eq i64 %30, %6
br i1 %31, label %32, label %19
32: ; preds = %19, %5
%33 = phi double [ %17, %5 ], [ %29, %19 ]
%34 = call double @exp(double %33)
ret double %34
}