// File: /workspace/github_c_makefile_star2_O2/zpole[P]IICV/vl/hikmeans.c
// Function: xmeans
static VlHIKMNode *
xmeans (VlHIKMTree *tree,
        vl_uint8 const *data,
        vl_size N, vl_size K, vl_size height)
{
  VlHIKMNode *node = vl_malloc (sizeof(*node)) ;
  vl_uint32 *ids = vl_malloc (sizeof(*ids) * N) ;

  node->filter = vl_ikm_new (tree -> method) ;
  node->children = (height == 1) ? 0 : vl_malloc (sizeof(*node->children) * K) ;

  vl_ikm_set_max_niters (node->filter, tree->max_niters) ;
  vl_ikm_set_verbosity  (node->filter, tree->verb - 1  ) ;
  vl_ikm_init_rand_data (node->filter, data, tree->M, N, K) ;
  vl_ikm_train (node->filter, data, N) ;
  vl_ikm_push (node->filter, ids, data, N) ;

  /* recursively process each child */
  if (height > 1) {
    vl_uindex k ;
    for (k = 0 ; k < K ; ++k) {
      vl_size partition_N ;
      vl_size partition_K ;
      vl_uint8 *partition ;

      partition = vl_hikm_copy_subset
        (data, ids, N, tree->M, (vl_uint32)k, &partition_N) ;

      partition_K = VL_MIN (K, partition_N) ;

      node->children [k] = xmeans
        (tree, partition, partition_N, partition_K, height - 1) ;

      vl_free (partition) ;

      if (tree->verb > (signed)tree->depth - (signed)height) {
        VL_PRINTF("hikmeans: branch at depth %d: %6.1f %% completed\n",
                  tree->depth - height,
                  (double) (k+1) / K * 100) ;
      }
    }
  }

  vl_free (ids) ;
  return node ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, %rbx
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, 0x18(%rsp)
movq %rdi, %r13
pushq $0x10
popq %rdi
callq 0x95e0
movq %rax, %rbp
movq %r15, 0x20(%rsp)
leaq (,%r15,4), %rdi
callq 0x95e0
movq %rax, 0x8(%rsp)
movl 0x20(%r13), %edi
callq 0x9700
movq %rax, (%rbp)
cmpq $0x1, %rbx
jne 0x1358d
xorl %ecx, %ecx
jmp 0x135a1
leaq (,%r14,8), %rdi
callq 0x95e0
movq %rax, %rcx
movq (%rbp), %rax
movq %rcx, 0x8(%rbp)
movq 0x18(%r13), %rsi
movq %rax, %rdi
callq 0x9560
movq (%rbp), %rdi
movl 0x24(%r13), %esi
decl %esi
callq 0x97c0
movq (%rbp), %rdi
movq (%r13), %rdx
movq 0x18(%rsp), %r12
movq %r12, %rsi
movq 0x20(%rsp), %r15
movq %r15, %rcx
movq %r14, %r8
callq 0x9060
movq (%rbp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x9790
movq %rbp, 0x10(%rsp)
movq (%rbp), %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x9070
cmpq $0x2, %rbx
jb 0x13703
movq %r14, %xmm0
punpckldq 0x19b41(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
leaq -0x1(%rbx), %r12
subpd 0x19b45(%rip), %xmm0    # 0x2d170
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, 0x30(%rsp)
xorl %r15d, %r15d
cmpq %r14, %r15
je 0x13703
movq (%r13), %rcx
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x20(%rsp), %rdx
movl %r15d, %r8d
leaq 0x28(%rsp), %r9
callq 0x133a8
movq %rax, %rbp
movq 0x28(%rsp), %rdx
cmpq %r14, %rdx
movq %r14, %rcx
cmovbq %rdx, %rcx
movq %r13, %rdi
movq %rax, %rsi
movq %r12, %r8
callq 0x13535
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq %rax, (%rcx,%r15,8)
movq %rbp, %rdi
callq 0x95b0
movl 0x10(%r13), %eax
subl %ebx, %eax
cmpl %eax, 0x24(%r13)
jle 0x136fb
callq 0x9180
movq %rax, %rcx
movq 0x10(%r13), %rsi
subq %rbx, %rsi
incq %r15
movq %r15, %xmm1
punpckldq 0x19a97(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x19a9f(%rip), %xmm1    # 0x2d170
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd 0x30(%rsp), %xmm0
mulsd 0x19dd5(%rip), %xmm0    # 0x2d4c0
leaq 0x1a21e(%rip), %rdi     # 0x2d910
movb $0x1, %al
callq *%rcx
jmp 0x13640
incq %r15
jmp 0x13640
movq 0x8(%rsp), %rdi
callq 0x95b0
movq 0x10(%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq