// File: /workspace/github_c_makefile_star2_O3/zpole[P]IICV/vl/liop.c
// Function: vl_liopdesc_process
void
vl_liopdesc_process (VlLiopDesc * self, float * desc, float const * patch)
{
  vl_index i,t ;
  vl_index offset,numPermutations ;
  vl_index spatialBinArea, spatialBinEnd, spatialBinIndex ;
  float threshold ;

  memset(desc, 0, sizeof(float) * self->dimension) ;

  /*
   * Sort pixels in the patch by increasing intensity.
   */

  for (i = 0 ; i < (signed)self->patchSize ; ++i) {
    vl_index pixel = self->patchPixels[i] ;
    self->patchIntensities[i] = patch[pixel] ;
    self->patchPermutation[i] = i ;
  }
  patch_sort(self, self->patchSize) ;

  /*
   * Tune the threshold if needed.
   */

  if (self->intensityThreshold < 0) {
    i = self->patchPermutation[0] ;
    t = self->patchPermutation[self->patchSize-1] ;
    threshold = - self->intensityThreshold
    * (self->patchIntensities[t] - self->patchIntensities[i]);
  } else {
    threshold = self->intensityThreshold ;
  }

  /*
   * Process pixels in order of increasing intenisity, dividing them into
   * spatial bins on the fly.
   */

  numPermutations = factorial(self->numNeighbours) ;
  spatialBinArea = self->patchSize / self->numSpatialBins ;
  spatialBinEnd = spatialBinArea ;
  spatialBinIndex = 0 ;
  offset = 0 ;

  for (i = 0 ; i < (signed)self->patchSize ; ++i) {
    vl_index permIndex ;
    double *sx, *sy ;

    /* advance to the next spatial bin if needed */
    if (i >= (signed)spatialBinEnd && spatialBinIndex < (signed)self->numSpatialBins - 1) {
      spatialBinEnd += spatialBinArea ;
      spatialBinIndex ++ ;
      offset += numPermutations ;
    }

    /* get intensities of neighbours of the current patch element and sort them */
    sx = self->neighSamplesX + self->numNeighbours * self->patchPermutation[i] ;
    sy = self->neighSamplesY + self->numNeighbours * self->patchPermutation[i] ;
    for (t = 0 ; t < self->numNeighbours ; ++t) {
      double x = *sx++ ;
      double y = *sy++ ;

      /* bilinear interpolation */
      vl_index ix = vl_floor_d(x) ;
      vl_index iy = vl_floor_d(y) ;

      double wx = x - ix ;
      double wy = y - iy ;

      double a = 0, b = 0, c = 0, d = 0 ;

      int L = (int) self->patchSideLength ;

      if (ix >= 0   && iy >= 0  ) { a = patch[ix   + iy * L] ; }
      if (ix <  L-1 && iy >= 0  ) { b = patch[ix+1 + iy * L] ; }
      if (ix >= 0   && iy <  L-1) { c = patch[ix   + (iy+1) * L] ; }
      if (ix <  L-1 && iy <  L-1) { d = patch[ix+1 + (iy+1) * L] ; }

      self->neighPermutation[t] = t;
      self->neighIntensities[t] = (1 - wy) * (a + (b - a) * wx) + wy * (c + (d - c) * wx) ;
    }
    neigh_sort (self, self->numNeighbours) ;

    /* get permutation index */
    permIndex = get_permutation_index(self->neighPermutation, self->numNeighbours);

    /*
     * Compute weight according to difference in intensity values and
     * accumulate.
     */
    {
      int k, t ;
      float weight = 0 ;
      for(k = 0; k < self->numNeighbours ; ++k) {
        for(t = k + 1; t < self->numNeighbours; ++t){
          double a = self->neighIntensities[k] ;
          double b = self->neighIntensities[t] ;
          weight += (a > b + threshold || b > a + threshold) ;
        }
      }
      desc[permIndex + offset] += weight ;
    }
  }

  /* normalization */
  {
    float norm = 0;
    for(i = 0; i < (signed)self->dimension; i++) {
      norm += desc[i]*desc[i];
    }
    norm = VL_MAX(sqrt(norm), 1e-12) ;
    for(i = 0; i < (signed)self->dimension; i++){
      desc[i] /= norm ;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
movq 0x10(%rdi), %rdx
shlq $0x2, %rdx
movq %rsi, %rdi
xorl %esi, %esi
callq 0x9400
movq 0x20(%r14), %rdx
testl %edx, %edx
jle 0x2430c
movq 0x28(%r14), %rax
movq 0x30(%r14), %rcx
movq 0x38(%r14), %rsi
xorl %edi, %edi
movq (%rax,%rdi,8), %rdx
movss (%r15,%rdx,4), %xmm0
movss %xmm0, (%rcx,%rdi,4)
movq %rdi, (%rsi,%rdi,8)
incq %rdi
movq 0x20(%r14), %rdx
movslq %edx, %r8
cmpq %r8, %rdi
jl 0x242ea
decq %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x24877
movss 0x8(%r14), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
jbe 0x24350
movq 0x38(%r14), %rax
movq (%rax), %rcx
movq 0x20(%r14), %rdx
movq 0x30(%r14), %rsi
movq -0x8(%rax,%rdx,8), %rax
xorps 0xdcce(%rip), %xmm0     # 0x32010
movss (%rsi,%rax,4), %xmm1
subss (%rsi,%rcx,4), %xmm1
mulss %xmm1, %xmm0
movl (%r14), %esi
movl $0x1, %eax
movq %rax, 0x20(%rsp)
cmpl $0x2, %esi
jl 0x24430
leal 0x2(%rsi), %eax
andl $-0x4, %eax
leal -0x2(%rsi), %ecx
movd %esi, %xmm1
pshufd $0x0, %xmm1, %xmm4      # xmm4 = xmm1[0,0,0,0]
paddd 0xee50(%rip), %xmm4     # 0x331d0
movd %ecx, %xmm1
pshufd $0x0, %xmm1, %xmm1      # xmm1 = xmm1[0,0,0,0]
movdqa 0xee4f(%rip), %xmm2     # 0x331e0
movl $0x4, %ecx
movdqa 0xee52(%rip), %xmm5     # 0x331f0
movdqa %xmm2, %xmm3
movdqa %xmm4, %xmm2
pmuludq %xmm3, %xmm2
pshufd $0xe8, %xmm2, %xmm2     # xmm2 = xmm2[0,2,2,3]
pshufd $0xf5, %xmm3, %xmm6     # xmm6 = xmm3[1,1,3,3]
pshufd $0xf5, %xmm4, %xmm7     # xmm7 = xmm4[1,1,3,3]
pmuludq %xmm6, %xmm7
pshufd $0xe8, %xmm7, %xmm6     # xmm6 = xmm7[0,2,2,3]
punpckldq %xmm6, %xmm2    # xmm2 = xmm2[0],xmm6[0],xmm2[1],xmm6[1]
paddd %xmm5, %xmm4
movl %ecx, %edx
addl $-0x4, %ecx
addl %eax, %edx
addl $-0x4, %edx
cmpl $0x4, %edx
jne 0x2439e
negl %ecx
movd %ecx, %xmm4
pshufd $0x0, %xmm4, %xmm4      # xmm4 = xmm4[0,0,0,0]
por 0xee14(%rip), %xmm4     # 0x33200
movdqa 0xdc1c(%rip), %xmm5     # 0x32010
pxor %xmm5, %xmm1
pxor %xmm5, %xmm4
pcmpgtd %xmm1, %xmm4
pand %xmm4, %xmm3
pandn %xmm2, %xmm4
por %xmm3, %xmm4
pshufd $0xee, %xmm4, %xmm1     # xmm1 = xmm4[2,3,2,3]
pshufd $0xff, %xmm4, %xmm2     # xmm2 = xmm4[3,3,3,3]
pshufd $0xf5, %xmm4, %xmm3     # xmm3 = xmm4[1,1,3,3]
pmuludq %xmm2, %xmm3
pmuludq %xmm4, %xmm1
pmuludq %xmm3, %xmm1
movd %xmm1, %eax
movq %rax, 0x20(%rsp)
movq 0x20(%r14), %rcx
movslq 0x4(%r14), %rdi
movq %rcx, %rax
xorl %edx, %edx
divq %rdi
movq %rax, 0x28(%rsp)
testl %ecx, %ecx
jle 0x247af
leaq 0x4(%r15), %rbp
xorps %xmm5, %xmm5
cvtss2sd %xmm0, %xmm5
xorl %ecx, %ecx
movsd 0xde0e(%rip), %xmm7     # 0x32270
movq $0x0, 0x18(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x10(%rsp)
movq $0x0, 0x30(%rsp)
movq %rbx, 0x38(%rsp)
movsd %xmm5, 0x40(%rsp)
movslq 0x10(%rsp), %rax
cmpq %rax, %rcx
movq %rcx, 0x8(%rsp)
jl 0x244cf
movslq 0x4(%r14), %rax
decq %rax
movq 0x30(%rsp), %rdx
cmpq %rax, %rdx
jge 0x244cf
movq 0x10(%rsp), %rax
addq 0x28(%rsp), %rax
movq %rax, 0x10(%rsp)
incq %rdx
movq %rdx, 0x30(%rsp)
movq 0x18(%rsp), %rax
addq 0x20(%rsp), %rax
movq %rax, 0x18(%rsp)
movslq %esi, %rdx
testl %edx, %edx
jle 0x24684
movq 0x38(%r14), %rcx
movq 0x48(%r14), %rax
movq 0x8(%rsp), %rsi
movq (%rcx,%rsi,8), %rcx
imulq %rdx, %rcx
shlq $0x3, %rcx
movq 0x60(%r14), %rsi
addq %rcx, %rsi
addq 0x58(%r14), %rcx
movq 0x50(%r14), %rdi
xorl %r8d, %r8d
movsd (%rcx,%r8,8), %xmm0
cvttsd2si %xmm0, %r10
movsd (%rsi,%r8,8), %xmm1
xorps %xmm3, %xmm3
cvtsi2sd %r10, %xmm3
cmpneqpd %xmm0, %xmm3
pxor %xmm2, %xmm2
pxor %xmm4, %xmm4
cmpnlepd %xmm0, %xmm4
andpd %xmm3, %xmm4
movq %xmm4, %r9
addq %r10, %r9
cvttsd2si %xmm1, %r11
xorps %xmm3, %xmm3
cvtsi2sd %r11, %xmm3
cmpneqpd %xmm1, %xmm3
xorpd %xmm4, %xmm4
cmpnlepd %xmm1, %xmm4
andpd %xmm3, %xmm4
movq %xmm4, %r10
addq %r11, %r10
movq 0x18(%r14), %r11
shlq $0x20, %r11
xorpd %xmm3, %xmm3
testq %r9, %r9
js 0x24592
testq %r10, %r10
js 0x24592
movq %r11, %rbx
sarq $0x20, %rbx
imulq %r10, %rbx
leaq (%r15,%r9,4), %r13
xorps %xmm3, %xmm3
cvtss2sd (%r13,%rbx,4), %xmm3
movabsq $-0x100000000, %rbx     # imm = 0xFFFFFFFF00000000
addq %r11, %rbx
sarq $0x20, %rbx
cmpq %rbx, %r9
jge 0x245cc
testq %r10, %r10
js 0x245cc
movq %r11, %r13
sarq $0x20, %r13
imulq %r10, %r13
leaq (,%r9,4), %r12
addq %rbp, %r12
xorps %xmm2, %xmm2
cvtss2sd (%r12,%r13,4), %xmm2
xorpd %xmm4, %xmm4
xorps %xmm5, %xmm5
testq %r9, %r9
js 0x245f9
cmpq %rbx, %r10
jge 0x245f9
leaq 0x1(%r10), %r12
movq %r11, %r13
sarq $0x20, %r13
imulq %r12, %r13
leaq (%r15,%r9,4), %r12
xorps %xmm5, %xmm5
cvtss2sd (%r12,%r13,4), %xmm5
cmpq %rbx, %r9
jge 0x24623
cmpq %rbx, %r10
jge 0x24623
leaq 0x1(%r10), %rbx
sarq $0x20, %r11
imulq %rbx, %r11
leaq (,%r9,4), %rbx
addq %rbp, %rbx
xorps %xmm4, %xmm4
cvtss2sd (%rbx,%r11,4), %xmm4
xorps %xmm6, %xmm6
cvtsi2sd %r9, %xmm6
subsd %xmm6, %xmm0
xorps %xmm6, %xmm6
cvtsi2sd %r10, %xmm6
subsd %xmm6, %xmm1
movapd %xmm7, %xmm6
subsd %xmm1, %xmm6
subsd %xmm3, %xmm2
mulsd %xmm0, %xmm2
addsd %xmm3, %xmm2
mulsd %xmm6, %xmm2
subsd %xmm5, %xmm4
mulsd %xmm0, %xmm4
addsd %xmm5, %xmm4
mulsd %xmm1, %xmm4
addsd %xmm2, %xmm4
xorps %xmm0, %xmm0
cvtsd2ss %xmm4, %xmm0
movq %r8, (%rdi,%r8,8)
movss %xmm0, (%rax,%r8,4)
incq %r8
cmpq %r8, %rdx
jne 0x24505
decq %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x2492a
movslq (%r14), %rsi
xorps %xmm0, %xmm0
testq %rsi, %rsi
jle 0x24778
movq 0x50(%r14), %rcx
xorl %edx, %edx
xorl %eax, %eax
movq 0x38(%rsp), %rbx
movsd 0x40(%rsp), %xmm5
movsd 0xdbb5(%rip), %xmm7     # 0x32270
movss 0xdc99(%rip), %xmm6     # 0x3235c
movq %rdx, %rdi
movq %rsi, %rdx
subq %rdi, %rdx
imulq %rdx, %rax
addq (%rcx,%rdi,8), %rax
leaq 0x1(%rdi), %rdx
cmpq %rsi, %rdx
jge 0x246f9
movq %rdx, %r8
movq (%rcx,%r8,8), %r9
cmpq (%rcx,%rdi,8), %r9
jbe 0x246f1
decq %r9
movq %r9, (%rcx,%r8,8)
incq %r8
cmpq %rsi, %r8
jl 0x246e0
cmpq %rsi, %rdx
jne 0x246c3
testl %esi, %esi
jle 0x24787
xorps %xmm0, %xmm0
movq %rsi, %rcx
xorl %edx, %edx
xorl %edi, %edi
movq %rdi, %r9
incq %rdi
cmpq %rsi, %rdi
jge 0x2476a
movq 0x48(%r14), %r8
xorps %xmm1, %xmm1
cvtss2sd (%r8,%r9,4), %xmm1
movapd %xmm5, %xmm2
addsd %xmm1, %xmm2
addq %rdx, %r8
movl $0x1, %r9d
xorps %xmm4, %xmm4
cvtss2sd (%r8,%r9,4), %xmm4
ucomisd %xmm2, %xmm4
movaps %xmm6, %xmm3
ja 0x2474e
xorps %xmm3, %xmm3
addsd %xmm5, %xmm4
ucomisd %xmm4, %xmm1
movaps %xmm6, %xmm4
ja 0x2475e
movaps %xmm3, %xmm4
addss %xmm4, %xmm0
incq %r9
cmpq %r9, %rcx
jne 0x24739
addq $0x4, %rdx
decq %rcx
cmpq %rsi, %rdi
jne 0x24710
jmp 0x24787
xorl %eax, %eax
movq 0x38(%rsp), %rbx
movsd 0xdae9(%rip), %xmm7     # 0x32270
leaq (%rbx,%rax,4), %rax
movq 0x18(%rsp), %rcx
addss (%rax,%rcx,4), %xmm0
movss %xmm0, (%rax,%rcx,4)
movq 0x8(%rsp), %rcx
incq %rcx
movslq 0x20(%r14), %rax
cmpq %rax, %rcx
jl 0x24489
movslq 0x10(%r14), %rax
pxor %xmm2, %xmm2
testq %rax, %rax
jle 0x247d3
xorl %ecx, %ecx
movss (%rbx,%rcx,4), %xmm0
mulss %xmm0, %xmm0
addss %xmm0, %xmm2
incq %rcx
cmpq %rcx, %rax
jne 0x247be
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x247e9
sqrtsd %xmm0, %xmm0
jmp 0x247fa
movss %xmm2, 0x8(%rsp)
callq 0x9990
movss 0x8(%rsp), %xmm2
ucomisd 0xdbce(%rip), %xmm0     # 0x323d0
jbe 0x24815
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm2
jb 0x2481f
xorps %xmm0, %xmm0
sqrtss %xmm2, %xmm0
jmp 0x24827
movss 0xdbc3(%rip), %xmm0     # 0x323e0
jmp 0x24827
movaps %xmm2, %xmm0
callq 0x95e0
movslq 0x10(%r14), %rax
testq %rax, %rax
jle 0x24848
xorl %ecx, %ecx
movss (%rbx,%rcx,4), %xmm1
divss %xmm0, %xmm1
movss %xmm1, (%rbx,%rcx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x24832
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq