// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/GSV/GSVSegment.cpp
// Function: gaps::GSVSegment::Front(double) const
R3Vector GSVSegment::
Front(RNScalar timestamp) const
{
  // Interpolate panorama front vectors
  if (NPanoramas() == 0) return R3zero_vector;
  GSVPanorama *panorama0 = FindPanoramaBeforeTimestamp(timestamp);
  if (!panorama0) return R3zero_vector;
  int i0 = panorama0->SegmentIndex();
  if (i0 >= NPanoramas()-1) return panorama0->Front();
  GSVPanorama *panorama1 = Panorama(i0 + 1);
  RNScalar t0 = panorama0->Timestamp();
  RNScalar t1 = panorama1->Timestamp();
  if (t1 <= t0) return panorama0->Front();
  RNScalar t = (timestamp - t0) / (t1 - t0);
  if (t <= 0) return panorama0->Front();
  else if (t >= 1) return panorama1->Front();
  R3Vector front = (1 - t) * panorama0->Front() + t * panorama1->Front();

  // Make sure orhtogonal to positive z (up)
  front[2] = 0; front.Normalize();

  // Return front direction of the car at timestamp
  return front;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
cmpl $0x0, 0x4c(%rsi)
je 0x39ebe
movq %rsi, %r15
movq %rsi, %rdi
movsd %xmm0, 0x10(%rsp)
callq 0x39a84
testq %rax, %rax
je 0x39ebe
movq %rax, %r14
movslq 0x10(%rax), %rax
movl 0x4c(%r15), %ecx
decl %ecx
cmpl %ecx, %eax
jge 0x39eca
movq 0x40(%r15), %rcx
movq 0x8(%rcx,%rax,8), %r15
movsd 0x70(%r14), %xmm2
ucomisd 0x1122cc(%rip), %xmm2   # 0x14c070
jne 0x39db6
jp 0x39db6
movq %r14, %rdi
callq 0x3cebc
movsd 0x70(%r14), %xmm2
movsd 0x70(%r15), %xmm0
ucomisd 0x1122ac(%rip), %xmm0   # 0x14c070
jne 0x39de2
jp 0x39de2
movq %r15, %rdi
movsd %xmm2, 0x8(%rsp)
callq 0x3cebc
movsd 0x8(%rsp), %xmm2
movsd 0x70(%r15), %xmm0
ucomisd %xmm0, %xmm2
jae 0x39eca
movsd 0x10(%rsp), %xmm1
subsd %xmm2, %xmm1
subsd %xmm2, %xmm0
divsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jae 0x39eca
ucomisd 0x112264(%rip), %xmm1   # 0x14c078
jae 0x39f06
movsd 0x112256(%rip), %xmm0   # 0x14c078
movsd %xmm1, 0x10(%rsp)
subsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r14, %r12
addq $0x40, %r12
leaq 0x11cf28(%rip), %rsi    # 0x156d68
movq %r12, %rdi
callq 0xd5124
testl %eax, %eax
je 0x39e54
movq %r14, %rdi
callq 0x3cc14
leaq 0x18(%rsp), %rdi
movq %r12, %rsi
movsd 0x8(%rsp), %xmm0
callq 0xd580e
leaq 0x40(%r15), %r14
leaq 0x11cef6(%rip), %rsi    # 0x156d68
movq %r14, %rdi
callq 0xd5124
testl %eax, %eax
je 0x39e86
movq %r15, %rdi
callq 0x3cc14
leaq 0x30(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movsd 0x10(%rsp), %xmm0
callq 0xd580e
leaq 0x18(%rsp), %rsi
movq %rbx, %rdi
movq %r15, %rdx
callq 0xd5acc
movq $0x0, 0x10(%rbx)
movq %rbx, %rdi
callq 0xd5188
jmp 0x39ef7
leaq 0x11cea3(%rip), %rsi    # 0x156d68
movq %rbx, %rdi
jmp 0x39ef2
movq %r14, %r15
addq $0x40, %r15
leaq 0x11ce90(%rip), %rsi    # 0x156d68
movq %r15, %rdi
callq 0xd5124
testl %eax, %eax
je 0x39eec
movq %r14, %rdi
callq 0x3cc14
movq %rbx, %rdi
movq %r15, %rsi
callq 0xd4e82
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x40(%r15), %r14
leaq 0x11ce57(%rip), %rsi    # 0x156d68
movq %r14, %rdi
callq 0xd5124
testl %eax, %eax
je 0x39f25
movq %r15, %rdi
callq 0x3cc14
movq %rbx, %rdi
movq %r14, %rsi
jmp 0x39ef2
nop