// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x288, %rsp            # imm = 0x288
movq %rdi, 0x278(%rsp)
movq %rsi, 0x270(%rsp)
movq %rdx, 0x268(%rsp)
movsd 0x9c29(%rip), %xmm0     # 0x590a0
movsd %xmm0, 0x260(%rsp)
movq 0x278(%rsp), %rax
cvtsi2sdl 0x3c(%rax), %xmm1
movsd 0x9c4b(%rip), %xmm0     # 0x590e0
callq 0x92b0
movsd %xmm0, 0x258(%rsp)
movq 0x278(%rsp), %rax
movl 0x58(%rax), %eax
movl %eax, 0x254(%rsp)
movq 0x278(%rsp), %rax
movl 0x5c(%rax), %eax
movl %eax, 0x250(%rsp)
movl $0x2, 0x24c(%rsp)
movl 0x254(%rsp), %eax
shll %eax
movl %eax, 0x248(%rsp)
movl 0x254(%rsp), %eax
shll %eax
imull 0x250(%rsp), %eax
movl %eax, 0x244(%rsp)
movq 0x268(%rsp), %rax
movss 0x10(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
divsd 0x258(%rsp), %xmm0
movsd %xmm0, 0x238(%rsp)
movq 0x268(%rsp), %rax
movss 0x14(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
divsd 0x258(%rsp), %xmm0
movsd %xmm0, 0x230(%rsp)
movq 0x268(%rsp), %rax
movss 0x1c(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
divsd 0x258(%rsp), %xmm0
movsd %xmm0, 0x228(%rsp)
movsd 0x9b15(%rip), %xmm0     # 0x59080
addsd 0x238(%rsp), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x224(%rsp)
movsd 0x9af9(%rip), %xmm0     # 0x59080
addsd 0x230(%rsp), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x220(%rsp)
movq 0x268(%rsp), %rax
movl 0xc(%rax), %eax
movl %eax, 0x21c(%rsp)
movsd 0x9aeb(%rip), %xmm0     # 0x590a0
mulsd 0x228(%rsp), %xmm0
movsd %xmm0, 0x210(%rsp)
movsd 0x9af9(%rip), %xmm0     # 0x590c8
mulsd 0x210(%rsp), %xmm0
callq 0x9a00
movsd 0x9af3(%rip), %xmm1     # 0x590d8
ucomisd %xmm1, %xmm0
jbe 0x4f609
movsd 0x9ad5(%rip), %xmm0     # 0x590c8
mulsd 0x210(%rsp), %xmm0
callq 0x9a00
movsd %xmm0, 0x28(%rsp)
jmp 0x4f619
movsd 0x9ac7(%rip), %xmm0     # 0x590d8
movsd %xmm0, 0x28(%rsp)
jmp 0x4f619
movsd 0x28(%rsp), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x20c(%rsp)
movl $0x0, 0x208(%rsp)
movq 0x268(%rsp), %rax
movl (%rax), %eax
movq 0x278(%rsp), %rcx
cmpl 0x3c(%rcx), %eax
je 0x4f65c
movl $0x0, 0x284(%rsp)
jmp 0x4fe5b
cmpl $0x0, 0x224(%rsp)
jl 0x4f6cc
movl 0x224(%rsp), %eax
movl 0x254(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jg 0x4f6cc
cmpl $0x0, 0x220(%rsp)
jl 0x4f6cc
movl 0x220(%rsp), %eax
movl 0x250(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jg 0x4f6cc
movl 0x21c(%rsp), %eax
movq 0x278(%rsp), %rcx
movl 0x34(%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jl 0x4f6cc
movl 0x21c(%rsp), %eax
movq 0x278(%rsp), %rcx
movl 0x38(%rcx), %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jle 0x4f6dc
movl $0x0, 0x284(%rsp)
jmp 0x4fe5b
movq 0x278(%rsp), %rdi
callq 0x4fe70
leaq 0xe0(%rsp), %rdi
xorl %esi, %esi
movl $0x120, %edx            # imm = 0x120
callq 0x9480
movq 0x278(%rsp), %rax
movq 0xb0(%rax), %rax
movl 0x224(%rsp), %ecx
shll %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movl 0x248(%rsp), %ecx
imull 0x220(%rsp), %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movl 0x244(%rsp), %ecx
movl 0x21c(%rsp), %edx
movq 0x278(%rsp), %rsi
subl 0x34(%rsi), %edx
subl $0x1, %edx
imull %edx, %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, 0xd0(%rsp)
xorl %eax, %eax
subl 0x20c(%rsp), %eax
xorl %ecx, %ecx
subl 0x220(%rsp), %ecx
cmpl %ecx, %eax
jle 0x4f78e
xorl %eax, %eax
subl 0x20c(%rsp), %eax
movl %eax, 0x24(%rsp)
jmp 0x4f79b
xorl %eax, %eax
subl 0x220(%rsp), %eax
movl %eax, 0x24(%rsp)
movl 0x24(%rsp), %eax
movl %eax, 0xc8(%rsp)
movl 0xc8(%rsp), %eax
movl %eax, 0x20(%rsp)
movl 0x20c(%rsp), %eax
movl 0x250(%rsp), %ecx
subl $0x1, %ecx
subl 0x220(%rsp), %ecx
cmpl %ecx, %eax
jge 0x4f7da
movl 0x20c(%rsp), %eax
movl %eax, 0x1c(%rsp)
jmp 0x4f7ef
movl 0x250(%rsp), %eax
subl $0x1, %eax
subl 0x220(%rsp), %eax
movl %eax, 0x1c(%rsp)
movl 0x20(%rsp), %eax
movl 0x1c(%rsp), %ecx
cmpl %ecx, %eax
jg 0x4fb2c
xorl %eax, %eax
subl 0x20c(%rsp), %eax
xorl %ecx, %ecx
subl 0x224(%rsp), %ecx
cmpl %ecx, %eax
jle 0x4f824
xorl %eax, %eax
subl 0x20c(%rsp), %eax
movl %eax, 0x18(%rsp)
jmp 0x4f831
xorl %eax, %eax
subl 0x224(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0xcc(%rsp)
movl 0xcc(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0x20c(%rsp), %eax
movl 0x254(%rsp), %ecx
subl $0x1, %ecx
subl 0x224(%rsp), %ecx
cmpl %ecx, %eax
jge 0x4f870
movl 0x20c(%rsp), %eax
movl %eax, 0x10(%rsp)
jmp 0x4f885
movl 0x254(%rsp), %eax
subl $0x1, %eax
subl 0x224(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x14(%rsp), %eax
movl 0x10(%rsp), %ecx
cmpl %ecx, %eax
jg 0x4fb14
movl 0x224(%rsp), %eax
addl 0xcc(%rsp), %eax
cvtsi2sd %eax, %xmm0
subsd 0x238(%rsp), %xmm0
movsd %xmm0, 0xb8(%rsp)
movl 0x220(%rsp), %eax
addl 0xc8(%rsp), %eax
cvtsi2sd %eax, %xmm0
subsd 0x230(%rsp), %xmm0
movsd %xmm0, 0xb0(%rsp)
movsd 0xb8(%rsp), %xmm0
movsd 0xb8(%rsp), %xmm2
movsd 0xb0(%rsp), %xmm1
mulsd 0xb0(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0xa8(%rsp)
movsd 0xa8(%rsp), %xmm0
movl 0x20c(%rsp), %eax
imull 0x20c(%rsp), %eax
cvtsi2sd %eax, %xmm1
movsd 0x9752(%rip), %xmm2     # 0x59088
addsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jb 0x4f945
jmp 0x4fafe
movsd 0xa8(%rsp), %xmm0
movsd 0x978a(%rip), %xmm1     # 0x590e0
mulsd 0x210(%rsp), %xmm1
mulsd 0x210(%rsp), %xmm1
divsd %xmm1, %xmm0
callq 0x50790
movsd %xmm0, 0xa0(%rsp)
movq 0xd0(%rsp), %rax
movl 0xcc(%rsp), %ecx
shll %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movl 0xc8(%rsp), %ecx
imull 0x248(%rsp), %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x98(%rsp)
movq 0xd0(%rsp), %rax
movl 0xcc(%rsp), %ecx
shll %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movl 0xc8(%rsp), %ecx
imull 0x248(%rsp), %ecx
movslq %ecx, %rcx
movss 0x4(%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x90(%rsp)
movsd 0xa75f(%rip), %xmm0     # 0x5a160
mulsd 0x90(%rsp), %xmm0
movsd 0x981e(%rip), %xmm1     # 0x59230
divsd %xmm1, %xmm0
movsd %xmm0, 0x88(%rsp)
movsd 0x88(%rsp), %xmm0
movsd 0x9650(%rip), %xmm1     # 0x59080
subsd %xmm1, %xmm0
callq 0x50860
movl %eax, 0x84(%rsp)
movsd 0x88(%rsp), %xmm0
cvtsi2sdl 0x84(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd 0x9622(%rip), %xmm1     # 0x59080
subsd %xmm1, %xmm0
movsd %xmm0, 0x78(%rsp)
movsd 0x9668(%rip), %xmm0     # 0x590d8
subsd 0x78(%rsp), %xmm0
mulsd 0x98(%rsp), %xmm0
movsd 0xa0(%rsp), %xmm2
movl 0x84(%rsp), %eax
addl $0x24, %eax
movl $0x24, %ecx
cltd
idivl %ecx
movslq %edx, %rax
movsd 0xe0(%rsp,%rax,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0xe0(%rsp,%rax,8)
movsd 0x78(%rsp), %xmm0
mulsd 0x98(%rsp), %xmm0
movsd 0xa0(%rsp), %xmm2
movl 0x84(%rsp), %eax
addl $0x1, %eax
movl $0x24, %ecx
cltd
idivl %ecx
movslq %edx, %rax
movsd 0xe0(%rsp,%rax,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0xe0(%rsp,%rax,8)
movl 0xcc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xcc(%rsp)
jmp 0x4f83c
jmp 0x4fb16
movl 0xc8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc8(%rsp)
jmp 0x4f7a6
movl $0x0, 0xc4(%rsp)
cmpl $0x6, 0xc4(%rsp)
jge 0x4fc32
movsd 0x1f8(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
movsd 0xe0(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
movl $0x0, 0x64(%rsp)
cmpl $0x23, 0x64(%rsp)
jge 0x4fbe8
movsd 0x70(%rsp), %xmm0
movslq 0x64(%rsp), %rax
addsd 0xe0(%rsp,%rax,8), %xmm0
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl $0x24, %ecx
cltd
idivl %ecx
movslq %edx, %rax
addsd 0xe0(%rsp,%rax,8), %xmm0
movsd 0x951f(%rip), %xmm1     # 0x590c8
divsd %xmm1, %xmm0
movsd %xmm0, 0x58(%rsp)
movslq 0x64(%rsp), %rax
movsd 0xe0(%rsp,%rax,8), %xmm0
movsd %xmm0, 0x70(%rsp)
movsd 0x58(%rsp), %xmm0
movslq 0x64(%rsp), %rax
movsd %xmm0, 0xe0(%rsp,%rax,8)
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x4fb6b
movsd 0x70(%rsp), %xmm0
movslq 0x64(%rsp), %rax
addsd 0xe0(%rsp,%rax,8), %xmm0
addsd 0x68(%rsp), %xmm0
movsd 0x94be(%rip), %xmm1     # 0x590c8
divsd %xmm1, %xmm0
movslq 0x64(%rsp), %rax
movsd %xmm0, 0xe0(%rsp,%rax,8)
movl 0xc4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc4(%rsp)
jmp 0x4fb37
xorps %xmm0, %xmm0
movsd %xmm0, 0xd8(%rsp)
movl $0x0, 0xc0(%rsp)
cmpl $0x24, 0xc0(%rsp)
jge 0x4fcb9
movsd 0xd8(%rsp), %xmm0
movslq 0xc0(%rsp), %rax
ucomisd 0xe0(%rsp,%rax,8), %xmm0
jbe 0x4fc80
movsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
jmp 0x4fc97
movslq 0xc0(%rsp), %rax
movsd 0xe0(%rsp,%rax,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0xd8(%rsp)
movl 0xc0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc0(%rsp)
jmp 0x4fc49
movl $0x0, 0x208(%rsp)
movl $0x0, 0xc0(%rsp)
cmpl $0x24, 0xc0(%rsp)
jge 0x4fe4b
movslq 0xc0(%rsp), %rax
movsd 0xe0(%rsp,%rax,8), %xmm0
movsd %xmm0, 0x50(%rsp)
movl 0xc0(%rsp), %eax
subl $0x1, %eax
addl $0x24, %eax
movl $0x24, %ecx
cltd
idivl %ecx
movslq %edx, %rax
movsd 0xe0(%rsp,%rax,8), %xmm0
movsd %xmm0, 0x48(%rsp)
movl 0xc0(%rsp), %eax
addl $0x1, %eax
addl $0x24, %eax
movl $0x24, %ecx
cltd
idivl %ecx
movslq %edx, %rax
movsd 0xe0(%rsp,%rax,8), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x50(%rsp), %xmm0
movsd 0x93b0(%rip), %xmm1     # 0x59100
mulsd 0xd8(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x4fe33
movsd 0x50(%rsp), %xmm0
ucomisd 0x48(%rsp), %xmm0
jbe 0x4fe33
movsd 0x50(%rsp), %xmm0
ucomisd 0x40(%rsp), %xmm0
jbe 0x4fe33
movsd 0x40(%rsp), %xmm1
subsd 0x48(%rsp), %xmm1
movsd 0x934d(%rip), %xmm0     # 0x590e8
mulsd %xmm1, %xmm0
movsd 0x40(%rsp), %xmm1
addsd 0x48(%rsp), %xmm1
movsd 0x50(%rsp), %xmm2
addsd %xmm2, %xmm2
subsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x38(%rsp)
cvtsi2sdl 0xc0(%rsp), %xmm1
addsd 0x38(%rsp), %xmm1
movsd 0x92a6(%rip), %xmm0     # 0x59080
addsd %xmm0, %xmm1
movsd 0x944a(%rip), %xmm0     # 0x59230
mulsd %xmm1, %xmm0
movsd 0xa36e(%rip), %xmm1     # 0x5a160
divsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x30(%rsp), %xmm0
movq 0x270(%rsp), %rax
movl 0x208(%rsp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0x208(%rsp)
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
cmpl $0x4, 0x208(%rsp)
jne 0x4fe31
jmp 0x4fe4d
jmp 0x4fe33
jmp 0x4fe35
movl 0xc0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc0(%rsp)
jmp 0x4fccf
jmp 0x4fe4d
movl 0x208(%rsp), %eax
movl %eax, 0x284(%rsp)
movl 0x284(%rsp), %eax
addq $0x288, %rsp            # imm = 0x288
retq
nopw (%rax,%rax)