#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 cos(double);
double exp(double);
int /*<<< orphan*/ generalMatrixMatrix(int, int, int, int, char, char,
                                       long double *, ...);
long double *malloc(int);
long double sin(double);
double mvvm_density_unregularized(int p, double *theta, double *mu,
                                  double *kappa, double *lambda) {
  double aux = 0;
  long double *s = malloc(sizeof(long double) * p);
  long double *v = malloc(sizeof(long double) * p);
  int i;
  for (i = 0; i < p; i++)
    s[i] = sin(theta[i] - mu[i]);
  generalMatrixMatrix(1, p, p, p, 'n', 'n', s, lambda, v);
  generalMatrixMatrix(1, p, p, 1, 'n', 'n', v, s, &aux);
  aux /= 2;
  for (i = 0; i < p; i++)
    aux += kappa[i] * cos(theta[i] - mu[i]);
  return (exp(aux));
}


x86 assembly (clang, -O0):
<mvvm_density_unregularized>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x4,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x38(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x4,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11e8 <mvvm_density_unregularized+0x98>
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movsd  (%rax,%rcx,8),%xmm1
subsd  %xmm1,%xmm0
call   1030 <sin@plt>
mov    -0x38(%rbp),%rax
movslq -0x44(%rbp),%rcx
shl    $0x4,%rcx
fstpt  (%rax,%rcx,1)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11a0 <mvvm_density_unregularized+0x50>
mov    -0x4(%rbp),%esi
mov    -0x4(%rbp),%edx
mov    -0x4(%rbp),%ecx
mov    -0x38(%rbp),%r11
mov    -0x28(%rbp),%r10
mov    -0x40(%rbp),%rax
mov    $0x1,%edi
mov    $0x6e,%r9d
mov    %r9d,%r8d
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
mov    $0x0,%al
call   1070 <generalMatrixMatrix@plt>
mov    -0x4(%rbp),%esi
mov    -0x4(%rbp),%edx
mov    -0x40(%rbp),%r11
mov    -0x38(%rbp),%r10
mov    $0x1,%ecx
mov    $0x6e,%r9d
lea    -0x30(%rbp),%rax
mov    %ecx,%edi
mov    %r9d,%r8d
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
mov    $0x0,%al
call   1070 <generalMatrixMatrix@plt>
movsd  -0x30(%rbp),%xmm0
movsd  0xd9c(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12d9 <mvvm_density_unregularized+0x189>
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x44(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
call   1060 <cos@plt>
movaps %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1274 <mvvm_density_unregularized+0x124>
movsd  -0x30(%rbp),%xmm0
call   1050 <exp@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mvvm_density_unregularized>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8,0x30(%rsp)
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %edi,%r12d
movq   $0x0,0x8(%rsp)
mov    %edi,%ebp
shl    $0x4,%ebp
mov    %ebp,%edi
call   1040 <malloc@plt>
mov    %rax,%r13
mov    %ebp,%edi
call   1040 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    %r12d,%eax
test   %r12d,%r12d
mov    %rax,0x18(%rsp)
jle    1233 <mvvm_density_unregularized+0xe3>
mov    %r13,0x28(%rsp)
mov    %r12d,0x24(%rsp)
cmp    $0x1,%r12d
jne    11b8 <mvvm_density_unregularized+0x68>
xor    %ebp,%ebp
jmp    1207 <mvvm_density_unregularized+0xb7>
mov    %eax,%r12d
and    $0xfffffffe,%r12d
mov    0x28(%rsp),%r13
add    $0x10,%r13
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsd  (%rbx,%rbp,8),%xmm0
subsd  (%r15,%rbp,8),%xmm0
call   1030 <sin@plt>
fstpt  -0x10(%r13)
movsd  0x8(%rbx,%rbp,8),%xmm0
subsd  0x8(%r15,%rbp,8),%xmm0
call   1030 <sin@plt>
fstpt  0x0(%r13)
add    $0x2,%rbp
add    $0x20,%r13
cmp    %rbp,%r12
jne    11d0 <mvvm_density_unregularized+0x80>
mov    0x18(%rsp),%rax
test   $0x1,%al
mov    0x24(%rsp),%r12d
mov    0x28(%rsp),%r13
je     1233 <mvvm_density_unregularized+0xe3>
movsd  (%rbx,%rbp,8),%xmm0
subsd  (%r15,%rbp,8),%xmm0
call   1030 <sin@plt>
shl    $0x4,%rbp
fstpt  0x0(%r13,%rbp,1)
sub    $0x8,%rsp
mov    $0x1,%edi
mov    %r12d,%esi
mov    %r12d,%edx
mov    %r12d,%ecx
mov    $0x6e,%r8d
mov    $0x6e,%r9d
xor    %eax,%eax
mov    0x18(%rsp),%rbp
push   %rbp
push   0x40(%rsp)
push   %r13
call   1070 <generalMatrixMatrix@plt>
add    $0x18,%rsp
lea    0x10(%rsp),%r10
mov    $0x1,%edi
mov    %r12d,%esi
mov    %r12d,%edx
mov    $0x1,%ecx
mov    $0x6e,%r8d
mov    $0x6e,%r9d
xor    %eax,%eax
push   %r10
push   %r13
push   %rbp
call   1070 <generalMatrixMatrix@plt>
add    $0x20,%rsp
movsd  0x8(%rsp),%xmm0
mulsd  0xd59(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
test   %r12d,%r12d
jle    136d <mvvm_density_unregularized+0x21d>
cmp    $0x1,%r12d
jne    12c0 <mvvm_density_unregularized+0x170>
xor    %ebp,%ebp
jmp    1338 <mvvm_density_unregularized+0x1e8>
mov    0x18(%rsp),%r12
and    $0xfffffffe,%r12d
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movsd  (%r14,%rbp,8),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  (%rbx,%rbp,8),%xmm0
subsd  (%r15,%rbp,8),%xmm0
call   1060 <cos@plt>
mulsd  0x10(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%r14,%rbp,8),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rbx,%rbp,8),%xmm0
subsd  0x8(%r15,%rbp,8),%xmm0
call   1060 <cos@plt>
mulsd  0x10(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
add    $0x2,%rbp
cmp    %rbp,%r12
jne    12d0 <mvvm_density_unregularized+0x180>
testb  $0x1,0x18(%rsp)
je     136d <mvvm_density_unregularized+0x21d>
movsd  (%r14,%rbp,8),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  (%rbx,%rbp,8),%xmm0
subsd  (%r15,%rbp,8),%xmm0
call   1060 <cos@plt>
mulsd  0x10(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1050 <exp@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @mvvm_density_unregularized(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 double
%12 = alloca x86_fp80*
%13 = alloca x86_fp80*
%14 = alloca i32
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* %11
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = mul i64 16, %16
%18 = trunc i64 %17 to i32
%19 = call x86_fp80* @malloc(i32 %18)
store x86_fp80* %19, x86_fp80** %12
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = mul i64 16, %21
%23 = trunc i64 %22 to i32
%24 = call x86_fp80* @malloc(i32 %23)
store x86_fp80* %24, x86_fp80** %13
store i32 0, i32* %14
br label %25
25: ; preds = %46, %5
%26 = load i32, i32* %14
%27 = load i32, i32* %6
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %49
29: ; preds = %25
%30 = load double*, double** %7
%31 = load i32, i32* %14
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
%34 = load double, double* %33
%35 = load double*, double** %8
%36 = load i32, i32* %14
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
%39 = load double, double* %38
%40 = fsub double %34, %39
%41 = call x86_fp80 @sin(double %40)
%42 = load x86_fp80*, x86_fp80** %12
%43 = load i32, i32* %14
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds x86_fp80, x86_fp80* %42, i64 %44
store x86_fp80 %41, x86_fp80* %45
br label %46
46: ; preds = %29
%47 = load i32, i32* %14
%48 = add nsw i32 %47, 1
store i32 %48, i32* %14
br label %25
49: ; preds = %25
%50 = load i32, i32* %6
%51 = load i32, i32* %6
%52 = load i32, i32* %6
%53 = load x86_fp80*, x86_fp80** %12
%54 = load double*, double** %10
%55 = load x86_fp80*, x86_fp80** %13
%56 = call i32 (i32, i32, i32, i32, i8, i8, x86_fp80*, ...) @generalMatrixMatrix(i32 1, i32 %50, i32 %51, i32 %52, i8 signext 110, i8 signext 110, x86_fp80* %53, double* %54, x86_fp80* %55)
%57 = load i32, i32* %6
%58 = load i32, i32* %6
%59 = load x86_fp80*, x86_fp80** %13
%60 = load x86_fp80*, x86_fp80** %12
%61 = call i32 (i32, i32, i32, i32, i8, i8, x86_fp80*, ...) @generalMatrixMatrix(i32 1, i32 %57, i32 %58, i32 1, i8 signext 110, i8 signext 110, x86_fp80* %59, x86_fp80* %60, double* %11)
%62 = load double, double* %11
%63 = fdiv double %62, 2.000000e+00
store double %63, double* %11
store i32 0, i32* %14
br label %64
64: ; preds = %88, %49
%65 = load i32, i32* %14
%66 = load i32, i32* %6
%67 = icmp slt i32 %65, %66
br i1 %67, label %68, label %91
68: ; preds = %64
%69 = load double*, double** %9
%70 = load i32, i32* %14
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds double, double* %69, i64 %71
%73 = load double, double* %72
%74 = load double*, double** %7
%75 = load i32, i32* %14
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds double, double* %74, i64 %76
%78 = load double, double* %77
%79 = load double*, double** %8
%80 = load i32, i32* %14
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds double, double* %79, i64 %81
%83 = load double, double* %82
%84 = fsub double %78, %83
%85 = call double @cos(double %84)
%86 = load double, double* %11
%87 = call double @llvm.fmuladd.f64(double %73, double %85, double %86)
store double %87, double* %11
br label %88
88: ; preds = %68
%89 = load i32, i32* %14
%90 = add nsw i32 %89, 1
store i32 %90, i32* %14
br label %64
91: ; preds = %64
%92 = load double, double* %11
%93 = call double @exp(double %92)
ret double %93
}

LLVM IR (-O2):
define double @mvvm_density_unregularized(i32 %0, double* nocapture %1, double* nocapture %2, double* nocapture %3, double* %4) {
%6 = alloca double
%7 = bitcast double* %6 to i8*
store double 0.000000e+00, double* %6
%8 = shl i32 %0, 4
%9 = tail call x86_fp80* @malloc(i32 %8)
%10 = tail call x86_fp80* @malloc(i32 %8)
%11 = icmp sgt i32 %0, 0
br i1 %11, label %12, label %50
12: ; preds = %5
%13 = zext i32 %0 to i64
%14 = and i64 %13, 1
%15 = icmp eq i32 %0, 1
br i1 %15, label %39, label %16
16: ; preds = %12
%17 = and i64 %13, 4294967294
br label %18
18: ; preds = %18, %16
%19 = phi i64 [ 0, %16 ], [ %36, %18 ]
%20 = phi i64 [ 0, %16 ], [ %37, %18 ]
%21 = getelementptr inbounds double, double* %1, i64 %19
%22 = load double, double* %21
%23 = getelementptr inbounds double, double* %2, i64 %19
%24 = load double, double* %23
%25 = fsub double %22, %24
%26 = tail call x86_fp80 @sin(double %25)
%27 = getelementptr inbounds x86_fp80, x86_fp80* %9, i64 %19
store x86_fp80 %26, x86_fp80* %27
%28 = or i64 %19, 1
%29 = getelementptr inbounds double, double* %1, i64 %28
%30 = load double, double* %29
%31 = getelementptr inbounds double, double* %2, i64 %28
%32 = load double, double* %31
%33 = fsub double %30, %32
%34 = tail call x86_fp80 @sin(double %33)
%35 = getelementptr inbounds x86_fp80, x86_fp80* %9, i64 %28
store x86_fp80 %34, x86_fp80* %35
%36 = add nuw nsw i64 %19, 2
%37 = add i64 %20, 2
%38 = icmp eq i64 %37, %17
br i1 %38, label %39, label %18
39: ; preds = %18, %12
%40 = phi i64 [ 0, %12 ], [ %36, %18 ]
%41 = icmp eq i64 %14, 0
br i1 %41, label %50, label %42
42: ; preds = %39
%43 = getelementptr inbounds double, double* %1, i64 %40
%44 = load double, double* %43
%45 = getelementptr inbounds double, double* %2, i64 %40
%46 = load double, double* %45
%47 = fsub double %44, %46
%48 = tail call x86_fp80 @sin(double %47)
%49 = getelementptr inbounds x86_fp80, x86_fp80* %9, i64 %40
store x86_fp80 %48, x86_fp80* %49
br label %50
50: ; preds = %42, %39, %5
%51 = tail call i32 (i32, i32, i32, i32, i8, i8, x86_fp80*, ...) @generalMatrixMatrix(i32 1, i32 %0, i32 %0, i32 %0, i8 signext 110, i8 signext 110, x86_fp80* %9, double* %4, x86_fp80* %10)
%52 = call i32 (i32, i32, i32, i32, i8, i8, x86_fp80*, ...) @generalMatrixMatrix(i32 1, i32 %0, i32 %0, i32 1, i8 signext 110, i8 signext 110, x86_fp80* %10, x86_fp80* %9, double* %6)
%53 = load double, double* %6
%54 = fmul double %53, 5.000000e-01
store double %54, double* %6
br i1 %11, label %55, label %103
55: ; preds = %50
%56 = zext i32 %0 to i64
%57 = and i64 %56, 1
%58 = icmp eq i32 %0, 1
br i1 %58, label %88, label %59
59: ; preds = %55
%60 = and i64 %56, 4294967294
br label %61
61: ; preds = %61, %59
%62 = phi i64 [ 0, %59 ], [ %85, %61 ]
%63 = phi i64 [ 0, %59 ], [ %86, %61 ]
%64 = getelementptr inbounds double, double* %3, i64 %62
%65 = load double, double* %64
%66 = getelementptr inbounds double, double* %1, i64 %62
%67 = load double, double* %66
%68 = getelementptr inbounds double, double* %2, i64 %62
%69 = load double, double* %68
%70 = fsub double %67, %69
%71 = call double @cos(double %70)
%72 = load double, double* %6
%73 = call double @llvm.fmuladd.f64(double %65, double %71, double %72)
store double %73, double* %6
%74 = or i64 %62, 1
%75 = getelementptr inbounds double, double* %3, i64 %74
%76 = load double, double* %75
%77 = getelementptr inbounds double, double* %1, i64 %74
%78 = load double, double* %77
%79 = getelementptr inbounds double, double* %2, i64 %74
%80 = load double, double* %79
%81 = fsub double %78, %80
%82 = call double @cos(double %81)
%83 = load double, double* %6
%84 = call double @llvm.fmuladd.f64(double %76, double %82, double %83)
store double %84, double* %6
%85 = add nuw nsw i64 %62, 2
%86 = add i64 %63, 2
%87 = icmp eq i64 %86, %60
br i1 %87, label %88, label %61
88: ; preds = %61, %55
%89 = phi double [ undef, %55 ], [ %84, %61 ]
%90 = phi i64 [ 0, %55 ], [ %85, %61 ]
%91 = icmp eq i64 %57, 0
br i1 %91, label %103, label %92
92: ; preds = %88
%93 = getelementptr inbounds double, double* %3, i64 %90
%94 = load double, double* %93
%95 = getelementptr inbounds double, double* %1, i64 %90
%96 = load double, double* %95
%97 = getelementptr inbounds double, double* %2, i64 %90
%98 = load double, double* %97
%99 = fsub double %96, %98
%100 = call double @cos(double %99)
%101 = load double, double* %6
%102 = call double @llvm.fmuladd.f64(double %94, double %100, double %101)
store double %102, double* %6
br label %103
103: ; preds = %92, %88, %50
%104 = phi double [ %54, %50 ], [ %89, %88 ], [ %102, %92 ]
%105 = call double @exp(double %104)
ret double %105
}