// File: 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:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movl %edx, 0x2c(%rsp)
movq 0x38(%rsp), %rdi
movq %rdi, 0x10(%rsp)
movl 0x2c(%rsp), %esi
callq 0x3d400
cmpl $0x0, %eax
jne 0x3e718
xorps %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
jmp 0x3ea11
movq 0x10(%rsp), %rax
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movl $0x0, 0x1c(%rsp)
movq 0x10(%rsp), %rdi
movl 0x1c(%rsp), %eax
movl %eax, 0xc(%rsp)
callq 0x3f6b0
movl %eax, %ecx
movl 0xc(%rsp), %eax
cmpl %ecx, %eax
jge 0x3ea05
movq 0x10(%rsp), %rdi
movl 0x1c(%rsp), %esi
callq 0x3f6e0
movl %eax, 0x18(%rsp)
movl 0x18(%rsp), %eax
cmpl 0x2c(%rsp), %eax
jne 0x3e8c1
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movslq 0x1c(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd 0x6c895(%rip), %xmm1    # 0xab020
ucomisd %xmm1, %xmm0
jne 0x3e7ac
jp 0x3e7ac
movsd 0x6c885(%rip), %xmm0    # 0xab020
mulsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
jmp 0x3e8bc
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movslq 0x1c(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd 0x6d211(%rip), %xmm1    # 0xab9d8
ucomisd %xmm1, %xmm0
jne 0x3e7fa
jp 0x3e7fa
movq 0x30(%rsp), %rax
movslq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsd 0x6d1f3(%rip), %xmm0    # 0xab9d8
mulsd (%rax), %xmm0
mulsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
jmp 0x3e8ba
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movslq 0x1c(%rsp), %rcx
movsd 0x6c810(%rip), %xmm0    # 0xab020
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x3e857
movq 0x30(%rsp), %rax
movslq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax), %xmm0
leaq 0x8baa8(%rip), %rax     # 0xca2d8
movsd (%rax), %xmm1
callq 0xb660
cmpl $0x0, %eax
je 0x3e857
leaq 0x8baa3(%rip), %rax     # 0xca2e8
movsd (%rax), %xmm0
mulsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
jmp 0x3e8b8
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rcx
movslq 0x1c(%rsp), %rdx
movsd (%rcx,%rdx,8), %xmm0
movsd %xmm0, (%rsp)
movq 0x30(%rsp), %rcx
movslq 0x18(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd (%rcx), %xmm0
movq 0x20(%rax), %rax
movslq 0x1c(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd 0x6c789(%rip), %xmm2    # 0xab020
subsd %xmm2, %xmm1
callq 0x44a0
movaps %xmm0, %xmm1
movsd (%rsp), %xmm0
mulsd %xmm1, %xmm0
mulsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
jmp 0x3e8ba
jmp 0x3e8bc
jmp 0x3e9f3
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movslq 0x1c(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd 0x6c744(%rip), %xmm1    # 0xab020
ucomisd %xmm1, %xmm0
jne 0x3e907
jp 0x3e907
movq 0x30(%rsp), %rax
movslq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax), %xmm0
mulsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
jmp 0x3e9f1
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movslq 0x1c(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd 0x6d0b6(%rip), %xmm1    # 0xab9d8
ucomisd %xmm1, %xmm0
jne 0x3e95f
jp 0x3e95f
movq 0x30(%rsp), %rax
movslq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax), %xmm0
movq 0x30(%rsp), %rax
movslq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rax
mulsd (%rax), %xmm0
mulsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
jmp 0x3e9ef
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movslq 0x1c(%rsp), %rcx
xorps %xmm0, %xmm0
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x3e9b7
movq 0x30(%rsp), %rax
movslq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax), %xmm0
leaq 0x8b948(%rip), %rax     # 0xca2d8
movsd (%rax), %xmm1
callq 0xb660
cmpl $0x0, %eax
je 0x3e9b7
leaq 0x8b943(%rip), %rax     # 0xca2e8
movsd (%rax), %xmm0
mulsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
jmp 0x3e9ed
movq 0x10(%rsp), %rax
movq 0x30(%rsp), %rcx
movslq 0x18(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd (%rcx), %xmm0
movq 0x20(%rax), %rax
movslq 0x1c(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm1
callq 0x44a0
mulsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
jmp 0x3e9ef
jmp 0x3e9f1
jmp 0x3e9f3
jmp 0x3e9f5
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x3e730
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x40(%rsp), %xmm0
addq $0x48, %rsp
retq
nopl (%rax)