#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 /*<<< orphan*/ bessi0_salahat(double);
int /*<<< orphan*/ bessi0_spd(double);
double cos(double);
double log(int /*<<< orphan*/);
double marginal_j_concentration(int, int, double *, double *, double *,
                                double *);
double marginal_j_mean(int, int, double *, double *, double *, double *);
double mv_vonmises_logpseudolikelihood_naive(int n, int p, double *mu,
                                             double *kappa, double *lambda,
                                             double *theta) {
  int j, i;
  double acum = 0.;
  double k_rest, m_rest;
  for (j = 0; j < p; j++) {
    for (i = 0; i < n; i++) {
      k_rest = marginal_j_concentration(p, j, mu, kappa, lambda, theta + i * p);
      m_rest = marginal_j_mean(p, j, mu, kappa, lambda, theta + i * p);
      acum += k_rest * cos(theta[i * p + j] - m_rest) -
              log((k_rest) < (1E31) ? (bessi0_spd(k_rest))
                                    : (bessi0_salahat(k_rest)));
    }
  }
  return -acum;
}


x86 assembly (clang, -O0):
<mv_vonmises_logpseudolikelihood_naive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12cc <mv_vonmises_logpseudolikelihood_naive+0x16c>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12b9 <mv_vonmises_logpseudolikelihood_naive+0x159>
mov    -0x8(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    -0x30(%rbp),%eax
imul   -0x8(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%r9
call   1030 <marginal_j_concentration@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    -0x30(%rbp),%eax
imul   -0x8(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%r9
call   1050 <marginal_j_mean@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%ecx
imul   -0x8(%rbp),%ecx
add    -0x2c(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x48(%rbp),%xmm0
call   1070 <cos@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  0xdbd(%rip),%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    1260 <mv_vonmises_logpseudolikelihood_naive+0x100>
movsd  -0x40(%rbp),%xmm0
call   1060 <bessi0_spd@plt>
mov    %eax,-0x5c(%rbp)
jmp    126d <mv_vonmises_logpseudolikelihood_naive+0x10d>
movsd  -0x40(%rbp),%xmm0
call   1040 <bessi0_salahat@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%edi
call   1080 <log@plt>
movsd  -0x50(%rbp),%xmm2
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11a0 <mv_vonmises_logpseudolikelihood_naive+0x40>
jmp    12be <mv_vonmises_logpseudolikelihood_naive+0x15e>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    118d <mv_vonmises_logpseudolikelihood_naive+0x2d>
movsd  -0x38(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mv_vonmises_logpseudolikelihood_naive>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %r9,0x38(%rsp)
mov    %r8,0x60(%rsp)
mov    %rcx,0x58(%rsp)
mov    %rdx,0x50(%rsp)
test   %esi,%esi
jle    12e7 <mv_vonmises_logpseudolikelihood_naive+0x187>
mov    %esi,0x1c(%rsp)
mov    %esi,%eax
mov    %edi,%ecx
mov    %rcx,0x30(%rsp)
mov    %rax,0x40(%rsp)
lea    0x0(,%rax,8),%rax
mov    %rax,0x48(%rsp)
xorpd  %xmm0,%xmm0
xor    %eax,%eax
mov    %rax,0x20(%rsp)
xor    %eax,%eax
mov    %rax,0x10(%rsp)
mov    %edi,0x18(%rsp)
mov    0x1c(%rsp),%r14d
mov    0x50(%rsp),%rbp
mov    0x58(%rsp),%rbx
mov    0x60(%rsp),%r12
jmp    1206 <mv_vonmises_logpseudolikelihood_naive+0xa6>
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rcx
add    $0x1,%rcx
addq   $0x8,0x20(%rsp)
mov    %rcx,%rax
mov    %rcx,0x10(%rsp)
cmp    0x40(%rsp),%rcx
mov    0x18(%rsp),%edi
je     12eb <mv_vonmises_logpseudolikelihood_naive+0x18b>
test   %edi,%edi
jle    11e0 <mv_vonmises_logpseudolikelihood_naive+0x80>
mov    0x30(%rsp),%r15
mov    0x38(%rsp),%r13
jmp    125c <mv_vonmises_logpseudolikelihood_naive+0xfc>
cs nopw 0x0(%rax,%rax,1)
movsd  0x8(%rsp),%xmm0
call   1040 <bessi0_salahat@plt>
mov    %eax,%edi
mov    0x28(%rsp),%r15
call   1080 <log@plt>
movsd  0x8(%rsp),%xmm1
mulsd  0x68(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd 0x70(%rsp),%xmm0
addsd  %xmm1,%xmm0
add    0x48(%rsp),%r13
add    $0xffffffffffffffff,%r15
je     11e0 <mv_vonmises_logpseudolikelihood_naive+0x80>
mov    %r15,0x28(%rsp)
movapd %xmm0,0x70(%rsp)
mov    %r14d,%edi
mov    0x10(%rsp),%r15
mov    %r15d,%esi
mov    %rbp,%rdx
mov    %rbx,%rcx
mov    %r12,%r8
mov    %r13,%r9
call   1030 <marginal_j_concentration@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r14d,%edi
mov    %r15d,%esi
mov    %rbp,%rdx
mov    %rbx,%rcx
mov    %r12,%r8
mov    %r13,%r9
call   1050 <marginal_j_mean@plt>
mov    0x20(%rsp),%rax
movsd  0x0(%r13,%rax,1),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1070 <cos@plt>
movapd %xmm0,%xmm1
movsd  0xd3b(%rip),%xmm0
ucomisd 0x8(%rsp),%xmm0
movsd  %xmm1,0x68(%rsp)
jbe    1220 <mv_vonmises_logpseudolikelihood_naive+0xc0>
movsd  0x8(%rsp),%xmm0
call   1060 <bessi0_spd@plt>
jmp    122b <mv_vonmises_logpseudolikelihood_naive+0xcb>
xorpd  %xmm0,%xmm0
xorpd  0xd1d(%rip),%xmm0
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @mv_vonmises_logpseudolikelihood_naive(i32 %0, i32 %1, double* %2, double* %3, double* %4, double* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca double*
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
%13 = alloca i32
%14 = alloca i32
%15 = alloca double
%16 = alloca double
%17 = alloca double
store i32 %0, i32* %7
store i32 %1, i32* %8
store double* %2, double** %9
store double* %3, double** %10
store double* %4, double** %11
store double* %5, double** %12
store double 0.000000e+00, double* %15
store i32 0, i32* %13
br label %18
18: ; preds = %84, %6
%19 = load i32, i32* %13
%20 = load i32, i32* %8
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %87
22: ; preds = %18
store i32 0, i32* %14
br label %23
23: ; preds = %80, %22
%24 = load i32, i32* %14
%25 = load i32, i32* %7
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %83
27: ; preds = %23
%28 = load i32, i32* %8
%29 = load i32, i32* %13
%30 = load double*, double** %9
%31 = load double*, double** %10
%32 = load double*, double** %11
%33 = load double*, double** %12
%34 = load i32, i32* %14
%35 = load i32, i32* %8
%36 = mul nsw i32 %34, %35
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %33, i64 %37
%39 = call double @marginal_j_concentration(i32 %28, i32 %29, double* %30, double* %31, double* %32, double* %38)
store double %39, double* %16
%40 = load i32, i32* %8
%41 = load i32, i32* %13
%42 = load double*, double** %9
%43 = load double*, double** %10
%44 = load double*, double** %11
%45 = load double*, double** %12
%46 = load i32, i32* %14
%47 = load i32, i32* %8
%48 = mul nsw i32 %46, %47
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %45, i64 %49
%51 = call double @marginal_j_mean(i32 %40, i32 %41, double* %42, double* %43, double* %44, double* %50)
store double %51, double* %17
%52 = load double, double* %16
%53 = load double*, double** %12
%54 = load i32, i32* %14
%55 = load i32, i32* %8
%56 = mul nsw i32 %54, %55
%57 = load i32, i32* %13
%58 = add nsw i32 %56, %57
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds double, double* %53, i64 %59
%61 = load double, double* %60
%62 = load double, double* %17
%63 = fsub double %61, %62
%64 = call double @cos(double %63)
%65 = load double, double* %16
%66 = fcmp olt double %65, 1.000000e+31
br i1 %66, label %67, label %70
67: ; preds = %27
%68 = load double, double* %16
%69 = call i32 @bessi0_spd(double %68)
br label %73
70: ; preds = %27
%71 = load double, double* %16
%72 = call i32 @bessi0_salahat(double %71)
br label %73
73: ; preds = %70, %67
%74 = phi i32 [ %69, %67 ], [ %72, %70 ]
%75 = call double @log(i32 %74)
%76 = fneg double %75
%77 = call double @llvm.fmuladd.f64(double %52, double %64, double %76)
%78 = load double, double* %15
%79 = fadd double %78, %77
store double %79, double* %15
br label %80
80: ; preds = %73
%81 = load i32, i32* %14
%82 = add nsw i32 %81, 1
store i32 %82, i32* %14
br label %23
83: ; preds = %23
br label %84
84: ; preds = %83
%85 = load i32, i32* %13
%86 = add nsw i32 %85, 1
store i32 %86, i32* %13
br label %18
87: ; preds = %18
%88 = load double, double* %15
%89 = fneg double %88
ret double %89
}

LLVM IR (-O2):
define double @mv_vonmises_logpseudolikelihood_naive(i32 %0, i32 %1, double* %2, double* %3, double* %4, double* %5) {
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %47
8: ; preds = %6
%9 = icmp sgt i32 %0, 0
%10 = zext i32 %1 to i64
%11 = zext i32 %1 to i64
%12 = zext i32 %0 to i64
br label %13
13: ; preds = %8, %43
%14 = phi i64 [ 0, %8 ], [ %45, %43 ]
%15 = phi double [ 0.000000e+00, %8 ], [ %44, %43 ]
br i1 %9, label %16, label %43
16: ; preds = %13
%17 = trunc i64 %14 to i32
br label %18
18: ; preds = %16, %35
%19 = phi i64 [ 0, %16 ], [ %41, %35 ]
%20 = phi double [ %15, %16 ], [ %40, %35 ]
%21 = mul nsw i64 %19, %10
%22 = getelementptr inbounds double, double* %5, i64 %21
%23 = tail call double @marginal_j_concentration(i32 %1, i32 %17, double* %2, double* %3, double* %4, double* %22)
%24 = tail call double @marginal_j_mean(i32 %1, i32 %17, double* %2, double* %3, double* %4, double* %22)
%25 = add nuw nsw i64 %21, %14
%26 = getelementptr inbounds double, double* %5, i64 %25
%27 = load double, double* %26
%28 = fsub double %27, %24
%29 = tail call double @cos(double %28)
%30 = fcmp olt double %23, 1.000000e+31
br i1 %30, label %31, label %33
31: ; preds = %18
%32 = tail call i32 @bessi0_spd(double %23)
br label %35
33: ; preds = %18
%34 = tail call i32 @bessi0_salahat(double %23)
br label %35
35: ; preds = %33, %31
%36 = phi i32 [ %32, %31 ], [ %34, %33 ]
%37 = tail call double @log(i32 %36)
%38 = fneg double %37
%39 = tail call double @llvm.fmuladd.f64(double %23, double %29, double %38)
%40 = fadd double %20, %39
%41 = add nuw nsw i64 %19, 1
%42 = icmp eq i64 %41, %12
br i1 %42, label %43, label %18
43: ; preds = %35, %13
%44 = phi double [ %15, %13 ], [ %40, %35 ]
%45 = add nuw nsw i64 %14, 1
%46 = icmp eq i64 %45, %11
br i1 %46, label %47, label %13
47: ; preds = %43, %6
%48 = phi double [ 0.000000e+00, %6 ], [ %44, %43 ]
%49 = fneg double %48
ret double %49
}