// File: /workspace/github_c_makefile_star2_O3/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 $0x58, %rsp
movq %r9, %rbp
movq %r8, %r12
movq %rdx, 0x10(%rsp)
movq %rsi, %r14
movq %rdi, %r15
movq 0x90(%rsp), %r13
movq 0x10(%rdi), %rbx
testl %ecx, %ecx
setne %cl
movq %rbx, %rax
shlq %cl, %rax
movq %rax, 0x40(%rsp)
movq %r8, %rsi
movq %r9, %rdx
movq %r13, %rcx
callq 0x15c5f
movslq %ebp, %rax
movq %rax, 0x20(%rsp)
testq %rax, %rax
jle 0x16155
movq %rbx, %xmm0
punpckldq 0x1c3dc(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x1c3e4(%rip), %xmm0    # 0x32190
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd 0x1cbc8(%rip), %xmm0    # 0x32988
divsd %xmm1, %xmm0
movq 0x58(%r15), %rcx
movq 0x60(%r15), %rax
movq %rax, %r9
imulq %rcx, %r9
movq %r13, %xmm2
punpckldq 0x1c3a0(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x1c3a8(%rip), %xmm2    # 0x32190
movslq %r12d, %rdx
movq %rdx, 0x8(%rsp)
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
movq %rcx, 0x18(%rsp)
decl %ecx
movslq %ecx, %rcx
movq %rcx, 0x38(%rsp)
decl %eax
cltq
movq %rax, 0x30(%rsp)
movsd 0x1c3c4(%rip), %xmm2    # 0x321e0
movsd 0x1c404(%rip), %xmm3    # 0x32228
xorps %xmm4, %xmm4
movss 0x1c52d(%rip), %xmm5    # 0x3235c
xorl %eax, %eax
cmpq $0x0, 0x8(%rsp)
movq %rax, 0x28(%rsp)
jle 0x16142
xorps %xmm6, %xmm6
cvtsi2sd %rax, %xmm6
addsd %xmm2, %xmm6
divsd %xmm1, %xmm6
addsd %xmm3, %xmm6
cvtsd2ss %xmm6, %xmm6
cvttss2si %xmm6, %rcx
xorps %xmm7, %xmm7
cvtsi2ss %rcx, %xmm7
cmpneqps %xmm6, %xmm7
xorps %xmm8, %xmm8
cmpnleps %xmm6, %xmm8
andps %xmm7, %xmm8
movd %xmm8, %eax
andl $0x1, %eax
subq %rax, %rcx
xorps %xmm7, %xmm7
cvtsi2ss %rcx, %xmm7
subss %xmm7, %xmm6
movaps %xmm5, %xmm7
subss %xmm6, %xmm7
movq %rcx, %rdi
movq 0x18(%rsp), %rax
imulq %rax, %rdi
movq %rcx, 0x48(%rsp)
leaq 0x1(%rcx), %r12
imulq %rax, %r12
xorl %r13d, %r13d
xorl %eax, %eax
movl %eax, (%rsp)
movl %eax, 0x4(%rsp)
movq %r14, 0x50(%rsp)
movss (%r14), %xmm8
ucomiss %xmm8, %xmm4
jae 0x16125
movq 0x10(%rsp), %rax
xorps %xmm9, %xmm9
cvtss2sd (%rax), %xmm9
divsd %xmm0, %xmm9
cvtsd2ss %xmm9, %xmm9
cvttss2si %xmm9, %rax
xorps %xmm10, %xmm10
cvtsi2ss %rax, %xmm10
cmpneqps %xmm9, %xmm10
xorps %xmm11, %xmm11
cmpnleps %xmm9, %xmm11
andps %xmm10, %xmm11
movd %xmm11, %ecx
andl $0x1, %ecx
subq %rcx, %rax
movq %rax, %rsi
jns 0x15f26
movq 0x10(%r15), %rcx
addq %rcx, %rcx
movq %rax, %rsi
addq %rcx, %rsi
js 0x15f21
xorps %xmm10, %xmm10
cvtsi2ss %rax, %xmm10
subss %xmm10, %xmm9
movaps %xmm5, %xmm10
subss %xmm9, %xmm10
cmpl $0x0, 0x1c(%r15)
movq 0x40(%rsp), %r8
je 0x15f64
leaq 0x1(%rsi), %rax
cqto
idivq %r8
movq %rdx, %rcx
movss %xmm10, (%rsp)
movss %xmm9, 0x4(%rsp)
jmp 0x15f7e
xorl %eax, %eax
ucomiss %xmm9, %xmm10
setbe %al
addq %rax, %rsi
movl $0x3f800000, (%rsp)     # imm = 0x3F800000
movq $-0x1, %rcx
movq 0x48(%rsp), %r10
cmpq 0x30(%rsp), %r10
setl %bl
testq %r10, %r10
setns %bpl
movq %rsi, %rax
cqto
xorps %xmm9, %xmm9
cvtsi2sd %r13, %xmm9
idivq %r8
addsd %xmm2, %xmm9
divsd %xmm1, %xmm9
addsd %xmm3, %xmm9
cvtsd2ss %xmm9, %xmm9
cvttss2si %xmm9, %rax
xorps %xmm10, %xmm10
cvtsi2ss %rax, %xmm10
cmpneqps %xmm9, %xmm10
xorps %xmm11, %xmm11
cmpnleps %xmm9, %xmm11
andps %xmm10, %xmm11
movd %xmm11, %esi
andl $0x1, %esi
subq %rsi, %rax
xorps %xmm10, %xmm10
cvtsi2ss %rax, %xmm10
setns %sil
movq %rax, %r8
orq %r10, %r8
setns %r10b
cmpq 0x38(%rsp), %rax
setl %r11b
andb %r11b, %bpl
andb %bl, %r11b
andb %bl, %sil
subss %xmm10, %xmm9
movaps %xmm5, %xmm10
subss %xmm9, %xmm10
movb $0x1, %bl
movq %rsp, %r8
testq %rdx, %rdx
js 0x1610f
movss (%r8), %xmm12
movaps %xmm10, %xmm11
mulss %xmm12, %xmm11
movaps %xmm7, %xmm13
mulss %xmm12, %xmm13
mulss %xmm8, %xmm11
testb %r10b, %r10b
je 0x16074
movq %rdx, %r8
imulq %r9, %r8
leaq (,%rax,4), %r14
addq 0x48(%r15), %r14
leaq (%r14,%rdi,4), %r14
movaps %xmm11, %xmm14
mulss %xmm13, %xmm14
addss (%r14,%r8,4), %xmm14
movss %xmm14, (%r14,%r8,4)
movaps %xmm9, %xmm14
mulss %xmm12, %xmm14
mulss %xmm8, %xmm14
testb %bpl, %bpl
je 0x160b1
movq %rdx, %r8
imulq %r9, %r8
leaq (,%rax,4), %r14
addq 0x48(%r15), %r14
leaq (%r14,%rdi,4), %r14
mulss %xmm14, %xmm13
addss 0x4(%r14,%r8,4), %xmm13
movss %xmm13, 0x4(%r14,%r8,4)
mulss %xmm6, %xmm12
testb %r11b, %r11b
je 0x160e5
movq %rdx, %r8
imulq %r9, %r8
leaq (,%rax,4), %r14
addq 0x48(%r15), %r14
leaq (%r14,%r12,4), %r14
mulss %xmm12, %xmm14
addss 0x4(%r14,%r8,4), %xmm14
movss %xmm14, 0x4(%r14,%r8,4)
testb %sil, %sil
je 0x1610f
imulq %r9, %rdx
leaq (,%rax,4), %r8
addq 0x48(%r15), %r8
leaq (%r8,%r12,4), %r8
mulss %xmm12, %xmm11
addss (%r8,%rdx,4), %xmm11
movss %xmm11, (%r8,%rdx,4)
movq %rcx, %rdx
leaq 0x4(%rsp), %r8
testb $0x1, %bl
movl $0x0, %ebx
jne 0x1601e
addq $0x4, 0x10(%rsp)
movq 0x50(%rsp), %r14
addq $0x4, %r14
incq %r13
cmpq 0x8(%rsp), %r13
jne 0x15eb2
movq 0x28(%rsp), %rax
incq %rax
cmpq 0x20(%rsp), %rax
jne 0x15e31
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq