// File: /workspace/github_c_makefile_star2_O2/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 $0xb8, %rsp
movq %r9, %rbp
movq %r8, 0x70(%rsp)
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r13
movq %rdx, %rsi
movq %rcx, %rdx
movq %r9, %rcx
callq 0x1457b
movq 0x60(%r13), %r12
imulq 0x58(%r13), %r12
leal -0x1(%r14), %eax
cltq
movq %rax, 0x48(%rsp)
leal -0x1(%rbx), %eax
movq %rbp, %xmm0
punpckldq 0x190c4(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x190cc(%rip), %xmm0    # 0x2d170
cltq
movq %rax, 0x78(%rsp)
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, 0x90(%rsp)
leaq (,%rbx,4), %rax
movq %rax, 0x40(%rsp)
leaq (%r15,%rbx,4), %rbp
addq $0x8, %rbp
imulq %rbx, %r14
shlq $0x2, %r14
addq $0x4, %r15
shlq $0x3, %rbx
movq %rbx, 0x68(%rsp)
pushq $0x1
popq %rcx
movss 0x1922f(%rip), %xmm4    # 0x2d324
cmpq 0x48(%rsp), %rcx
jge 0x14569
movq %rcx, 0x50(%rsp)
cvtsi2sd %rcx, %xmm0
addsd 0x190ae(%rip), %xmm0    # 0x2d1c0
divsd 0x90(%rsp), %xmm0
addsd 0x190cd(%rip), %xmm0    # 0x2d1f0
cvtsd2ss %xmm0, %xmm2
cvttss2si %xmm2, %rbx
cvtsi2ss %rbx, %xmm0
cmpneqps %xmm2, %xmm0
xorpd %xmm1, %xmm1
cmpnleps %xmm2, %xmm1
andps %xmm0, %xmm1
movd %xmm1, %eax
andl $0x1, %eax
subq %rax, %rbx
cvtsi2ss %rbx, %xmm0
subss %xmm0, %xmm2
movaps %xmm2, 0x80(%rsp)
movaps %xmm4, %xmm0
subss %xmm2, %xmm0
movss %xmm0, 0x4(%rsp)
leaq 0x1(%rbx), %rax
movq %rax, 0x18(%rsp)
movq %r15, 0x60(%rsp)
movq %rbp, 0x58(%rsp)
pushq $0x1
popq %rax
cmpq 0x78(%rsp), %rax
jge 0x14547
movq %rax, 0x10(%rsp)
movq 0x68(%rsp), %rax
addq %r15, %rax
xorps %xmm0, %xmm0
movq 0x70(%rsp), %rcx
xorl %edx, %edx
xorps %xmm5, %xmm5
xorps %xmm6, %xmm6
subq $0x1, %rcx
jb 0x14200
movss (%rbp,%rdx), %xmm1
subss -0x8(%rbp,%rdx), %xmm1
movss (%rax,%rdx), %xmm2
subss (%r15,%rdx), %xmm2
movaps %xmm2, %xmm4
mulss %xmm2, %xmm4
movaps %xmm1, %xmm3
mulss %xmm1, %xmm3
addss %xmm4, %xmm3
ucomiss %xmm0, %xmm3
ja 0x141dd
movaps %xmm6, %xmm1
movaps %xmm3, %xmm4
maxss %xmm0, %xmm4
cmpltss %xmm3, %xmm0
andps %xmm0, %xmm2
andnps %xmm5, %xmm0
orps %xmm2, %xmm0
movaps %xmm0, %xmm5
addq %r14, %rdx
movaps %xmm4, %xmm0
movaps %xmm1, %xmm6
jmp 0x141a6
ucomiss 0x197a9(%rip), %xmm0    # 0x2d9b0
jb 0x1420f
sqrtss %xmm0, %xmm7
jmp 0x14231
movaps %xmm5, 0x20(%rsp)
movaps %xmm6, 0xa0(%rsp)
callq 0x9610
movaps 0xa0(%rsp), %xmm6
movaps 0x20(%rsp), %xmm5
movaps %xmm0, %xmm7
movaps 0x19138(%rip), %xmm4    # 0x2d370
movq 0x10(%r13), %rax
pushq $-0x1
popq %rdx
movq %rdx, %rcx
movss 0x1915e(%rip), %xmm0    # 0x2d3a8
movaps %xmm0, %xmm1
xorl %esi, %esi
cmpq %rsi, %rax
je 0x142af
movq 0x38(%r13), %rdi
movq 0x40(%r13), %r8
movss (%r8,%rsi,4), %xmm2
mulss %xmm5, %xmm2
movss (%rdi,%rsi,4), %xmm3
mulss %xmm6, %xmm3
addss %xmm2, %xmm3
movaps %xmm3, %xmm2
xorps %xmm4, %xmm2
ucomiss %xmm3, %xmm2
movl $0x0, %edi
cmovaq %rax, %rdi
maxss %xmm3, %xmm2
addq %rsi, %rdi
ucomiss %xmm0, %xmm2
jbe 0x1429f
movq %rdx, %rcx
movaps %xmm0, %xmm1
movq %rdi, %rdx
movaps %xmm2, %xmm0
jmp 0x142aa
ucomiss %xmm1, %xmm2
jbe 0x142aa
movq %rdi, %rcx
movaps %xmm2, %xmm1
incq %rsi
jmp 0x1424f
movss %xmm1, 0xc(%rsp)
movq %rcx, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
cmpl $0x0, 0x1c(%r13)
je 0x1434b
cvtss2sd %xmm0, %xmm0
cvtss2sd %xmm7, %xmm1
maxsd 0x1968e(%rip), %xmm1    # 0x2d968
divsd %xmm1, %xmm0
minsd 0x18f52(%rip), %xmm0    # 0x2d238
cvtsd2ss %xmm0, %xmm0
movss %xmm7, 0x20(%rsp)
callq 0x9550
movss 0x20(%rsp), %xmm7
cvtss2sd %xmm0, %xmm0
movsd 0x10(%r13), %xmm1
unpcklps 0x18e54(%rip), %xmm1    # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x18e5c(%rip), %xmm1    # 0x2d170
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
movsd 0x19620(%rip), %xmm1    # 0x2d948
divsd %xmm2, %xmm1
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xc(%rsp)
movss 0x18fe2(%rip), %xmm4    # 0x2d324
movaps %xmm4, %xmm1
subss %xmm0, %xmm1
jmp 0x1435c
orq $-0x1, 0x38(%rsp)
movss 0x18fcb(%rip), %xmm4    # 0x2d324
movaps %xmm4, %xmm1
movabsq $-0x100000000, %r11     # imm = 0xFFFFFFFF00000000
movaps 0x80(%rsp), %xmm5
movss 0x4(%rsp), %xmm6
cvtsi2sdq 0x10(%rsp), %xmm0
addsd 0x18e3d(%rip), %xmm0    # 0x2d1c0
divsd 0x90(%rsp), %xmm0
addsd 0x18e5c(%rip), %xmm0    # 0x2d1f0
cvtsd2ss %xmm0, %xmm0
cvttss2si %xmm0, %rax
cvtsi2ss %rax, %xmm2
cmpneqps %xmm0, %xmm2
xorps %xmm3, %xmm3
cmpnleps %xmm0, %xmm3
andps %xmm2, %xmm3
movd %xmm3, %ecx
andl $0x1, %ecx
subq %rcx, %rax
cvtsi2ss %rax, %xmm2
movss %xmm1, 0x8(%rsp)
subss %xmm2, %xmm0
movaps %xmm4, %xmm1
subss %xmm0, %xmm1
movq %rax, %rcx
orq %rbx, %rcx
setns %cl
xorl %edx, %edx
cmpq $0x2, %rdx
je 0x14532
movq 0x30(%rsp,%rdx,8), %rsi
testq %rsi, %rsi
js 0x1452a
movq 0x58(%r13), %rdi
movss 0x8(%rsp,%rdx,4), %xmm2
mulss %xmm7, %xmm2
testb %cl, %cl
je 0x1443a
movaps %xmm1, %xmm3
mulss %xmm2, %xmm3
movq %rdi, %r8
imulq %rbx, %r8
movq %rsi, %r9
imulq %r12, %r9
leaq (,%rax,4), %r10
addq 0x48(%r13), %r10
leaq (%r10,%r8,4), %r8
mulss %xmm6, %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, %rax
jge 0x14493
testq %rbx, %rbx
js 0x14493
movaps %xmm0, %xmm3
mulss %xmm2, %xmm3
movq %rdi, %r9
imulq %rbx, %r9
movq %rsi, %r10
imulq %r12, %r10
leaq (,%rax,4), %r11
addq 0x48(%r13), %r11
leaq (%r11,%r9,4), %r9
movabsq $-0x100000000, %r11     # imm = 0xFFFFFFFF00000000
mulss %xmm6, %xmm3
addss 0x4(%r9,%r10,4), %xmm3
movss %xmm3, 0x4(%r9,%r10,4)
cmpq %r8, %rax
jge 0x144e5
movq 0x60(%r13), %r8
shlq $0x20, %r8
addq %r11, %r8
sarq $0x20, %r8
cmpq %r8, %rbx
jge 0x144e5
movaps %xmm0, %xmm3
mulss %xmm2, %xmm3
movq %rdi, %r8
imulq 0x18(%rsp), %r8
movq %rsi, %r9
imulq %r12, %r9
leaq (,%rax,4), %r10
addq 0x48(%r13), %r10
leaq (%r10,%r8,4), %r8
mulss %xmm5, %xmm3
addss 0x4(%r8,%r9,4), %xmm3
movss %xmm3, 0x4(%r8,%r9,4)
testq %rax, %rax
js 0x1452a
movq 0x60(%r13), %r8
shlq $0x20, %r8
addq %r11, %r8
sarq $0x20, %r8
cmpq %r8, %rbx
jge 0x1452a
mulss %xmm1, %xmm2
imulq 0x18(%rsp), %rdi
imulq %r12, %rsi
leaq (,%rax,4), %r8
addq 0x48(%r13), %r8
leaq (%r8,%rdi,4), %rdi
mulss %xmm5, %xmm2
addss (%rdi,%rsi,4), %xmm2
movss %xmm2, (%rdi,%rsi,4)
incq %rdx
jmp 0x143db
movq 0x10(%rsp), %rax
incq %rax
addq $0x4, %rbp
addq $0x4, %r15
jmp 0x1417e
movq 0x50(%rsp), %rcx
incq %rcx
movq 0x40(%rsp), %rax
movq 0x58(%rsp), %rbp
addq %rax, %rbp
movq 0x60(%rsp), %r15
addq %rax, %r15
jmp 0x140f5
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq