// File: /workspace/github_cpp_makefile_star2_O1/ingowald[P]closestSurfacePointQueries/src/distanceQueries.cpp
// Function: rtdqComputeClosestPointsfi
void rtdqComputeClosestPointsfi(distance_query_scene scene,
                                  float   *out_closest_point_pos_x,
                                  float   *out_closest_point_pos_y,
                                  float   *out_closest_point_pos_z,
                                  size_t   out_closest_point_pos_stride,
                                  float   *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 float *in_query_point_x,
                                  const float *in_query_point_y,
                                  const float *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, %r13
movq 0xd8(%rsp), %rbx
movq %rdi, 0x50(%rsp)
testq %rdi, %rdi
sete %al
testq %rbx, %rbx
sete %sil
orb %al, %sil
jne 0x5245
movq 0xd0(%rsp), %rax
movq 0xb0(%rsp), %rsi
movq 0xa8(%rsp), %r15
movq 0xa0(%rsp), %rdi
shlq $0x2, %rdi
movq %rdi, 0x28(%rsp)
shlq $0x2, %rsi
movq %rsi, 0x30(%rsp)
shlq $0x2, (%rsp)
shlq $0x2, %rax
movq %rax, 0x38(%rsp)
xorl %ebp, %ebp
xorl %r14d, %r14d
movq 0x8(%rsp), %r12
movq %rcx, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq 0xb8(%rsp), %rax
movss (%rax,%rbp), %xmm0
movq 0xc0(%rsp), %rax
movss (%rax,%rbp), %xmm1
movq 0xc8(%rsp), %rax
movss (%rax,%rbp), %xmm2
movss %xmm0, 0x58(%rsp)
movss %xmm1, 0x5c(%rsp)
movss %xmm2, 0x60(%rsp)
movabsq $-0x80800000, %rax      # imm = 0xFFFFFFFF7F800000
movq %rax, 0x20(%rsp)
leaq 0x10(%rsp), %rdi
movq 0x50(%rsp), %rsi
leaq 0x58(%rsp), %rdx
callq 0x4c54
testq %r13, %r13
je 0x51d7
movss 0x10(%rsp), %xmm0
movss %xmm0, (%r13,%r14)
movq 0x40(%rsp), %rdx
testq %rdx, %rdx
movq 0x48(%rsp), %rcx
je 0x51f2
movss 0x14(%rsp), %xmm0
movss %xmm0, (%rdx,%r14)
testq %rcx, %rcx
je 0x5203
movss 0x18(%rsp), %xmm0
movss %xmm0, (%rcx,%r14)
cmpq $0x0, 0xa8(%rsp)
je 0x5215
movl 0x24(%rsp), %eax
movl %eax, (%r15)
cmpq $0x0, 0x8(%rsp)
je 0x5229
movss 0x20(%rsp), %xmm0
movss %xmm0, (%r12)
addq 0x28(%rsp), %r12
addq 0x30(%rsp), %r15
addq (%rsp), %r14
addq 0x38(%rsp), %rbp
decq %rbx
jne 0x5169
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq