// File: /workspace/github_cpp_makefile_star2_O2/ingowald[P]closestSurfacePointQueries/src/distanceQueries.cpp
// Function: rtdqComputeClosestPointsdi
void rtdqComputeClosestPointsdi(distance_query_scene scene,
                                  double   *out_closest_point_pos_x,
                                  double   *out_closest_point_pos_y,
                                  double   *out_closest_point_pos_z,
                                  size_t   out_closest_point_pos_stride,
                                  double   *out_closest_point_dist,
                                  size_t   out_closest_point_dist_stride,
                                  int32_t *out_closest_point_primID,
                                  size_t   out_closest_point_primID_stride,
                                  const double *in_query_point_x,
                                  const double *in_query_point_y,
                                  const double *in_query_point_z,
                                  const size_t in_query_point_stride,
                                  const size_t numQueryPoints)
  {
    QueryObject *qo = (QueryObject *)scene;
    if (!qo)
      return; 

#if CACHE_LAST_RESULT
    vec3f lastPoint;
#endif
    for (size_t qpi=0;qpi<numQueryPoints;qpi++) {
      const vec3fa queryPoint(in_query_point_x[qpi*in_query_point_stride],
                              in_query_point_y[qpi*in_query_point_stride],
                              in_query_point_z[qpi*in_query_point_stride]);
      
      QueryResult qr;
      qr.distance = std::numeric_limits<float>::infinity();
      qr.primID   = -1;
  
#if CACHE_LAST_RESULT
      if (qpi > 0) {
        qr.distance = length(queryPoint-lastPoint)*(((1<<22)+1)/float(1<<22));
      }
#endif
      oneQuery(qr,qo,queryPoint);
#if CACHE_LAST_RESULT
      lastPoint = qr.point;
#endif
      
      if (out_closest_point_pos_x)
        out_closest_point_pos_x[qpi*out_closest_point_pos_stride] = qr.point.x;
      if (out_closest_point_pos_y)
        out_closest_point_pos_y[qpi*out_closest_point_pos_stride] = qr.point.y;
      if (out_closest_point_pos_z)
        out_closest_point_pos_z[qpi*out_closest_point_pos_stride] = qr.point.z;
      if (out_closest_point_primID)
        out_closest_point_primID[qpi*out_closest_point_primID_stride] = qr.primID;
      if (out_closest_point_dist)
        out_closest_point_dist[qpi*out_closest_point_dist_stride] = qr.distance;
    }
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, 0x8(%rsp)
movq %r8, (%rsp)
movq %rsi, 0x48(%rsp)
movq %rdi, 0x40(%rsp)
testq %rdi, %rdi
je 0x4ad7
movq %rcx, %r13
movq %rdx, %r14
movq 0xd8(%rsp), %rbx
movq 0xd0(%rsp), %rax
movq 0xb0(%rsp), %rsi
movq 0xa8(%rsp), %r15
movq 0xa0(%rsp), %rdi
shlq $0x3, %rax
movq %rax, 0x38(%rsp)
shlq $0x3, (%rsp)
shlq $0x2, %rsi
movq %rsi, 0x30(%rsp)
shlq $0x3, %rdi
movq %rdi, 0x28(%rsp)
xorl %ebp, %ebp
movq 0x8(%rsp), %rsi
xorl %r12d, %r12d
subq $0x1, %rbx
jb 0x4ad7
movq %r15, 0x50(%rsp)
movq %rsi, %r15
movq 0xc8(%rsp), %rax
cvtsd2ss (%rax,%r12), %xmm0
movq 0xb8(%rsp), %rax
movsd (%rax,%r12), %xmm1
movq 0xc0(%rsp), %rax
movhpd (%rax,%r12), %xmm1      # xmm1 = xmm1[0],mem[0]
cvtpd2ps %xmm1, %xmm1
movlpd %xmm1, 0x58(%rsp)
movss %xmm0, 0x60(%rsp)
movabsq $-0x80800000, %rax      # imm = 0xFFFFFFFF7F800000
movq %rax, 0x20(%rsp)
leaq 0x10(%rsp), %rdi
movq 0x40(%rsp), %rsi
leaq 0x58(%rsp), %rdx
callq 0x4524
movq 0x48(%rsp), %rax
testq %rax, %rax
je 0x4a70
cvtss2sd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax,%rbp)
testq %r14, %r14
je 0x4a81
cvtss2sd 0x14(%rsp), %xmm0
movsd %xmm0, (%r14,%rbp)
testq %r13, %r13
movq %r15, %rsi
movq 0x50(%rsp), %r15
je 0x4a9b
cvtss2sd 0x18(%rsp), %xmm0
movsd %xmm0, (%r13,%rbp)
cmpq $0x0, 0xa8(%rsp)
je 0x4aad
movl 0x24(%rsp), %eax
movl %eax, (%r15)
cmpq $0x0, 0x8(%rsp)
je 0x4abf
cvtss2sd 0x20(%rsp), %xmm0
movsd %xmm0, (%rsi)
addq 0x38(%rsp), %r12
addq (%rsp), %rbp
addq 0x30(%rsp), %r15
addq 0x28(%rsp), %rsi
jmp 0x49ec
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq