// File: /workspace/github_c_makefile_star2_O1/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 $0x68, %rsp
movq %r9, %rbp
movq %r8, %r12
movq %rdx, 0x30(%rsp)
movq %rsi, %r14
movq %rdi, %r15
movq 0xa0(%rsp), %rbx
movq 0x10(%rdi), %r13
testl %ecx, %ecx
setne %cl
movq %r13, %rax
shlq %cl, %rax
movq %rax, 0x20(%rsp)
movq %r8, %rsi
movq %r9, %rdx
movq %rbx, %rcx
callq 0x15c90
movslq %ebp, %rax
movq %rax, 0x40(%rsp)
testq %rax, %rax
jle 0x161b1
movq %r13, %xmm0
punpckldq 0x1d3a6(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x1d3ae(%rip), %xmm0    # 0x33190
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd 0x1db92(%rip), %xmm0    # 0x33988
divsd %xmm1, %xmm0
movq 0x58(%r15), %rcx
movq 0x60(%r15), %rax
movq %rax, %r8
imulq %rcx, %r8
movq %rbx, %xmm2
punpckldq 0x1d36a(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
movslq %r12d, %rdx
movq %rdx, 0x28(%rsp)
subpd 0x1d36a(%rip), %xmm2    # 0x33190
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
movq %rcx, 0x38(%rsp)
decl %ecx
movslq %ecx, %rcx
movq %rcx, 0x58(%rsp)
decl %eax
cltq
movq %rax, 0x50(%rsp)
xorl %eax, %eax
movsd 0x1d37c(%rip), %xmm2    # 0x331d0
movsd 0x1d3bc(%rip), %xmm3    # 0x33218
xorps %xmm4, %xmm4
movss 0x1d4e5(%rip), %xmm5    # 0x3334c
pcmpeqd %xmm6, %xmm6
cmpq $0x0, 0x28(%rsp)
movq %rax, 0x48(%rsp)
jle 0x1619e
xorps %xmm7, %xmm7
cvtsi2sd %rax, %xmm7
addsd %xmm2, %xmm7
divsd %xmm1, %xmm7
addsd %xmm3, %xmm7
cvtsd2ss %xmm7, %xmm7
cvttss2si %xmm7, %rcx
xorps %xmm8, %xmm8
cvtsi2ss %rcx, %xmm8
cmpneqps %xmm7, %xmm8
xorps %xmm9, %xmm9
cmpnleps %xmm7, %xmm9
andps %xmm8, %xmm9
movd %xmm9, %eax
andl $0x1, %eax
subq %rax, %rcx
xorps %xmm8, %xmm8
cvtsi2ss %rcx, %xmm8
subss %xmm8, %xmm7
movaps %xmm5, %xmm8
subss %xmm7, %xmm8
movq %rcx, %rbp
movq 0x38(%rsp), %rax
imulq %rax, %rbp
movq %rcx, 0x60(%rsp)
leaq 0x1(%rcx), %rdi
imulq %rax, %rdi
xorl %r12d, %r12d
movq $0x0, 0x8(%rsp)
movdqa %xmm6, 0x10(%rsp)
movss (%r14), %xmm9
ucomiss %xmm9, %xmm4
jae 0x16186
movq 0x30(%rsp), %rax
xorps %xmm10, %xmm10
cvtss2sd (%rax), %xmm10
divsd %xmm0, %xmm10
cvtsd2ss %xmm10, %xmm10
cvttss2si %xmm10, %rax
xorps %xmm11, %xmm11
cvtsi2ss %rax, %xmm11
cmpneqps %xmm10, %xmm11
xorps %xmm12, %xmm12
cmpnleps %xmm10, %xmm12
andps %xmm11, %xmm12
movd %xmm12, %ecx
andl $0x1, %ecx
subq %rcx, %rax
movq %rax, %rcx
jns 0x15f67
movq 0x10(%r15), %rdx
addq %rdx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
js 0x15f62
xorps %xmm11, %xmm11
cvtsi2ss %rax, %xmm11
subss %xmm11, %xmm10
movaps %xmm5, %xmm11
subss %xmm10, %xmm11
cmpl $0x0, 0x1c(%r15)
je 0x15fb7
movq %rcx, %rax
cqto
movq 0x20(%rsp), %rsi
idivq %rsi
movq %rdx, 0x10(%rsp)
incq %rcx
movq %rcx, %rax
cqto
idivq %rsi
movq %rdx, 0x18(%rsp)
movss %xmm11, 0x8(%rsp)
movss %xmm10, 0xc(%rsp)
jmp 0x15fe3
xorl %eax, %eax
ucomiss %xmm10, %xmm11
setbe %al
addq %rax, %rcx
movq %rcx, %rax
cqto
idivq 0x20(%rsp)
movq %rdx, 0x10(%rsp)
movl $0x3f800000, 0x8(%rsp)  # imm = 0x3F800000
movq $-0x1, 0x18(%rsp)
movq 0x50(%rsp), %rax
movq 0x60(%rsp), %rsi
cmpq %rax, %rsi
setl %r9b
cmpq %rax, %rsi
xorps %xmm10, %xmm10
cvtsi2sd %r12, %xmm10
setl %al
addsd %xmm2, %xmm10
divsd %xmm1, %xmm10
addsd %xmm3, %xmm10
cvtsd2ss %xmm10, %xmm10
cvttss2si %xmm10, %rcx
testq %rsi, %rsi
xorps %xmm11, %xmm11
cvtsi2ss %rcx, %xmm11
setns %dl
cmpneqps %xmm10, %xmm11
xorps %xmm12, %xmm12
cmpnleps %xmm10, %xmm12
andps %xmm11, %xmm12
movd %xmm12, %r10d
andl $0x1, %r10d
subq %r10, %rcx
xorps %xmm11, %xmm11
cvtsi2ss %rcx, %xmm11
subss %xmm11, %xmm10
movaps %xmm5, %xmm11
subss %xmm10, %xmm11
setns %r10b
movq %rcx, %r11
orq %rsi, %r11
setns %r13b
cmpq 0x58(%rsp), %rcx
setl %r11b
andb %r11b, %dl
andb %r11b, %al
andb %r9b, %r10b
xorl %r11d, %r11d
movq 0x10(%rsp,%r11,8), %rsi
testq %rsi, %rsi
js 0x16179
movss 0x8(%rsp,%r11,4), %xmm13
movaps %xmm11, %xmm12
mulss %xmm13, %xmm12
movaps %xmm8, %xmm14
mulss %xmm13, %xmm14
mulss %xmm9, %xmm12
testb %r13b, %r13b
je 0x160e0
movq %rsi, %r9
imulq %r8, %r9
leaq (,%rcx,4), %rbx
addq 0x48(%r15), %rbx
leaq (%rbx,%rbp,4), %rbx
movaps %xmm12, %xmm15
mulss %xmm14, %xmm15
addss (%rbx,%r9,4), %xmm15
movss %xmm15, (%rbx,%r9,4)
movaps %xmm10, %xmm15
mulss %xmm13, %xmm15
mulss %xmm9, %xmm15
testb %dl, %dl
je 0x1611c
movq %rsi, %r9
imulq %r8, %r9
leaq (,%rcx,4), %rbx
addq 0x48(%r15), %rbx
leaq (%rbx,%rbp,4), %rbx
mulss %xmm15, %xmm14
addss 0x4(%rbx,%r9,4), %xmm14
movss %xmm14, 0x4(%rbx,%r9,4)
mulss %xmm7, %xmm13
testb %al, %al
je 0x1614f
movq %rsi, %r9
imulq %r8, %r9
leaq (,%rcx,4), %rbx
addq 0x48(%r15), %rbx
leaq (%rbx,%rdi,4), %rbx
mulss %xmm13, %xmm15
addss 0x4(%rbx,%r9,4), %xmm15
movss %xmm15, 0x4(%rbx,%r9,4)
testb %r10b, %r10b
je 0x16179
imulq %r8, %rsi
leaq (,%rcx,4), %r9
addq 0x48(%r15), %r9
leaq (%r9,%rdi,4), %r9
mulss %xmm13, %xmm12
addss (%r9,%rsi,4), %xmm12
movss %xmm12, (%r9,%rsi,4)
incq %r11
cmpq $0x1, %r11
je 0x16083
addq $0x4, 0x30(%rsp)
addq $0x4, %r14
incq %r12
cmpq 0x28(%rsp), %r12
jne 0x15ef2
movq 0x48(%rsp), %rax
incq %rax
cmpq 0x40(%rsp), %rax
jne 0x15e6b
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq