// File: /workspace/github_cpp_makefile_star2_O1/manikandan5[P]Image-Matching-Stitching-Warping/siftpp/sift.cpp
// Function: VL::Sift::computeKeypointDescriptor(float*, VL::Sift::Keypoint, float)
void
Sift::computeKeypointDescriptor
(VL::float_t* descr_pt,
 Keypoint keypoint, 
 VL::float_t angle0)
{

  /* The SIFT descriptor is a  three dimensional histogram of the position
   * and orientation of the gradient.  There are NBP bins for each spatial
   * dimesions and NBO  bins for the orientation dimesion,  for a total of
   * NBP x NBP x NBO bins.
   *
   * The support  of each  spatial bin  has an extension  of SBP  = 3sigma
   * pixels, where sigma is the scale  of the keypoint.  Thus all the bins
   * together have a  support SBP x NBP pixels wide  . Since weighting and
   * interpolation of  pixel is used, another  half bin is  needed at both
   * ends of  the extension. Therefore, we  need a square window  of SBP x
   * (NBP + 1) pixels. Finally, since the patch can be arbitrarly rotated,
   * we need to consider  a window 2W += sqrt(2) x SBP  x (NBP + 1) pixels
   * wide.
   */      

  // octave
  int o = keypoint.o ;
  VL::float_t xperiod = getOctaveSamplingPeriod(o) ;

  // offsets to move in Gaussian scale space octave
  const int ow = getOctaveWidth(o) ;
  const int oh = getOctaveHeight(o) ;
  const int xo = 2 ;
  const int yo = xo * ow ;
  const int so = yo * oh ;

  // keypoint fractional geometry
  VL::float_t x     = keypoint.x / xperiod;
  VL::float_t y     = keypoint.y / xperiod ;
  VL::float_t sigma = keypoint.sigma / xperiod ;

  VL::float_t st0   = sinf( angle0 ) ;
  VL::float_t ct0   = cosf( angle0 ) ;
  
  // shall we use keypoints.ix,iy,is here?
  int xi = ((int) (x+0.5)) ; 
  int yi = ((int) (y+0.5)) ;
  int si = keypoint.is ;

  // const VL::float_t magnif = 3.0f ;
  const int NBO = 8 ;
  const int NBP = 4 ;
  const VL::float_t SBP = magnif * sigma ;
  const int   W = (int) floor (sqrt(2.0) * SBP * (NBP + 1) / 2.0 + 0.5) ;
  
  /* Offsets to move in the descriptor. */
  /* Use Lowe's convention. */
  const int binto = 1 ;
  const int binyo = NBO * NBP ;
  const int binxo = NBO ;
  // const int bino  = NBO * NBP * NBP ;
  
  int bin ;
  
  // check bounds
  if(o  < omin   ||
     o  >=omin+O ||
     xi < 0      || 
     xi > ow-1   || 
     yi < 0      || 
     yi > oh-1   ||
     si < smin+1 ||
     si > smax-2 )
        return ;
  
  // make sure gradient buffer is up-to-date
  prepareGrad(o) ;

  std::fill( descr_pt, descr_pt + NBO*NBP*NBP, 0 ) ;

  /* 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).
   */
  pixel_t const * pt = temp + xi*xo + yi*yo + (si - smin - 1)*so ;
  VL::float_t *  dpt = descr_pt + (NBP/2) * binyo + (NBP/2) * binxo ;
     
#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(int dyi = std::max(-W, 1-yi) ; dyi <= std::min(+W, oh-2-yi) ; ++dyi) {
    for(int dxi = std::max(-W, 1-xi) ; dxi <= std::min(+W, ow-2-xi) ; ++dxi) {
      
      // retrieve 
      VL::float_t mod   = *( pt + dxi*xo + dyi*yo + 0 ) ;
      VL::float_t angle = *( pt + dxi*xo + dyi*yo + 1 ) ;
      VL::float_t theta = fast_mod_2pi(-angle + angle0) ; // lowe compatible ?
      
      // fractional displacement
      VL::float_t dx = xi + dxi - x;
      VL::float_t dy = yi + dyi - y;
      
      // get the displacement normalized w.r.t. the keypoint
      // orientation and extension.
      VL::float_t nx = ( ct0 * dx + st0 * dy) / SBP ;
      VL::float_t ny = (-st0 * dx + ct0 * dy) / SBP ; 
      VL::float_t nt = NBO * theta / (2*M_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::float_t const wsigma = NBP/2 ;
      VL::float_t win = VL::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 = fast_floor( nx - 0.5 ) ;
      int biny = fast_floor( ny - 0.5 ) ;
      int bint = fast_floor( nt ) ;
      VL::float_t rbinx = nx - (binx+0.5) ;
      VL::float_t rbiny = ny - (biny+0.5) ;
      VL::float_t 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::float_t weight = win 
                * mod 
                * fast_abs (1 - dbinx - rbinx)
                * fast_abs (1 - dbiny - rbiny)
                * fast_abs (1 - dbint - rbint) ;
              
              atd(binx+dbinx, biny+dbiny, (bint+dbint) % NBO) += weight ;
            }
          }            
        }
      }
    }  
  }

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

    /* Normalize the histogram to L2 unit length. */        
    Detail::normalize_histogram(descr_pt, descr_pt + NBO*NBP*NBP) ;
    
    /* Truncate at 0.2. */
    for(bin = 0; bin < NBO*NBP*NBP ; ++bin) {
      if (descr_pt[bin] > 0.2) descr_pt[bin] = 0.2;
    }
    
    /* Normalize again. */
    Detail::normalize_histogram(descr_pt, descr_pt + NBO*NBP*NBP) ;
  }

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movss %xmm0, 0x1c(%rsp)
movq %rsi, %r15
movl 0x130(%rsp), %ebp
testl %ebp, %ebp
js 0x6fe60
movl $0x1, %eax
movl %ebp, %ecx
shll %cl, %eax
cvtsi2ss %eax, %xmm1
jmp 0x6fe7e
movl %ebp, %ecx
negb %cl
movl $0x1, %eax
shll %cl, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss 0x1436(%rip), %xmm1     # 0x712b0
divss %xmm0, %xmm1
movl 0x14(%rdi), %eax
cmpl %ebp, %eax
jg 0x705ff
addl 0xc(%rdi), %eax
cmpl %ebp, %eax
jle 0x705ff
movl 0x20(%rdi), %ebx
movq %rdi, 0x20(%rsp)
movl %ebx, %edx
movl %ebp, %ecx
sarl %cl, %edx
movl %ebp, %eax
negb %al
movl %eax, %ecx
shll %cl, %ebx
leaq 0x130(%rsp), %r14
movq 0x20(%rsp), %rcx
movl 0x24(%rcx), %r12d
movl %r12d, %esi
movl %ebp, %ecx
sarl %cl, %esi
movl %eax, %ecx
shll %cl, %r12d
testl %ebp, %ebp
cmovnsl %edx, %ebx
cmovnsl %esi, %r12d
movss 0x10(%r14), %xmm0
movss %xmm0, 0x14(%rsp)
movss 0x14(%r14), %xmm0
movss %xmm0, 0x10(%rsp)
movss 0x1c(%r14), %xmm0
movss %xmm1, 0x8(%rsp)
divss %xmm1, %xmm0
movss %xmm0, 0x18(%rsp)
movss 0x1c(%rsp), %xmm0
callq 0x4470
movaps %xmm0, 0xb0(%rsp)
movss 0x1c(%rsp), %xmm0
callq 0x43c0
movss %xmm0, 0x2c(%rsp)
movsd 0x1146(%rip), %xmm1     # 0x71070
movq 0x20(%rsp), %rax
movss 0x18(%rsp), %xmm0
mulss 0x28(%rax), %xmm0
movl 0xc(%r14), %r13d
movss %xmm0, 0x18(%rsp)
cvtss2sd %xmm0, %xmm0
mulsd 0x280e8(%rip), %xmm0    # 0x98038
mulsd 0x10c8(%rip), %xmm0     # 0x71020
mulsd %xmm1, %xmm0
addsd %xmm1, %xmm0
callq 0x48f0
movq 0x20(%rsp), %rdi
movl 0x14(%rdi), %eax
cmpl %eax, %ebp
jge 0x6ff83
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addl 0xc(%rdi), %eax
cmpl %eax, %ebp
jge 0x6ff71
movss 0x14(%rsp), %xmm1
divss 0x8(%rsp), %xmm1
movss %xmm1, 0x14(%rsp)
cvtss2sd %xmm1, %xmm1
addsd 0x10c8(%rip), %xmm1     # 0x71070
cvttsd2si %xmm1, %ecx
movq %rcx, 0x40(%rsp)
testl %ecx, %ecx
js 0x6ff71
movl %ebx, %eax
subl 0x40(%rsp), %eax
movq %rax, 0x30(%rsp)
jle 0x6ff71
movss 0x10(%rsp), %xmm1
divss 0x8(%rsp), %xmm1
movss %xmm1, 0x10(%rsp)
cvtss2sd %xmm1, %xmm1
addsd 0x1090(%rip), %xmm1     # 0x71070
cvttsd2si %xmm1, %ecx
testl %ecx, %ecx
js 0x6ff71
movl %r12d, %r14d
subl %ecx, %r14d
jle 0x6ff71
cmpl 0x18(%rdi), %r13d
jle 0x6ff71
movl 0x1c(%rdi), %eax
addl $-0x2, %eax
cmpl %eax, %r13d
jg 0x6ff71
cvttsd2si %xmm0, %eax
movl %eax, 0x8(%rsp)
movl %ebp, %esi
movq %rcx, %rbp
callq 0x6f402
movl $0x200, %edx            # imm = 0x200
movq %r15, 0x60(%rsp)
movq %r15, %rdi
xorl %esi, %esi
callq 0x4290
movl 0x8(%rsp), %r11d
movl %r11d, %ecx
negl %ecx
movl $0x1, %edx
movq %rbp, 0x68(%rsp)
subl %ebp, %edx
cmpl %ecx, %edx
movl %ecx, %eax
cmovgl %edx, %eax
addl $-0x2, %r14d
cmpl %r11d, %r14d
cmovgel %r11d, %r14d
cmpl %r14d, %eax
jg 0x7049b
movl %r14d, %r10d
addl %ebx, %ebx
movq 0x40(%rsp), %r9
leal (%r9,%r9), %esi
shlq $0x2, %rsi
movq 0x20(%rsp), %r8
addq 0x30(%r8), %rsi
movl %ebx, %edi
imull 0x68(%rsp), %edi
movslq %edi, %rdi
leaq (%rsi,%rdi,4), %rsi
movl 0x18(%r8), %edi
notl %edi
addl %edi, %r13d
imull %ebx, %r12d
imull %r12d, %r13d
movslq %r13d, %rdi
leaq (%rsi,%rdi,4), %rsi
movq %rsi, 0x98(%rsp)
movl $0x1, %edi
subl %r9d, %edi
cmpl %ecx, %edi
cmovlel %ecx, %edi
movq 0x30(%rsp), %r14
addl $-0x2, %r14d
cmpl %r11d, %r14d
cmovgel %r11d, %r14d
movq 0x60(%rsp), %rsi
leaq 0x140(%rsi), %rbp
movaps 0x1097(%rip), %xmm0     # 0x71170
xorps 0xb0(%rsp), %xmm0
movaps %xmm0, 0xc0(%rsp)
cmpl %edx, %ecx
cmovgl %ecx, %edx
movl %edi, 0x54(%rsp)
movslq %edi, %rcx
movq %rcx, 0x90(%rsp)
movslq %edx, %rcx
movq %rcx, 0x38(%rsp)
addl %ecx, %r10d
subl %eax, %r10d
movq %r14, 0x30(%rsp)
leal 0x1(%r14), %eax
movl %eax, 0x58(%rsp)
movslq %ebx, %rax
movq %rax, 0x88(%rsp)
incl %r10d
movl %r10d, 0x50(%rsp)
movl 0x54(%rsp), %eax
cmpl 0x30(%rsp), %eax
jg 0x70484
movq 0x38(%rsp), %rdx
movq %rdx, %rax
imulq 0x88(%rsp), %rax
movq 0x98(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
movq %rax, 0xa0(%rsp)
movq 0x68(%rsp), %rax
addl %edx, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
subss 0x10(%rsp), %xmm0
movaps 0xb0(%rsp), %xmm1
mulss %xmm0, %xmm1
movaps %xmm1, 0xd0(%rsp)
mulss 0x2c(%rsp), %xmm0
movss %xmm0, 0x5c(%rsp)
movq 0x90(%rsp), %r12
movq 0xa0(%rsp), %rax
movss (%rax,%r12,8), %xmm0
movss %xmm0, 0x8(%rsp)
movss 0x1c(%rsp), %xmm0
subss 0x4(%rax,%r12,8), %xmm0
movss %xmm0, 0xc(%rsp)
movss 0x27e23(%rip), %xmm1    # 0x97fec
callq 0x4660
movq 0x40(%rsp), %rax
addl %r12d, %eax
xorps %xmm2, %xmm2
cvtsi2ss %eax, %xmm2
subss 0x14(%rsp), %xmm2
movss 0x2c(%rsp), %xmm3
mulss %xmm2, %xmm3
addss 0xd0(%rsp), %xmm3
movss 0x18(%rsp), %xmm1
divss %xmm1, %xmm3
mulss 0xc0(%rsp), %xmm2
addss 0x5c(%rsp), %xmm2
divss %xmm1, %xmm2
movss %xmm2, 0x70(%rsp)
mulss %xmm2, %xmm2
movss %xmm3, 0x48(%rsp)
movaps %xmm3, %xmm1
mulss %xmm3, %xmm1
addss %xmm2, %xmm1
mulss 0x27dc2(%rip), %xmm1    # 0x97ff8
ucomiss 0x10cb(%rip), %xmm1     # 0x71308
jb 0x705e0
movss 0x10d1(%rip), %xmm2     # 0x7131c
ucomiss %xmm1, %xmm2
jb 0x705e0
xorps %xmm2, %xmm2
cvtss2sd %xmm0, %xmm2
movsd 0x27dc5(%rip), %xmm4    # 0x98028
addsd %xmm4, %xmm2
cvtsd2ss %xmm2, %xmm2
xorps %xmm3, %xmm3
cmpnless 0xc(%rsp), %xmm3
andps %xmm3, %xmm2
andnps %xmm0, %xmm3
orps %xmm2, %xmm3
mulss 0x27d76(%rip), %xmm3    # 0x97ffc
xorps %xmm0, %xmm0
cvtss2sd %xmm3, %xmm0
divsd %xmm4, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xc(%rsp)
xorps 0xece(%rip), %xmm1      # 0x71170
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
callq 0x4980
cvtsd2ss %xmm0, %xmm0
movss 0x8(%rsp), %xmm1
mulss %xmm0, %xmm1
movss %xmm1, 0x8(%rsp)
movss 0x48(%rsp), %xmm1
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
movsd %xmm0, 0xa8(%rsp)
movss 0x27d20(%rip), %xmm0    # 0x98000
addss %xmm0, %xmm1
movaps %xmm1, %xmm0
callq 0x41b0
movaps %xmm0, 0xe0(%rsp)
cvttss2si %xmm0, %r14d
movss 0x70(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
movsd %xmm1, 0x48(%rsp)
addss 0x27cec(%rip), %xmm0    # 0x98000
callq 0x41b0
movaps %xmm0, 0x70(%rsp)
cvttss2si %xmm0, %r15d
movss 0xc(%rsp), %xmm0
callq 0x41b0
movss 0x8(%rsp), %xmm7
cvttss2si %xmm0, %eax
cvttps2dq 0xe0(%rsp), %xmm1
cvtdq2pd %xmm1, %xmm1
movsd 0xd23(%rip), %xmm3      # 0x71070
addsd %xmm3, %xmm1
movsd 0xa8(%rsp), %xmm2
subsd %xmm1, %xmm2
xorps %xmm1, %xmm1
cvtsd2ss %xmm2, %xmm1
cvttps2dq 0x70(%rsp), %xmm2
cvtdq2pd %xmm2, %xmm2
addsd %xmm3, %xmm2
movsd 0x48(%rsp), %xmm3
subsd %xmm2, %xmm3
xorps %xmm2, %xmm2
cvtsd2ss %xmm3, %xmm2
cvttps2dq %xmm0, %xmm0
cvtdq2ps %xmm0, %xmm0
subss 0xc(%rsp), %xmm0
movslq %r15d, %rcx
movslq %r14d, %rdx
xorl %esi, %esi
movaps 0xd80(%rip), %xmm6      # 0x71120
movl $0x1, %edi
subl %esi, %edi
xorps %xmm3, %xmm3
cvtsi2ss %edi, %xmm3
leaq (%rsi,%rdx), %rdi
leal -0x2(%rdi), %r8d
subss %xmm1, %xmm3
andps %xmm6, %xmm3
mulss %xmm7, %xmm3
shlq $0x5, %rdi
addq %rbp, %rdi
xorl %r9d, %r9d
cmpl $-0x4, %r8d
setb %r15b
leaq (%r9,%rcx), %r10
leal -0x2(%r10), %r11d
cmpl $-0x4, %r11d
setb %r11b
movl $0x1, %r14d
subl %r9d, %r14d
xorps %xmm4, %xmm4
cvtsi2ss %r14d, %xmm4
movl $0x1, %r14d
subss %xmm2, %xmm4
andps %xmm6, %xmm4
mulss %xmm3, %xmm4
shlq $0x7, %r10
addq %rdi, %r10
orb %r15b, %r11b
movl %eax, %r15d
testb %r11b, %r11b
jne 0x7044e
xorps %xmm5, %xmm5
cvtsi2ss %r14d, %xmm5
addss %xmm0, %xmm5
andps %xmm6, %xmm5
leal 0x7(%r15), %r13d
testl %r15d, %r15d
cmovnsl %r15d, %r13d
mulss %xmm4, %xmm5
andl $-0x8, %r13d
movl %r15d, %ebx
subl %r13d, %ebx
movslq %ebx, %rbx
addss (%r10,%rbx,4), %xmm5
movss %xmm5, (%r10,%rbx,4)
incl %r15d
decl %r14d
je 0x70412
leaq 0x1(%r9), %r10
testq %r9, %r9
movq %r10, %r9
je 0x703cb
leaq 0x1(%rsi), %rdi
testq %rsi, %rsi
movq %rdi, %rsi
je 0x703a0
incq %r12
cmpl %r12d, 0x58(%rsp)
jne 0x7019a
movq 0x38(%rsp), %rax
incq %rax
movq %rax, 0x38(%rsp)
cmpl %eax, 0x50(%rsp)
jne 0x7012b
movq 0x20(%rsp), %rax
cmpb $0x1, 0x2c(%rax)
movq 0x60(%rsp), %rbx
jne 0x6ff71
xorpd %xmm0, %xmm0
xorl %eax, %eax
movss (%rbx,%rax), %xmm1
mulss %xmm1, %xmm1
addss %xmm1, %xmm0
addq $0x4, %rax
cmpq $0x200, %rax            # imm = 0x200
jne 0x704b5
xorpd %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x704dd
sqrtss %xmm0, %xmm0
jmp 0x704e2
callq 0x49c0
addss 0x27b0a(%rip), %xmm0    # 0x97ff4
shufps $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
xorl %eax, %eax
movups (%rbx,%rax,4), %xmm1
divps %xmm0, %xmm1
movups %xmm1, (%rbx,%rax,4)
addq $0x4, %rax
cmpq $0x80, %rax
jne 0x704f0
xorl %eax, %eax
movsd 0x27b2f(%rip), %xmm0    # 0x98040
movapd 0x27bb7(%rip), %xmm1    # 0x980d0
cvtps2pd 0x8(%rbx,%rax,4), %xmm2
cvtps2pd (%rbx,%rax,4), %xmm3
ucomisd %xmm0, %xmm3
jbe 0x7052f
movl $0x3e4ccccd, (%rbx,%rax,4) # imm = 0x3E4CCCCD
movapd %xmm1, %xmm4
cmpltpd %xmm3, %xmm4
pextrw $0x4, %xmm4, %ecx
testb $0x1, %cl
je 0x7054a
movl $0x3e4ccccd, 0x4(%rbx,%rax,4) # imm = 0x3E4CCCCD
movapd %xmm1, %xmm3
cmpltpd %xmm2, %xmm3
pextrw $0x0, %xmm3, %ecx
testb $0x1, %cl
je 0x70565
movl $0x3e4ccccd, 0x8(%rbx,%rax,4) # imm = 0x3E4CCCCD
pextrw $0x4, %xmm3, %ecx
testb $0x1, %cl
je 0x70577
movl $0x3e4ccccd, 0xc(%rbx,%rax,4) # imm = 0x3E4CCCCD
addq $0x4, %rax
cmpq $0x80, %rax
jne 0x70519
xorpd %xmm0, %xmm0
xorl %eax, %eax
movss (%rbx,%rax), %xmm1
mulss %xmm1, %xmm1
addss %xmm1, %xmm0
addq $0x4, %rax
cmpq $0x200, %rax            # imm = 0x200
jne 0x70589
xorpd %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x705b1
sqrtss %xmm0, %xmm0
jmp 0x705b6
callq 0x49c0
addss 0x27a36(%rip), %xmm0    # 0x97ff4
shufps $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
xorl %eax, %eax
movups (%rbx,%rax,4), %xmm1
divps %xmm0, %xmm1
movups %xmm1, (%rbx,%rax,4)
addq $0x4, %rax
cmpq $0x80, %rax
jne 0x705c4
jmp 0x6ff71
leaq 0x27c57(%rip), %rdi     # 0x9823e
leaq 0x27bd7(%rip), %rsi     # 0x981c5
leaq 0x27c7a(%rip), %rcx     # 0x9826f
movl $0xdb, %edx
callq 0x4340
leaq 0x27ba5(%rip), %rdi     # 0x981ab
leaq 0x27bb8(%rip), %rsi     # 0x981c5
leaq 0x27bc1(%rip), %rcx     # 0x981d5
movl $0x59, %edx
callq 0x4340