// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Polyline.cpp
// Function: gaps::R3Polyline::VertexDerivative(int) const
R3Vector R3Polyline::
VertexDerivative(int i) const
{
  // Return derivative of polyline at ith vertex
  if (nvertices < 2) return R3zero_vector;
  if (i == 0) {
    RNScalar denom = VertexParameter(1) - VertexParameter(0);
    if (RNIsZero(denom)) return R3zero_vector;
    else return (VertexPosition(1) - VertexPosition(0)) / denom;
  }
  else if (i == nvertices-1) {
    RNScalar denom = VertexParameter(nvertices-1) - VertexParameter(nvertices-2);
    if (RNIsZero(denom)) return R3zero_vector;
    else return (VertexPosition(nvertices-1) - VertexPosition(nvertices-2)) / denom;
  }
  else {
    assert(nvertices > 3);
    RNScalar denom = VertexParameter(i+1) - VertexParameter(i-1);
    if (RNIsZero(denom)) return R3zero_vector;
    else return (VertexPosition(i+1) - VertexPosition(i-1)) / denom;
  }

  // Should never get here
  return R3zero_vector;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
movslq 0x20(%rsi), %rcx
cmpq $0x1, %rcx
jg 0x4f354
leaq 0x59399(%rip), %rsi     # 0xa86e0
movq %rbx, %rdi
callq 0x3cfd6
jmp 0x4f53f
movl %edx, %r15d
movq %rsi, %r14
testl %edx, %edx
je 0x4f386
leal -0x1(%rcx), %eax
cmpl %r15d, %eax
jne 0x4f39a
movq 0x10(%r14), %rdx
movl %r15d, %eax
testq %rdx, %rdx
je 0x4f414
movsd (%rdx,%rax,8), %xmm2
movsd -0x10(%rdx,%rcx,8), %xmm0
jmp 0x4f420
movq 0x10(%r14), %rax
testq %rax, %rax
je 0x4f3c4
movsd 0x8(%rax), %xmm2
subsd (%rax), %xmm2
jmp 0x4f3cc
leal 0x1(%r15), %edx
movq 0x10(%r14), %rcx
movslq %edx, %rax
testq %rcx, %rcx
je 0x4f4a9
movsd (%rcx,%rax,8), %xmm2
movslq %r15d, %rdx
decl %r15d
movsd -0x8(%rcx,%rdx,8), %xmm0
jmp 0x4f4b5
movsd 0x52c6c(%rip), %xmm2    # 0xa2038
leaq 0x967c5(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm0
movapd 0x52c41(%rip), %xmm1    # 0xa2020
xorpd %xmm0, %xmm1
ucomisd %xmm1, %xmm2
jb 0x4f3f3
ucomisd %xmm2, %xmm0
jae 0x4f340
movq 0x8(%r14), %rsi
addq $0x18, %rsi
leaq 0x28(%rsp), %r15
movq %r15, %rdi
movsd %xmm2, 0x8(%rsp)
callq 0x3c542
movq 0x8(%r14), %rsi
jmp 0x4f47e
cvtsi2sd %r15d, %xmm2
addl $-0x2, %ecx
cvtsi2sd %ecx, %xmm0
subsd %xmm0, %xmm2
leaq 0x9676d(%rip), %rcx     # 0xe5b98
movsd (%rcx), %xmm0
movapd 0x52be9(%rip), %xmm1    # 0xa2020
xorpd %xmm0, %xmm1
ucomisd %xmm1, %xmm2
jb 0x4f44b
ucomisd %xmm2, %xmm0
jae 0x4f340
leaq (%rax,%rax,2), %rsi
shlq $0x3, %rsi
addq 0x8(%r14), %rsi
leaq 0x28(%rsp), %r15
movq %r15, %rdi
movsd %xmm2, 0x8(%rsp)
callq 0x3c542
movslq 0x20(%r14), %rax
movq 0x8(%r14), %rcx
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rsi
addq $-0x30, %rsi
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x3c542
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x3c78e
movq %rbx, %rdi
movq %r12, %rsi
jmp 0x4f534
cvtsi2sd %edx, %xmm2
decl %r15d
cvtsi2sd %r15d, %xmm0
subsd %xmm0, %xmm2
leaq 0x966d8(%rip), %rcx     # 0xe5b98
movsd (%rcx), %xmm0
movapd 0x52b54(%rip), %xmm1    # 0xa2020
xorpd %xmm0, %xmm1
ucomisd %xmm1, %xmm2
jb 0x4f4e0
ucomisd %xmm2, %xmm0
jae 0x4f340
leaq (%rax,%rax,2), %rsi
shlq $0x3, %rsi
addq 0x8(%r14), %rsi
leaq 0x28(%rsp), %r12
movq %r12, %rdi
movsd %xmm2, 0x8(%rsp)
callq 0x3c542
movslq %r15d, %rax
leaq (%rax,%rax,2), %rsi
shlq $0x3, %rsi
addq 0x8(%r14), %rsi
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x3c542
leaq 0x40(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x3c78e
movq %rbx, %rdi
movq %r15, %rsi
movsd 0x8(%rsp), %xmm0
callq 0x3dcac
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq