// File: fhirschman[P]CANF-gp/source/CPU_functions.cc
// Function: get_fdf(std::complex<double>&, std::vector<double, std::allocator<double>>&, int, std::vector<double, std::allocator<double>>&)
complex<double> get_fdf(complex<double>& z, vector<double>& params, int n_terms, vector<double>& exponents){
	complex<double> res = 0;  
	complex<double> f = 0;
	double rationalExponent = 0;
	for(int i = n_terms-1; i>-1;i--){
		rationalExponent = exponents[i];
		complex<double> temp1 = (pow(z,rationalExponent));
		f += double(params[i])*temp1;
	}
	complex<double> df = 0;
	for(int i = n_terms-1; i>-1;i--){
		rationalExponent = exponents[i];
		// Normal derivative
		if(FRAC_DER_MODE==0){
			if(params[i] != 0){
				complex<double> temp2 = (pow(z,rationalExponent-1));
				df += double(params[i]*(rationalExponent))*temp2;
			}
		}
		// Riemann-Liouville derivative
		else{
			rationalExponent = abs(int(exponents[i]));
			if((abs(params[i]) > 0.00000000001)){
				if( (abs(rationalExponent)  > 0.00000000001)) {
				 	complex<double> temp2 = (pow(z,int(rationalExponent)-ALPHA_FRAC_DER));
					df +=  ( exp(cgammln(rationalExponent)+1.0)/exp(cgammln(rationalExponent-ALPHA_FRAC_DER+1.0)))*temp2;
				}
				else{
				 	complex<double> temp2 = params[i]*(pow(z,-ALPHA_FRAC_DER));
					df +=  temp2/exp(cgammln(1.0-ALPHA_FRAC_DER));
				}
			}
		}
	}
	res = -(f/df);
	return res;
}

// Assembly:
subq $0x208, %rsp            # imm = 0x208
movq %rdi, 0x1e8(%rsp)
movq %rsi, 0x1e0(%rsp)
movl %edx, 0x1dc(%rsp)
movq %rcx, 0x1d0(%rsp)
leaq 0x1f0(%rsp), %rdi
xorps %xmm1, %xmm1
movaps %xmm1, %xmm0
callq 0xc0c0
leaq 0x1c0(%rsp), %rdi
xorps %xmm1, %xmm1
movaps %xmm1, %xmm0
callq 0xc0c0
xorps %xmm0, %xmm0
movsd %xmm0, 0x1b8(%rsp)
movl 0x1dc(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x1b4(%rsp)
cmpl $-0x1, 0x1b4(%rsp)
jle 0x177b4
movq 0x1d0(%rsp), %rdi
movslq 0x1b4(%rsp), %rsi
callq 0xbe70
movsd (%rax), %xmm0
movsd %xmm0, 0x1b8(%rsp)
movq 0x1e8(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
callq 0x18b90
movsd %xmm0, 0x1a0(%rsp)
movsd %xmm1, 0x1a8(%rsp)
movq 0x1e0(%rsp), %rdi
movslq 0x1b4(%rsp), %rsi
callq 0xbe70
movsd (%rax), %xmm0
movsd %xmm0, 0x188(%rsp)
leaq 0x188(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
callq 0xc270
movsd %xmm0, 0x190(%rsp)
movsd %xmm1, 0x198(%rsp)
leaq 0x1c0(%rsp), %rdi
leaq 0x190(%rsp), %rsi
callq 0x11340
movl 0x1b4(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x1b4(%rsp)
jmp 0x176e9
leaq 0x178(%rsp), %rdi
xorps %xmm1, %xmm1
movaps %xmm1, %xmm0
callq 0xc0c0
movl 0x1dc(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x174(%rsp)
cmpl $-0x1, 0x174(%rsp)
jle 0x17c4e
movq 0x1d0(%rsp), %rdi
movslq 0x174(%rsp), %rsi
callq 0xbe70
movsd (%rax), %xmm0
movsd %xmm0, 0x1b8(%rsp)
leaq 0x120f9(%rip), %rax     # 0x29908
cmpl $0x0, (%rax)
jne 0x178f2
movq 0x1e0(%rsp), %rdi
movslq 0x174(%rsp), %rsi
callq 0xbe70
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x17841
jp 0x17841
jmp 0x178ed
movq 0x1e8(%rsp), %rdi
movsd 0x1b8(%rsp), %xmm0
movsd 0x7736(%rip), %xmm1     # 0x1ef90
subsd %xmm1, %xmm0
movsd %xmm0, 0x158(%rsp)
leaq 0x158(%rsp), %rsi
callq 0x18b90
movsd %xmm0, 0x160(%rsp)
movsd %xmm1, 0x168(%rsp)
movq 0x1e0(%rsp), %rdi
movslq 0x174(%rsp), %rsi
callq 0xbe70
movsd (%rax), %xmm0
mulsd 0x1b8(%rsp), %xmm0
movsd %xmm0, 0x140(%rsp)
leaq 0x140(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0xc270
movsd %xmm0, 0x148(%rsp)
movsd %xmm1, 0x150(%rsp)
leaq 0x178(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0x11340
jmp 0x17c36
movq 0x1d0(%rsp), %rdi
movslq 0x174(%rsp), %rsi
callq 0xbe70
cvttsd2si (%rax), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x1b8(%rsp)
movq 0x1e0(%rsp), %rdi
movslq 0x174(%rsp), %rsi
callq 0xbe70
movsd (%rax), %xmm0
callq 0xbe50
movsd 0x7653(%rip), %xmm1     # 0x1ef98
ucomisd %xmm1, %xmm0
jbe 0x17c34
movsd 0x1b8(%rsp), %xmm0
callq 0xbe50
movsd 0x7633(%rip), %xmm1     # 0x1ef98
ucomisd %xmm1, %xmm0
jbe 0x17b30
movq 0x1e8(%rsp), %rdi
cvttsd2si 0x1b8(%rsp), %eax
cvtsi2sd %eax, %xmm0
leaq 0x12045(%rip), %rax     # 0x299d0
subsd (%rax), %xmm0
movsd %xmm0, 0x128(%rsp)
leaq 0x128(%rsp), %rsi
callq 0x18b90
movsd %xmm0, 0x130(%rsp)
movsd %xmm1, 0x138(%rsp)
movsd 0x1b8(%rsp), %xmm0
leaq 0xc8(%rsp), %rdi
xorps %xmm1, %xmm1
callq 0xc0c0
movsd 0xc8(%rsp), %xmm0
movsd 0xd0(%rsp), %xmm1
callq 0x17370
movsd %xmm0, 0xd8(%rsp)
movsd %xmm1, 0xe0(%rsp)
movsd 0x758f(%rip), %xmm0     # 0x1ef90
movsd %xmm0, 0xc0(%rsp)
leaq 0xd8(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x18900
movsd %xmm0, 0xe8(%rsp)
movsd %xmm1, 0xf0(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x18c90
movsd %xmm0, 0xf8(%rsp)
movsd %xmm1, 0x100(%rsp)
movsd 0x1b8(%rsp), %xmm0
leaq 0x11f70(%rip), %rax     # 0x299d0
subsd (%rax), %xmm0
movsd 0x7524(%rip), %xmm1     # 0x1ef90
addsd %xmm1, %xmm0
leaq 0x90(%rsp), %rdi
xorps %xmm1, %xmm1
callq 0xc0c0
movsd 0x90(%rsp), %xmm0
movsd 0x98(%rsp), %xmm1
callq 0x17370
movsd %xmm0, 0xa0(%rsp)
movsd %xmm1, 0xa8(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x18c90
movsd %xmm0, 0xb0(%rsp)
movsd %xmm1, 0xb8(%rsp)
leaq 0xf8(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x18b50
movsd %xmm0, 0x108(%rsp)
movsd %xmm1, 0x110(%rsp)
leaq 0x108(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x18940
movsd %xmm0, 0x118(%rsp)
movsd %xmm1, 0x120(%rsp)
leaq 0x178(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x11340
jmp 0x17c32
movq 0x1e0(%rsp), %rdi
movslq 0x174(%rsp), %rsi
callq 0xbe70
movq %rax, (%rsp)
movq 0x1e8(%rsp), %rdi
leaq 0x11e78(%rip), %rax     # 0x299d0
movsd (%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, 0x68(%rsp)
leaq 0x68(%rsp), %rsi
callq 0x18b90
movq (%rsp), %rdi
movsd %xmm0, 0x70(%rsp)
movsd %xmm1, 0x78(%rsp)
leaq 0x70(%rsp), %rsi
callq 0xc270
movsd %xmm0, 0x80(%rsp)
movsd %xmm1, 0x88(%rsp)
movsd 0x73d9(%rip), %xmm0     # 0x1ef90
leaq 0x11e12(%rip), %rax     # 0x299d0
subsd (%rax), %xmm0
leaq 0x28(%rsp), %rdi
xorps %xmm1, %xmm1
callq 0xc0c0
movsd 0x28(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
callq 0x17370
movsd %xmm0, 0x38(%rsp)
movsd %xmm1, 0x40(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x18c90
movsd %xmm0, 0x48(%rsp)
movsd %xmm1, 0x50(%rsp)
leaq 0x80(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x18b50
movsd %xmm0, 0x58(%rsp)
movsd %xmm1, 0x60(%rsp)
leaq 0x178(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x11340
jmp 0x17c34
jmp 0x17c36
jmp 0x17c38
movl 0x174(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x174(%rsp)
jmp 0x177d8
leaq 0x1c0(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0x18b50
movsd %xmm0, 0x8(%rsp)
movsd %xmm1, 0x10(%rsp)
leaq 0x8(%rsp), %rdi
callq 0x18af0
movsd %xmm0, 0x18(%rsp)
movsd %xmm1, 0x20(%rsp)
movups 0x18(%rsp), %xmm0
movaps %xmm0, 0x1f0(%rsp)
movsd 0x1f0(%rsp), %xmm0
movsd 0x1f8(%rsp), %xmm1
addq $0x208, %rsp            # imm = 0x208
retq
nopl (%rax)