// File: /workspace/github_c_makefile_star2_O3/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 0x5679(%rip), %xmm0     # 0x32270
callq 0x90c0
cvtss2sd 0x1c(%r15), %xmm1
movapd %xmm0, 0x10(%rsp)
divsd %xmm0, %xmm1
movq 0x58(%r14), %r13
cvtps2pd 0x10(%r15), %xmm0
movaps %xmm0, 0x30(%rsp)
movl 0xc(%r15), %ebx
mulsd 0x55ea(%rip), %xmm1     # 0x32210
movsd 0x55f2(%rip), %xmm0     # 0x32220
movsd %xmm1, 0x48(%rsp)
mulsd %xmm1, %xmm0
callq 0x9880
movl (%r15), %ecx
xorl %eax, %eax
cmpl 0x3c(%r14), %ecx
jne 0x2d1f8
movq %r12, 0x40(%rsp)
movapd 0x10(%rsp), %xmm1
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
movapd 0x30(%rsp), %xmm4
divpd %xmm1, %xmm4
movapd 0x5483(%rip), %xmm1     # 0x320f0
addpd %xmm4, %xmm1
cvttpd2dq %xmm1, %xmm2
movd %xmm2, %r12d
testl %r12d, %r12d
js 0x2d1f8
movq %r13, %xmm1
movdqa %xmm1, %xmm3
pcmpgtd %xmm2, %xmm3
pshufd $0x50, %xmm3, %xmm3     # xmm3 = xmm3[0,0,1,1]
movmskpd %xmm3, %ecx
movl %ecx, %edx
shrb %dl
pshufd $0x55, %xmm2, %xmm2     # xmm2 = xmm2[1,1,1,1]
movd %xmm2, %r8d
testl %r8d, %r8d
setns %sil
andb %cl, %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x2d1f8
cmpl 0x34(%r14), %ebx
jle 0x2d1f8
movl 0x38(%r14), %ecx
addl $-0x2, %ecx
cmpl %ecx, %ebx
jg 0x2d1f8
movapd %xmm4, 0x30(%rsp)
pshufd $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
movd %xmm1, 0x10(%rsp)
maxsd 0x5580(%rip), %xmm0     # 0x32270
cvttsd2si %xmm0, %r15d
movq %r14, %rdi
movq %r8, 0x28(%rsp)
callq 0x2d20a
leaq 0x50(%rsp), %rdi
xorl %ebp, %ebp
movl $0x120, %edx            # imm = 0x120
xorl %esi, %esi
callq 0x9400
movl 0x10(%rsp), %esi
movq 0x28(%rsp), %rdx
cmpl %edx, %r15d
movl %edx, %eax
cmovll %r15d, %eax
movl %eax, %r9d
negl %r9d
movl %edx, %r8d
notl %r8d
addl %esi, %r8d
cmpl %r15d, %r8d
cmovgel %r15d, %r8d
xorpd %xmm0, %xmm0
cmpl %r9d, %r8d
jl 0x2d075
leal (,%r13,2), %edi
movl %edi, 0xc(%rsp)
imull %edi, %esi
imull %edx, %edi
movl 0x34(%r14), %ecx
notl %ecx
addl %ecx, %ebx
imull %esi, %ebx
cmpl %r12d, %r15d
movl %r12d, %ecx
cmovll %r15d, %ecx
movl %ecx, %esi
negl %esi
movl %esi, 0x10(%rsp)
movl %r12d, %esi
notl %esi
addl %r13d, %esi
cmpl %r15d, %esi
cmovgel %r15d, %esi
movslq %r15d, %r10
imull %r15d, %r15d
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movl %r12d, %r11d
cmpq %r11, %r10
cmovlq %r10, %r11
addl %r8d, %eax
movl %edx, %r8d
cmpq %r8, %r10
cmovlq %r10, %r8
subl %r8d, %eax
movslq %edi, %rdi
movslq %ebx, %r8
shlq $0x2, %rdi
leaq (%rdi,%r8,4), %rdi
leal (%r12,%r12), %r8d
incl %eax
leaq (%rdi,%r8,4), %r8
movslq %edx, %rbx
cmpq %r10, %rbx
cmovgeq %r10, %rbx
movslq 0xc(%rsp), %rdi
imulq %rdi, %rbx
shlq $0x2, %rbx
subq %rbx, %r8
movslq %r12d, %rbx
cmpq %r10, %rbx
cmovlq %rbx, %r10
leaq (,%r10,8), %rbx
subq %rbx, %r8
movq 0xb0(%r14), %rbx
addq %rbx, %r8
addq $0x4, %r8
addsd 0x53ea(%rip), %xmm0     # 0x321f8
subl %r10d, %r12d
addl %esi, %ecx
addl %r10d, %ecx
movsd 0x48(%rsp), %xmm2
movapd %xmm2, %xmm1
addsd %xmm2, %xmm1
mulsd %xmm2, %xmm1
movslq %r9d, %r9
movapd 0x30(%rsp), %xmm9
movapd %xmm9, %xmm2
unpckhpd %xmm9, %xmm2            # xmm2 = xmm2[1],xmm9[1]
shlq $0x2, %rdi
subl %r11d, %ecx
incl %ecx
movsd 0x655b(%rip), %xmm3     # 0x333a8
movsd 0x6563(%rip), %xmm4     # 0x333b8
movsd 0x5553(%rip), %xmm5     # 0x323b0
movsd 0x53c3(%rip), %xmm6     # 0x32228
movsd 0x6543(%rip), %xmm7     # 0x333b0
leaq 0xe8ac(%rip), %r10      # 0x3b720
movsd 0x53f3(%rip), %xmm15    # 0x32270
cmpl 0x10(%rsp), %esi
jl 0x2d05d
movq 0x28(%rsp), %rdx
leal (%rdx,%r9), %r11d
xorps %xmm8, %xmm8
cvtsi2sd %r11d, %xmm8
subsd %xmm2, %xmm8
mulsd %xmm8, %xmm8
xorl %r11d, %r11d
leal (%r12,%r11), %ebx
xorps %xmm10, %xmm10
cvtsi2sd %ebx, %xmm10
subsd %xmm9, %xmm10
mulsd %xmm10, %xmm10
addsd %xmm8, %xmm10
ucomisd %xmm0, %xmm10
jae 0x2d051
divsd %xmm1, %xmm10
xorpd %xmm9, %xmm9
ucomisd %xmm3, %xmm10
ja 0x2cf4f
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, %r14
addq %rbx, %r14
xorps %xmm9, %xmm9
cvtsi2sd %r14d, %xmm9
subsd %xmm9, %xmm10
movslq %r14d, %rbx
shlq $0x20, %r14
movsd (%r10,%rbx,8), %xmm11
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
leaq (%rdx,%r14), %rbx
incq %rbx
sarq $0x1d, %rbx
movsd (%rbx,%r10), %xmm9
subsd %xmm11, %xmm9
mulsd %xmm10, %xmm9
addsd %xmm11, %xmm9
xorps %xmm11, %xmm11
cvtss2sd -0x4(%r8,%r11,8), %xmm11
xorps %xmm10, %xmm10
cvtss2sd (%r8,%r11,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, %r14d
leal (%rbx,%r14), %r15d
xorps %xmm12, %xmm12
cvtsi2sd %r15d, %xmm12
subsd %xmm12, %xmm10
addsd %xmm6, %xmm10
movapd %xmm15, %xmm12
subsd %xmm10, %xmm12
mulsd %xmm11, %xmm12
leal (%rbx,%r14), %r15d
addl $0x24, %r15d
movslq %r15d, %r15
imulq $0x38e38e39, %r15, %r13 # imm = 0x38E38E39
movq %r13, %rdx
shrq $0x3f, %rdx
sarq $0x23, %r13
addl %edx, %r13d
shll $0x2, %r13d
leal (%r13,%r13,8), %edx
subl %edx, %r15d
movslq %r15d, %rdx
mulsd %xmm9, %xmm12
addsd 0x50(%rsp,%rdx,8), %xmm12
movsd %xmm12, 0x50(%rsp,%rdx,8)
mulsd %xmm11, %xmm10
leal (%rbx,%r14), %edx
incl %edx
movslq %edx, %rdx
imulq $0x38e38e39, %rdx, %rbx # imm = 0x38E38E39
movq %rbx, %r14
shrq $0x3f, %r14
sarq $0x23, %rbx
addl %r14d, %ebx
shll $0x2, %ebx
leal (%rbx,%rbx,8), %ebx
subl %ebx, %edx
movslq %edx, %rdx
mulsd %xmm9, %xmm10
addsd 0x50(%rsp,%rdx,8), %xmm10
movsd %xmm10, 0x50(%rsp,%rdx,8)
movapd 0x30(%rsp), %xmm9
incq %r11
cmpl %r11d, %ecx
jne 0x2cea6
incq %r9
addq %rdi, %r8
cmpl %r9d, %eax
jne 0x2ce7d
movsd 0x168(%rsp), %xmm0
movsd 0x51a3(%rip), %xmm1     # 0x32220
movl $0x1, %eax
movsd 0x50(%rsp), %xmm2
movapd %xmm2, %xmm3
movapd %xmm0, %xmm4
movapd %xmm3, %xmm0
addsd %xmm3, %xmm4
movsd 0x50(%rsp,%rax,8), %xmm3
addsd %xmm3, %xmm4
divsd %xmm1, %xmm4
movsd %xmm4, 0x48(%rsp,%rax,8)
incq %rax
cmpq $0x24, %rax
jne 0x2d08c
addsd 0x168(%rsp), %xmm0
addsd %xmm0, %xmm2
divsd %xmm1, %xmm2
movsd %xmm2, 0x168(%rsp)
incl %ebp
movapd %xmm2, %xmm0
cmpl $0x6, %ebp
jne 0x2d07d
xorpd %xmm0, %xmm0
xorl %eax, %eax
maxsd 0x50(%rsp,%rax,8), %xmm0
incq %rax
cmpq $0x24, %rax
jne 0x2d0e0
mulsd 0x5171(%rip), %xmm0     # 0x32268
xorl %ecx, %ecx
movl $0x23, %edx
movsd 0x50da(%rip), %xmm1     # 0x321e0
movsd 0x52a2(%rip), %xmm2     # 0x323b0
movsd 0x62a2(%rip), %xmm3     # 0x333b8
xorl %esi, %esi
movq 0x40(%rsp), %r15
leal 0x25(%rcx), %edi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
leaq (%rcx,%rax), %r8
leaq (%rsp,%rcx,8), %r9
addq $0x50, %r9
movl %edi, %r10d
xorl %eax, %eax
movl %r10d, %ebx
leaq (%rcx,%rax), %r10
cmpq $0x24, %r10
je 0x2d1f6
movsd (%r9,%rax,8), %xmm4
movl %eax, %r11d
leal (%r8,%r11), %r14d
testq %r10, %r10
cmoveq %rdx, %r14
incq %rax
leal 0x1(%rbx), %r10d
ucomisd %xmm0, %xmm4
jbe 0x2d136
movsd 0x50(%rsp,%r14,8), %xmm5
ucomisd %xmm5, %xmm4
jbe 0x2d136
movzbl %bl, %ebx
imull $0x39, %ebx, %ebx
shrl $0x9, %ebx
andl $-0x4, %ebx
leal (%rbx,%rbx,8), %ebx
movl %edi, %ebp
subb %bl, %bpl
movzbl %bpl, %ebx
addl %r11d, %ebx
movzbl %bl, %r11d
movsd 0x50(%rsp,%r11,8), %xmm6
ucomisd %xmm6, %xmm4
jbe 0x2d136
leal (%rcx,%rax), %edi
decl %edi
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 %edi, %xmm4
subsd %xmm7, %xmm4
addsd %xmm1, %xmm4
mulsd %xmm2, %xmm4
divsd %xmm3, %xmm4
movl %esi, %edi
incl %esi
movsd %xmm4, (%r15,%rdi,8)
addq %rax, %rcx
movl $0x4, %eax
cmpl $0x4, %esi
jne 0x2d11d
jmp 0x2d1f8
movl %esi, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq