// File: TBody[P]atomicpp/atomicpp/RateEquations.cpp
// Function: atomicpp::RateEquations::computeDerivs(double, double, double, double, double, std::vector<double, std::allocator<double>> const&, std::vector<double, std::allocator<double>> const&)
DerivStruct RateEquations::computeDerivs(
	const double Te,
	const double Ne,
	const double Vi,
	const double Nn,
	const double Vn,
	const std::vector<double>& Nzk,
	const std::vector<double>& Vzk){

	resetDerivatives(); //Reset all the derivatives to zero, since the object has a memory of the previous step

	calculateElectronImpactPopulationEquation(Ne, Nzk, Vzk, Te);

	if (use_charge_exchange){
		calculateChargeExchangePopulationEquation(Nn, Nzk, Vzk, Te, Ne);
	}

	verifyNeumaierSummation(Te, Ne);

	calculateIonIonDrag(Ne, Te, Vi, Nzk, Vzk);

	calculateIonNeutralDrag(Nn, Vn, Nzk, Vzk);

	calculateElectronImpactPowerEquation(Ne, Nzk, Te);
	
	if (use_charge_exchange){
		calculateChargeExchangePowerEquation(Nn, Nzk, Te, Ne);
	}

	// Apply neumairSum corrections
	for(int k=0; k<=Z; ++k){
		dNzk[k] += dNzk_correction[k];
		F_zk[k] += F_zk_correction[k];
	}
	
	DerivStruct derivative_struct = makeDerivativeStruct();
	return derivative_struct;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x68(%rbp)
movq %rdi, %rax
movq %rax, -0x60(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movsd %xmm1, -0x20(%rbp)
movsd %xmm2, -0x28(%rbp)
movsd %xmm3, -0x30(%rbp)
movsd %xmm4, -0x38(%rbp)
movq %rdx, -0x40(%rbp)
movq %rcx, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x58(%rbp)
callq 0x32690
movq -0x58(%rbp), %rdi
movsd -0x20(%rbp), %xmm0
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
movsd -0x18(%rbp), %xmm1
callq 0x32770
movq -0x58(%rbp), %rax
testb $0x1, 0x30(%rax)
je 0x32529
movq -0x58(%rbp), %rdi
movsd -0x30(%rbp), %xmm0
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
movsd -0x18(%rbp), %xmm1
movsd -0x20(%rbp), %xmm2
movsd 0x6d4c(%rip), %xmm3     # 0x39270
callq 0x33a80
movq -0x58(%rbp), %rdi
movsd -0x18(%rbp), %xmm0
movsd -0x20(%rbp), %xmm1
movsd 0x3ac9(%rip), %xmm2     # 0x36008
callq 0x34750
movq -0x58(%rbp), %rdi
movsd -0x20(%rbp), %xmm0
movsd -0x18(%rbp), %xmm1
movsd -0x28(%rbp), %xmm2
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x34af0
movq -0x58(%rbp), %rdi
movsd -0x30(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x34c40
movq -0x58(%rbp), %rdi
movsd -0x20(%rbp), %xmm0
movq -0x40(%rbp), %rsi
movsd -0x18(%rbp), %xmm1
callq 0x34d60
movq -0x58(%rbp), %rax
testb $0x1, 0x30(%rax)
je 0x325bc
movq -0x58(%rbp), %rdi
movsd -0x30(%rbp), %xmm0
movq -0x40(%rbp), %rsi
movsd -0x18(%rbp), %xmm1
movsd -0x20(%rbp), %xmm2
callq 0x35080
movl $0x0, -0x4c(%rbp)
movq -0x58(%rbp), %rcx
movl -0x4c(%rbp), %eax
cmpl 0x34(%rcx), %eax
jg 0x3265a
movq -0x58(%rbp), %rdi
addq $0xa0, %rdi
movslq -0x4c(%rbp), %rsi
callq 0x5950
movq -0x58(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x78(%rbp)
addq $0x70, %rdi
movslq -0x4c(%rbp), %rsi
callq 0x5950
movsd -0x78(%rbp), %xmm0
movq -0x58(%rbp), %rdi
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
addq $0xb8, %rdi
movslq -0x4c(%rbp), %rsi
callq 0x5950
movq -0x58(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x70(%rbp)
addq $0x88, %rdi
movslq -0x4c(%rbp), %rsi
callq 0x5950
movsd -0x70(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x325c3
movq -0x58(%rbp), %rsi
movq -0x68(%rbp), %rdi
movb $0x0, -0x4d(%rbp)
callq 0x35240
movb $0x1, -0x4d(%rbp)
testb $0x1, -0x4d(%rbp)
jne 0x3267e
movq -0x68(%rbp), %rdi
callq 0x5a10
movq -0x60(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)