// File: /workspace/github_c_makefile_star2_O0/archer1357[P]Offline-Raytracer/kdtree.c
// Function: searchKdTree
bool searchKdTree(const float *P, const float *V,
                        const float *invV,
                        float ray_tmax,
                        struct KdTraverseNode *stack,
                        int *stackSize,
                        const struct KdNode *rootNode) {


  while((*stackSize)>0) {
    float tmin,tmax;
    const struct KdNode *node;

    //
    node=stack[(*stackSize)-1].node;
    tmin=stack[(*stackSize)-1].tmin;
    tmax=stack[(*stackSize)-1].tmax;
    (*stackSize)--;


    //
    if(ray_tmax < tmin) {
      return false;
    }

    //

    if(node->type==3) {
      return true;
    }

    //branch


    int axis,belowFirst;
    float tplane,split;
    struct KdNode *firstNode,*secondNode;

    axis=node->type;
    split=node->thing.branch.split;

    // Compute parametric distance along ray to split plane
    tplane=(node->thing.branch.split-P[axis])*invV[axis];



    // Get node children pointers for ray
    //node under plane is always stored after parent
    // node in memory aka left node is under
    belowFirst=(P[axis]<split) || (P[axis] == split && V[axis] <= 0);

    //if below: first=left, second=right
    // else first=right,second=left
    if(belowFirst) {
      firstNode=node->thing.branch.left;
      secondNode=node->thing.branch.right;
    } else {
      firstNode=node->thing.branch.right;
      secondNode=node->thing.branch.left;

    }

    // Advance to next child node, possibly enqueue other child
    if(tplane > tmax
       || tplane <= 0.0f
       ) {
      //push first
      if(firstNode) {
        stack[*stackSize].node=firstNode;
        stack[*stackSize].tmin=tmin;
        stack[*stackSize].tmax=tmax;
        (*stackSize)++;
      }


    } else if (tplane < tmin) {
      //push second
      if(secondNode) {
        stack[*stackSize].node=secondNode;
        stack[*stackSize].tmin=tmin;
        stack[*stackSize].tmax=tmax;
        (*stackSize)++;
      }
    } else {
      // Enqueue _secondChild_ in todo list
      //push second and then first

      if(secondNode) {
        stack[*stackSize].node=secondNode;
        stack[*stackSize].tmin=tplane;
        stack[*stackSize].tmax=tmax;
        (*stackSize)++;
      }
      if(firstNode) {
        stack[*stackSize].node=firstNode;
        stack[*stackSize].tmin=tmin;
        stack[*stackSize].tmax=tplane;
        (*stackSize)++;
      }
    }
  }

  return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movss %xmm0, -0x24(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
jle 0x40acb8
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movss 0x8(%rax), %xmm0
movss %xmm0, -0x44(%rbp)
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movss 0xc(%rax), %xmm0
movss %xmm0, -0x48(%rbp)
movq -0x38(%rbp), %rax
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
movss -0x24(%rbp), %xmm1
movss -0x44(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x40aa11
movb $0x0, -0x1(%rbp)
jmp 0x40acbc
movq -0x50(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x40aa23
movb $0x1, -0x1(%rbp)
jmp 0x40acbc
movq -0x50(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x54(%rbp)
movq -0x50(%rbp), %rax
movss 0x8(%rax), %xmm0
movss %xmm0, -0x60(%rbp)
movq -0x50(%rbp), %rax
movss 0x8(%rax), %xmm0
movq -0x10(%rbp), %rax
movslq -0x54(%rbp), %rcx
subss (%rax,%rcx,4), %xmm0
movq -0x20(%rbp), %rax
movslq -0x54(%rbp), %rcx
mulss (%rax,%rcx,4), %xmm0
movss %xmm0, -0x5c(%rbp)
movq -0x10(%rbp), %rax
movslq -0x54(%rbp), %rcx
movss (%rax,%rcx,4), %xmm1
movss -0x60(%rbp), %xmm0
movb $0x1, %al
ucomiss %xmm1, %xmm0
movb %al, -0x71(%rbp)
ja 0x40aab3
movq -0x10(%rbp), %rax
movslq -0x54(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
xorl %eax, %eax
ucomiss -0x60(%rbp), %xmm0
movb %al, -0x72(%rbp)
jne 0x40aaad
jp 0x40aaad
movq -0x18(%rbp), %rax
movslq -0x54(%rbp), %rcx
xorps %xmm0, %xmm0
ucomiss (%rax,%rcx,4), %xmm0
setae %al
movb %al, -0x72(%rbp)
movb -0x72(%rbp), %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x58(%rbp)
je 0x40aade
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x70(%rbp)
jmp 0x40aaf6
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x70(%rbp)
movss -0x5c(%rbp), %xmm0
ucomiss -0x48(%rbp), %xmm0
ja 0x40ab0a
xorps %xmm0, %xmm0
ucomiss -0x5c(%rbp), %xmm0
jb 0x40ab72
cmpq $0x0, -0x68(%rbp)
je 0x40ab6d
movq -0x68(%rbp), %rcx
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rdx
movslq (%rdx), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movss -0x44(%rbp), %xmm0
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movslq (%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0x8(%rax)
movss -0x48(%rbp), %xmm0
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movslq (%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0xc(%rax)
movq -0x38(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x40acb3
movss -0x5c(%rbp), %xmm1
movss -0x44(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x40abe9
cmpq $0x0, -0x70(%rbp)
je 0x40abe4
movq -0x70(%rbp), %rcx
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rdx
movslq (%rdx), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movss -0x44(%rbp), %xmm0
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movslq (%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0x8(%rax)
movss -0x48(%rbp), %xmm0
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movslq (%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0xc(%rax)
movq -0x38(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x40acb1
cmpq $0x0, -0x70(%rbp)
je 0x40ac4c
movq -0x70(%rbp), %rcx
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rdx
movslq (%rdx), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movss -0x5c(%rbp), %xmm0
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movslq (%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0x8(%rax)
movss -0x48(%rbp), %xmm0
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movslq (%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0xc(%rax)
movq -0x38(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
cmpq $0x0, -0x68(%rbp)
je 0x40acaf
movq -0x68(%rbp), %rcx
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rdx
movslq (%rdx), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movss -0x44(%rbp), %xmm0
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movslq (%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0x8(%rax)
movss -0x5c(%rbp), %xmm0
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movslq (%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0xc(%rax)
movq -0x38(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x40acb1
jmp 0x40acb3
jmp 0x40a981
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)