// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/RNMath/RNPolynomial.cpp
// Function: gaps::RNPolynomialTerm::PartialDerivative(double const* const*, int) const
RNScalar RNPolynomialTerm::
PartialDerivative(double const* const* x, int variable) const
{
  // Check if has variable
  if (!HasVariable(variable)) return 0.0;

  // Evaluate the derivative with respect to variable
  RNScalar result = c;
  for (int i = 0; i < NVariables(); i++) {
    int k = Variable(i);
    if (k == variable) {
      if (e[i] == 1.0) result *= 1.0;
      else if (e[i] == 2.0) result *= 2.0 * x[k][0];
      else if ((e[i] < 1.0) && RNIsZero(x[k][0])) result *= RN_INFINITY;
      else result *= e[i] * pow(x[k][0], e[i] - 1.0);
    }
    else {
      if (e[i] == 1.0) result *= x[k][0];
      else if (e[i] == 2.0) result *= x[k][0] * x[k][0];
      else if ((e[i] < 0) && RNIsZero(x[k][0])) result *= RN_INFINITY;
      else result *= pow(x[k][0], e[i]);
    }
  }
  return result;
}

// Assembly:
movslq 0x8(%rdi), %rax
xorpd %xmm3, %xmm3
testq %rax, %rax
jle 0x21fe0
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r15
movq 0x18(%rdi), %rcx
cmpl %edx, (%rcx)
je 0x21e5e
movl $0x1, %esi
movq %rsi, %rdx
cmpq %rsi, %rax
je 0x21e55
leaq 0x1(%rdx), %rsi
cmpl %ebx, (%rcx,%rdx,4)
jne 0x21e44
cmpq %rax, %rdx
jae 0x21fd2
movsd 0x10(%r15), %xmm3
movslq %ebx, %r12
xorl %r13d, %r13d
movsd 0x3719e(%rip), %xmm4    # 0x59010
movsd 0x3884e(%rip), %xmm5    # 0x5a6c8
leaq 0x5a51f(%rip), %rbp     # 0x7c3a0
movq 0x18(%r15), %rax
movq 0x20(%r15), %rcx
movslq (%rax,%r13,4), %rax
movsd (%rcx,%r13,8), %xmm6
cmpl %ebx, %eax
jne 0x21ebc
ucomisd %xmm4, %xmm6
jne 0x21ea3
jnp 0x21fc2
ucomisd %xmm5, %xmm6
jne 0x21eea
jp 0x21eea
movq (%r14,%r12,8), %rax
movsd (%rax), %xmm0
addsd %xmm0, %xmm0
jmp 0x21fbe
ucomisd %xmm4, %xmm6
jne 0x21ed1
jp 0x21ed1
movq (%r14,%rax,8), %rax
mulsd (%rax), %xmm3
jmp 0x21fc2
ucomisd %xmm5, %xmm6
jne 0x21f1b
jp 0x21f1b
movq (%r14,%rax,8), %rax
movsd (%rax), %xmm0
mulsd %xmm0, %xmm0
jmp 0x21fbe
ucomisd %xmm6, %xmm4
jbe 0x21f7d
movq (%r14,%r12,8), %rax
movsd (%rax), %xmm0
movsd (%rbp), %xmm1
movapd %xmm1, %xmm2
xorpd 0x37153(%rip), %xmm2    # 0x59060
ucomisd %xmm2, %xmm0
jb 0x21f85
ucomisd %xmm0, %xmm1
jae 0x21f4a
jmp 0x21f85
xorpd %xmm0, %xmm0
ucomisd %xmm6, %xmm0
movq (%r14,%rax,8), %rax
movsd (%rax), %xmm0
jbe 0x21f56
movsd (%rbp), %xmm1
movapd %xmm1, %xmm2
xorpd 0x37122(%rip), %xmm2    # 0x59060
ucomisd %xmm2, %xmm0
jb 0x21f56
ucomisd %xmm0, %xmm1
jb 0x21f56
leaq 0x5a45f(%rip), %rax     # 0x7c3b0
jmp 0x21ec8
movapd %xmm6, %xmm1
movsd %xmm3, 0x8(%rsp)
callq 0x44b0
movsd 0x3875b(%rip), %xmm5    # 0x5a6c8
movsd 0x3709b(%rip), %xmm4    # 0x59010
movsd 0x8(%rsp), %xmm3
jmp 0x21fbe
movq (%r14,%r12,8), %rax
movsd (%rax), %xmm0
movapd %xmm6, %xmm1
addsd 0x37877(%rip), %xmm1    # 0x59808
movsd %xmm3, 0x8(%rsp)
movsd %xmm6, 0x10(%rsp)
callq 0x44b0
movsd 0x3871e(%rip), %xmm5    # 0x5a6c8
movsd 0x3705e(%rip), %xmm4    # 0x59010
movsd 0x8(%rsp), %xmm3
mulsd 0x10(%rsp), %xmm0
mulsd %xmm0, %xmm3
incq %r13
movslq 0x8(%r15), %rax
cmpq %rax, %r13
jl 0x21e81
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
movapd %xmm3, %xmm0
retq
nop