// File: 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:
subq $0x228, %rsp            # imm = 0x228
movq %rdi, 0x1d0(%rsp)
movq %rdi, %rax
movq %rax, 0x1d8(%rsp)
movq %rdi, 0x220(%rsp)
movsd %xmm0, 0x218(%rsp)
movl %esi, 0x214(%rsp)
xorl %eax, %eax
cmpl $0x0, 0x214(%rsp)
movb %al, 0x1e7(%rsp)
jl 0x33a7
cmpl $0x2, 0x214(%rsp)
setle %al
movb %al, 0x1e7(%rsp)
movb 0x1e7(%rsp), %al
testb $0x1, %al
jne 0x33b4
jmp 0x33b6
jmp 0x33d5
leaq 0xec73(%rip), %rdi      # 0x12030
leaq 0xec85(%rip), %rsi      # 0x12049
movl $0x77, %edx
leaq 0xed41(%rip), %rcx      # 0x12111
callq 0x20d0
movq 0x1d0(%rsp), %rdi
movb $0x0, 0x213(%rsp)
movl $0x3, %edx
movq %rdx, %rsi
callq 0xcaa0
movl 0x214(%rsp), %eax
movl %eax, 0x1cc(%rsp)
testl %eax, %eax
je 0x3b9f
jmp 0x340a
movl 0x1cc(%rsp), %eax
subl $0x1, %eax
je 0x3949
jmp 0x341c
movl 0x1cc(%rsp), %eax
subl $0x2, %eax
jne 0x3c21
jmp 0x342e
movsd 0x218(%rsp), %xmm0
callq 0x4990
movsd %xmm0, 0x1c0(%rsp)
jmp 0x3447
movsd 0x1c0(%rsp), %xmm0
leaq 0x13da9(%rip), %rax     # 0x17200
movsd (%rax), %xmm1
mulsd %xmm1, %xmm0
movsd 0xeba1(%rip), %xmm1     # 0x12008
callq 0x22a0
movsd 0xeb9c(%rip), %xmm1     # 0x12010
mulsd %xmm1, %xmm0
movsd %xmm0, 0x1f8(%rsp)
movsd 0x1f8(%rsp), %xmm0
movsd %xmm0, 0x1b0(%rsp)
movsd 0x218(%rsp), %xmm0
callq 0x2ea0
movsd %xmm0, 0x1b8(%rsp)
jmp 0x34ac
movsd 0x1b8(%rsp), %xmm0
callq 0x2060
movsd %xmm0, 0x1a0(%rsp)
movsd 0x218(%rsp), %xmm0
xorl %edi, %edi
callq 0x2fc0
movsd %xmm0, 0x1a8(%rsp)
jmp 0x34de
movsd 0x1a8(%rsp), %xmm1
movsd 0x1a0(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd 0xeb0c(%rip), %xmm1     # 0x12008
callq 0x22a0
movq 0x1d0(%rsp), %rdi
movaps %xmm0, %xmm1
movsd 0x1b0(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x190(%rsp)
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0xce30
movq %rax, 0x198(%rsp)
jmp 0x3538
movsd 0x190(%rsp), %xmm0
movq 0x198(%rsp), %rdi
callq 0x4680
jmp 0x3550
movsd 0x1f8(%rsp), %xmm0
movsd %xmm0, 0x180(%rsp)
movsd 0x218(%rsp), %xmm0
callq 0x2ea0
movsd %xmm0, 0x188(%rsp)
jmp 0x357b
movsd 0x188(%rsp), %xmm0
callq 0x22d0
movsd %xmm0, 0x170(%rsp)
movsd 0x218(%rsp), %xmm0
xorl %edi, %edi
callq 0x3090
movsd %xmm0, 0x178(%rsp)
jmp 0x35ad
movsd 0x178(%rsp), %xmm1
movsd 0x170(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd 0xea3d(%rip), %xmm1     # 0x12008
callq 0x22a0
movq 0x1d0(%rsp), %rdi
movaps %xmm0, %xmm1
movsd 0x180(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x160(%rsp)
movl $0x1, %edx
movq %rdx, %rsi
callq 0xce30
movq %rax, 0x168(%rsp)
jmp 0x3608
movsd 0x160(%rsp), %xmm0
movq 0x168(%rsp), %rdi
callq 0x4680
jmp 0x3620
movsd 0x1f8(%rsp), %xmm0
movsd %xmm0, 0x150(%rsp)
movsd 0x218(%rsp), %xmm0
callq 0x2ea0
movsd %xmm0, 0x158(%rsp)
jmp 0x364b
movsd 0x158(%rsp), %xmm0
callq 0x2060
movsd %xmm0, 0x140(%rsp)
movsd 0x218(%rsp), %xmm0
xorl %edi, %edi
callq 0x2fc0
movsd %xmm0, 0x148(%rsp)
jmp 0x367d
movsd 0x148(%rsp), %xmm1
movsd 0x140(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd 0xe96d(%rip), %xmm1     # 0x12008
callq 0x22a0
movsd %xmm0, 0x130(%rsp)
movsd 0x218(%rsp), %xmm0
callq 0x2ea0
movsd %xmm0, 0x138(%rsp)
jmp 0x36c2
movsd 0x138(%rsp), %xmm0
callq 0x22d0
movsd %xmm0, 0x120(%rsp)
movsd 0x218(%rsp), %xmm0
xorl %edi, %edi
callq 0x3090
movsd %xmm0, 0x128(%rsp)
jmp 0x36f4
movsd 0x128(%rsp), %xmm1
movsd 0x120(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd 0xe8f6(%rip), %xmm1     # 0x12008
callq 0x22a0
movsd 0x130(%rsp), %xmm1
movq 0x1d0(%rsp), %rdi
movaps %xmm0, %xmm2
movsd 0x150(%rsp), %xmm0
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0x110(%rsp)
movl $0x2, %edx
movq %rdx, %rsi
callq 0xce30
movq %rax, 0x118(%rsp)
jmp 0x375c
movsd 0x110(%rsp), %xmm0
movq 0x118(%rsp), %rdi
callq 0x4680
jmp 0x3774
movsd 0x1f8(%rsp), %xmm0
movsd %xmm0, 0x100(%rsp)
movsd 0x218(%rsp), %xmm0
callq 0x31e0
movsd %xmm0, 0x108(%rsp)
jmp 0x379f
movsd 0x108(%rsp), %xmm1
movsd 0x100(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0xf0(%rsp)
movsd 0x218(%rsp), %xmm0
xorl %edi, %edi
callq 0x2fc0
movsd %xmm0, 0xf8(%rsp)
jmp 0x37d9
movsd 0x218(%rsp), %xmm0
xorl %edi, %edi
callq 0x2ef0
movsd %xmm0, 0xe8(%rsp)
jmp 0x37f4
movq 0x1d0(%rsp), %rdi
movsd 0xf0(%rsp), %xmm0
movsd 0xe8(%rsp), %xmm2
movsd 0xf8(%rsp), %xmm1
mulsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0xd8(%rsp)
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %esi
callq 0xce30
movq %rax, 0xe0(%rsp)
jmp 0x3840
movsd 0xd8(%rsp), %xmm0
movq 0xe0(%rsp), %rdi
callq 0x4680
jmp 0x3858
movaps 0xe7c1(%rip), %xmm1     # 0x12020
movsd 0x1f8(%rsp), %xmm0
pxor %xmm1, %xmm0
movsd %xmm0, 0xc8(%rsp)
movsd 0x218(%rsp), %xmm0
callq 0x31e0
movsd %xmm0, 0xd0(%rsp)
jmp 0x388e
movsd 0xd0(%rsp), %xmm1
movsd 0xc8(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0xb8(%rsp)
movsd 0x218(%rsp), %xmm0
xorl %edi, %edi
callq 0x3090
movsd %xmm0, 0xc0(%rsp)
jmp 0x38c8
movsd 0x218(%rsp), %xmm0
xorl %edi, %edi
callq 0x2ef0
movsd %xmm0, 0xb0(%rsp)
jmp 0x38e3
movq 0x1d0(%rsp), %rdi
movsd 0xb8(%rsp), %xmm0
movsd 0xb0(%rsp), %xmm2
movsd 0xc0(%rsp), %xmm1
mulsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0xa0(%rsp)
xorl %eax, %eax
movl %eax, %esi
movl $0x1, %edx
callq 0xce30
movq %rax, 0xa8(%rsp)
jmp 0x392f
movsd 0xa0(%rsp), %xmm0
movq 0xa8(%rsp), %rdi
callq 0x4680
jmp 0x3947
jmp 0x3949
movsd 0x218(%rsp), %xmm0
callq 0x4990
movsd %xmm0, 0x98(%rsp)
jmp 0x3962
movsd 0x98(%rsp), %xmm0
leaq 0x1388e(%rip), %rax     # 0x17200
movsd (%rax), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0x88(%rsp)
movsd 0x218(%rsp), %xmm0
callq 0x2ea0
movsd %xmm0, 0x90(%rsp)
jmp 0x399c
movsd 0x90(%rsp), %xmm0
callq 0x2060
movaps %xmm0, %xmm1
movsd 0x88(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x78(%rsp)
movsd 0x218(%rsp), %xmm0
xorl %edi, %edi
callq 0x2fc0
movsd %xmm0, 0x80(%rsp)
jmp 0x39db
movsd 0x80(%rsp), %xmm1
movsd 0x78(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x208(%rsp)
movsd 0x218(%rsp), %xmm0
callq 0x4990
movsd %xmm0, 0x70(%rsp)
jmp 0x3a0d
movsd 0x70(%rsp), %xmm0
leaq 0x137e6(%rip), %rax     # 0x17200
movsd (%rax), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0x60(%rsp)
movsd 0x218(%rsp), %xmm0
callq 0x2ea0
movsd %xmm0, 0x68(%rsp)
jmp 0x3a3e
movsd 0x68(%rsp), %xmm0
callq 0x22d0
movaps %xmm0, %xmm1
movsd 0x60(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x218(%rsp), %xmm0
xorl %edi, %edi
callq 0x3090
movsd %xmm0, 0x58(%rsp)
jmp 0x3a74
movq 0x1d0(%rsp), %rdi
movsd 0x58(%rsp), %xmm1
movsd 0x50(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x200(%rsp)
movaps 0xe584(%rip), %xmm1     # 0x12020
movsd 0x208(%rsp), %xmm0
pxor %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0xce30
movq %rax, 0x48(%rsp)
jmp 0x3ac4
movsd 0x40(%rsp), %xmm0
movq 0x48(%rsp), %rdi
callq 0x4680
jmp 0x3ad6
movq 0x1d0(%rsp), %rdi
movsd 0x200(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movl $0x1, %esi
movl $0x2, %edx
callq 0xce30
movq %rax, 0x38(%rsp)
jmp 0x3b03
movsd 0x30(%rsp), %xmm0
movq 0x38(%rsp), %rdi
callq 0x4680
jmp 0x3b15
movq 0x1d0(%rsp), %rdi
movsd 0x208(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
xorl %eax, %eax
movl %eax, %edx
movl $0x2, %esi
callq 0xce30
movq %rax, 0x28(%rsp)
jmp 0x3b41
movsd 0x20(%rsp), %xmm0
movq 0x28(%rsp), %rdi
callq 0x4680
jmp 0x3b53
movq 0x1d0(%rsp), %rdi
movaps 0xe4be(%rip), %xmm1     # 0x12020
movsd 0x200(%rsp), %xmm0
pxor %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movl $0x2, %esi
movl $0x1, %edx
callq 0xce30
movq %rax, 0x18(%rsp)
jmp 0x3b8b
movsd 0x10(%rsp), %xmm0
movq 0x18(%rsp), %rdi
callq 0x4680
jmp 0x3b9d
jmp 0x3b9f
movl $0x0, 0x1e8(%rsp)
cmpl $0x3, 0x1e8(%rsp)
jge 0x3c1f
movq 0x1d0(%rsp), %rdi
movslq 0x1e8(%rsp), %rdx
movq %rdx, %rsi
callq 0xce30
movq %rax, 0x8(%rsp)
jmp 0x3bd3
movq 0x8(%rsp), %rdi
movsd 0xe438(%rip), %xmm0     # 0x12018
callq 0x4680
jmp 0x3be7
jmp 0x3be9
movl 0x1e8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1e8(%rsp)
jmp 0x3baa
movq 0x1d0(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
callq 0xce00
jmp 0x3c50
jmp 0x3c21
movb $0x1, 0x213(%rsp)
testb $0x1, 0x213(%rsp)
jne 0x3c40
movq 0x1d0(%rsp), %rdi
callq 0xce00
movq 0x1d8(%rsp), %rax
addq $0x228, %rsp            # imm = 0x228
retq
movq 0x1f0(%rsp), %rdi
callq 0x22b0
nopl (%rax)