// File: /workspace/github_c_makefile_star2_O2/zpole[P]IICV/vl/hog.c
// Function: vl_hog_put_polar_field
void vl_hog_put_polar_field (VlHog * self,
                             float const * modulus,
                             float const * angle,
                             vl_bool directed,
                             vl_size width, vl_size height,
                             vl_size cellSize)
{
  vl_size hogStride ;
  vl_index x, y, o ;
  vl_index period = self->numOrientations * (directed ? 2 : 1) ;
  double angleStep = VL_PI / self->numOrientations ;

  assert(self) ;
  assert(modulus) ;
  assert(angle) ;

  /* clear features */
  vl_hog_prepare_buffers(self, width, height, cellSize) ;
  hogStride = self->hogWidth * self->hogHeight ;

#define at(x,y,k) (self->hog[(x) + (y) * self->hogWidth + (k) * hogStride])
#define atNorm(x,y) (self->hogNorm[(x) + (y) * self->hogWidth])

  /* fill HOG cells from gradient field */
  for (y = 0 ; y < (signed)height ; ++y) {
    for (x = 0 ; x < (signed)width ; ++x) {
      float ho, hx, hy, wo1, wo2, wx1, wx2, wy1, wy2 ;
      vl_index bino, binx, biny ;
      float orientationWeights [2] = {0,0} ;
      vl_index orientationBins [2] = {-1,-1} ;
      vl_index orientation = 0 ;
      float thisAngle = *angle++ ;
      float thisModulus = *modulus++ ;

      if (thisModulus <= 0.0f) continue ;

      /*  (x - (w-1)/2) / w = (x + 0.5)/w - 0.5 */

      ho = (float)thisAngle / angleStep ;
      bino = vl_floor_f(ho) ;
      wo2 = ho - bino ;
      wo1 = 1.0f - wo2 ;

      while (bino < 0) { bino += self->numOrientations * 2 ; }

      if (self->useBilinearOrientationAssigment) {
        orientationBins[0] = bino % period ;
        orientationBins[1] = (bino + 1) % period ;
        orientationWeights[0] = wo1 ;
        orientationWeights[1] = wo2 ;
      } else {
        orientationBins[0] = (bino + ((wo1 > wo2) ? 0 : 1)) % period ;
        orientationWeights[0] = 1 ;
        orientationBins[1] = -1 ;
      }

      for (o = 0 ; o < 2 ; ++o) {
        /*
         Accumulate the gradient. hx is the distance of the
         pixel x to the cell center at its left, in units of cellSize.
         With this parametrixation, a pixel on the cell center
         has hx = 0, which gradually increases to 1 moving to the next
         center.
         */

        orientation = orientationBins[o] ;
        if (orientation < 0) continue ;

        hx = (x + 0.5) / cellSize - 0.5 ;
        hy = (y + 0.5) / cellSize - 0.5 ;
        binx = vl_floor_f(hx) ;
        biny = vl_floor_f(hy) ;
        wx2 = hx - binx ;
        wy2 = hy - biny ;
        wx1 = 1.0 - wx2 ;
        wy1 = 1.0 - wy2 ;

        wx1 *= orientationWeights[o] ;
        wx2 *= orientationWeights[o] ;
        wy1 *= orientationWeights[o] ;
        wy2 *= orientationWeights[o] ;

        /*VL_PRINTF("%d %d - %d %d %f %f - %f %f %f %f - %d \n ",x,y,binx,biny,hx,hy,wx1,wx2,wy1,wy2,o);*/

        if (binx >= 0 && biny >=0) {
          at(binx,biny,orientation) += thisModulus * wx1 * wy1 ;
        }
        if (binx < (signed)self->hogWidth - 1 && biny >=0) {
          at(binx+1,biny,orientation) += thisModulus * wx2 * wy1 ;
        }
        if (binx < (signed)self->hogWidth - 1 && biny < (signed)self->hogHeight - 1) {
          at(binx+1,biny+1,orientation) += thisModulus * wx2 * wy2 ;
        }
        if (binx >= 0 && biny < (signed)self->hogHeight - 1) {
          at(binx,biny+1,orientation) += thisModulus * wx1 * wy2 ;
        }
      } /* next o */
    } /* next x */
  } /* next y */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, %r13
movq %r8, %r12
movq %rdx, 0x18(%rsp)
movq %rsi, %r14
movq %rdi, %r15
movq 0xb0(%rsp), %rbx
movq 0x10(%rdi), %rax
testl %ecx, %ecx
setne %cl
movq %rax, %xmm0
shlq %cl, %rax
movq %rax, 0x10(%rsp)
punpckldq 0x18acb(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x18ad3(%rip), %xmm0    # 0x2d170
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd 0x19297(%rip), %xmm0    # 0x2d948
divsd %xmm1, %xmm0
movsd %xmm0, 0x38(%rsp)
movq %r8, %rsi
movq %r9, %rdx
movq %rbx, %rcx
callq 0x1457b
movsd 0x38(%rsp), %xmm15
movq 0x58(%r15), %rcx
movq 0x60(%r15), %rax
movq %rax, %rdi
imulq %rcx, %rdi
movslq %r13d, %rdx
movslq %r12d, %rsi
movq %rbx, %xmm1
punpckldq 0x18a6e(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x18a76(%rip), %xmm1    # 0x2d170
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movq %rcx, 0x40(%rsp)
decl %ecx
movslq %ecx, %rcx
movq %rcx, 0x60(%rsp)
decl %eax
cltq
movq %rax, 0x58(%rsp)
xorl %eax, %eax
testq %rsi, %rsi
cmovleq %rax, %rsi
movq %rsi, 0x70(%rsp)
testq %rdx, %rdx
cmovleq %rax, %rdx
movq %rdx, 0x48(%rsp)
movsd 0x18a80(%rip), %xmm1    # 0x2d1c0
movsd 0x18aa8(%rip), %xmm2    # 0x2d1f0
xorps %xmm3, %xmm3
movss 0x18bd1(%rip), %xmm4    # 0x2d324
pcmpeqd %xmm5, %xmm5
cmpq 0x48(%rsp), %rax
je 0x14a5c
movq %rax, 0x50(%rsp)
cvtsi2sd %rax, %xmm6
addsd %xmm1, %xmm6
divsd %xmm0, %xmm6
addsd %xmm2, %xmm6
cvtsd2ss %xmm6, %xmm6
cvttss2si %xmm6, %rcx
cvtsi2ss %rcx, %xmm7
cmpneqps %xmm6, %xmm7
xorps %xmm8, %xmm8
cmpnleps %xmm6, %xmm8
andps %xmm7, %xmm8
movd %xmm8, %eax
andl $0x1, %eax
subq %rax, %rcx
cvtsi2ss %rcx, %xmm7
subss %xmm7, %xmm6
movaps %xmm4, %xmm7
subss %xmm6, %xmm7
movq %rcx, %r13
movq 0x40(%rsp), %rax
imulq %rax, %r13
movq %rcx, 0x68(%rsp)
leaq 0x1(%rcx), %rsi
imulq %rax, %rsi
xorl %r12d, %r12d
cmpq 0x70(%rsp), %r12
je 0x14a4f
andq $0x0, 0x8(%rsp)
movdqa %xmm5, 0x20(%rsp)
movss (%r14), %xmm8
ucomiss %xmm8, %xmm3
jae 0x14a3d
movq 0x18(%rsp), %rax
cvtss2sd (%rax), %xmm9
divsd %xmm15, %xmm9
cvtsd2ss %xmm9, %xmm9
cvttss2si %xmm9, %rcx
cvtsi2ss %rcx, %xmm10
cmpneqps %xmm9, %xmm10
xorps %xmm11, %xmm11
cmpnleps %xmm9, %xmm11
andps %xmm10, %xmm11
movd %xmm11, %eax
andl $0x1, %eax
subq %rax, %rcx
cvtsi2ss %rcx, %xmm10
subss %xmm10, %xmm9
testq %rcx, %rcx
jns 0x14848
movq 0x10(%r15), %rax
leaq (%rcx,%rax,2), %rcx
jmp 0x14839
movaps %xmm4, %xmm10
subss %xmm9, %xmm10
cmpl $0x0, 0x1c(%r15)
je 0x1488a
movq %rcx, %rax
cqto
movq 0x10(%rsp), %r8
idivq %r8
movq %rdx, 0x20(%rsp)
incq %rcx
movq %rcx, %rax
cqto
idivq %r8
movq %rdx, 0x28(%rsp)
movss %xmm10, 0x8(%rsp)
movss %xmm9, 0xc(%rsp)
jmp 0x148ad
xorl %eax, %eax
ucomiss %xmm9, %xmm10
setbe %al
addq %rax, %rcx
movq %rcx, %rax
cqto
idivq 0x10(%rsp)
movq %rdx, 0x20(%rsp)
movl $0x3f800000, 0x8(%rsp)  # imm = 0x3F800000
movq 0x68(%rsp), %r8
cmpq 0x58(%rsp), %r8
cvtsi2sd %r12, %xmm9
setl %r9b
addsd %xmm1, %xmm9
divsd %xmm0, %xmm9
addsd %xmm2, %xmm9
cvtsd2ss %xmm9, %xmm9
cvttss2si %xmm9, %rax
testq %r8, %r8
cvtsi2ss %rax, %xmm10
setns %cl
cmpneqps %xmm9, %xmm10
xorps %xmm11, %xmm11
cmpnleps %xmm9, %xmm11
andps %xmm10, %xmm11
movd %xmm11, %edx
andl $0x1, %edx
subq %rdx, %rax
cvtsi2ss %rax, %xmm10
subss %xmm10, %xmm9
movaps %xmm4, %xmm10
subss %xmm9, %xmm10
setns %dl
movq %rax, %r10
orq %r8, %r10
setns %r10b
cmpq 0x60(%rsp), %rax
setl %r11b
andb %r11b, %cl
andb %r9b, %r11b
andb %r9b, %dl
xorl %ebp, %ebp
cmpq $0x2, %rbp
je 0x14a3d
movq 0x20(%rsp,%rbp,8), %r8
testq %r8, %r8
js 0x14a35
movss 0x8(%rsp,%rbp,4), %xmm12
movaps %xmm10, %xmm11
mulss %xmm12, %xmm11
movaps %xmm7, %xmm13
mulss %xmm12, %xmm13
mulss %xmm8, %xmm11
testb %r10b, %r10b
je 0x1499c
movq %r8, %r9
imulq %rdi, %r9
leaq (,%rax,4), %rbx
addq 0x48(%r15), %rbx
leaq (%rbx,%r13,4), %rbx
movaps %xmm11, %xmm14
mulss %xmm13, %xmm14
addss (%rbx,%r9,4), %xmm14
movss %xmm14, (%rbx,%r9,4)
movaps %xmm9, %xmm14
mulss %xmm12, %xmm14
mulss %xmm8, %xmm14
testb %cl, %cl
je 0x149d8
movq %r8, %r9
imulq %rdi, %r9
leaq (,%rax,4), %rbx
addq 0x48(%r15), %rbx
leaq (%rbx,%r13,4), %rbx
mulss %xmm14, %xmm13
addss 0x4(%rbx,%r9,4), %xmm13
movss %xmm13, 0x4(%rbx,%r9,4)
mulss %xmm6, %xmm12
testb %r11b, %r11b
je 0x14a0c
movq %r8, %r9
imulq %rdi, %r9
leaq (,%rax,4), %rbx
addq 0x48(%r15), %rbx
leaq (%rbx,%rsi,4), %rbx
mulss %xmm12, %xmm14
addss 0x4(%rbx,%r9,4), %xmm14
movss %xmm14, 0x4(%rbx,%r9,4)
testb %dl, %dl
je 0x14a35
imulq %rdi, %r8
leaq (,%rax,4), %r9
addq 0x48(%r15), %r9
leaq (%r9,%rsi,4), %r9
mulss %xmm12, %xmm11
addss (%r9,%r8,4), %xmm11
movss %xmm11, (%r9,%r8,4)
incq %rbp
jmp 0x14935
addq $0x4, 0x18(%rsp)
addq $0x4, %r14
incq %r12
jmp 0x147ce
movq 0x50(%rsp), %rax
incq %rax
jmp 0x14757
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq