// File: TBody[P]atomicpp/atomicpp/RateEquations.cpp
// Function: atomicpp::RateEquations::verifyNeumaierSummation(double, double, double)
void RateEquations::verifyNeumaierSummation(const double Te, const double Ne, const double NeumaierTolerance){
	// Verify that the sum over all elements equals zero (or very close to) 
	
	std::vector<double> check_dNzk(2*(Z+1), 0.0);
	std::vector<double> check_F_zk(2*(Z+1), 0.0);
	for(int k=0; k<=Z; ++k){
		check_dNzk[2*k] = dNzk[k];
		check_dNzk[2*k+1] = dNzk_correction[k];
		check_F_zk[2*k] = F_zk[k];
		check_F_zk[2*k+1] = F_zk_correction[k];
	}
	std::pair<double, double> neumaier_pair_total_dNzk = neumaierSum(check_dNzk);
	std::pair<double, double> neumaier_pair_total_F_zk = neumaierSum(check_F_zk); 

	// std::printf("Total sum: %e\n", neumaier_pair_total_dNzk.first + neumaier_pair_total_dNzk.second); 
	if(std::fabs(neumaier_pair_total_dNzk.first + neumaier_pair_total_dNzk.second) > NeumaierTolerance){ 
		std::printf("Warning: total sum of dNzk elements is non-zero (=%e) for Te = %f, Ne = %e- may result in error\n>>>in Prad.cpp/computeDerivs (May be an error with Kahan-Neumaier summation)\n", neumaier_pair_total_dNzk.first + neumaier_pair_total_dNzk.second, Te, Ne);
	}

	// std::printf("Total sum: %e\n", neumaier_pair_total_F_zk.first + neumaier_pair_total_F_zk.second); 
	if(std::fabs(neumaier_pair_total_F_zk.first + neumaier_pair_total_F_zk.second) > NeumaierTolerance){ 
		std::printf("Warning: total sum of F_zk elements is non-zero (=%e) for Te = %f, Ne = %e- may result in error\n>>>in Prad.cpp/computeDerivs (May be an error with Kahan-Neumaier summation)\n", neumaier_pair_total_F_zk.first + neumaier_pair_total_F_zk.second, Te, Ne);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movsd %xmm0, -0x10(%rbp)
movsd %xmm1, -0x18(%rbp)
movsd %xmm2, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movl 0x34(%rax), %ecx
movl %ecx, %eax
leal 0x2(%rax,%rax), %eax
cltq
movq %rax, -0xb0(%rbp)
movq $0x0, -0x40(%rbp)
leaq -0x41(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
callq 0x58a0
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rcx
leaq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rdx
callq 0x26390
jmp 0x347c0
leaq -0x41(%rbp), %rdi
callq 0x5930
movq -0xb8(%rbp), %rax
movl 0x34(%rax), %ecx
movl %ecx, %eax
leal 0x2(%rax,%rax), %eax
cltq
movq %rax, -0xc8(%rbp)
movq $0x0, -0x78(%rbp)
leaq -0x79(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x58a0
movq -0xc8(%rbp), %rsi
movq -0xc0(%rbp), %rcx
leaq -0x70(%rbp), %rdi
leaq -0x78(%rbp), %rdx
callq 0x26390
jmp 0x34817
leaq -0x79(%rbp), %rdi
callq 0x5930
movl $0x0, -0x80(%rbp)
movq -0xb8(%rbp), %rcx
movl -0x80(%rbp), %eax
cmpl 0x34(%rcx), %eax
jg 0x3497f
movq -0xb8(%rbp), %rdi
addq $0x70, %rdi
movslq -0x80(%rbp), %rsi
callq 0x5950
movsd (%rax), %xmm0
movsd %xmm0, -0xe8(%rbp)
movl -0x80(%rbp), %eax
shll %eax
movslq %eax, %rsi
leaq -0x38(%rbp), %rdi
callq 0x5950
movsd -0xe8(%rbp), %xmm0
movq -0xb8(%rbp), %rdi
movsd %xmm0, (%rax)
addq $0xa0, %rdi
movslq -0x80(%rbp), %rsi
callq 0x5950
movsd (%rax), %xmm0
movsd %xmm0, -0xe0(%rbp)
movl -0x80(%rbp), %eax
shll %eax
addl $0x1, %eax
movslq %eax, %rsi
leaq -0x38(%rbp), %rdi
callq 0x5950
movsd -0xe0(%rbp), %xmm0
movq -0xb8(%rbp), %rdi
movsd %xmm0, (%rax)
addq $0x88, %rdi
movslq -0x80(%rbp), %rsi
callq 0x5950
movsd (%rax), %xmm0
movsd %xmm0, -0xd8(%rbp)
movl -0x80(%rbp), %eax
shll %eax
movslq %eax, %rsi
leaq -0x70(%rbp), %rdi
callq 0x5950
movsd -0xd8(%rbp), %xmm0
movq -0xb8(%rbp), %rdi
movsd %xmm0, (%rax)
addq $0xb8, %rdi
movslq -0x80(%rbp), %rsi
callq 0x5950
movsd (%rax), %xmm0
movsd %xmm0, -0xd0(%rbp)
movl -0x80(%rbp), %eax
shll %eax
addl $0x1, %eax
movslq %eax, %rsi
leaq -0x70(%rbp), %rdi
callq 0x5950
movsd -0xd0(%rbp), %xmm0
movsd %xmm0, (%rax)
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x34827
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x41(%rbp), %rdi
callq 0x5930
jmp 0x34ada
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x79(%rbp), %rdi
callq 0x5930
jmp 0x34ad1
leaq -0x38(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x35490
movsd %xmm1, -0xf8(%rbp)
movsd %xmm0, -0xf0(%rbp)
jmp 0x3499d
movsd -0xf8(%rbp), %xmm0
movsd -0xf0(%rbp), %xmm1
movsd %xmm1, -0x90(%rbp)
movsd %xmm0, -0x88(%rbp)
leaq -0x70(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x35490
movsd %xmm1, -0x108(%rbp)
movsd %xmm0, -0x100(%rbp)
jmp 0x349db
movsd -0x108(%rbp), %xmm0
movsd -0x100(%rbp), %xmm1
movsd %xmm1, -0xa0(%rbp)
movsd %xmm0, -0x98(%rbp)
movsd -0x90(%rbp), %xmm0
addsd -0x88(%rbp), %xmm0
movaps 0x425e(%rip), %xmm1     # 0x38c70
pand %xmm1, %xmm0
ucomisd -0x20(%rbp), %xmm0
jbe 0x34a64
movsd -0x90(%rbp), %xmm0
movsd -0x88(%rbp), %xmm1
addsd %xmm1, %xmm0
movsd -0x10(%rbp), %xmm1
movsd -0x18(%rbp), %xmm2
leaq 0x486e(%rip), %rdi      # 0x392b0
movb $0x3, %al
callq 0x4080
jmp 0x34a4b
jmp 0x34a64
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x59b0
jmp 0x34ad1
movsd -0xa0(%rbp), %xmm0
addsd -0x98(%rbp), %xmm0
movaps 0x41f5(%rip), %xmm1     # 0x38c70
pand %xmm1, %xmm0
ucomisd -0x20(%rbp), %xmm0
jbe 0x34ab6
movsd -0xa0(%rbp), %xmm0
movsd -0x98(%rbp), %xmm1
addsd %xmm1, %xmm0
movsd -0x10(%rbp), %xmm1
movsd -0x18(%rbp), %xmm2
leaq 0x48b3(%rip), %rdi      # 0x3935e
movb $0x3, %al
callq 0x4080
jmp 0x34ab4
jmp 0x34ab6
leaq -0x70(%rbp), %rdi
callq 0x59b0
leaq -0x38(%rbp), %rdi
callq 0x59b0
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x59b0
movq -0x50(%rbp), %rdi
callq 0x45e0
nopw %cs:(%rax,%rax)