// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movq %rdx, 0x50(%rsp)
movq %rcx, 0x48(%rsp)
movq %r8, 0x40(%rsp)
movl $0x10, %edi
callq 0x9660
movq %rax, 0x38(%rsp)
movq 0x50(%rsp), %rdi
shlq $0x2, %rdi
callq 0x9660
movq %rax, 0x30(%rsp)
movq 0x60(%rsp), %rax
movl 0x20(%rax), %edi
callq 0x97e0
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq %rcx, (%rax)
cmpq $0x1, 0x40(%rsp)
jne 0x1de88
xorl %eax, %eax
movq %rax, 0x8(%rsp)
jmp 0x1de9b
movq 0x48(%rsp), %rdi
shlq $0x3, %rdi
callq 0x9660
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x38(%rsp), %rax
movq (%rax), %rdi
movq 0x60(%rsp), %rax
movq 0x18(%rax), %rsi
callq 0x95d0
movq 0x38(%rsp), %rax
movq (%rax), %rdi
movq 0x60(%rsp), %rax
movl 0x24(%rax), %esi
subl $0x1, %esi
callq 0x98d0
movq 0x38(%rsp), %rax
movq (%rax), %rdi
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rax
movq (%rax), %rdx
movq 0x50(%rsp), %rcx
movq 0x48(%rsp), %r8
callq 0x9050
movq 0x38(%rsp), %rax
movq (%rax), %rdi
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %rdx
callq 0x98a0
movq 0x38(%rsp), %rax
movq (%rax), %rdi
movq 0x30(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq 0x50(%rsp), %rcx
callq 0x9060
cmpq $0x1, 0x40(%rsp)
jbe 0x1e09a
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x48(%rsp), %rax
jae 0x1e098
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq 0x60(%rsp), %rax
movq (%rax), %rcx
movq 0x28(%rsp), %rax
movl %eax, %r8d
leaq 0x20(%rsp), %r9
callq 0x1dac0
movq %rax, 0x10(%rsp)
movq 0x48(%rsp), %rax
cmpq 0x20(%rsp), %rax
jae 0x1df98
movq 0x48(%rsp), %rax
movq %rax, (%rsp)
jmp 0x1dfa1
movq 0x20(%rsp), %rax
movq %rax, (%rsp)
movq (%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x60(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rcx
movq 0x40(%rsp), %r8
subq $0x1, %r8
callq 0x1de20
movq %rax, %rdx
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x28(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x10(%rsp), %rdi
callq 0x9620
movq 0x60(%rsp), %rax
movl 0x24(%rax), %eax
movq 0x60(%rsp), %rcx
movq 0x10(%rcx), %rcx
movq 0x40(%rsp), %rdx
subl %edx, %ecx
cmpl %ecx, %eax
jle 0x1e083
callq 0x91a0
movq %rax, %rcx
movq 0x60(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x40(%rsp), %rax
subq %rax, %rsi
movq 0x28(%rsp), %rax
incq %rax
movq %rax, %xmm0
movaps 0x3b12c(%rip), %xmm3    # 0x59160
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x3b130(%rip), %xmm2    # 0x59170
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq 0x48(%rsp), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd 0x3b2dc(%rip), %xmm1    # 0x59350
mulsd %xmm1, %xmm0
leaq 0x3b735(%rip), %rdi     # 0x597b4
movb $0x1, %al
callq *%rcx
jmp 0x1e085
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
jmp 0x1df43
jmp 0x1e09a
movq 0x30(%rsp), %rdi
callq 0x9620
movq 0x38(%rsp), %rax
addq $0x68, %rsp
retq
nop