// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq 0x40(%rsp), %rcx
movq 0x50(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x48(%rsp), %rcx
movq 0x50(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x50(%rsp), %rax
movq 0x40(%rax), %rdi
shlq $0x3, %rdi
callq 0x9660
movq %rax, %rcx
movq 0x50(%rsp), %rax
movq %rcx, 0x38(%rax)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
movq 0x30(%rsp), %rax
movq 0x50(%rsp), %rcx
cmpq 0x40(%rcx), %rax
jae 0x2c51c
movl $0x28, %edi
callq 0x9660
movq %rax, %rdx
movq 0x50(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x30(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x50(%rsp), %rax
movq 0x20(%rax), %rdi
shlq $0x4, %rdi
callq 0x9660
movq %rax, %rcx
movq 0x50(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x30(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x18(%rax)
movq $0x0, 0x38(%rsp)
movq 0x38(%rsp), %rax
movq 0x50(%rsp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x2c400
movq 0x38(%rsp), %rcx
movq 0x50(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x30(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movq 0x18(%rax), %rax
movq 0x38(%rsp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq 0x38(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x38(%rsp)
jmp 0x2c3b6
movq 0x50(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x30(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq $0x0, 0x8(%rax)
movq 0x50(%rsp), %rax
movq 0x20(%rax), %rcx
shlq %rcx
subq $0x1, %rcx
movq 0x50(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x30(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x10(%rax)
movq 0x50(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x30(%rsp), %rcx
movq (%rax,%rcx,8), %rax
imulq $0x38, 0x10(%rax), %rdi
callq 0x9660
movq %rax, %rcx
movq 0x50(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x30(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, (%rax)
movq 0x50(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x30(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl $0x0, 0x20(%rax)
movq 0x50(%rsp), %rax
movq %rax, (%rsp)
movq 0x50(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x30(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x8(%rsp)
movq 0x50(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x30(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2cf70
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rax, %rdx
movq 0x50(%rsp), %rax
movq 0x20(%rax), %r8
xorl %eax, %eax
movl %eax, %ecx
xorl %r9d, %r9d
callq 0x2c630
movq 0x50(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x30(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
addq 0x28(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
jmp 0x2c34f
movq 0x50(%rsp), %rax
movq (%rax), %rdi
shlq $0x4, %rdi
callq 0x9660
movq %rax, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movq 0x30(%rsp), %rax
movq 0x50(%rsp), %rcx
cmpq 0x40(%rcx), %rax
jae 0x2c605
movq 0x20(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq 0x50(%rsp), %rcx
movq (%rcx), %rcx
shlq %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rax
cmpq 0x10(%rsp), %rax
jae 0x2c5d2
movss 0x2d457(%rip), %xmm0    # 0x599e0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
cvtss2sd %xmm0, %xmm0
movq 0x18(%rsp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, 0x18(%rsp)
movsd %xmm0, (%rax)
movss 0x2d429(%rip), %xmm0    # 0x599e0
cvtss2sd %xmm0, %xmm0
movq 0x18(%rsp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, 0x18(%rsp)
movsd %xmm0, (%rax)
jmp 0x2c575
movq 0x50(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x30(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x20(%rsp), %rdx
xorl %eax, %eax
movl %eax, %esi
callq 0x2d000
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
jmp 0x2c53b
movq 0x20(%rsp), %rdi
callq 0x9620
movq 0x28(%rsp), %rcx
movq 0x50(%rsp), %rax
movq %rcx, 0xd8(%rax)
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)