// File: /workspace/github_c_makefile_star2_O0/zpole[P]IICV/vl/vlad.c
// Function: vl_vlad_encode_f
static void
VL_XCAT(_vl_vlad_encode_, SFX)
(TYPE * enc,
 TYPE const * means, vl_size dimension, vl_size numClusters,
 TYPE const * data, vl_size numData,
 TYPE const * assignments,
 int flags)
{
  vl_uindex dim ;
  vl_index i_cl, i_d ;

  memset(enc, 0, sizeof(TYPE) * dimension * numClusters) ;

#if defined(_OPENMP)
#pragma omp parallel for default(shared) private(i_cl,i_d,dim) num_threads(vl_get_max_threads())
#endif
  for (i_cl = 0; i_cl < (signed)numClusters; i_cl++) {
    double clusterMass = 0 ;
    for (i_d = 0; i_d < (signed)numData; i_d++) {
      if (assignments[i_d*numClusters + i_cl] > 0) {
        double q = assignments[i_d*numClusters+i_cl] ;
        clusterMass +=  q ;
        for(dim = 0; dim < dimension; dim++) {
          enc [i_cl * dimension + dim] += q * data [i_d  * dimension + dim] ;
        }
      }
    }

    if (clusterMass > 0) {
      if (flags & VL_VLAD_FLAG_NORMALIZE_MASS) {
        for(dim = 0; dim < dimension; dim++) {
          enc[i_cl*dimension + dim] /= clusterMass ;
          enc[i_cl*dimension + dim] -= means[i_cl*dimension+dim];
        }
      } else {
        for(dim = 0; dim < dimension; dim++) {
          enc[i_cl*dimension + dim] -= clusterMass * means[i_cl*dimension+dim];
        }
      }
    }

    if (flags & VL_VLAD_FLAG_SQUARE_ROOT) {
      for(dim = 0; dim < dimension; dim++) {
        TYPE z = enc[i_cl*dimension + dim] ;
        if (z >= 0) {
          enc[i_cl*dimension + dim] = VL_XCAT(vl_sqrt_, SFX)(z) ;
        } else {
          enc[i_cl*dimension + dim] = - VL_XCAT(vl_sqrt_, SFX)(- z) ;
        }
      }
    }

    if (flags & VL_VLAD_FLAG_NORMALIZE_COMPONENTS) {
      TYPE n = 0 ;
      dim = 0 ;
      for(dim = 0; dim < dimension; dim++) {
        TYPE z = enc[i_cl*dimension + dim] ;
        n += z * z ;
      }
      n = VL_XCAT(vl_sqrt_, SFX)(n) ;
      n = VL_MAX(n, 1e-12) ;
      for(dim = 0; dim < dimension; dim++) {
        enc[i_cl*dimension + dim] /= n ;
      }
    }
  }

  if (! (flags & VL_VLAD_FLAG_UNNORMALIZED)) {
    TYPE n = 0 ;
    for(dim = 0 ; dim < dimension * numClusters ; dim++) {
      TYPE z = enc [dim] ;
      n += z * z ;
    }
    n = VL_XCAT(vl_sqrt_, SFX)(n) ;
    n = VL_MAX(n, 1e-12) ;
    for(dim = 0 ; dim < dimension * numClusters ; dim++) {
      enc[dim] /= n ;
    }
  }
}

// Assembly:
subq $0x88, %rsp
movl 0x98(%rsp), %eax
movq 0x90(%rsp), %rax
movq %rdi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movq %rdx, 0x70(%rsp)
movq %rcx, 0x68(%rsp)
movq %r8, 0x60(%rsp)
movq %r9, 0x58(%rsp)
movq 0x80(%rsp), %rdi
movq 0x70(%rsp), %rdx
shlq $0x2, %rdx
imulq 0x68(%rsp), %rdx
xorl %esi, %esi
callq 0x9480
movq $0x0, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq 0x68(%rsp), %rcx
movslq %ecx, %rcx
cmpq %rcx, %rax
jge 0x58508
xorps %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
movq $0x0, 0x40(%rsp)
movq 0x40(%rsp), %rax
movq 0x58(%rsp), %rcx
movslq %ecx, %rcx
cmpq %rcx, %rax
jge 0x58170
movq 0x90(%rsp), %rax
movq 0x40(%rsp), %rcx
imulq 0x68(%rsp), %rcx
addq 0x48(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x5815b
movq 0x90(%rsp), %rax
movq 0x40(%rsp), %rcx
imulq 0x68(%rsp), %rcx
addq 0x48(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x30(%rsp), %xmm0
addsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movq $0x0, 0x50(%rsp)
movq 0x50(%rsp), %rax
cmpq 0x70(%rsp), %rax
jae 0x58159
movsd 0x30(%rsp), %xmm0
movq 0x60(%rsp), %rax
movq 0x40(%rsp), %rcx
imulq 0x70(%rsp), %rcx
addq 0x50(%rsp), %rcx
movss (%rax,%rcx,4), %xmm1
cvtss2sd %xmm1, %xmm2
movq 0x80(%rsp), %rax
movq 0x48(%rsp), %rcx
imulq 0x70(%rsp), %rcx
addq 0x50(%rsp), %rcx
movss (%rax,%rcx,4), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
movq 0x50(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x50(%rsp)
jmp 0x580e7
jmp 0x5815b
jmp 0x5815d
movq 0x40(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x40(%rsp)
jmp 0x58066
movsd 0x38(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x582d8
movl 0x98(%rsp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x5823b
movq $0x0, 0x50(%rsp)
movq 0x50(%rsp), %rax
cmpq 0x70(%rsp), %rax
jae 0x58236
movsd 0x38(%rsp), %xmm1
movq 0x80(%rsp), %rax
movq 0x48(%rsp), %rcx
imulq 0x70(%rsp), %rcx
addq 0x50(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
movq 0x78(%rsp), %rax
movq 0x48(%rsp), %rcx
imulq 0x70(%rsp), %rcx
addq 0x50(%rsp), %rcx
movss (%rax,%rcx,4), %xmm1
movq 0x80(%rsp), %rax
movq 0x48(%rsp), %rcx
imulq 0x70(%rsp), %rcx
addq 0x50(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
subss %xmm1, %xmm0
movss %xmm0, (%rax,%rcx,4)
movq 0x50(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x50(%rsp)
jmp 0x5819f
jmp 0x582d6
movq $0x0, 0x50(%rsp)
movq 0x50(%rsp), %rax
cmpq 0x70(%rsp), %rax
jae 0x582d4
movsd 0x38(%rsp), %xmm0
movq 0x78(%rsp), %rax
movq 0x48(%rsp), %rcx
imulq 0x70(%rsp), %rcx
addq 0x50(%rsp), %rcx
movss (%rax,%rcx,4), %xmm1
cvtss2sd %xmm1, %xmm2
movq 0x80(%rsp), %rax
movq 0x48(%rsp), %rcx
imulq 0x70(%rsp), %rcx
addq 0x50(%rsp), %rcx
movss (%rax,%rcx,4), %xmm1
cvtss2sd %xmm1, %xmm1
movq %xmm0, %rdx
movabsq $-0x8000000000000000, %rsi # imm = 0x8000000000000000
xorq %rsi, %rdx
movq %rdx, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
movq 0x50(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x50(%rsp)
jmp 0x58244
jmp 0x582d6
jmp 0x582d8
movl 0x98(%rsp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x583b8
movq $0x0, 0x50(%rsp)
movq 0x50(%rsp), %rax
cmpq 0x70(%rsp), %rax
jae 0x583b6
movq 0x80(%rsp), %rax
movq 0x48(%rsp), %rcx
imulq 0x70(%rsp), %rcx
addq 0x50(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, 0x2c(%rsp)
movss 0x2c(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x5835f
movss 0x2c(%rsp), %xmm0
callq 0x58cc0
movq 0x80(%rsp), %rax
movq 0x48(%rsp), %rcx
imulq 0x70(%rsp), %rcx
addq 0x50(%rsp), %rcx
movss %xmm0, (%rax,%rcx,4)
jmp 0x583a1
movss 0x2c(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
callq 0x58cc0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movq 0x80(%rsp), %rax
movq 0x48(%rsp), %rcx
imulq 0x70(%rsp), %rcx
addq 0x50(%rsp), %rcx
movss %xmm0, (%rax,%rcx,4)
jmp 0x583a3
movq 0x50(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x50(%rsp)
jmp 0x582f4
jmp 0x583b8
movl 0x98(%rsp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x584f3
xorps %xmm0, %xmm0
movss %xmm0, 0x28(%rsp)
movq $0x0, 0x50(%rsp)
movq $0x0, 0x50(%rsp)
movq 0x50(%rsp), %rax
cmpq 0x70(%rsp), %rax
jae 0x58445
movq 0x80(%rsp), %rax
movq 0x48(%rsp), %rcx
imulq 0x70(%rsp), %rcx
addq 0x50(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, 0x24(%rsp)
movss 0x24(%rsp), %xmm0
movss 0x24(%rsp), %xmm2
movss 0x28(%rsp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x28(%rsp)
movq 0x50(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x50(%rsp)
jmp 0x583e6
movss 0x28(%rsp), %xmm0
callq 0x58cc0
movss %xmm0, 0x28(%rsp)
movss 0x28(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0xdd8(%rip), %xmm1      # 0x59240
ucomisd %xmm1, %xmm0
jbe 0x58480
movss 0x28(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
jmp 0x58490
movsd 0xdb8(%rip), %xmm0      # 0x59240
movsd %xmm0, 0x10(%rsp)
jmp 0x58490
movsd 0x10(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x28(%rsp)
movq $0x0, 0x50(%rsp)
movq 0x50(%rsp), %rax
cmpq 0x70(%rsp), %rax
jae 0x584f1
movss 0x28(%rsp), %xmm1
movq 0x80(%rsp), %rax
movq 0x48(%rsp), %rcx
imulq 0x70(%rsp), %rcx
addq 0x50(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
divss %xmm1, %xmm0
movss %xmm0, (%rax,%rcx,4)
movq 0x50(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x50(%rsp)
jmp 0x584a9
jmp 0x584f3
jmp 0x584f5
movq 0x48(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x48(%rsp)
jmp 0x5803e
movl 0x98(%rsp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x58636
xorps %xmm0, %xmm0
movss %xmm0, 0x20(%rsp)
movq $0x0, 0x50(%rsp)
movq 0x50(%rsp), %rax
movq 0x70(%rsp), %rcx
imulq 0x68(%rsp), %rcx
cmpq %rcx, %rax
jae 0x5858a
movq 0x80(%rsp), %rax
movq 0x50(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, 0x1c(%rsp)
movss 0x1c(%rsp), %xmm0
movss 0x1c(%rsp), %xmm2
movss 0x20(%rsp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x20(%rsp)
movq 0x50(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x50(%rsp)
jmp 0x5852d
movss 0x20(%rsp), %xmm0
callq 0x58cc0
movss %xmm0, 0x20(%rsp)
movss 0x20(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0xc93(%rip), %xmm1      # 0x59240
ucomisd %xmm1, %xmm0
jbe 0x585c5
movss 0x20(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
jmp 0x585d5
movsd 0xc73(%rip), %xmm0      # 0x59240
movsd %xmm0, 0x8(%rsp)
jmp 0x585d5
movsd 0x8(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x20(%rsp)
movq $0x0, 0x50(%rsp)
movq 0x50(%rsp), %rax
movq 0x70(%rsp), %rcx
imulq 0x68(%rsp), %rcx
cmpq %rcx, %rax
jae 0x58634
movss 0x20(%rsp), %xmm1
movq 0x80(%rsp), %rax
movq 0x50(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
divss %xmm1, %xmm0
movss %xmm0, (%rax,%rcx,4)
movq 0x50(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x50(%rsp)
jmp 0x585ee
jmp 0x58636
addq $0x88, %rsp
retq
nop