// File: /workspace/github_c_makefile_star2_O1/zpole[P]IICV/vl/sift.c
// Function: vl_sift_calc_keypoint_orientations
VL_EXPORT
int
vl_sift_calc_keypoint_orientations (VlSiftFilt *f,
                                    double angles [4],
                                    VlSiftKeypoint const *k)
{
  double const winf   = 1.5 ;
  double       xper   = pow (2.0, f->o_cur) ;

  int          w      = f-> octave_width ;
  int          h      = f-> octave_height ;
  int const    xo     = 2 ;         /* x-stride */
  int const    yo     = 2 * w ;     /* y-stride */
  int const    so     = 2 * w * h ; /* s-stride */
  double       x      = k-> x     / xper ;
  double       y      = k-> y     / xper ;
  double       sigma  = k-> sigma / xper ;

  int          xi     = (int) (x + 0.5) ;
  int          yi     = (int) (y + 0.5) ;
  int          si     = k-> is ;

  double const sigmaw = winf * sigma ;
  int          W      = VL_MAX(floor (3.0 * sigmaw), 1) ;

  int          nangles= 0 ;

  enum {nbins = 36} ;

  double hist [nbins], maxh ;
  vl_sift_pix const * pt ;
  int xs, ys, iter, i ;

  /* skip if the keypoint octave is not current */
  if(k->o != f->o_cur)
    return 0 ;

  /* skip the keypoint if it is out of bounds */
  if(xi < 0            ||
     xi > w - 1        ||
     yi < 0            ||
     yi > h - 1        ||
     si < f->s_min + 1 ||
     si > f->s_max - 2  ) {
    return 0 ;
  }

  /* make gradient up to date */
  update_gradient (f) ;

  /* clear histogram */
  memset (hist, 0, sizeof(double) * nbins) ;

  /* compute orientation histogram */
  pt = f-> grad + xo*xi + yo*yi + so*(si - f->s_min - 1) ;

#undef  at
#define at(dx,dy) (*(pt + xo * (dx) + yo * (dy)))

  for(ys  =  VL_MAX (- W,       - yi) ;
      ys <=  VL_MIN (+ W, h - 1 - yi) ; ++ys) {

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


      double dx = (double)(xi + xs) - x;
      double dy = (double)(yi + ys) - y;
      double r2 = dx*dx + dy*dy ;
      double wgt, mod, ang, fbin ;

      /* limit to a circular window */
      if (r2 >= W*W + 0.6) continue ;

      wgt  = fast_expn (r2 / (2*sigmaw*sigmaw)) ;
      mod  = *(pt + xs*xo + ys*yo    ) ;
      ang  = *(pt + xs*xo + ys*yo + 1) ;
      fbin = nbins * ang / (2 * VL_PI) ;

#if defined(VL_SIFT_BILINEAR_ORIENTATIONS)
      {
        int bin = (int) vl_floor_d (fbin - 0.5) ;
        double rbin = fbin - bin - 0.5 ;
        hist [(bin + nbins) % nbins] += (1 - rbin) * mod * wgt ;
        hist [(bin + 1    ) % nbins] += (    rbin) * mod * wgt ;
      }
#else
      {
        int    bin  = vl_floor_d (fbin) ;
        bin = vl_floor_d (nbins * ang / (2*VL_PI)) ;
        hist [(bin) % nbins] += mod * wgt ;
      }
#endif

    } /* for xs */
  } /* for ys */

  /* smooth histogram */
  for (iter = 0; iter < 6; iter ++) {
    double prev  = hist [nbins - 1] ;
    double first = hist [0] ;
    int i ;
    for (i = 0; i < nbins - 1; i++) {
      double newh = (prev + hist[i] + hist[(i+1) % nbins]) / 3.0;
      prev = hist[i] ;
      hist[i] = newh ;
    }
    hist[i] = (prev + hist[i] + first) / 3.0 ;
  }

  /* find the histogram maximum */
  maxh = 0 ;
  for (i = 0 ; i < nbins ; ++i)
    maxh = VL_MAX (maxh, hist [i]) ;

  /* find peaks within 80% from max */
  nangles = 0 ;
  for(i = 0 ; i < nbins ; ++i) {
    double h0 = hist [i] ;
    double hm = hist [(i - 1 + nbins) % nbins] ;
    double hp = hist [(i + 1 + nbins) % nbins] ;

    /* is this a peak? */
    if (h0 > 0.8*maxh && h0 > hm && h0 > hp) {

      /* quadratic interpolation */
      double di = - 0.5 * (hp - hm) / (hp + hm - 2 * h0) ;
      double th = 2 * VL_PI * (i + di + 0.5) / nbins ;
      angles [ nangles++ ] = th ;
      if( nangles == 4 )
        goto enough_angles ;
    }
  }
 enough_angles:
  return nangles ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
movl 0x3c(%rdi), %edi
movsd 0x634a(%rip), %xmm0     # 0x33260
callq 0x90c0
cvtss2sd 0x1c(%r15), %xmm1
movapd %xmm0, 0x20(%rsp)
divsd %xmm0, %xmm1
movq 0x58(%r14), %rbx
cvtps2pd 0x10(%r15), %xmm0
movaps %xmm0, 0x30(%rsp)
movl 0xc(%r15), %ebp
mulsd 0x62bb(%rip), %xmm1     # 0x33200
movsd 0x62c3(%rip), %xmm0     # 0x33210
movsd %xmm1, 0x48(%rsp)
mulsd %xmm1, %xmm0
callq 0x9880
movl (%r15), %eax
xorl %ecx, %ecx
cmpl 0x3c(%r14), %eax
jne 0x2d514
movapd 0x20(%rsp), %xmm1
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
movapd 0x30(%rsp), %xmm4
divpd %xmm1, %xmm4
movapd 0x6169(%rip), %xmm1     # 0x330f0
addpd %xmm4, %xmm1
cvttpd2dq %xmm1, %xmm2
movd %xmm2, %r15d
testl %r15d, %r15d
js 0x2d514
movq %rbx, %xmm1
movdqa %xmm1, %xmm3
pcmpgtd %xmm2, %xmm3
pshufd $0x50, %xmm3, %xmm3     # xmm3 = xmm3[0,0,1,1]
movmskpd %xmm3, %eax
movl %eax, %edx
shrb %dl
pshufd $0x55, %xmm2, %xmm2     # xmm2 = xmm2[1,1,1,1]
movd %xmm2, %esi
movq %rsi, 0x10(%rsp)
testl %esi, %esi
setns %sil
andb %al, %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x2d514
cmpl 0x34(%r14), %ebp
jle 0x2d514
movl 0x38(%r14), %eax
addl $-0x2, %eax
cmpl %eax, %ebp
jg 0x2d514
movq %r12, 0x40(%rsp)
pshufd $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
movd %xmm1, 0xc(%rsp)
movsd 0x6254(%rip), %xmm1     # 0x33260
maxsd %xmm1, %xmm0
cvttsd2si %xmm0, %r13d
movq %r14, %rdi
movapd %xmm4, 0x30(%rsp)
callq 0x2d528
leaq 0x50(%rsp), %rdi
xorl %r12d, %r12d
movl $0x120, %edx            # imm = 0x120
xorl %esi, %esi
callq 0x9400
movl 0xc(%rsp), %edx
movapd 0x30(%rsp), %xmm9
movsd 0x6215(%rip), %xmm15    # 0x33260
movq 0x10(%rsp), %rcx
cmpl %ecx, %r13d
movl %ecx, %r9d
cmovll %r13d, %r9d
movl %r9d, 0x20(%rsp)
negl %r9d
movl %ecx, %edi
notl %edi
addl %edx, %edi
cmpl %r13d, %edi
cmovgel %r13d, %edi
cmpl %r9d, %edi
jl 0x2d396
leal (%rbx,%rbx), %r8d
movl %r8d, 0x1c(%rsp)
imull %r8d, %edx
movq 0x10(%rsp), %rax
imull %eax, %r8d
movl 0x34(%r14), %ecx
notl %ecx
addl %ecx, %ebp
imull %edx, %ebp
cmpl %r15d, %r13d
movl %r15d, %ecx
cmovll %r13d, %ecx
movl %ecx, %esi
negl %esi
movl %esi, 0xc(%rsp)
movl %r15d, %edx
notl %edx
addl %ebx, %edx
cmpl %r13d, %edx
cmovgel %r13d, %edx
movslq %r13d, %r10
imull %r13d, %r13d
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movl %r15d, %r11d
cmpq %r11, %r10
cmovlq %r10, %r11
movl 0x20(%rsp), %r13d
addl %edi, %r13d
movl %eax, %edi
cmpq %rdi, %r10
cmovlq %r10, %rdi
subl %edi, %r13d
movslq 0x1c(%rsp), %rsi
movslq %r8d, %r8
movslq %ebp, %rbx
shlq $0x2, %r8
leaq (%r8,%rbx,4), %r8
leal (%r15,%r15), %ebx
incl %r13d
movl %r13d, 0x20(%rsp)
leaq (%r8,%rbx,4), %r8
movslq %eax, %rbx
cmpq %r10, %rbx
cmovgeq %r10, %rbx
imulq %rsi, %rbx
shlq $0x2, %rbx
subq %rbx, %r8
movslq %r15d, %rbx
cmpq %r10, %rbx
cmovlq %rbx, %r10
leaq (,%r10,8), %rbx
subq %rbx, %r8
movq 0xb0(%r14), %rbx
addsd 0x60a6(%rip), %xmm0     # 0x331e8
addq %rbx, %r8
addq $0x4, %r8
movsd 0x48(%rsp), %xmm2
movapd %xmm2, %xmm1
addsd %xmm2, %xmm1
mulsd %xmm2, %xmm1
movslq %r9d, %r9
movapd %xmm9, %xmm2
unpckhpd %xmm9, %xmm2            # xmm2 = xmm2[1],xmm9[1]
shlq $0x2, %rsi
subl %r10d, %r15d
movl %edx, %eax
addl %edx, %ecx
addl %r10d, %ecx
subl %r11d, %ecx
incl %ecx
movsd 0x7235(%rip), %xmm3     # 0x343b8
movsd 0x723d(%rip), %xmm4     # 0x343c8
movsd 0x620d(%rip), %xmm5     # 0x333a0
movsd 0x607d(%rip), %xmm6     # 0x33218
movsd 0x721d(%rip), %xmm7     # 0x343c0
leaq 0xf576(%rip), %r10      # 0x3c720
movabsq $0x100000000, %r11      # imm = 0x100000000
cmpl 0xc(%rsp), %eax
jl 0x2d385
movq 0x10(%rsp), %rdx
leal (%rdx,%r9), %ebx
xorps %xmm8, %xmm8
cvtsi2sd %ebx, %xmm8
subsd %xmm2, %xmm8
mulsd %xmm8, %xmm8
xorl %r14d, %r14d
leal (%r15,%r14), %ebx
xorps %xmm10, %xmm10
cvtsi2sd %ebx, %xmm10
subsd %xmm9, %xmm10
mulsd %xmm10, %xmm10
addsd %xmm8, %xmm10
ucomisd %xmm0, %xmm10
jae 0x2d379
divsd %xmm1, %xmm10
xorpd %xmm9, %xmm9
ucomisd %xmm3, %xmm10
ja 0x2d27e
mulsd %xmm7, %xmm10
cvttsd2si %xmm10, %rbx
xorps %xmm9, %xmm9
cvtsi2sd %rbx, %xmm9
xorpd %xmm11, %xmm11
cmpnlepd %xmm10, %xmm11
cmpneqpd %xmm10, %xmm9
andpd %xmm11, %xmm9
movq %xmm9, %r13
addq %rbx, %r13
xorps %xmm9, %xmm9
cvtsi2sd %r13d, %xmm9
subsd %xmm9, %xmm10
movslq %r13d, %rbx
shlq $0x20, %r13
addq %r11, %r13
movsd (%r10,%rbx,8), %xmm11
sarq $0x1d, %r13
movsd (%r13,%r10), %xmm9
subsd %xmm11, %xmm9
mulsd %xmm10, %xmm9
addsd %xmm11, %xmm9
xorps %xmm11, %xmm11
cvtss2sd -0x4(%r8,%r14,8), %xmm11
xorps %xmm10, %xmm10
cvtss2sd (%r8,%r14,8), %xmm10
mulsd %xmm4, %xmm10
divsd %xmm5, %xmm10
movapd %xmm10, %xmm12
addsd %xmm6, %xmm12
cvttsd2si %xmm12, %rbx
xorps %xmm13, %xmm13
cvtsi2sd %rbx, %xmm13
cmpneqpd %xmm12, %xmm13
xorpd %xmm14, %xmm14
cmpnlepd %xmm12, %xmm14
andpd %xmm13, %xmm14
movd %xmm14, %r13d
leal (%rbx,%r13), %ebp
xorps %xmm12, %xmm12
cvtsi2sd %ebp, %xmm12
subsd %xmm12, %xmm10
addsd %xmm6, %xmm10
movapd %xmm15, %xmm12
subsd %xmm10, %xmm12
mulsd %xmm11, %xmm12
leal (%rbx,%r13), %ebp
addl $0x24, %ebp
movslq %ebp, %rbp
imulq $0x38e38e39, %rbp, %rdx # imm = 0x38E38E39
movq %rdx, %rdi
shrq $0x3f, %rdi
sarq $0x23, %rdx
addl %edi, %edx
shll $0x2, %edx
leal (%rdx,%rdx,8), %edx
subl %edx, %ebp
movslq %ebp, %rdx
mulsd %xmm9, %xmm12
addsd 0x50(%rsp,%rdx,8), %xmm12
movsd %xmm12, 0x50(%rsp,%rdx,8)
mulsd %xmm11, %xmm10
leal (%rbx,%r13), %edx
incl %edx
movslq %edx, %rdx
imulq $0x38e38e39, %rdx, %rdi # imm = 0x38E38E39
movq %rdi, %rbx
shrq $0x3f, %rbx
sarq $0x23, %rdi
addl %ebx, %edi
shll $0x2, %edi
leal (%rdi,%rdi,8), %edi
subl %edi, %edx
movslq %edx, %rdx
mulsd %xmm9, %xmm10
addsd 0x50(%rsp,%rdx,8), %xmm10
movsd %xmm10, 0x50(%rsp,%rdx,8)
movapd 0x30(%rsp), %xmm9
incq %r14
cmpl %r14d, %ecx
jne 0x2d1dd
incq %r9
addq %rsi, %r8
cmpl %r9d, 0x20(%rsp)
jne 0x2d1b4
movsd 0x5e72(%rip), %xmm0     # 0x33210
movsd 0x50(%rsp), %xmm1
movsd 0x168(%rsp), %xmm2
xorl %eax, %eax
movapd %xmm2, %xmm3
movsd 0x50(%rsp,%rax,8), %xmm2
addsd %xmm2, %xmm3
addsd 0x58(%rsp,%rax,8), %xmm3
divsd %xmm0, %xmm3
movsd %xmm3, 0x50(%rsp,%rax,8)
leaq 0x1(%rax), %rcx
movq %rcx, %rax
cmpq $0x23, %rcx
jne 0x2d3af
addsd 0x168(%rsp), %xmm2
addsd %xmm2, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x168(%rsp)
incl %r12d
cmpl $0x6, %r12d
jne 0x2d39e
xorpd %xmm0, %xmm0
xorl %eax, %eax
maxsd 0x50(%rsp,%rax,8), %xmm0
incq %rax
cmpq $0x24, %rax
jne 0x2d403
mulsd 0x5e3e(%rip), %xmm0     # 0x33258
leaq 0x178(%rsp), %r9
xorl %r10d, %r10d
movl $0x25, %esi
movl $0x23, %edi
leaq 0x168(%rsp), %r11
movabsq $-0x1c71c71c71c71c71, %rbx # imm = 0xE38E38E38E38E38F
movsd 0x5d87(%rip), %xmm1     # 0x331d0
movsd 0x5f4f(%rip), %xmm2     # 0x333a0
movsd 0x6f6f(%rip), %xmm3     # 0x343c8
xorl %ecx, %ecx
movq 0x40(%rsp), %r14
movq %rsi, %rax
mulq %rbx
movq %rdx, %r8
movq %rdi, %rax
mulq %rbx
cmpq $0x24, %r10
je 0x2d514
movsd 0x50(%rsp,%r10,8), %xmm4
ucomisd %xmm0, %xmm4
movb $0x1, %al
jbe 0x2d4fb
andq $-0x20, %rdx
leaq (%rdx,%rdx,8), %rdx
negq %rdx
movsd (%r11,%rdx), %xmm5
ucomisd %xmm5, %xmm4
jbe 0x2d4fb
andq $-0x20, %r8
leaq (%r8,%r8,8), %rdx
negq %rdx
movsd (%r9,%rdx), %xmm6
ucomisd %xmm6, %xmm4
jbe 0x2d4fb
movapd %xmm6, %xmm7
subsd %xmm5, %xmm7
mulsd %xmm1, %xmm7
addsd %xmm6, %xmm5
addsd %xmm4, %xmm4
subsd %xmm4, %xmm5
divsd %xmm5, %xmm7
xorps %xmm4, %xmm4
cvtsi2sd %r10d, %xmm4
subsd %xmm7, %xmm4
addsd %xmm1, %xmm4
mulsd %xmm2, %xmm4
divsd %xmm3, %xmm4
movslq %ecx, %rax
incl %ecx
movsd %xmm4, (%r14,%rax,8)
cmpl $0x4, %ecx
setne %al
addq $0x8, %r9
incq %rsi
addq $0x8, %r11
incq %rdi
incq %r10
testb %al, %al
jne 0x2d460
movl %ecx, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq