// File: /workspace/github_cpp_makefile_star2_O1/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 0x4ff2a
leaq 0x587c3(%rip), %rsi     # 0xa86e0
movq %rbx, %rdi
callq 0x3d4ce
jmp 0x50100
movq %rsi, %r14
testl %edx, %edx
je 0x4ff50
leal -0x1(%rcx), %eax
cmpl %edx, %eax
jne 0x4ff60
movq 0x10(%r14), %rdx
testq %rdx, %rdx
je 0x4ffe3
movsd -0x8(%rdx,%rcx,8), %xmm2
jmp 0x4ffe7
movq 0x10(%r14), %rax
testq %rax, %rax
je 0x4ff7d
movsd 0x8(%rax), %xmm2
jmp 0x4ff85
leal 0x1(%rdx), %esi
movq 0x10(%r14), %rcx
movslq %esi, %rax
testq %rcx, %rcx
je 0x4fff9
movsd (%rcx,%rax,8), %xmm2
jmp 0x4fffd
movsd 0x520b3(%rip), %xmm2    # 0xa2038
testq %rax, %rax
je 0x4ff90
movsd (%rax), %xmm0
jmp 0x4ff94
xorpd %xmm0, %xmm0
subsd %xmm0, %xmm2
leaq 0x95bf9(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm0
movapd 0x52075(%rip), %xmm1    # 0xa2020
xorpd %xmm0, %xmm1
ucomisd %xmm1, %xmm2
jb 0x4ffbf
ucomisd %xmm2, %xmm0
jae 0x4ff16
movq 0x8(%r14), %rsi
addq $0x18, %rsi
leaq 0x28(%rsp), %r15
movq %r15, %rdi
movsd %xmm2, 0x8(%rsp)
callq 0x3ca36
movq 0x8(%r14), %rsi
jmp 0x500cf
cvtsi2sd %eax, %xmm2
addl $-0x2, %ecx
testq %rdx, %rdx
je 0x5000f
movslq %ecx, %rcx
movsd (%rdx,%rcx,8), %xmm0
jmp 0x50013
cvtsi2sd %esi, %xmm2
decl %edx
movslq %edx, %r12
testq %rcx, %rcx
je 0x50075
movsd (%rcx,%r12,8), %xmm0
jmp 0x50079
cvtsi2sd %ecx, %xmm0
subsd %xmm0, %xmm2
leaq 0x95b7a(%rip), %rcx     # 0xe5b98
movsd (%rcx), %xmm0
movapd 0x51ff6(%rip), %xmm1    # 0xa2020
xorpd %xmm0, %xmm1
ucomisd %xmm1, %xmm2
jb 0x5003e
ucomisd %xmm2, %xmm0
jae 0x4ff16
cltq
leaq (%rax,%rax,2), %rsi
shlq $0x3, %rsi
addq 0x8(%r14), %rsi
leaq 0x28(%rsp), %r15
movq %r15, %rdi
movsd %xmm2, 0x8(%rsp)
callq 0x3ca36
movslq 0x20(%r14), %rax
movq 0x8(%r14), %rcx
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rsi
addq $-0x30, %rsi
jmp 0x500cf
cvtsi2sd %edx, %xmm0
subsd %xmm0, %xmm2
leaq 0x95b14(%rip), %rcx     # 0xe5b98
movsd (%rcx), %xmm0
movapd 0x51f90(%rip), %xmm1    # 0xa2020
xorpd %xmm0, %xmm1
ucomisd %xmm1, %xmm2
jb 0x500a4
ucomisd %xmm2, %xmm0
jae 0x4ff16
leaq (%rax,%rax,2), %rsi
shlq $0x3, %rsi
addq 0x8(%r14), %rsi
leaq 0x28(%rsp), %r15
movq %r15, %rdi
movsd %xmm2, 0x8(%rsp)
callq 0x3ca36
leaq (%r12,%r12,2), %rsi
shlq $0x3, %rsi
addq 0x8(%r14), %rsi
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x3ca36
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x3cc88
movq %rbx, %rdi
movq %r12, %rsi
movsd 0x8(%rsp), %xmm0
callq 0x3e200
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop