// File: /workspace/github_c_makefile_star2_O2/zpole[P]IICV/vl/sift.c
// Function: vl_sift_calc_raw_descriptor
VL_EXPORT
void
vl_sift_calc_raw_descriptor (VlSiftFilt const *f,
                             vl_sift_pix const* grad,
                             vl_sift_pix *descr,
                             int width, int height,
                             double x, double y,
                             double sigma,
                             double angle0)
{
  double const magnif = f-> magnif ;

  int          w      = width ;
  int          h      = height ;
  int const    xo     = 2 ;         /* x-stride */
  int const    yo     = 2 * w ;     /* y-stride */

  int          xi     = (int) (x + 0.5) ;
  int          yi     = (int) (y + 0.5) ;

  double const st0    = sin (angle0) ;
  double const ct0    = cos (angle0) ;
  double const SBP    = magnif * sigma + VL_EPSILON_D ;
  int    const W      = floor
    (sqrt(2.0) * SBP * (NBP + 1) / 2.0 + 0.5) ;

  int const binto = 1 ;          /* bin theta-stride */
  int const binyo = NBO * NBP ;  /* bin y-stride */
  int const binxo = NBO ;        /* bin x-stride */

  int bin, dxi, dyi ;
  vl_sift_pix const *pt ;
  vl_sift_pix       *dpt ;

  /* check bounds */
  if(xi    <  0               ||
     xi    >= w               ||
     yi    <  0               ||
     yi    >= h -    1        )
    return ;

  /* clear descriptor */
  memset (descr, 0, sizeof(vl_sift_pix) * NBO*NBP*NBP) ;

  /* Center the scale space and the descriptor on the current keypoint.
   * Note that dpt is pointing to the bin of center (SBP/2,SBP/2,0).
   */
  pt  = grad + xi*xo + yi*yo ;
  dpt = descr + (NBP/2) * binyo + (NBP/2) * binxo ;

#undef atd
#define atd(dbinx,dbiny,dbint) *(dpt + (dbint)*binto + (dbiny)*binyo + (dbinx)*binxo)

  /*
   * Process pixels in the intersection of the image rectangle
   * (1,1)-(M-1,N-1) and the keypoint bounding box.
   */
  for(dyi =  VL_MAX(- W,   - yi   ) ;
      dyi <= VL_MIN(+ W, h - yi -1) ; ++ dyi) {

    for(dxi =  VL_MAX(- W,   - xi   ) ;
        dxi <= VL_MIN(+ W, w - xi -1) ; ++ dxi) {

      /* retrieve */
      vl_sift_pix mod   = *( pt + dxi*xo + dyi*yo + 0 ) ;
      vl_sift_pix angle = *( pt + dxi*xo + dyi*yo + 1 ) ;
      vl_sift_pix theta = vl_mod_2pi_f (angle - angle0) ;

      /* fractional displacement */
      vl_sift_pix dx = xi + dxi - x;
      vl_sift_pix dy = yi + dyi - y;

      /* get the displacement normalized w.r.t. the keypoint
         orientation and extension */
      vl_sift_pix nx = ( ct0 * dx + st0 * dy) / SBP ;
      vl_sift_pix ny = (-st0 * dx + ct0 * dy) / SBP ;
      vl_sift_pix nt = NBO * theta / (2 * VL_PI) ;

      /* Get the Gaussian weight of the sample. The Gaussian window
       * has a standard deviation equal to NBP/2. Note that dx and dy
       * are in the normalized frame, so that -NBP/2 <= dx <=
       * NBP/2. */
      vl_sift_pix const wsigma = f->windowSize ;
      vl_sift_pix win = fast_expn
        ((nx*nx + ny*ny)/(2.0 * wsigma * wsigma)) ;

      /* The sample will be distributed in 8 adjacent bins.
         We start from the ``lower-left'' bin. */
      int         binx = (int)vl_floor_f (nx - 0.5) ;
      int         biny = (int)vl_floor_f (ny - 0.5) ;
      int         bint = (int)vl_floor_f (nt) ;
      vl_sift_pix rbinx = nx - (binx + 0.5) ;
      vl_sift_pix rbiny = ny - (biny + 0.5) ;
      vl_sift_pix rbint = nt - bint ;
      int         dbinx ;
      int         dbiny ;
      int         dbint ;

      /* Distribute the current sample into the 8 adjacent bins*/
      for(dbinx = 0 ; dbinx < 2 ; ++dbinx) {
        for(dbiny = 0 ; dbiny < 2 ; ++dbiny) {
          for(dbint = 0 ; dbint < 2 ; ++dbint) {

            if (binx + dbinx >= - (NBP/2) &&
                binx + dbinx <    (NBP/2) &&
                biny + dbiny >= - (NBP/2) &&
                biny + dbiny <    (NBP/2) ) {
              vl_sift_pix weight = win
                * mod
                * vl_abs_f (1 - dbinx - rbinx)
                * vl_abs_f (1 - dbiny - rbiny)
                * vl_abs_f (1 - dbint - rbint) ;

              atd(binx+dbinx, biny+dbiny, (bint+dbint) % NBO) += weight ;
            }
          }
        }
      }
    }
  }

  /* Standard SIFT descriptors are normalized, truncated and normalized again */
  if(1) {

    /* normalize L2 norm */
    vl_sift_pix norm = normalize_histogram (descr, descr + NBO*NBP*NBP) ;

    /*
       Set the descriptor to zero if it is lower than our
       norm_threshold.  We divide by the number of samples in the
       descriptor region because the Gaussian window used in the
       calculation of the descriptor is not normalized.
     */
    int numSamples =
      (VL_MIN(W, w - xi -1) - VL_MAX(-W, - xi) + 1) *
      (VL_MIN(W, h - yi -1) - VL_MAX(-W, - yi) + 1) ;

    if(f-> norm_thresh && norm < f-> norm_thresh * numSamples) {
        for(bin = 0; bin < NBO*NBP*NBP ; ++ bin)
            descr [bin] = 0;
    }
    else {
      /* truncate at 0.2. */
      for(bin = 0; bin < NBO*NBP*NBP ; ++ bin) {
        if (descr [bin] > 0.2) descr [bin] = 0.2;
      }

      /* normalize again. */
      normalize_histogram (descr, descr + NBO*NBP*NBP) ;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movsd %xmm3, 0x48(%rsp)
movsd %xmm1, 0x8(%rsp)
movl %r8d, %r13d
movl %ecx, %r12d
movq %rdx, %rbx
movq %rsi, %r14
movsd %xmm0, 0xc8(%rsp)
addsd 0x4865(%rip), %xmm0     # 0x2d1c0
cvttsd2si %xmm0, %r15d
movq %rdi, 0x40(%rsp)
mulsd 0xa0(%rdi), %xmm2
movapd %xmm2, 0x20(%rsp)
movaps %xmm3, %xmm0
callq 0x98d0
movaps %xmm0, 0x50(%rsp)
movsd 0x48(%rsp), %xmm0
callq 0x9470
movaps %xmm0, 0x60(%rsp)
movapd 0x20(%rsp), %xmm1
addsd 0x51fa(%rip), %xmm1     # 0x2db98
movsd 0x599a(%rip), %xmm0     # 0x2e340
movapd %xmm1, 0x20(%rsp)
mulsd %xmm1, %xmm0
mulsd 0x4888(%rip), %xmm0     # 0x2d240
movsd 0x4800(%rip), %xmm1     # 0x2d1c0
mulsd %xmm1, %xmm0
addsd %xmm1, %xmm0
callq 0x98f0
testl %r15d, %r15d
js 0x28ebd
movsd 0x8(%rsp), %xmm1
addsd 0x47dc(%rip), %xmm1     # 0x2d1c0
cvttsd2si %xmm1, %esi
cmpl %r12d, %r15d
setl %al
testl %esi, %esi
setns %cl
leal -0x1(%r13), %edx
cmpl %esi, %edx
setg %dl
andb %cl, %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x28ebd
movq %r14, 0x10(%rsp)
movq %rbx, %r14
leal (%r12,%r12), %ebx
cvttsd2si %xmm0, %ebp
movl $0x200, %edx            # imm = 0x200
movq %r14, %rdi
movq %rsi, 0x38(%rsp)
xorl %esi, %esi
callq 0x9420
movq 0x38(%rsp), %rdx
leal (%r15,%r15), %eax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
movl %ebx, %ecx
imull %edx, %ecx
movslq %ecx, %rcx
leaq (%rax,%rcx,4), %rax
movq %rax, 0xa8(%rsp)
movq %r14, 0x90(%rsp)
leaq 0x140(%r14), %rax
movq %rax, 0x10(%rsp)
cmpl %edx, %ebp
movl %edx, %eax
cmovll %ebp, %eax
movq %rax, 0x88(%rsp)
negl %eax
movl %edx, %esi
notl %esi
addl %r13d, %esi
cmpl %ebp, %esi
cmovgel %ebp, %esi
cmpl %r15d, %ebp
movl %r15d, %ecx
cmovll %ebp, %ecx
movq %rcx, 0x78(%rsp)
negl %ecx
movq %r15, 0xc0(%rsp)
notl %r15d
addl %r12d, %r15d
cmpl %ebp, %r15d
cmovgel %ebp, %r15d
movaps 0x60(%rsp), %xmm2
movaps %xmm2, %xmm0
movaps 0x50(%rsp), %xmm1
movlhps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
movaps %xmm0, 0xe0(%rsp)
xorps 0x45d8(%rip), %xmm1     # 0x2d0a0
movslq %ecx, %rcx
movq %rcx, 0xa0(%rsp)
movq %r15, 0x70(%rsp)
movslq %r15d, %rcx
movq %rcx, 0xd8(%rsp)
movslq %eax, %rcx
movq %rsi, 0x80(%rsp)
movslq %esi, %rax
movq %rax, 0xb0(%rsp)
movslq %ebx, %rax
movq %rax, 0x98(%rsp)
movapd 0x20(%rsp), %xmm0
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
movapd %xmm0, 0x20(%rsp)
movlhps %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0]
movaps %xmm1, 0x50(%rsp)
pushq $0x1
popq %r15
pushq $0x8
popq %rbx
movsd 0x8(%rsp), %xmm1
cmpq 0xb0(%rsp), %rcx
jg 0x28e41
movq %rcx, %rax
imulq 0x98(%rsp), %rax
movq %rcx, 0xb8(%rsp)
addl %edx, %ecx
cvtsi2sd %ecx, %xmm0
movq 0xa8(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
movq %rax, 0xd0(%rsp)
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
movlhps %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd 0xe0(%rsp), %xmm0
movapd %xmm0, 0xf0(%rsp)
movq 0xa0(%rsp), %rcx
cmpq 0xd8(%rsp), %rcx
jg 0x28e31
movq 0xd0(%rsp), %rax
cvtss2sd 0x4(%rax,%rcx,8), %xmm0
movss (%rax,%rcx,8), %xmm1
movss %xmm1, 0x1c(%rsp)
subsd 0x48(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movq %rcx, %r14
callq 0x28f11
movq 0xc0(%rsp), %rax
movq %r14, 0x60(%rsp)
addl %r14d, %eax
cvtsi2sd %eax, %xmm1
subsd 0xc8(%rsp), %xmm1
cvtsd2ss %xmm1, %xmm1
mulss 0x5780(%rip), %xmm0     # 0x2e370
cvtss2sd %xmm0, %xmm0
divsd 0x4784(%rip), %xmm0     # 0x2d380
cvtsd2ss %xmm0, %xmm0
movaps %xmm0, 0x120(%rsp)
movq 0x40(%rsp), %rax
cvtsd2ss 0xa8(%rax), %xmm0
cvtss2sd %xmm1, %xmm1
cvtss2sd %xmm0, %xmm0
movaps %xmm0, %xmm2
addsd %xmm0, %xmm2
mulsd %xmm0, %xmm2
movlhps %xmm1, %xmm1            # xmm1 = xmm1[0,0]
mulpd 0x50(%rsp), %xmm1
addpd 0xf0(%rsp), %xmm1
divpd 0x20(%rsp), %xmm1
cvtpd2ps %xmm1, %xmm1
movapd %xmm1, 0x100(%rsp)
movapd %xmm1, %xmm0
mulss %xmm1, %xmm0
movaps %xmm1, %xmm3
shufps $0x55, %xmm1, %xmm3     # xmm3 = xmm3[1,1],xmm1[1,1]
movaps %xmm3, 0x110(%rsp)
movaps %xmm3, %xmm1
mulss %xmm3, %xmm1
addss %xmm0, %xmm1
cvtss2sd %xmm1, %xmm0
divsd %xmm2, %xmm0
callq 0x288a4
movaps 0x44cd(%rip), %xmm7     # 0x2d150
cvtsd2ss %xmm0, %xmm0
movaps 0x100(%rsp), %xmm5
movaps %xmm5, %xmm1
addps 0x56c7(%rip), %xmm1     # 0x2e360
movaps %xmm1, %xmm2
shufps $0x55, %xmm1, %xmm2     # xmm2 = xmm2[1,1],xmm1[1,1]
cvttss2si %xmm2, %rax
cvtsi2ss %rax, %xmm3
mulss 0x1c(%rsp), %xmm0
xorps %xmm4, %xmm4
ucomiss %xmm3, %xmm2
cmpnleps %xmm1, %xmm4
setp %cl
setne %dl
orb %cl, %dl
unpcklps %xmm4, %xmm4            # xmm4 = xmm4[0,0,1,1]
movmskpd %xmm4, %esi
movl %esi, %ecx
shrb %cl
andb %dl, %cl
movzbl %cl, %edx
cvttss2si %xmm1, %rcx
subq %rdx, %rax
cvtsi2ss %rcx, %xmm2
ucomiss %xmm2, %xmm1
setp %dl
setne %dil
orb %dl, %dil
andb %sil, %dil
movaps 0x120(%rsp), %xmm6
cvttss2si %xmm6, %rsi
cvtss2sd 0x110(%rsp), %xmm1
cvtsi2ss %rsi, %xmm3
cvtss2sd %xmm5, %xmm2
movzbl %dil, %edx
cvtsi2sd %eax, %xmm4
movsd 0x44a2(%rip), %xmm5     # 0x2d1c0
addsd %xmm5, %xmm4
subsd %xmm4, %xmm1
cvtsd2ss %xmm1, %xmm1
subq %rdx, %rcx
cvtsi2sd %ecx, %xmm4
addsd %xmm5, %xmm4
subsd %xmm4, %xmm2
cvtsd2ss %xmm2, %xmm2
cmpneqps %xmm6, %xmm3
xorpd %xmm4, %xmm4
cmpnleps %xmm6, %xmm4
andps %xmm3, %xmm4
movd %xmm4, %edx
addl %edx, %esi
cvtsi2ss %esi, %xmm3
subss %xmm6, %xmm3
movslq %ecx, %rdi
movslq %eax, %r8
xorl %r9d, %r9d
cmpq $0x2, %r9
je 0x28e19
movl %r15d, %eax
subl %r9d, %eax
cvtsi2ss %eax, %xmm4
leaq (%r9,%r8), %r10
leal -0x2(%r10), %r11d
subss %xmm1, %xmm4
andps %xmm7, %xmm4
mulss %xmm0, %xmm4
shlq $0x5, %r10
addq 0x10(%rsp), %r10
xorl %r12d, %r12d
cmpq $0x2, %r12
je 0x28e11
cmpl $-0x4, %r11d
setb %al
leaq (%r12,%rdi), %r14
leal -0x2(%r14), %ecx
cmpl $-0x4, %ecx
setb %bpl
movl %r15d, %ecx
subl %r12d, %ecx
cvtsi2ss %ecx, %xmm5
subss %xmm2, %xmm5
andps %xmm7, %xmm5
mulss %xmm4, %xmm5
shlq $0x7, %r14
addq %r10, %r14
orb %al, %bpl
movl %esi, %ecx
movl %r15d, %r13d
cmpl $-0x1, %r13d
je 0x28e0c
testb %bpl, %bpl
jne 0x28e05
cvtsi2ss %r13d, %xmm6
addss %xmm3, %xmm6
andps %xmm7, %xmm6
mulss %xmm5, %xmm6
movl %ecx, %eax
cltd
idivl %ebx
movslq %edx, %rax
addss (%r14,%rax,4), %xmm6
movss %xmm6, (%r14,%rax,4)
decl %r13d
incl %ecx
jmp 0x28dd6
incq %r12
jmp 0x28d96
incq %r9
jmp 0x28d63
movq 0x60(%rsp), %rcx
incq %rcx
movsd 0x8(%rsp), %xmm1
movq 0x38(%rsp), %rdx
jmp 0x28b8e
movq 0xb8(%rsp), %rcx
incq %rcx
jmp 0x28b29
movq 0x90(%rsp), %rbx
leaq 0x200(%rbx), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x28f3b
movq 0x40(%rsp), %rax
movsd 0x98(%rax), %xmm1
xorps %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jne 0x28e73
jnp 0x28ecf
movq 0x78(%rsp), %rax
movq 0x70(%rsp), %rcx
addl %ecx, %eax
incl %eax
movq 0x88(%rsp), %rcx
movq 0x80(%rsp), %rdx
addl %edx, %ecx
incl %ecx
imull %eax, %ecx
cvtsi2sd %ecx, %xmm2
cvtss2sd %xmm0, %xmm0
mulsd %xmm2, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x28ecf
xorl %eax, %eax
cmpq $0x80, %rax
je 0x28ebd
andl $0x0, (%rbx,%rax,4)
incq %rax
jmp 0x28eac
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
movsd 0x4a9f(%rip), %xmm0     # 0x2d978
cmpq $0x80, %rax
je 0x28ef8
cvtss2sd (%rbx,%rax,4), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x28ef3
movl $0x3e4ccccd, (%rbx,%rax,4) # imm = 0x3E4CCCCD
incq %rax
jmp 0x28ed9
movq %rbx, %rdi
movq %r15, %rsi
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x28f3b