// File: /workspace/github_c_makefile_star2_O2/zpole[P]IICV/vl/kdtree.c
// Function: vl_kdforest_build
void
vl_kdforest_build (VlKDForest * self, vl_size numData, void const * data)
{
  vl_uindex di, ti ;
  vl_size maxNumNodes ;
  double * searchBounds;

  assert(data) ;
  assert(numData >= 1) ;

  /* need to check: if alredy built, clean first */
  self->data = data ;
  self->numData = numData ;
  self->trees = vl_malloc (sizeof(VlKDTree*) * self->numTrees) ;
  maxNumNodes = 0 ;

  for (ti = 0 ; ti < self->numTrees ; ++ ti) {
    self->trees[ti] = vl_malloc (sizeof(VlKDTree)) ;
    self->trees[ti]->dataIndex = vl_malloc (sizeof(VlKDTreeDataIndexEntry) * self->numData) ;
    for (di = 0 ; di < self->numData ; ++ di) {
      self->trees[ti]->dataIndex[di].index = di ;
    }
    self->trees[ti]->numUsedNodes = 0 ;
    /* num. nodes of a complete binary tree with numData leaves */
    self->trees[ti]->numAllocatedNodes = 2 * self->numData - 1 ;
    self->trees[ti]->nodes = vl_malloc (sizeof(VlKDTreeNode) * self->trees[ti]->numAllocatedNodes) ;
    self->trees[ti]->depth = 0 ;
    vl_kdtree_build_recursively (self, self->trees[ti],
                                 vl_kdtree_node_new(self->trees[ti], 0), 0,
                                 self->numData, 0) ;
    maxNumNodes += self->trees[ti]->numUsedNodes ;
  }

  searchBounds = vl_malloc(sizeof(double) * 2 * self->dimension);

  for (ti = 0 ; ti < self->numTrees ; ++ ti) {
    double * iter = searchBounds  ;
    double * end = iter + 2 * self->dimension ;
    while (iter < end) {
      *iter++ = - VL_INFINITY_F ;
      *iter++ = + VL_INFINITY_F ;
    }

    vl_kdtree_calc_bounds_recursively (self->trees[ti], 0, searchBounds) ;
  }

  vl_free(searchBounds);
  self -> maxNumNodes = maxNumNodes;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq %rdx, 0x18(%rdi)
movq %rsi, 0x20(%rdi)
movq 0x40(%rdi), %rdi
shlq $0x3, %rdi
callq 0x95e0
movq %rax, 0x38(%rbx)
xorl %r15d, %r15d
pushq $0x28
popq %r14
xorl %r12d, %r12d
cmpq 0x40(%rbx), %r12
jae 0x1a26c
movq %r14, %rdi
callq 0x95e0
movq 0x38(%rbx), %rcx
movq %rax, (%rcx,%r12,8)
movq 0x20(%rbx), %rdi
shlq $0x4, %rdi
callq 0x95e0
movq 0x38(%rbx), %rcx
movq (%rcx,%r12,8), %rdx
movq %rax, 0x18(%rdx)
movq 0x20(%rbx), %rax
movq (%rcx,%r12,8), %rcx
xorl %edx, %edx
xorl %esi, %esi
cmpq %rsi, %rax
je 0x1a1f5
movq 0x18(%rcx), %rdi
movq %rsi, (%rdi,%rdx)
incq %rsi
addq $0x10, %rdx
jmp 0x1a1df
andq $0x0, 0x8(%rcx)
leaq -0x1(,%rax,2), %rax
movq %rax, 0x10(%rcx)
imulq $0x38, %rax, %rdi
callq 0x95e0
movq 0x38(%rbx), %rcx
movq (%rcx,%r12,8), %rdx
movq %rax, (%rdx)
movq (%rcx,%r12,8), %rsi
andl $0x0, 0x20(%rsi)
movq (%rsi), %rax
movq 0x8(%rsi), %rdx
leaq 0x1(%rdx), %rcx
movq %rcx, 0x8(%rsi)
imulq $0x38, %rdx, %rcx
andq $0x0, 0x20(%rax,%rcx)
xorps %xmm0, %xmm0
movups %xmm0, 0xc(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
movq 0x20(%rbx), %r8
movq %rbx, %rdi
xorl %ecx, %ecx
xorl %r9d, %r9d
callq 0x1a2df
movq 0x38(%rbx), %rax
movq (%rax,%r12,8), %rax
addq 0x8(%rax), %r15
incq %r12
jmp 0x1a1a0
movq (%rbx), %rdi
shlq $0x4, %rdi
callq 0x95e0
movq %rax, %r14
xorl %r12d, %r12d
movaps 0x1392b(%rip), %xmm0    # 0x2dbb0
cmpq 0x40(%rbx), %r12
jae 0x1a2c4
movq (%rbx), %rax
shlq $0x4, %rax
addq %r14, %rax
movq %r14, %rcx
cmpq %rax, %rcx
jae 0x1a2a6
movups %xmm0, (%rcx)
addq $0x10, %rcx
jmp 0x1a298
movq 0x38(%rbx), %rax
movq (%rax,%r12,8), %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x1a80c
movaps 0x138f1(%rip), %xmm0    # 0x2dbb0
incq %r12
jmp 0x1a285
movq %r14, %rdi
callq 0x95b0
movq %r15, 0xd8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq