// File: /workspace/github_c_makefile_star2_O1/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 0x24243
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 0x24221
decq %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x247a1
movss 0x8(%r14), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
jbe 0x24287
movq 0x38(%r14), %rax
movq (%rax), %rcx
movq 0x20(%r14), %rdx
movq 0x30(%r14), %rsi
movq -0x8(%rax,%rdx,8), %rax
xorps 0xed97(%rip), %xmm0     # 0x33010
movss (%rsi,%rax,4), %xmm1
subss (%rsi,%rcx,4), %xmm1
mulss %xmm1, %xmm0
movl (%r14), %ecx
movl $0x1, %eax
movq %rax, 0x20(%rsp)
cmpl $0x2, %ecx
jl 0x24367
leal 0x2(%rcx), %eax
andl $-0x4, %eax
movd %ecx, %xmm1
addl $-0x2, %ecx
pshufd $0x0, %xmm1, %xmm4      # xmm4 = xmm1[0,0,0,0]
paddd 0xff29(%rip), %xmm4     # 0x341e0
movd %ecx, %xmm1
pshufd $0x0, %xmm1, %xmm1      # xmm1 = xmm1[0,0,0,0]
movdqa 0xff28(%rip), %xmm2     # 0x341f0
movl $0x4, %ecx
movdqa 0xff2b(%rip), %xmm5     # 0x34200
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 0x242d5
negl %ecx
movd %ecx, %xmm4
pshufd $0x0, %xmm4, %xmm4      # xmm4 = xmm4[0,0,0,0]
por 0xfeed(%rip), %xmm4     # 0x34210
movdqa 0xece5(%rip), %xmm5     # 0x33010
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), %rsi
movq %rcx, %rax
xorl %edx, %edx
divq %rsi
movq %rax, 0x28(%rsp)
testl %ecx, %ecx
jle 0x246d9
leaq 0x4(%r15), %rbp
xorps %xmm5, %xmm5
cvtss2sd %xmm0, %xmm5
xorl %ecx, %ecx
movsd 0xeec7(%rip), %xmm7     # 0x33260
movq $0x0, 0x18(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x10(%rsp)
movq $0x0, 0x30(%rsp)
movq %rbx, 0x40(%rsp)
movsd %xmm5, 0x38(%rsp)
movslq 0x10(%rsp), %rax
cmpq %rax, %rcx
movq %rcx, 0x8(%rsp)
jl 0x24409
movslq 0x4(%r14), %rax
decq %rax
movq 0x30(%rsp), %rdx
cmpq %rax, %rdx
jge 0x24409
movq %rdx, %rcx
movq 0x10(%rsp), %rax
addq 0x28(%rsp), %rax
movq %rax, 0x10(%rsp)
incq %rcx
movq %rcx, 0x30(%rsp)
movq 0x18(%rsp), %rax
addq 0x20(%rsp), %rax
movq %rax, 0x18(%rsp)
movslq (%r14), %rdx
testq %rdx, %rdx
jle 0x245bb
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), %xmm1
movsd (%rsi,%r8,8), %xmm0
cvttsd2si %xmm1, %r10
xorps %xmm3, %xmm3
cvtsi2sd %r10, %xmm3
cmpneqpd %xmm1, %xmm3
pxor %xmm2, %xmm2
pxor %xmm4, %xmm4
cmpnlepd %xmm1, %xmm4
andpd %xmm3, %xmm4
movq %xmm4, %r9
cvttsd2si %xmm0, %r11
addq %r10, %r9
xorps %xmm3, %xmm3
cvtsi2sd %r11, %xmm3
cmpneqpd %xmm0, %xmm3
xorpd %xmm4, %xmm4
cmpnlepd %xmm0, %xmm4
andpd %xmm3, %xmm4
movq %xmm4, %r10
addq %r11, %r10
movq 0x18(%r14), %r11
xorpd %xmm3, %xmm3
testq %r9, %r9
js 0x244c5
testq %r10, %r10
js 0x244c5
movslq %r11d, %rbx
imulq %r10, %rbx
leaq (%r15,%r9,4), %r13
xorps %xmm3, %xmm3
cvtss2sd (%r13,%rbx,4), %xmm3
shlq $0x20, %r11
movabsq $-0x100000000, %rbx     # imm = 0xFFFFFFFF00000000
addq %r11, %rbx
sarq $0x20, %rbx
cmpq %rbx, %r9
jge 0x24503
testq %r10, %r10
js 0x24503
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 0x24530
cmpq %rbx, %r10
jge 0x24530
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 0x2455a
cmpq %rbx, %r10
jge 0x2455a
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, %xmm1
xorps %xmm6, %xmm6
cvtsi2sd %r10, %xmm6
subsd %xmm6, %xmm0
movapd %xmm7, %xmm6
subsd %xmm0, %xmm6
subsd %xmm3, %xmm2
mulsd %xmm1, %xmm2
addsd %xmm3, %xmm2
mulsd %xmm6, %xmm2
subsd %xmm5, %xmm4
mulsd %xmm1, %xmm4
addsd %xmm5, %xmm4
mulsd %xmm0, %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 0x24440
decq %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x24846
movslq (%r14), %rax
movl $0x0, %ecx
testq %rax, %rax
movq 0x40(%rsp), %rbx
movsd 0x38(%rsp), %xmm5
movss 0xed66(%rip), %xmm6     # 0x3334c
jle 0x2462b
movq 0x50(%r14), %rdx
xorl %esi, %esi
xorl %ecx, %ecx
movq %rsi, %rdi
movq %rax, %rsi
subq %rdi, %rsi
imulq %rsi, %rcx
addq (%rdx,%rdi,8), %rcx
leaq 0x1(%rdi), %rsi
cmpq %rax, %rsi
jge 0x24626
movq %rsi, %r8
movq (%rdx,%r8,8), %r9
cmpq (%rdx,%rdi,8), %r9
jbe 0x2461e
decq %r9
movq %r9, (%rdx,%r8,8)
incq %r8
cmpq %rax, %r8
jl 0x2460d
cmpq %rax, %rsi
jne 0x245f0
xorps %xmm0, %xmm0
testl %eax, %eax
jle 0x246a9
movq %rax, %rdx
xorl %esi, %esi
xorl %edi, %edi
movsd 0xec1f(%rip), %xmm7     # 0x33260
movq %rdi, %r9
incq %rdi
cmpq %rax, %rdi
jae 0x2469b
movq 0x48(%r14), %r8
xorps %xmm1, %xmm1
cvtss2sd (%r8,%r9,4), %xmm1
movapd %xmm5, %xmm2
addsd %xmm1, %xmm2
addq %rsi, %r8
movl $0x1, %r9d
xorps %xmm4, %xmm4
cvtss2sd (%r8,%r9,4), %xmm4
ucomisd %xmm2, %xmm4
movaps %xmm6, %xmm3
ja 0x2467f
xorps %xmm3, %xmm3
addsd %xmm5, %xmm4
ucomisd %xmm4, %xmm1
movaps %xmm6, %xmm4
ja 0x2468f
movaps %xmm3, %xmm4
addss %xmm4, %xmm0
incq %r9
cmpq %r9, %rdx
jne 0x2466a
addq $0x4, %rsi
decq %rdx
cmpq %rax, %rdi
jne 0x24641
jmp 0x246b1
movsd 0xebaf(%rip), %xmm7     # 0x33260
leaq (%rbx,%rcx,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 0x243c0
movslq 0x10(%r14), %rax
pxor %xmm2, %xmm2
testq %rax, %rax
jle 0x246fd
xorl %ecx, %ecx
movss (%rbx,%rcx,4), %xmm0
mulss %xmm0, %xmm0
addss %xmm0, %xmm2
incq %rcx
cmpq %rcx, %rax
jne 0x246e8
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x24713
sqrtsd %xmm0, %xmm0
jmp 0x24724
movss %xmm2, 0x8(%rsp)
callq 0x9990
movss 0x8(%rsp), %xmm2
ucomisd 0xec94(%rip), %xmm0     # 0x333c0
jbe 0x2473f
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm2
jb 0x24749
xorps %xmm0, %xmm0
sqrtss %xmm2, %xmm0
jmp 0x24751
movss 0xec89(%rip), %xmm0     # 0x333d0
jmp 0x24751
movaps %xmm2, %xmm0
callq 0x95e0
movslq 0x10(%r14), %rax
testq %rax, %rax
jle 0x24772
xorl %ecx, %ecx
movss (%rbx,%rcx,4), %xmm1
divss %xmm0, %xmm1
movss %xmm1, (%rbx,%rcx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x2475c
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq