// File: /workspace/github_cpp_makefile_star2_O2/PeterDenton[P]Nu-Pert/src/Check.cpp
// Function: Check::W(double, int)
Matrix<std::complex<double> > W(double a, int order)
{
	assert (order >= 0 && order <= 2); // order valid for 0, 1, 2

	Matrix<std::complex<double> > W(3, 3);
	double e31, e32, coef;

	switch (order)
	{
		case 2:
			// Second order from eq. 3.2.6
			coef = -pow(epsp(a) * Dmsqee, 2) / 2.;
			W(0, 0) += coef * pow(sin(psi(a)) / Dl31(a), 2);
			W(1, 1) += coef * pow(cos(psi(a)) / Dl32(a), 2);
			W(2, 2) += coef * (pow(sin(psi(a)) / Dl31(a), 2) + pow(cos(psi(a)) / Dl32(a), 2));
			W(1, 0) += coef * s2psi(a) / (Dl31(a) * Dl21(a));
			W(0, 1) += -coef * s2psi(a) / (Dl32(a) * Dl21(a));

		case 1:
			// First order from eq. 3.2.5
			e31 = epsp(a) * Dmsqee * sin(psi(a)) / Dl31(a);
			e32 = epsp(a) * Dmsqee * cos(psi(a)) / Dl32(a);
			W(0, 2) += -e31;
			W(1, 2) += e32;
			W(2, 0) += e31;
			W(2, 1) += -e32;

		case 0:
			// zeroth order
			for (int i = 0; i < 3; i++)
				W(i, i) += 1;
	}
	return W;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x50, %rsp
movsd %xmm0, (%rsp)
cmpl $0x3, %esi
jae 0x30a1
movl %esi, %ebp
movq %rdi, %rbx
pushq $0x3
popq %rdx
movq %rdx, %rsi
callq 0x8682
testl %ebp, %ebp
je 0x3069
cmpl $0x1, %ebp
je 0x2f3a
movsd (%rsp), %xmm0
callq 0x37ac
movapd %xmm0, 0x20(%rsp)
leaq 0xe46c(%rip), %rax      # 0x11178
movapd 0x20(%rsp), %xmm0
mulsd (%rax), %xmm0
movapd %xmm0, 0x20(%rsp)
movsd (%rsp), %xmm0
callq 0x299c
callq 0x2060
movsd %xmm0, 0x8(%rsp)
movsd (%rsp), %xmm0
xorl %edi, %edi
callq 0x2a4f
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x87b0
movapd 0x20(%rsp), %xmm0
mulsd %xmm0, %xmm0
mulsd 0x92af(%rip), %xmm0     # 0xc010
movsd 0x8(%rsp), %xmm1
divsd 0x10(%rsp), %xmm1
mulsd %xmm1, %xmm1
movapd %xmm0, 0x20(%rsp)
mulsd %xmm0, %xmm1
addsd (%rax), %xmm1
movsd %xmm1, (%rax)
movsd (%rsp), %xmm0
callq 0x299c
callq 0x2290
movsd %xmm0, 0x8(%rsp)
movsd (%rsp), %xmm0
xorl %edi, %edi
callq 0x2ac7
movsd %xmm0, 0x10(%rsp)
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x87b0
movsd 0x8(%rsp), %xmm0
divsd 0x10(%rsp), %xmm0
mulsd %xmm0, %xmm0
mulsd 0x20(%rsp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movsd (%rsp), %xmm0
callq 0x299c
callq 0x2060
movsd %xmm0, 0x8(%rsp)
movsd (%rsp), %xmm0
xorl %edi, %edi
callq 0x2a4f
movsd %xmm0, 0x10(%rsp)
movsd (%rsp), %xmm0
callq 0x299c
callq 0x2290
movsd %xmm0, 0x18(%rsp)
movsd (%rsp), %xmm0
xorl %edi, %edi
callq 0x2ac7
movsd %xmm0, 0x38(%rsp)
pushq $0x2
popq %rdx
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x87b0
movsd 0x8(%rsp), %xmm0
divsd 0x10(%rsp), %xmm0
mulsd %xmm0, %xmm0
movsd 0x18(%rsp), %xmm1
divsd 0x38(%rsp), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
mulsd 0x20(%rsp), %xmm1
addsd (%rax), %xmm1
movsd %xmm1, (%rax)
movsd (%rsp), %xmm0
callq 0x2ba0
movsd %xmm0, 0x8(%rsp)
movsd (%rsp), %xmm0
xorl %edi, %edi
callq 0x2a4f
movsd %xmm0, 0x10(%rsp)
movsd (%rsp), %xmm0
xorl %edi, %edi
callq 0x29d7
movsd %xmm0, 0x18(%rsp)
pushq $0x1
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x87b0
movsd 0x8(%rsp), %xmm0
mulsd 0x20(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
mulsd 0x18(%rsp), %xmm1
divsd %xmm1, %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movsd (%rsp), %xmm0
callq 0x2ba0
movsd %xmm0, 0x8(%rsp)
movsd (%rsp), %xmm0
xorl %edi, %edi
callq 0x2ac7
movsd %xmm0, 0x10(%rsp)
movsd (%rsp), %xmm0
xorl %edi, %edi
callq 0x29d7
movsd %xmm0, 0x18(%rsp)
pushq $0x1
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x87b0
movapd 0x20(%rsp), %xmm0
xorpd 0x9108(%rip), %xmm0     # 0xc020
movsd 0x8(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
mulsd 0x18(%rsp), %xmm0
divsd %xmm0, %xmm1
addsd (%rax), %xmm1
movsd %xmm1, (%rax)
movsd (%rsp), %xmm0
callq 0x37ac
movsd %xmm0, 0x20(%rsp)
leaq 0xe227(%rip), %r14      # 0x11178
movsd (%r14), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd (%rsp), %xmm0
callq 0x299c
callq 0x2060
movsd %xmm0, 0x18(%rsp)
movsd (%rsp), %xmm0
xorl %edi, %edi
callq 0x2a4f
movsd %xmm0, 0x38(%rsp)
movsd (%rsp), %xmm0
callq 0x37ac
movsd %xmm0, 0x8(%rsp)
movsd (%r14), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd (%rsp), %xmm0
callq 0x299c
callq 0x2290
movsd %xmm0, 0x40(%rsp)
movsd (%rsp), %xmm0
xorl %edi, %edi
callq 0x2ac7
movsd %xmm0, (%rsp)
pushq $0x2
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x87b0
movsd 0x20(%rsp), %xmm1
mulsd 0x10(%rsp), %xmm1
mulsd 0x18(%rsp), %xmm1
divsd 0x38(%rsp), %xmm1
movsd (%rax), %xmm0
movsd %xmm1, 0x20(%rsp)
subsd %xmm1, %xmm0
movsd %xmm0, (%rax)
pushq $0x1
popq %rsi
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0x87b0
movsd 0x8(%rsp), %xmm1
mulsd 0x48(%rsp), %xmm1
mulsd 0x40(%rsp), %xmm1
divsd (%rsp), %xmm1
movsd (%rax), %xmm0
movsd %xmm1, 0x8(%rsp)
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
pushq $0x2
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x87b0
movsd 0x20(%rsp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x87b0
movsd (%rax), %xmm0
subsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
xorl %r14d, %r14d
cmpq $0x3, %r14
je 0x3095
movq %rbx, %rdi
movq %r14, %rsi
movq %r14, %rdx
callq 0x87b0
movsd (%rax), %xmm0
addsd 0x8f8c(%rip), %xmm0     # 0xc018
movsd %xmm0, (%rax)
incq %r14
jmp 0x306c
movq %rbx, %rax
addq $0x50, %rsp
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x8f88(%rip), %rdi      # 0xc030
leaq 0x8f9a(%rip), %rsi      # 0xc049
leaq 0x905b(%rip), %rcx      # 0xc111
pushq $0x77
popq %rdx
callq 0x2100
jmp 0x30c0
movq %rax, %r14
movq %rbx, %rdi
callq 0x87a2
movq %r14, %rdi
callq 0x2280