// File: /workspace/github_c_makefile_star2_O1/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, %rbp
movl $0x10, %edi
callq 0x95b0
movq %rax, %r12
movq %r15, 0x20(%rsp)
leaq (,%r15,4), %rdi
callq 0x95b0
movq %rax, 0x8(%rsp)
movl 0x20(%rbp), %edi
callq 0x96b0
movq %r12, 0x10(%rsp)
movq %rax, (%r12)
cmpq $0x1, %rbx
jne 0x14b67
xorl %eax, %eax
jmp 0x14b74
leaq (,%r14,8), %rdi
callq 0x95b0
movq 0x10(%rsp), %r13
movq %rax, 0x8(%r13)
movq (%r13), %rdi
movq 0x18(%rbp), %rsi
callq 0x9530
movq (%r13), %rdi
movl 0x24(%rbp), %esi
decl %esi
callq 0x9760
movq (%r13), %rdi
movq (%rbp), %rdx
movq 0x18(%rsp), %r12
movq %r12, %rsi
movq 0x20(%rsp), %r15
movq %r15, %rcx
movq %r14, %r8
callq 0x9060
movq (%r13), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x9730
movq (%r13), %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x9070
cmpq $0x2, %rbx
setb %al
testq %r14, %r14
sete %cl
orb %al, %cl
jne 0x14cd6
movq %r14, %xmm0
punpckldq 0x1e583(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
leaq -0x1(%rbx), %r12
subpd 0x1e587(%rip), %xmm0    # 0x33190
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, 0x30(%rsp)
xorl %r15d, %r15d
movq (%rbp), %rcx
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x20(%rsp), %rdx
movl %r15d, %r8d
leaq 0x28(%rsp), %r9
callq 0x14958
movq %rax, %r13
movq 0x28(%rsp), %rdx
cmpq %r14, %rdx
movq %r14, %rcx
cmovbq %rdx, %rcx
movq %rbp, %rdi
movq %rax, %rsi
movq %r12, %r8
callq 0x14b09
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq %rax, (%rcx,%r15,8)
movq %r13, %rdi
callq 0x9580
movl 0x10(%rbp), %eax
subl %ebx, %eax
cmpl %eax, 0x24(%rbp)
jle 0x14cca
callq 0x9180
movq %rax, %rcx
movq 0x10(%rbp), %rsi
subq %rbx, %rsi
leaq 0x1(%r15), %rax
movq %rax, %xmm1
punpckldq 0x1e4e3(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x1e4eb(%rip), %xmm1    # 0x33190
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd 0x30(%rsp), %xmm0
mulsd 0x1e841(%rip), %xmm0    # 0x33500
leaq 0x1ec8a(%rip), %rdi     # 0x33950
movb $0x1, %al
callq *%rcx
incq %r15
cmpq %r15, %r14
jne 0x14c1e
movq 0x8(%rsp), %rdi
callq 0x9580
movq 0x10(%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq