// File: /workspace/github_cpp_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
subq $0x50, %rsp
movq %rdi, %rbx
movslq 0x20(%rsi), %rax
cmpq $0x1, %rax
jg 0x48a0e
leaq 0x50c8f(%rip), %rsi     # 0x99690
movq %rbx, %rdi
callq 0x3831c
jmp 0x48bee
movl %edx, %r15d
movq %rsi, %r14
testl %edx, %edx
je 0x48a40
leal -0x1(%rax), %ecx
cmpl %r15d, %ecx
jne 0x48a54
movq 0x10(%r14), %rcx
testq %rcx, %rcx
je 0x48af6
movl %r15d, %edx
movsd (%rcx,%rdx,8), %xmm2
movsd -0x10(%rcx,%rax,8), %xmm0
jmp 0x48b02
movq 0x10(%r14), %rax
testq %rax, %rax
je 0x48a7e
movsd 0x8(%rax), %xmm2
subsd (%rax), %xmm2
jmp 0x48a86
leal 0x1(%r15), %edx
movq 0x10(%r14), %rax
testq %rax, %rax
je 0x48b6c
movslq %edx, %rcx
movsd (%rax,%rcx,8), %xmm2
movslq %r15d, %rcx
decl %r15d
movsd -0x8(%rax,%rcx,8), %xmm0
jmp 0x48b78
movsd 0x4a582(%rip), %xmm2    # 0x93008
leaq 0x9211b(%rip), %rax     # 0xdaba8
movsd (%rax), %xmm0
movapd 0x4a597(%rip), %xmm1    # 0x93030
xorpd %xmm0, %xmm1
ucomisd %xmm1, %xmm2
jb 0x48aad
ucomisd %xmm2, %xmm0
jae 0x489fa
movq 0x8(%r14), %rsi
addq $0x18, %rsi
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movsd %xmm2, (%rsp)
callq 0x37b5c
movq 0x8(%r14), %rsi
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x37b5c
leaq 0x38(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x37d29
movq %rbx, %rdi
movq %r12, %rsi
jmp 0x48be4
cvtsi2sd %r15d, %xmm2
addl $-0x2, %eax
cvtsi2sd %eax, %xmm0
subsd %xmm0, %xmm2
leaq 0x9209b(%rip), %rax     # 0xdaba8
movsd (%rax), %xmm0
movapd 0x4a517(%rip), %xmm1    # 0x93030
xorpd %xmm0, %xmm1
ucomisd %xmm1, %xmm2
jb 0x48b2d
ucomisd %xmm2, %xmm0
jae 0x489fa
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movl %r15d, %edx
movsd %xmm2, (%rsp)
callq 0x4844c
movl 0x20(%r14), %edx
addl $-0x2, %edx
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x4844c
leaq 0x38(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
jmp 0x48bd9
cvtsi2sd %edx, %xmm2
decl %r15d
cvtsi2sd %r15d, %xmm0
subsd %xmm0, %xmm2
leaq 0x92025(%rip), %rax     # 0xdaba8
movsd (%rax), %xmm0
movapd 0x4a4a1(%rip), %xmm1    # 0x93030
xorpd %xmm0, %xmm1
ucomisd %xmm1, %xmm2
jb 0x48ba3
ucomisd %xmm2, %xmm0
jae 0x489fa
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movsd %xmm2, (%rsp)
callq 0x4844c
leaq 0x8(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x4844c
leaq 0x38(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x37d29
movq %rbx, %rdi
movq %r14, %rsi
movsd (%rsp), %xmm0
callq 0x38d1e
movq %rbx, %rax
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
nop