#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 exp(double);
double pow(int, int);
double sqrt(double);
double ighmm_rand_multivariate_normal_density(int length, const double *x,
                                              double *mean, double *sigmainv,
                                              double det) {
  int i, j;
  double ay, tempv;
  ay = 0;
  for (i = 0; i < length; ++i) {
    tempv = 0;
    for (j = 0; j < length; ++j) {
      tempv += (x[j] - mean[j]) * sigmainv[j * length + i];
    }
    ay += tempv * (x[i] - mean[i]);
  }
  ay = exp(-0.5 * ay) / sqrt(pow((2 * 3.141592653589793116), length) * det);
  return ay;
}


x86 assembly (clang, -O0):
<ighmm_rand_multivariate_normal_density>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1211 <ighmm_rand_multivariate_normal_density+0xe1>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11d2 <ighmm_rand_multivariate_normal_density+0xa2>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%ecx
imul   -0x4(%rbp),%ecx
add    -0x2c(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1176 <ighmm_rand_multivariate_normal_density+0x46>
movsd  -0x40(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    115b <ighmm_rand_multivariate_normal_density+0x2b>
movsd  0xde7(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
call   1030 <exp@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x4(%rbp),%esi
mov    $0x6,%edi
call   1040 <pow@plt>
mulsd  -0x28(%rbp),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ighmm_rand_multivariate_normal_density>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %edi,%r14d
test   %edi,%edi
jle    1214 <ighmm_rand_multivariate_normal_density+0xe4>
mov    %r14d,%eax
mov    %eax,%r10d
and    $0xfffffffe,%r10d
mov    %rax,%rbx
shl    $0x4,%rbx
xorpd  %xmm0,%xmm0
xor    %r9d,%r9d
mov    %rcx,%r8
jmp    1191 <ighmm_rand_multivariate_normal_density+0x61>
cs nopw 0x0(%rax,%rax,1)
movsd  (%rsi,%r9,8),%xmm2
subsd  (%rdx,%r9,8),%xmm2
mulsd  %xmm1,%xmm2
addsd  %xmm2,%xmm0
add    $0x1,%r9
add    $0x8,%r8
cmp    %rax,%r9
je     120a <ighmm_rand_multivariate_normal_density+0xda>
cmp    $0x1,%r14d
jne    11a0 <ighmm_rand_multivariate_normal_density+0x70>
xor    %ebp,%ebp
xorpd  %xmm1,%xmm1
jmp    11e7 <ighmm_rand_multivariate_normal_density+0xb7>
nop
xorpd  %xmm2,%xmm2
mov    %r8,%rdi
xor    %ebp,%ebp
nopl   0x0(%rax)
movsd  (%rsi,%rbp,8),%xmm3
subsd  (%rdx,%rbp,8),%xmm3
movsd  0x8(%rsi,%rbp,8),%xmm1
mulsd  (%rdi),%xmm3
addsd  %xmm2,%xmm3
subsd  0x8(%rdx,%rbp,8),%xmm1
mulsd  (%rdi,%rax,8),%xmm1
addsd  %xmm3,%xmm1
add    $0x2,%rbp
add    %rbx,%rdi
movapd %xmm1,%xmm2
cmp    %rbp,%r10
jne    11b0 <ighmm_rand_multivariate_normal_density+0x80>
test   $0x1,%al
je     1170 <ighmm_rand_multivariate_normal_density+0x40>
movsd  (%rsi,%rbp,8),%xmm2
subsd  (%rdx,%rbp,8),%xmm2
imul   %rax,%rbp
add    %r9,%rbp
mulsd  (%rcx,%rbp,8),%xmm2
addsd  %xmm2,%xmm1
jmp    1170 <ighmm_rand_multivariate_normal_density+0x40>
mulsd  0xdf6(%rip),%xmm0
jmp    121c <ighmm_rand_multivariate_normal_density+0xec>
movsd  0xde4(%rip),%xmm0
call   1030 <exp@plt>
movsd  %xmm0,(%rsp)
mov    $0x6,%edi
mov    %r14d,%esi
call   1040 <pow@plt>
mulsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1249 <ighmm_rand_multivariate_normal_density+0x119>
sqrtsd %xmm0,%xmm0
jmp    124e <ighmm_rand_multivariate_normal_density+0x11e>
call   1050 <sqrt@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @ighmm_rand_multivariate_normal_density(i32 %0, double* %1, double* %2, double* %3, double %4) {
%6 = alloca i32
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca double
%11 = alloca i32
%12 = alloca i32
%13 = alloca double
%14 = alloca double
store i32 %0, i32* %6
store double* %1, double** %7
store double* %2, double** %8
store double* %3, double** %9
store double %4, double* %10
store double 0.000000e+00, double* %13
store i32 0, i32* %11
br label %15
15: ; preds = %65, %5
%16 = load i32, i32* %11
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %68
19: ; preds = %15
store double 0.000000e+00, double* %14
store i32 0, i32* %12
br label %20
20: ; preds = %47, %19
%21 = load i32, i32* %12
%22 = load i32, i32* %6
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %50
24: ; preds = %20
%25 = load double*, double** %7
%26 = load i32, i32* %12
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double, double* %25, i64 %27
%29 = load double, double* %28
%30 = load double*, double** %8
%31 = load i32, i32* %12
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
%34 = load double, double* %33
%35 = fsub double %29, %34
%36 = load double*, double** %9
%37 = load i32, i32* %12
%38 = load i32, i32* %6
%39 = mul nsw i32 %37, %38
%40 = load i32, i32* %11
%41 = add nsw i32 %39, %40
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %36, i64 %42
%44 = load double, double* %43
%45 = load double, double* %14
%46 = call double @llvm.fmuladd.f64(double %35, double %44, double %45)
store double %46, double* %14
br label %47
47: ; preds = %24
%48 = load i32, i32* %12
%49 = add nsw i32 %48, 1
store i32 %49, i32* %12
br label %20
50: ; preds = %20
%51 = load double, double* %14
%52 = load double*, double** %7
%53 = load i32, i32* %11
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %52, i64 %54
%56 = load double, double* %55
%57 = load double*, double** %8
%58 = load i32, i32* %11
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds double, double* %57, i64 %59
%61 = load double, double* %60
%62 = fsub double %56, %61
%63 = load double, double* %13
%64 = call double @llvm.fmuladd.f64(double %51, double %62, double %63)
store double %64, double* %13
br label %65
65: ; preds = %50
%66 = load i32, i32* %11
%67 = add nsw i32 %66, 1
store i32 %67, i32* %11
br label %15
68: ; preds = %15
%69 = load double, double* %13
%70 = fmul double -5.000000e-01, %69
%71 = call double @exp(double %70)
%72 = load i32, i32* %6
%73 = call double @pow(i32 6, i32 %72)
%74 = load double, double* %10
%75 = fmul double %73, %74
%76 = call double @sqrt(double %75)
%77 = fdiv double %71, %76
store double %77, double* %13
%78 = load double, double* %13
ret double %78
}

LLVM IR (-O2):
define double @ighmm_rand_multivariate_normal_density(i32 %0, double* nocapture %1, double* nocapture %2, double* nocapture %3, double %4) {
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %72
7: ; preds = %5
%8 = zext i32 %0 to i64
%9 = zext i32 %0 to i64
%10 = and i64 %9, 1
%11 = icmp eq i32 %0, 1
%12 = and i64 %9, 4294967294
%13 = icmp eq i64 %10, 0
br label %14
14: ; preds = %60, %7
%15 = phi i64 [ 0, %7 ], [ %68, %60 ]
%16 = phi double [ 0.000000e+00, %7 ], [ %67, %60 ]
br i1 %11, label %45, label %17
17: ; preds = %14, %17
%18 = phi i64 [ %42, %17 ], [ 0, %14 ]
%19 = phi double [ %41, %17 ], [ 0.000000e+00, %14 ]
%20 = phi i64 [ %43, %17 ], [ 0, %14 ]
%21 = getelementptr inbounds double, double* %1, i64 %18
%22 = load double, double* %21
%23 = getelementptr inbounds double, double* %2, i64 %18
%24 = load double, double* %23
%25 = fsub double %22, %24
%26 = mul nsw i64 %18, %8
%27 = add nuw nsw i64 %26, %15
%28 = getelementptr inbounds double, double* %3, i64 %27
%29 = load double, double* %28
%30 = tail call double @llvm.fmuladd.f64(double %25, double %29, double %19)
%31 = or i64 %18, 1
%32 = getelementptr inbounds double, double* %1, i64 %31
%33 = load double, double* %32
%34 = getelementptr inbounds double, double* %2, i64 %31
%35 = load double, double* %34
%36 = fsub double %33, %35
%37 = mul nsw i64 %31, %8
%38 = add nuw nsw i64 %37, %15
%39 = getelementptr inbounds double, double* %3, i64 %38
%40 = load double, double* %39
%41 = tail call double @llvm.fmuladd.f64(double %36, double %40, double %30)
%42 = add nuw nsw i64 %18, 2
%43 = add i64 %20, 2
%44 = icmp eq i64 %43, %12
br i1 %44, label %45, label %17
45: ; preds = %17, %14
%46 = phi double [ undef, %14 ], [ %41, %17 ]
%47 = phi i64 [ 0, %14 ], [ %42, %17 ]
%48 = phi double [ 0.000000e+00, %14 ], [ %41, %17 ]
br i1 %13, label %60, label %49
49: ; preds = %45
%50 = getelementptr inbounds double, double* %1, i64 %47
%51 = load double, double* %50
%52 = getelementptr inbounds double, double* %2, i64 %47
%53 = load double, double* %52
%54 = fsub double %51, %53
%55 = mul nsw i64 %47, %8
%56 = add nuw nsw i64 %55, %15
%57 = getelementptr inbounds double, double* %3, i64 %56
%58 = load double, double* %57
%59 = tail call double @llvm.fmuladd.f64(double %54, double %58, double %48)
br label %60
60: ; preds = %45, %49
%61 = phi double [ %46, %45 ], [ %59, %49 ]
%62 = getelementptr inbounds double, double* %1, i64 %15
%63 = load double, double* %62
%64 = getelementptr inbounds double, double* %2, i64 %15
%65 = load double, double* %64
%66 = fsub double %63, %65
%67 = tail call double @llvm.fmuladd.f64(double %61, double %66, double %16)
%68 = add nuw nsw i64 %15, 1
%69 = icmp eq i64 %68, %9
br i1 %69, label %70, label %14
70: ; preds = %60
%71 = fmul double %67, -5.000000e-01
br label %72
72: ; preds = %70, %5
%73 = phi double [ -0.000000e+00, %5 ], [ %71, %70 ]
%74 = tail call double @exp(double %73)
%75 = tail call double @pow(i32 6, i32 %0)
%76 = fmul double %75, %4
%77 = tail call double @sqrt(double %76)
%78 = fdiv double %74, %77
ret double %78
}