// File: /workspace/github_c_makefile_star2_O1/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, %rbx
movq %rcx, %r14
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %r12
movq %rdx, %rsi
movq %rcx, %rdx
movq %r9, %rcx
callq 0x15c90
leal -0x1(%r14), %eax
cltq
movq %rax, 0x88(%rsp)
cmpq $0x2, %rax
jl 0x15c7e
movq %r14, %rdx
movq %rbx, %rcx
movq %rbp, %rdi
movq 0x60(%r12), %rbp
imulq 0x58(%r12), %rbp
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %r13, %rsi
shlq $0x20, %rsi
addq %rax, %rsi
sarq $0x20, %rsi
movq %rsi, 0x60(%rsp)
movq %rdi, %xmm0
punpckldq 0x1da7f(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x1da87(%rip), %xmm0    # 0x33190
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, 0xb0(%rsp)
leaq 0x4(%r15,%r13,8), %rax
movq %rax, 0x50(%rsp)
leaq (,%r13,4), %rax
movq %rax, 0x80(%rsp)
imulq %r13, %rdx
shlq $0x2, %rdx
leaq (%r15,%r13,4), %rax
addq $0x8, %rax
movq %rax, 0x48(%rsp)
addq $0x4, %r15
movq %r15, 0x58(%rsp)
movl $0x1, %eax
movq %rax, 0x18(%rsp)
movss 0x1dbe4(%rip), %xmm4    # 0x3334c
movq %rbx, 0x98(%rsp)
movq %rdx, 0x90(%rsp)
cmpq $0x2, 0x60(%rsp)
jl 0x15c4c
xorps %xmm0, %xmm0
cvtsi2sdq 0x18(%rsp), %xmm0
addsd 0x1da3a(%rip), %xmm0    # 0x331d0
divsd 0xb0(%rsp), %xmm0
addsd 0x1da71(%rip), %xmm0    # 0x33218
xorps %xmm2, %xmm2
cvtsd2ss %xmm0, %xmm2
cvttss2si %xmm2, %r15
xorps %xmm0, %xmm0
cvtsi2ss %r15, %xmm0
cmpneqps %xmm2, %xmm0
xorpd %xmm1, %xmm1
cmpnleps %xmm2, %xmm1
andps %xmm0, %xmm1
movd %xmm1, %eax
andl $0x1, %eax
subq %rax, %r15
xorps %xmm0, %xmm0
cvtsi2ss %r15, %xmm0
subss %xmm0, %xmm2
movaps %xmm2, 0xa0(%rsp)
subss %xmm2, %xmm4
movss %xmm4, 0x14(%rsp)
leaq 0x1(%r15), %rax
movq %rax, 0x68(%rsp)
movl $0x1, %eax
movq %rax, 0x20(%rsp)
movq 0x48(%rsp), %rbx
movq 0x58(%rsp), %r14
movq 0x50(%rsp), %r13
movabsq $-0x407fffff40800000, %rax # imm = 0xBF800000BF800000
movq %rax, 0x8(%rsp)
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0x30(%rsp)
testq %rcx, %rcx
je 0x15897
xorps %xmm2, %xmm2
xorl %eax, %eax
xorps %xmm5, %xmm5
xorps %xmm1, %xmm1
movss (%rbx,%rax), %xmm6
subss -0x8(%rbx,%rax), %xmm6
movss (%r13,%rax), %xmm3
subss (%r14,%rax), %xmm3
movaps %xmm3, %xmm0
mulss %xmm3, %xmm0
movaps %xmm6, %xmm4
mulss %xmm6, %xmm4
addss %xmm0, %xmm4
ucomiss %xmm1, %xmm4
ja 0x1586f
movaps %xmm2, %xmm6
movaps %xmm4, %xmm0
maxss %xmm1, %xmm0
cmpltss %xmm4, %xmm1
andps %xmm1, %xmm3
andnps %xmm5, %xmm1
orps %xmm3, %xmm1
movaps %xmm1, %xmm5
addq %rdx, %rax
movaps %xmm6, %xmm2
movaps %xmm0, %xmm1
decq %rcx
jne 0x1583d
jmp 0x158a1
pxor %xmm0, %xmm0
xorps %xmm5, %xmm5
xorps %xmm6, %xmm6
ucomiss 0x1dad0(%rip), %xmm0    # 0x33378
jb 0x158b0
sqrtss %xmm0, %xmm7
jmp 0x158ce
movaps %xmm5, 0x70(%rsp)
movss %xmm6, 0x2c(%rsp)
callq 0x95e0
movss 0x2c(%rsp), %xmm6
movaps 0x70(%rsp), %xmm5
movaps %xmm0, %xmm7
movaps 0x1d73b(%rip), %xmm4    # 0x33010
movq 0x10(%r12), %rcx
movss 0x8(%rsp), %xmm0
movq 0x30(%rsp), %rax
testq %rcx, %rcx
je 0x15965
movq 0x38(%r12), %rdx
movq 0x40(%r12), %rsi
movss 0xc(%rsp), %xmm1
movq 0x38(%rsp), %rdi
xorl %r8d, %r8d
movss (%rsi,%r8,4), %xmm2
mulss %xmm5, %xmm2
movss (%rdx,%r8,4), %xmm3
mulss %xmm6, %xmm3
addss %xmm2, %xmm3
movaps %xmm3, %xmm2
xorps %xmm4, %xmm2
ucomiss %xmm3, %xmm2
movl $0x0, %r9d
cmovaq %rcx, %r9
maxss %xmm3, %xmm2
addq %r8, %r9
ucomiss %xmm0, %xmm2
jbe 0x15947
movq %rax, %rdi
movaps %xmm0, %xmm1
movq %r9, %rax
movaps %xmm2, %xmm0
jmp 0x15952
ucomiss %xmm1, %xmm2
jbe 0x15952
movq %r9, %rdi
movaps %xmm2, %xmm1
incq %r8
cmpq %r8, %rcx
jne 0x15902
movss %xmm1, 0xc(%rsp)
movq %rdi, 0x38(%rsp)
movss %xmm0, 0x8(%rsp)
movq %rax, 0x30(%rsp)
cmpl $0x0, 0x1c(%r12)
je 0x15a16
xorps %xmm0, %xmm0
cvtss2sd 0x8(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm7, %xmm1
maxsd 0x1e014(%rip), %xmm1    # 0x339a8
divsd %xmm1, %xmm0
minsd 0x1d8c0(%rip), %xmm0    # 0x33260
cvtsd2ss %xmm0, %xmm0
movss %xmm7, 0x70(%rsp)
callq 0x9520
movss 0x70(%rsp), %xmm7
cvtss2sd %xmm0, %xmm0
movsd 0x10(%r12), %xmm1
unpcklps 0x1d7b9(%rip), %xmm1    # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x1d7c1(%rip), %xmm1    # 0x33190
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
movsd 0x1dfa5(%rip), %xmm1    # 0x33988
divsd %xmm2, %xmm1
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xc(%rsp)
movss 0x1d94f(%rip), %xmm4    # 0x3334c
movaps %xmm4, %xmm1
subss %xmm0, %xmm1
movss %xmm1, 0x8(%rsp)
movabsq $-0x100000000, %r11     # imm = 0xFFFFFFFF00000000
jmp 0x15a39
movl $0x3f800000, 0x8(%rsp)  # imm = 0x3F800000
movq $-0x1, 0x38(%rsp)
movabsq $-0x100000000, %r11     # imm = 0xFFFFFFFF00000000
movss 0x1d913(%rip), %xmm4    # 0x3334c
movaps 0xa0(%rsp), %xmm5
movss 0x14(%rsp), %xmm6
xorps %xmm0, %xmm0
cvtsi2sdq 0x20(%rsp), %xmm0
addsd 0x1d777(%rip), %xmm0    # 0x331d0
divsd 0xb0(%rsp), %xmm0
addsd 0x1d7ae(%rip), %xmm0    # 0x33218
cvtsd2ss %xmm0, %xmm0
cvttss2si %xmm0, %rax
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
cmpneqps %xmm0, %xmm1
xorps %xmm2, %xmm2
cmpnleps %xmm0, %xmm2
andps %xmm1, %xmm2
movd %xmm2, %ecx
andl $0x1, %ecx
subq %rcx, %rax
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
subss %xmm1, %xmm0
movaps %xmm4, %xmm1
subss %xmm0, %xmm1
movq %rax, %rcx
orq %r15, %rcx
setns %cl
xorl %edx, %edx
movq 0x30(%rsp,%rdx,8), %rsi
testq %rsi, %rsi
js 0x15c0b
movss 0x8(%rsp,%rdx,4), %xmm2
testb %cl, %cl
je 0x15b05
movaps %xmm7, %xmm3
mulss %xmm2, %xmm3
mulss %xmm1, %xmm3
movq 0x58(%r12), %rdi
imulq %r15, %rdi
movq %rsi, %r8
imulq %rbp, %r8
leaq (,%rax,4), %r9
addq 0x48(%r12), %r9
leaq (%r9,%rdi,4), %rdi
mulss %xmm6, %xmm3
addss (%rdi,%r8,4), %xmm3
movss %xmm3, (%rdi,%r8,4)
movq 0x58(%r12), %rdi
movq %rdi, %r8
shlq $0x20, %r8
addq %r11, %r8
sarq $0x20, %r8
cmpq %r8, %rax
jge 0x15b68
testq %r15, %r15
js 0x15b68
movaps %xmm7, %xmm3
mulss %xmm2, %xmm3
mulss %xmm0, %xmm3
movq %rdi, %r9
imulq %r15, %r9
movq %rsi, %r10
imulq %rbp, %r10
leaq (,%rax,4), %r11
addq 0x48(%r12), %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 0x15bc0
movq 0x60(%r12), %r8
shlq $0x20, %r8
addq %r11, %r8
sarq $0x20, %r8
cmpq %r8, %r15
jge 0x15bc0
movaps %xmm7, %xmm3
mulss %xmm2, %xmm3
mulss %xmm0, %xmm3
movq %rdi, %r8
imulq 0x68(%rsp), %r8
movq %rsi, %r9
imulq %rbp, %r9
leaq (,%rax,4), %r10
addq 0x48(%r12), %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 0x15c0b
movq 0x60(%r12), %r8
shlq $0x20, %r8
addq %r11, %r8
sarq $0x20, %r8
cmpq %r8, %r15
jge 0x15c0b
mulss %xmm7, %xmm2
mulss %xmm1, %xmm2
imulq 0x68(%rsp), %rdi
imulq %rbp, %rsi
leaq (,%rax,4), %r8
addq 0x48(%r12), %r8
leaq (%r8,%rdi,4), %rdi
mulss %xmm5, %xmm2
addss (%rdi,%rsi,4), %xmm2
movss %xmm2, (%rdi,%rsi,4)
incq %rdx
cmpq $0x1, %rdx
je 0x15ab1
movq 0x20(%rsp), %rax
incq %rax
addq $0x4, %r13
addq $0x4, %r14
addq $0x4, %rbx
movq %rax, 0x20(%rsp)
cmpq 0x60(%rsp), %rax
movq 0x98(%rsp), %rcx
movq 0x90(%rsp), %rdx
jne 0x15814
movq 0x18(%rsp), %rsi
incq %rsi
movq 0x80(%rsp), %rax
addq %rax, 0x50(%rsp)
addq %rax, 0x58(%rsp)
addq %rax, 0x48(%rsp)
movq %rsi, 0x18(%rsp)
cmpq 0x88(%rsp), %rsi
jne 0x15778
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq