// File: /workspace/github_c_makefile_star2_O0/archer1357[P]Offline-Raytracer/utils.c
// Function: intersectKdtreeP
bool intersectKdtreeP(const float *rayOrigin,const float *rayVec,
                      float rayMax,
                      const float *minBound,const float *maxBound,
                      struct KdTraverseNode *stack,
                      const struct KdNode *rootNode,
                      const struct Triangle *triangles,int trianglesNum,
                      const struct Sphere *spheres,int spheresNum) {
  int stackSize=1;
  float invV[3];
  float bc[3];

  stack[0].node=rootNode;

  invV[0]=1.0f/rayVec[0];
  invV[1]=1.0f/rayVec[1];
  invV[2]=1.0f/rayVec[2];

  if(intersectRayBox(rayOrigin,invV,
                     minBound,maxBound,
                     &stack[0].tmin,
                     &stack[0].tmax
                     )) {

    bool result;

    while((result=searchKdTree(rayOrigin,rayVec,invV,
                               rayMax,
                               stack,&stackSize,rootNode))) {
      int i;

      for(i=0;i<stack[stackSize].node->thing.leaf.primsNum;i++) {
        int q;
        float colPt[3];
        float t;

        q=stack[stackSize].node->thing.leaf.primInds[i];

        if(q<trianglesNum) {
          if(intersectRayTriangle(rayOrigin,rayVec,
                                  triangles[q].pt0,
                                  triangles[q].pt1,
                                  triangles[q].pt2,
                                  triangles[q].plane,
                                  &t,colPt,bc)) {
            if(t <= rayMax) {
              return true;
            }
          }
        } else {
          if(intersectRaySphere(rayOrigin,rayVec,
                                spheres[q-trianglesNum].pos,
                                spheres[q-trianglesNum].radius,
                                &t)) {
            if(t <= rayMax) {
              return true;
            }
          }
        }

        //insert primitives here
      }
    }
  }

  return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movl 0x28(%rbp), %eax
movq 0x20(%rbp), %rax
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movss %xmm0, -0x1c(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movl $0x1, -0x44(%rbp)
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movss 0xc1170(%rip), %xmm0    # 0x4e3484
divss (%rax), %xmm0
movss %xmm0, -0x50(%rbp)
movq -0x18(%rbp), %rax
movss 0xc115b(%rip), %xmm0    # 0x4e3484
divss 0x4(%rax), %xmm0
movss %xmm0, -0x4c(%rbp)
movq -0x18(%rbp), %rax
movss 0xc1145(%rip), %xmm0    # 0x4e3484
divss 0x8(%rax), %xmm0
movss %xmm0, -0x48(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x50(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
addq $0x8, %r8
movq -0x38(%rbp), %r9
addq $0xc, %r9
callq 0x40e720
testb $0x1, %al
jne 0x422377
jmp 0x422506
jmp 0x422379
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x50(%rbp), %rdx
movss -0x1c(%rbp), %xmm0
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r9
leaq -0x44(%rbp), %r8
callq 0x40a960
movb %al, %cl
andb $0x1, %cl
movb %cl, -0x5d(%rbp)
testb $0x1, %al
jne 0x4223ac
jmp 0x422504
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
movq -0x38(%rbp), %rcx
movslq -0x44(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
cmpl 0x10(%rcx), %eax
jge 0x4224ff
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movslq -0x64(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %eax
cmpl 0x18(%rbp), %eax
jge 0x42248f
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq 0x10(%rbp), %rdx
movslq -0x68(%rbp), %rax
imulq $0x74, %rax, %rax
addq %rax, %rdx
addq $0x1c, %rdx
movq 0x10(%rbp), %rcx
movslq -0x68(%rbp), %rax
imulq $0x74, %rax, %rax
addq %rax, %rcx
addq $0x28, %rcx
movq 0x10(%rbp), %r8
movslq -0x68(%rbp), %rax
imulq $0x74, %rax, %rax
addq %rax, %r8
addq $0x34, %r8
movq 0x10(%rbp), %r9
movslq -0x68(%rbp), %rax
imulq $0x74, %rax, %rax
addq %rax, %r9
addq $0x64, %r9
leaq -0x74(%rbp), %r10
leaq -0x5c(%rbp), %rax
leaq -0x78(%rbp), %r11
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x40e220
testb $0x1, %al
jne 0x422476
jmp 0x42248d
movss -0x78(%rbp), %xmm1
movss -0x1c(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jb 0x42248b
movb $0x1, -0x1(%rbp)
jmp 0x42250a
jmp 0x42248d
jmp 0x4224ef
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq 0x20(%rbp), %rdx
movl -0x68(%rbp), %eax
subl 0x18(%rbp), %eax
cltq
imulq $0x2c, %rax, %rax
addq %rax, %rdx
addq $0x1c, %rdx
movq 0x20(%rbp), %rax
movl -0x68(%rbp), %ecx
subl 0x18(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x2c, %rcx, %rcx
addq %rcx, %rax
movss 0x28(%rax), %xmm0
leaq -0x78(%rbp), %rcx
callq 0x40e100
testb $0x1, %al
jne 0x4224d6
jmp 0x4224ed
movss -0x78(%rbp), %xmm1
movss -0x1c(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jb 0x4224eb
movb $0x1, -0x1(%rbp)
jmp 0x42250a
jmp 0x4224ed
jmp 0x4224ef
jmp 0x4224f1
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x4223b3
jmp 0x422379
jmp 0x422506
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)