// File: /workspace/github_c_makefile_star2_O3/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 0x95b0
movq %rax, 0x38(%rbx)
cmpq $0x0, 0x40(%rbx)
je 0x1d1ec
xorl %r14d, %r14d
xorl %r12d, %r12d
xorl %r15d, %r15d
movl $0x28, %edi
callq 0x95b0
movq 0x38(%rbx), %rcx
movq %rax, (%rcx,%r12,8)
movq 0x20(%rbx), %rdi
shlq $0x4, %rdi
callq 0x95b0
movq 0x38(%rbx), %rcx
movq (%rcx,%r12,8), %rdx
movq %rax, 0x18(%rdx)
movq 0x20(%rbx), %rax
movq (%rcx,%r12,8), %rcx
testq %rax, %rax
movdqa 0x14f44(%rip), %xmm5    # 0x32010
pcmpeqd %xmm6, %xmm6
movdqa 0x14f48(%rip), %xmm7    # 0x32020
je 0x1d16a
movq 0x18(%rcx), %rdx
leaq 0x1(%rax), %rsi
andq $-0x2, %rsi
leaq -0x1(%rax), %rdi
movq %rdi, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
addq $0x10, %rdx
pxor %xmm5, %xmm0
xorl %edi, %edi
movdqa 0x14ef6(%rip), %xmm1    # 0x32000
movdqa %xmm1, %xmm2
pxor %xmm5, %xmm2
movdqa %xmm2, %xmm3
pcmpgtd %xmm0, %xmm3
pcmpeqd %xmm0, %xmm2
pshufd $0xf5, %xmm2, %xmm4     # xmm4 = xmm2[1,1,3,3]
pand %xmm3, %xmm4
pshufd $0xf5, %xmm3, %xmm2     # xmm2 = xmm3[1,1,3,3]
por %xmm4, %xmm2
movd %xmm2, %r8d
notl %r8d
testb $0x1, %r8b
je 0x1d142
movq %rdi, -0x10(%rdx)
pxor %xmm6, %xmm2
pextrw $0x4, %xmm2, %r8d
testb $0x1, %r8b
je 0x1d159
leaq 0x1(%rdi), %r8
movq %r8, (%rdx)
addq $0x2, %rdi
paddq %xmm7, %xmm1
addq $0x20, %rdx
cmpq %rdi, %rsi
jne 0x1d10a
movq %r14, 0x8(%rcx)
leaq -0x1(,%rax,2), %rax
movq %rax, 0x10(%rcx)
imulq $0x38, %rax, %rdi
callq 0x95b0
movq 0x38(%rbx), %rcx
movq (%rcx,%r12,8), %rdx
movq %rax, (%rdx)
movq (%rcx,%r12,8), %rsi
movl $0x0, 0x20(%rsi)
movq (%rsi), %rax
movq 0x8(%rsi), %rdx
leaq 0x1(%rdx), %rcx
movq %rcx, 0x8(%rsi)
imulq $0x38, %rdx, %rcx
movq %r14, 0x20(%rax,%rcx)
pxor %xmm0, %xmm0
movdqu %xmm0, 0xc(%rax,%rcx)
movdqu %xmm0, (%rax,%rcx)
movq 0x20(%rbx), %r8
movq %rbx, %rdi
xorl %ecx, %ecx
xorl %r9d, %r9d
callq 0x1d26d
movq 0x38(%rbx), %rax
movq (%rax,%r12,8), %rax
addq 0x8(%rax), %r15
incq %r12
cmpq 0x40(%rbx), %r12
jb 0x1d08e
jmp 0x1d1ef
xorl %r15d, %r15d
movq (%rbx), %rdi
shlq $0x4, %rdi
callq 0x95b0
movq %rax, %r14
cmpq $0x0, 0x40(%rbx)
je 0x1d252
xorl %r12d, %r12d
movdqa 0x159d0(%rip), %xmm0    # 0x32be0
movq (%rbx), %rax
shlq $0x4, %rax
testq %rax, %rax
jle 0x1d22f
addq %r14, %rax
movq %r14, %rcx
movdqu %xmm0, (%rcx)
addq $0x10, %rcx
cmpq %rax, %rcx
jb 0x1d222
movq 0x38(%rbx), %rax
movq (%rax,%r12,8), %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x1d85e
movdqa 0x15997(%rip), %xmm0    # 0x32be0
incq %r12
cmpq 0x40(%rbx), %r12
jb 0x1d210
movq %r14, %rdi
callq 0x9580
movq %r15, 0xd8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq