// File: /workspace/github_c_makefile_star2_O0/zpole[P]IICV/vl/kmeans.c
// Function: vl_kmeans_init_centers_plus_plus_f
static void
VL_XCAT(_vl_kmeans_init_centers_plus_plus_, SFX)
(VlKMeans * self,
 TYPE const * data,
 vl_size dimension,
 vl_size numData,
 vl_size numCenters)
{
  vl_uindex x, c ;
  VlRand * rand = vl_get_rand () ;
  TYPE * distances = vl_malloc (sizeof(TYPE) * numData) ;
  TYPE * minDistances = vl_malloc (sizeof(TYPE) * numData) ;
#if (FLT == VL_TYPE_FLOAT)
  VlFloatVectorComparisonFunction distFn = vl_get_vector_comparison_function_f(self->distance) ;
#else
  VlDoubleVectorComparisonFunction distFn = vl_get_vector_comparison_function_d(self->distance) ;
#endif

  self->dimension = dimension ;
  self->numCenters = numCenters ;
  self->centers = vl_malloc (sizeof(TYPE) * dimension * numCenters) ;

  for (x = 0 ; x < numData ; ++x) {
    minDistances[x] = (TYPE) VL_INFINITY_D ;
  }

  /* select the first point at random */
  x = vl_rand_uindex (rand, numData) ;
  c = 0 ;
  while (1) {
    TYPE energy = 0 ;
    TYPE acc = 0 ;
    TYPE thresh = (TYPE) vl_rand_real1 (rand) ;

    memcpy ((TYPE*)self->centers + c * dimension,
            data + x * dimension,
            sizeof(TYPE) * dimension) ;

    c ++ ;
    if (c == numCenters) break ;

    VL_XCAT(vl_eval_vector_comparison_on_all_pairs_, SFX)
    (distances,
     dimension,
     (TYPE*)self->centers + (c - 1) * dimension, 1,
     data, numData,
     distFn) ;

    for (x = 0 ; x < numData ; ++x) {
      minDistances[x] = VL_MIN(minDistances[x], distances[x]) ;
      energy += minDistances[x] ;
    }

    for (x = 0 ; x < numData - 1 ; ++x) {
      acc += minDistances[x] ;
      if (acc >= thresh * energy) break ;
    }
  }

  vl_free(distances) ;
  vl_free(minDistances) ;
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq %rdx, 0x60(%rsp)
movq %rcx, 0x58(%rsp)
movq %r8, 0x50(%rsp)
callq 0x9a20
movq %rax, 0x38(%rsp)
movq 0x58(%rsp), %rdi
shlq $0x2, %rdi
callq 0x9660
movq %rax, 0x30(%rsp)
movq 0x58(%rsp), %rdi
shlq $0x2, %rdi
callq 0x9660
movq %rax, 0x28(%rsp)
movq 0x70(%rsp), %rax
movl 0x30(%rax), %edi
callq 0x9940
movq %rax, 0x20(%rsp)
movq 0x60(%rsp), %rcx
movq 0x70(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x50(%rsp), %rcx
movq 0x70(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x60(%rsp), %rdi
shlq $0x2, %rdi
imulq 0x50(%rsp), %rdi
callq 0x9660
movq %rax, %rcx
movq 0x70(%rsp), %rax
movq %rcx, 0x58(%rax)
movq $0x0, 0x48(%rsp)
movq 0x48(%rsp), %rax
cmpq 0x58(%rsp), %rax
jae 0x2f56b
movsd 0x2a4d8(%rip), %xmm0    # 0x59a20
cvtsd2ss %xmm0, %xmm0
movq 0x28(%rsp), %rax
movq 0x48(%rsp), %rcx
movss %xmm0, (%rax,%rcx,4)
movq 0x48(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x48(%rsp)
jmp 0x2f534
movq 0x38(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x30770
movq %rax, 0x48(%rsp)
movq $0x0, 0x40(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0x1c(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0x18(%rsp)
movq 0x38(%rsp), %rdi
callq 0x30870
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x14(%rsp)
movq 0x70(%rsp), %rax
movq 0x58(%rax), %rdi
movq 0x40(%rsp), %rax
imulq 0x60(%rsp), %rax
shlq $0x2, %rax
addq %rax, %rdi
movq 0x68(%rsp), %rsi
movq 0x48(%rsp), %rax
imulq 0x60(%rsp), %rax
shlq $0x2, %rax
addq %rax, %rsi
movq 0x60(%rsp), %rdx
shlq $0x2, %rdx
callq 0x9640
movq 0x40(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
cmpq 0x50(%rsp), %rax
jne 0x2f60d
jmp 0x2f765
movq 0x30(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x70(%rsp), %rax
movq 0x58(%rax), %rdx
movq 0x40(%rsp), %rax
subq $0x1, %rax
imulq 0x60(%rsp), %rax
shlq $0x2, %rax
addq %rax, %rdx
movq 0x68(%rsp), %r8
movq 0x58(%rsp), %r9
movq 0x20(%rsp), %rax
movl $0x1, %ecx
movq %rax, (%rsp)
callq 0x9c20
movq $0x0, 0x48(%rsp)
movq 0x48(%rsp), %rax
cmpq 0x58(%rsp), %rax
jae 0x2f6fe
movq 0x28(%rsp), %rax
movq 0x48(%rsp), %rcx
movss (%rax,%rcx,4), %xmm1
movq 0x30(%rsp), %rax
movq 0x48(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x2f6a6
movq 0x28(%rsp), %rax
movq 0x48(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, 0x10(%rsp)
jmp 0x2f6bb
movq 0x30(%rsp), %rax
movq 0x48(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, 0x10(%rsp)
movss 0x10(%rsp), %xmm0
movq 0x28(%rsp), %rax
movq 0x48(%rsp), %rcx
movss %xmm0, (%rax,%rcx,4)
movq 0x28(%rsp), %rax
movq 0x48(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
addss 0x1c(%rsp), %xmm0
movss %xmm0, 0x1c(%rsp)
movq 0x48(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x48(%rsp)
jmp 0x2f65c
movq $0x0, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq 0x58(%rsp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x2f760
movq 0x28(%rsp), %rax
movq 0x48(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
addss 0x18(%rsp), %xmm0
movss %xmm0, 0x18(%rsp)
movss 0x18(%rsp), %xmm0
movss 0x14(%rsp), %xmm1
mulss 0x1c(%rsp), %xmm1
ucomiss %xmm1, %xmm0
jb 0x2f74e
jmp 0x2f760
jmp 0x2f750
movq 0x48(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x48(%rsp)
jmp 0x2f707
jmp 0x2f588
movq 0x30(%rsp), %rdi
callq 0x9620
movq 0x28(%rsp), %rdi
callq 0x9620
addq $0x78, %rsp
retq
nop