// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/RNMath/RNPolynomial.cpp
// Function: gaps::RNPolynomialTerm::PartialDerivative(double const*, int) const
RNScalar RNPolynomialTerm::
PartialDerivative(const RNScalar *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 (variable == k) {
      if (e[i] == 1.0) result *= 1.0;
      else if (e[i] == 2.0) result *= 2.0 * x[k];
      else if ((e[i] < 1.0) && RNIsZero(x[k])) result *= RN_INFINITY;
      else result *= e[i] * pow(x[k], e[i] - 1.0);
    }
    else {
      if (e[i] == 1.0) result *= x[k];
      else if (e[i] == 2.0) result *= x[k] * x[k];
      else if ((e[i] < 0) && RNIsZero(x[k])) result *= RN_INFINITY;
      else result *= pow(x[k], e[i]);
    }
  }
  return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r15
movslq 0x8(%rdi), %rax
testq %rax, %rax
setg %cl
jle 0x21d40
movq 0x18(%r15), %rcx
cmpl %ebx, (%rcx)
je 0x21d4c
movl $0x1, %esi
movq %rsi, %rdx
cmpq %rsi, %rax
je 0x21d3a
leaq 0x1(%rdx), %rsi
cmpl %ebx, (%rcx,%rdx,4)
jne 0x21d29
cmpq %rax, %rdx
setb %cl
xorpd %xmm4, %xmm4
testb %cl, %cl
je 0x21ec6
movsd 0x10(%r15), %xmm4
cmpl $0x0, 0x8(%r15)
jle 0x21ec6
xorl %r12d, %r12d
movsd 0x372a8(%rip), %xmm5    # 0x59010
movsd 0x38948(%rip), %xmm6    # 0x5a6b8
leaq 0x5a621(%rip), %r13     # 0x7c398
leaq 0x5a62a(%rip), %rbp     # 0x7c3a8
movq 0x18(%r15), %rax
movslq (%rax,%r12,4), %rax
cmpl %ebx, %eax
jne 0x21db7
movq 0x20(%r15), %rcx
movsd (%rcx,%r12,8), %xmm3
ucomisd %xmm5, %xmm3
jne 0x21da0
jnp 0x21eb6
ucomisd %xmm6, %xmm3
jne 0x21deb
jp 0x21deb
movsd (%r14,%rax,8), %xmm0
addsd %xmm0, %xmm0
jmp 0x21eb2
movq 0x20(%r15), %rcx
movsd (%rcx,%r12,8), %xmm1
ucomisd %xmm5, %xmm1
jne 0x21dd4
jp 0x21dd4
mulsd (%r14,%rax,8), %xmm4
jmp 0x21eb6
ucomisd %xmm6, %xmm1
jne 0x21e56
jp 0x21e56
movsd (%r14,%rax,8), %xmm0
mulsd %xmm0, %xmm0
jmp 0x21eb2
ucomisd %xmm3, %xmm5
jbe 0x21e15
movsd (%r14,%rax,8), %xmm0
movsd (%r13), %xmm1
movapd %xmm1, %xmm2
xorpd 0x37257(%rip), %xmm2    # 0x59060
ucomisd %xmm2, %xmm0
jb 0x21e15
ucomisd %xmm0, %xmm1
jae 0x21e84
movsd (%r14,%rax,8), %xmm0
movapd %xmm3, %xmm1
addsd 0x379e1(%rip), %xmm1    # 0x59808
movsd %xmm4, 0x8(%rsp)
movsd %xmm3, 0x10(%rsp)
callq 0x44a0
movsd 0x38878(%rip), %xmm6    # 0x5a6b8
movsd 0x371c8(%rip), %xmm5    # 0x59010
movsd 0x8(%rsp), %xmm4
mulsd 0x10(%rsp), %xmm0
jmp 0x21eb2
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x21e8b
movsd (%r14,%rax,8), %xmm0
movsd (%r13), %xmm2
movapd %xmm2, %xmm3
xorpd 0x371e8(%rip), %xmm3    # 0x59060
ucomisd %xmm3, %xmm0
jb 0x21e8b
ucomisd %xmm0, %xmm2
jb 0x21e8b
mulsd (%rbp), %xmm4
jmp 0x21eb6
movsd (%r14,%rax,8), %xmm0
movsd %xmm4, 0x8(%rsp)
callq 0x44a0
movsd 0x38814(%rip), %xmm6    # 0x5a6b8
movsd 0x37164(%rip), %xmm5    # 0x59010
movsd 0x8(%rsp), %xmm4
mulsd %xmm0, %xmm4
incq %r12
movslq 0x8(%r15), %rax
cmpq %rax, %r12
jl 0x21d7e
movapd %xmm4, %xmm0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop