// File: /workspace/github_c_makefile_star2_O3/zpole[P]IICV/vl/hog.c
// Function: vl_hog_put_image
void
vl_hog_put_image (VlHog * self,
                  float const * image,
                  vl_size width, vl_size height, vl_size numChannels,
                  vl_size cellSize)
{
  vl_size hogStride ;
  vl_size channelStride = width * height ;
  vl_index x, y ;
  vl_uindex k ;

  assert(self) ;
  assert(image) ;

  /* 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])

  /* compute gradients and map the to HOG cells by bilinear interpolation */
  for (y = 1 ; y < (signed)height - 1 ; ++y) {
    for (x = 1 ; x < (signed)width - 1 ; ++x) {
      float gradx = 0 ;
      float grady = 0 ;
      float gradNorm ;
      float orientationWeights [2] = {-1, -1} ;
      vl_index orientationBins [2] = {-1, -1} ;
      vl_index orientation = 0 ;
      float hx, hy, wx1, wx2, wy1, wy2 ;
      vl_index binx, biny, o ;

      /*
       Compute the gradient at (x,y). The image channel with
       the maximum gradient at each location is selected.
       */
      {
        float const * iter = image + y * width + x ;
        float gradNorm2 = 0 ;
        for (k = 0 ; k < numChannels ; ++k) {
          float gradx_ = *(iter + 1) - *(iter - 1) ;
          float grady_ = *(iter + width)  - *(iter - width) ;
          float gradNorm2_ = gradx_ * gradx_ + grady_ * grady_ ;
          if (gradNorm2_ > gradNorm2) {
            gradx = gradx_ ;
            grady = grady_ ;
            gradNorm2 = gradNorm2_ ;
          }
          iter += channelStride ;
        }
        gradNorm = sqrtf(gradNorm2) ;
      }

      /*
       Map the gradient to the closest and second closets orientation bins.
       There are numOrientations orientation in the interval [0,pi).
       The next numOriantations are the symmetric ones, for a total
       of 2*numOrientation directed orientations.
       */
      for (k = 0 ; k < self->numOrientations ; ++k) {
        float orientationScore_ = gradx * self->orientationX[k] +  grady * self->orientationY[k] ;
        vl_index orientationBin_ = k ;
        if (orientationScore_ < 0) {
          orientationScore_ = - orientationScore_ ;
          orientationBin_ += self->numOrientations ;
        }
        if (orientationScore_ > orientationWeights[0]) {
          orientationBins[1] = orientationBins[0] ;
          orientationWeights[1] = orientationWeights[0] ;
          orientationBins[0] = orientationBin_ ; ;
          orientationWeights[0] = orientationScore_ ;
        } else if (orientationScore_ > orientationWeights[1]) {
          orientationBins[1] = orientationBin_ ;
          orientationWeights[1] = orientationScore_ ;
        }
      }

      if (self->useBilinearOrientationAssigment) {
        /* min(1.0,...) guards against small overflows causing NaNs */
        float angle0 = acosf(VL_MIN(orientationWeights[0] / VL_MAX(gradNorm, 1e-10),1.0)) ;
        orientationWeights[1] = angle0 / (VL_PI / self->numOrientations) ;
        orientationWeights[0] = 1 - orientationWeights[1] ;
      } else {
        orientationWeights[0] = 1 ;
        orientationBins[1] = -1 ;
      }

      for (o = 0 ; o < 2 ; ++o) {
        float ow ;
        /*
         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 ;

        /*  (x - (w-1)/2) / w = (x + 0.5)/w - 0.5 */
        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 ;

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %r9, %rbp
movq %r8, %r14
movq %rcx, %r13
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r12
movq %rdx, %rsi
movq %rcx, %rdx
movq %r9, %rcx
callq 0x15c5f
leal -0x1(%r13), %eax
cltq
movq %rax, 0x80(%rsp)
cmpq $0x2, %rax
jl 0x15c4d
movabsq $-0x100000000, %r11     # imm = 0xFFFFFFFF00000000
movq 0x60(%r12), %rax
imulq 0x58(%r12), %rax
movq %rax, 0x18(%rsp)
movq %r15, %rax
shlq $0x20, %rax
addq %r11, %rax
movq %rbp, %xmm0
punpckldq 0x1cae9(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
sarq $0x20, %rax
movq %rax, 0x50(%rsp)
subpd 0x1cae8(%rip), %xmm0    # 0x32190
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, 0xa0(%rsp)
leaq 0x4(%rbx,%r15,8), %rax
movq %rax, 0x40(%rsp)
leaq (,%r15,4), %rax
movq %rax, 0x78(%rsp)
imulq %r15, %r13
shlq $0x2, %r13
leaq (%rbx,%r15,4), %rax
addq $0x8, %rax
movq %rax, 0x38(%rsp)
addq $0x4, %rbx
movq %rbx, 0x48(%rsp)
movl $0x1, %eax
movq %rax, 0x20(%rsp)
movss 0x1cc58(%rip), %xmm5    # 0x3235c
movaps 0x1c905(%rip), %xmm6    # 0x32010
movq %r14, 0x90(%rsp)
movq %r13, 0x88(%rsp)
cmpq $0x2, 0x50(%rsp)
jl 0x15c1e
xorps %xmm0, %xmm0
cvtsi2sdq 0x20(%rsp), %xmm0
addsd 0x1caa7(%rip), %xmm0    # 0x321e0
divsd 0xa0(%rsp), %xmm0
addsd 0x1cade(%rip), %xmm0    # 0x32228
cvtsd2ss %xmm0, %xmm7
cvttss2si %xmm7, %rbx
xorps %xmm0, %xmm0
cvtsi2ss %rbx, %xmm0
cmpneqps %xmm7, %xmm0
xorpd %xmm1, %xmm1
cmpnleps %xmm7, %xmm1
andps %xmm0, %xmm1
movd %xmm1, %eax
andl $0x1, %eax
subq %rax, %rbx
xorps %xmm0, %xmm0
cvtsi2ss %rbx, %xmm0
subss %xmm0, %xmm7
movaps %xmm5, %xmm8
subss %xmm7, %xmm8
leaq 0x1(%rbx), %rax
movq %rax, 0x58(%rsp)
movl $0x1, %eax
movq %rax, 0x28(%rsp)
movq 0x38(%rsp), %r15
movq 0x48(%rsp), %rdx
movq 0x40(%rsp), %rbp
movaps %xmm7, 0xb0(%rsp)
movss %xmm8, 0x14(%rsp)
movl $0xbf800000, %eax       # imm = 0xBF800000
movl %eax, 0x10(%rsp)
movl %eax, 0xc(%rsp)
testq %r14, %r14
je 0x15838
xorps %xmm2, %xmm2
xorl %eax, %eax
xorps %xmm9, %xmm9
xorps %xmm1, %xmm1
movss (%r15,%rax), %xmm10
subss -0x8(%r15,%rax), %xmm10
movss (%rbp,%rax), %xmm3
subss (%rdx,%rax), %xmm3
movaps %xmm3, %xmm0
mulss %xmm3, %xmm0
movaps %xmm10, %xmm4
mulss %xmm10, %xmm4
addss %xmm0, %xmm4
ucomiss %xmm1, %xmm4
ja 0x1580d
movaps %xmm2, %xmm10
movaps %xmm4, %xmm0
maxss %xmm1, %xmm0
cmpltss %xmm4, %xmm1
andps %xmm1, %xmm3
andnps %xmm9, %xmm1
orps %xmm3, %xmm1
movaps %xmm1, %xmm9
addq %r13, %rax
movaps %xmm10, %xmm2
movaps %xmm0, %xmm1
decq %r14
jne 0x157d8
jmp 0x15843
xorps %xmm0, %xmm0
xorps %xmm9, %xmm9
xorps %xmm10, %xmm10
ucomiss 0x1cb3e(%rip), %xmm0    # 0x32388
movq %rdx, 0x98(%rsp)
jb 0x1585d
xorps %xmm4, %xmm4
sqrtss %xmm0, %xmm4
jmp 0x158a7
movaps %xmm9, 0x60(%rsp)
movss %xmm10, 0x34(%rsp)
callq 0x95e0
movss 0x34(%rsp), %xmm10
movaps 0x60(%rsp), %xmm9
movss 0x14(%rsp), %xmm8
movaps 0xb0(%rsp), %xmm7
movaps 0x1c77e(%rip), %xmm6    # 0x32010
movss 0x1cac2(%rip), %xmm5    # 0x3235c
movabsq $-0x100000000, %r11     # imm = 0xFFFFFFFF00000000
movaps %xmm0, %xmm4
movq 0x10(%r12), %rcx
movq $-0x1, %rax
movq $-0x1, %r14
movq $-0x1, %r13
movsd 0x1c93f(%rip), %xmm0    # 0x32208
testq %rcx, %rcx
je 0x15947
movq 0x38(%r12), %rdx
movq 0x40(%r12), %rsi
movss 0x1caf8(%rip), %xmm0    # 0x323d8
movaps %xmm0, %xmm1
xorl %edi, %edi
movss (%rsi,%rdi,4), %xmm2
mulss %xmm9, %xmm2
movss (%rdx,%rdi,4), %xmm3
mulss %xmm10, %xmm3
addss %xmm2, %xmm3
movaps %xmm3, %xmm2
xorps %xmm6, %xmm2
ucomiss %xmm3, %xmm2
movl $0x0, %r8d
cmovaq %rcx, %r8
maxss %xmm3, %xmm2
addq %rdi, %r8
ucomiss %xmm0, %xmm2
jbe 0x1592a
movq %r13, %r14
movaps %xmm0, %xmm1
movq %r8, %r13
movaps %xmm2, %xmm0
jmp 0x15935
ucomiss %xmm1, %xmm2
jbe 0x15935
movq %r8, %r14
movaps %xmm2, %xmm1
incq %rdi
cmpq %rdi, %rcx
jne 0x158e5
movss %xmm1, 0xc(%rsp)
cvtss2sd %xmm0, %xmm0
cmpl $0x0, 0x1c(%r12)
movaps %xmm5, %xmm1
je 0x159f8
xorps %xmm1, %xmm1
cvtss2sd %xmm4, %xmm1
maxsd 0x1d043(%rip), %xmm1    # 0x329a8
divsd %xmm1, %xmm0
minsd 0x1c8ff(%rip), %xmm0    # 0x32270
cvtsd2ss %xmm0, %xmm0
movss %xmm4, 0x60(%rsp)
callq 0x9520
movss 0x60(%rsp), %xmm4
movss 0x14(%rsp), %xmm8
movaps 0xb0(%rsp), %xmm7
movaps 0x1c674(%rip), %xmm6    # 0x32010
movss 0x1c9b8(%rip), %xmm5    # 0x3235c
movabsq $-0x100000000, %r11     # imm = 0xFFFFFFFF00000000
cvtss2sd %xmm0, %xmm0
movsd 0x10(%r12), %xmm1
unpcklps 0x1c7c0(%rip), %xmm1    # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x1c7c8(%rip), %xmm1    # 0x32190
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
movsd 0x1cfac(%rip), %xmm1    # 0x32988
divsd %xmm2, %xmm1
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xc(%rsp)
movaps %xmm5, %xmm1
subss %xmm0, %xmm1
movq %r14, %rax
xorps %xmm0, %xmm0
cvtsi2sdq 0x28(%rsp), %xmm0
addsd 0x1c7d6(%rip), %xmm0    # 0x321e0
divsd 0xa0(%rsp), %xmm0
addsd 0x1c80d(%rip), %xmm0    # 0x32228
cvtsd2ss %xmm0, %xmm0
cvttss2si %xmm0, %rcx
xorps %xmm2, %xmm2
cvtsi2ss %rcx, %xmm2
movss %xmm1, 0x10(%rsp)
cmpneqps %xmm0, %xmm2
xorps %xmm1, %xmm1
cmpnleps %xmm0, %xmm1
andps %xmm2, %xmm1
movd %xmm1, %edx
andl $0x1, %edx
subq %rdx, %rcx
xorps %xmm1, %xmm1
cvtsi2ss %rcx, %xmm1
subss %xmm1, %xmm0
movaps %xmm5, %xmm1
subss %xmm0, %xmm1
movq %rcx, %rdx
orq %rbx, %rdx
setns %dl
movb $0x1, %sil
leaq 0x10(%rsp), %rdi
movq 0x90(%rsp), %r14
testq %r13, %r13
js 0x15bd3
movss (%rdi), %xmm2
movq 0x58(%r12), %rdi
testb %dl, %dl
je 0x15ac9
movaps %xmm4, %xmm3
mulss %xmm2, %xmm3
mulss %xmm1, %xmm3
movq %rdi, %r8
imulq %rbx, %r8
movq %r13, %r9
imulq 0x18(%rsp), %r9
leaq (,%rcx,4), %r10
addq 0x48(%r12), %r10
leaq (%r10,%r8,4), %r8
mulss %xmm8, %xmm3
addss (%r8,%r9,4), %xmm3
movss %xmm3, (%r8,%r9,4)
movq %rdi, %r8
shlq $0x20, %r8
addq %r11, %r8
sarq $0x20, %r8
cmpq %r8, %rcx
jge 0x15b2a
testq %rbx, %rbx
js 0x15b2a
movaps %xmm4, %xmm3
mulss %xmm2, %xmm3
mulss %xmm0, %xmm3
movq %rdi, %r9
imulq %rbx, %r9
movq %r13, %r10
imulq 0x18(%rsp), %r10
leaq (,%rcx,4), %r11
addq 0x48(%r12), %r11
leaq (%r11,%r9,4), %r9
movabsq $-0x100000000, %r11     # imm = 0xFFFFFFFF00000000
mulss %xmm8, %xmm3
addss 0x4(%r9,%r10,4), %xmm3
movss %xmm3, 0x4(%r9,%r10,4)
cmpq %r8, %rcx
jge 0x15b84
movq 0x60(%r12), %r8
shlq $0x20, %r8
addq %r11, %r8
sarq $0x20, %r8
cmpq %r8, %rbx
jge 0x15b84
movaps %xmm4, %xmm3
mulss %xmm2, %xmm3
mulss %xmm0, %xmm3
movq %rdi, %r8
imulq 0x58(%rsp), %r8
movq %r13, %r9
imulq 0x18(%rsp), %r9
leaq (,%rcx,4), %r10
addq 0x48(%r12), %r10
leaq (%r10,%r8,4), %r8
mulss %xmm7, %xmm3
addss 0x4(%r8,%r9,4), %xmm3
movss %xmm3, 0x4(%r8,%r9,4)
testq %rcx, %rcx
js 0x15bd3
movq 0x60(%r12), %r8
shlq $0x20, %r8
addq %r11, %r8
sarq $0x20, %r8
cmpq %r8, %rbx
jge 0x15bd3
mulss %xmm4, %xmm2
mulss %xmm1, %xmm2
imulq 0x58(%rsp), %rdi
imulq 0x18(%rsp), %r13
leaq (,%rcx,4), %r8
addq 0x48(%r12), %r8
leaq (%r8,%rdi,4), %rdi
mulss %xmm7, %xmm2
addss (%rdi,%r13,4), %xmm2
movss %xmm2, (%rdi,%r13,4)
movq %rax, %r13
leaq 0xc(%rsp), %rdi
testb $0x1, %sil
movl $0x0, %esi
jne 0x15a76
movq 0x28(%rsp), %rax
incq %rax
addq $0x4, %rbp
movq 0x98(%rsp), %rdx
addq $0x4, %rdx
addq $0x4, %r15
movq %rax, 0x28(%rsp)
cmpq 0x50(%rsp), %rax
movq 0x88(%rsp), %r13
jne 0x157ba
movq 0x20(%rsp), %rcx
incq %rcx
movq 0x78(%rsp), %rax
addq %rax, 0x40(%rsp)
addq %rax, 0x48(%rsp)
addq %rax, 0x38(%rsp)
movq %rcx, 0x20(%rsp)
cmpq 0x80(%rsp), %rcx
jne 0x1571b
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq