// File: PeterDenton[P]Nu-Pert/src/Check.cpp
// Function: Check::Palphabeta(int, int, double, double, double, int)
double Palphabeta(int alpha, int beta, double a, double LE, double delta, int order)
{
	assert (alpha >= 0 && alpha <= 2); // alpha valid for 0, 1, 2
	assert (beta >= 0 && beta <= 2); // beta valid for 0, 1, 2
	assert (order >= 0 && order <= 2); // order valid for 0, 1, 2

	double L2E = km_per_GeV_to_per_eV2 * LE / 2; // in eV^-2 now

	double l1, l2, l3;
	if (order < 2) // first order is same as zeroth order
	{
		l1 = l10(a);
		l2 = l20(a);
		l3 = l30(a);
	}
	else
	{
		l1 = Check::l1(a);
		l2 = Check::l2(a);
		l3 = Check::l3(a);
	}

	// See eq. 4.0.1 or eq. 3.12 in arXiv:1505.01826
	std::complex<double> A(0, 0);
	A += Talphabetai(alpha, beta, 0, a, delta, order) * std::complex<double>(cos(l1 * L2E), -sin(l1 * L2E));
	A += Talphabetai(alpha, beta, 1, a, delta, order) * std::complex<double>(cos(l2 * L2E), -sin(l2 * L2E));
	A += Talphabetai(alpha, beta, 2, a, delta, order) * std::complex<double>(cos(l3 * L2E), -sin(l3 * L2E));

	double P = std::norm(A);
	ProbabilityWarning W(&P);
	return P;
}

// Assembly:
subq $0x168, %rsp            # imm = 0x168
movl %edi, 0x164(%rsp)
movl %esi, 0x160(%rsp)
movsd %xmm0, 0x158(%rsp)
movsd %xmm1, 0x150(%rsp)
movsd %xmm2, 0x148(%rsp)
movl %edx, 0x144(%rsp)
xorl %eax, %eax
cmpl $0x0, 0x164(%rsp)
movb %al, 0x2f(%rsp)
jl 0x41f6
cmpl $0x2, 0x164(%rsp)
setle %al
movb %al, 0x2f(%rsp)
movb 0x2f(%rsp), %al
testb $0x1, %al
jne 0x4200
jmp 0x4202
jmp 0x4221
leaq 0xdf76(%rip), %rdi      # 0x1217f
leaq 0xde39(%rip), %rsi      # 0x12049
movl $0xb0, %edx
leaq 0xdff0(%rip), %rcx      # 0x1220c
callq 0x20d0
xorl %eax, %eax
cmpl $0x0, 0x160(%rsp)
movb %al, 0x2e(%rsp)
jl 0x4240
cmpl $0x2, 0x160(%rsp)
setle %al
movb %al, 0x2e(%rsp)
movb 0x2e(%rsp), %al
testb $0x1, %al
jne 0x424a
jmp 0x424c
jmp 0x426b
leaq 0xdf91(%rip), %rdi      # 0x121e4
leaq 0xddef(%rip), %rsi      # 0x12049
movl $0xb1, %edx
leaq 0xdfa6(%rip), %rcx      # 0x1220c
callq 0x20d0
xorl %eax, %eax
cmpl $0x0, 0x144(%rsp)
movb %al, 0x2d(%rsp)
jl 0x428a
cmpl $0x2, 0x144(%rsp)
setle %al
movb %al, 0x2d(%rsp)
movb 0x2d(%rsp), %al
testb $0x1, %al
jne 0x4294
jmp 0x4296
jmp 0x42b5
leaq 0xdd93(%rip), %rdi      # 0x12030
leaq 0xdda5(%rip), %rsi      # 0x12049
movl $0xb2, %edx
leaq 0xdf5c(%rip), %rcx      # 0x1220c
callq 0x20d0
leaq 0xe01c(%rip), %rax      # 0x122d8
movsd (%rax), %xmm0
mulsd 0x150(%rsp), %xmm0
movsd 0xdd37(%rip), %xmm1     # 0x12008
divsd %xmm1, %xmm0
movsd %xmm0, 0x138(%rsp)
cmpl $0x2, 0x144(%rsp)
jge 0x432f
movsd 0x158(%rsp), %xmm0
callq 0x28a0
movsd %xmm0, 0x130(%rsp)
movsd 0x158(%rsp), %xmm0
callq 0x2b10
movsd %xmm0, 0x128(%rsp)
movsd 0x158(%rsp), %xmm0
callq 0x2d80
movsd %xmm0, 0x120(%rsp)
jmp 0x4383
movsd 0x158(%rsp), %xmm0
movl $0x2, %edi
callq 0x2810
movsd %xmm0, 0x130(%rsp)
movsd 0x158(%rsp), %xmm0
movl $0x2, %edi
callq 0x2a80
movsd %xmm0, 0x128(%rsp)
movsd 0x158(%rsp), %xmm0
movl $0x2, %edi
callq 0x2cf0
movsd %xmm0, 0x120(%rsp)
leaq 0x110(%rsp), %rdi
xorps %xmm1, %xmm1
movaps %xmm1, %xmm0
callq 0x4750
movl 0x164(%rsp), %edi
movl 0x160(%rsp), %esi
movsd 0x158(%rsp), %xmm0
movsd 0x148(%rsp), %xmm1
movl 0x144(%rsp), %ecx
xorl %edx, %edx
callq 0x3f30
movsd %xmm0, 0xf0(%rsp)
movsd %xmm1, 0xf8(%rsp)
movsd 0x130(%rsp), %xmm0
mulsd 0x138(%rsp), %xmm0
callq 0x22d0
movsd %xmm0, 0x8(%rsp)
movsd 0x130(%rsp), %xmm0
mulsd 0x138(%rsp), %xmm0
callq 0x2060
movaps %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
leaq 0xe0(%rsp), %rdi
callq 0x4750
leaq 0xf0(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x46b0
movsd %xmm0, 0x100(%rsp)
movsd %xmm1, 0x108(%rsp)
leaq 0x110(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x4780
movl 0x164(%rsp), %edi
movl 0x160(%rsp), %esi
movsd 0x158(%rsp), %xmm0
movsd 0x148(%rsp), %xmm1
movl 0x144(%rsp), %ecx
movl $0x1, %edx
callq 0x3f30
movsd %xmm0, 0xc0(%rsp)
movsd %xmm1, 0xc8(%rsp)
movsd 0x128(%rsp), %xmm0
mulsd 0x138(%rsp), %xmm0
callq 0x22d0
movsd %xmm0, 0x10(%rsp)
movsd 0x128(%rsp), %xmm0
mulsd 0x138(%rsp), %xmm0
callq 0x2060
movaps %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
leaq 0xb0(%rsp), %rdi
callq 0x4750
leaq 0xc0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x46b0
movsd %xmm0, 0xd0(%rsp)
movsd %xmm1, 0xd8(%rsp)
leaq 0x110(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x4780
movl 0x164(%rsp), %edi
movl 0x160(%rsp), %esi
movsd 0x158(%rsp), %xmm0
movsd 0x148(%rsp), %xmm1
movl 0x144(%rsp), %ecx
movl $0x2, %edx
callq 0x3f30
movsd %xmm0, 0x90(%rsp)
movsd %xmm1, 0x98(%rsp)
movsd 0x120(%rsp), %xmm0
mulsd 0x138(%rsp), %xmm0
callq 0x22d0
movsd %xmm0, 0x18(%rsp)
movsd 0x120(%rsp), %xmm0
mulsd 0x138(%rsp), %xmm0
callq 0x2060
movaps %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
leaq 0x80(%rsp), %rdi
callq 0x4750
leaq 0x90(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x46b0
movsd %xmm0, 0xa0(%rsp)
movsd %xmm1, 0xa8(%rsp)
leaq 0x110(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x4780
leaq 0x110(%rsp), %rdi
callq 0x47d0
movsd %xmm0, 0x78(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x110a0
movsd 0x78(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x47e0
movsd 0x20(%rsp), %xmm0
addq $0x168, %rsp            # imm = 0x168
retq
nopl (%rax)