// File: /workspace/github_c_makefile_star2_O2/zpole[P]IICV/vl/imopv.c
// Function: vl_imgradient_f
VL_EXPORT void
VL_XCAT(vl_imgradient_, SFX)
(T * xGradient, T * yGradient,
 vl_size gradWidthStride, vl_size gradHeightStride,
 T const * image,
 vl_size imageWidth, vl_size imageHeight,
 vl_size imageStride)
{
  /* Shortcuts */
  vl_index const xo = 1 ;
  vl_index const yo = imageStride ;
  vl_size const w = imageWidth;
  vl_size const h = imageHeight;

  T const *src, *end ;
  T *pgrad_x, *pgrad_y;
  vl_size y;

  src  = image ;
  pgrad_x = xGradient ;
  pgrad_y = yGradient ;

  /* first pixel of the first row */
  *pgrad_x = src[+xo] - src[0] ;
  pgrad_x += gradWidthStride;
  *pgrad_y = src[+yo] - src[0] ;
  pgrad_y += gradWidthStride;
  src++;

  /* middle pixels of the  first row */
  end = (src - 1) + w - 1 ;
  while (src < end) {
    *pgrad_x = 0.5 * (src[+xo] - src[-xo]) ;
    pgrad_x += gradWidthStride;
    *pgrad_y =        src[+yo] - src[0] ;
    pgrad_y += gradWidthStride;
    src++;
  }

  /* last pixel of the first row */
  *pgrad_x = src[0]   - src[-xo] ;
  pgrad_x += gradWidthStride;
  *pgrad_y = src[+yo] - src[0] ;
  pgrad_y += gradWidthStride;
  src++;

  xGradient += gradHeightStride;
  pgrad_x = xGradient;
  yGradient += gradHeightStride;
  pgrad_y = yGradient;
  image += yo;
  src = image;

  for (y = 1 ; y < h -1 ; ++y) {

    /* first pixel of the middle rows */
    *pgrad_x =        src[+xo] - src[0] ;
    pgrad_x += gradWidthStride;
    *pgrad_y = 0.5 * (src[+yo] - src[-yo]) ;
    pgrad_y += gradWidthStride;
    src++;

    /* middle pixels of the middle rows */
    end = (src - 1) + w - 1 ;
    while (src < end) {
      *pgrad_x = 0.5 * (src[+xo] - src[-xo]) ;
      pgrad_x += gradWidthStride;
      *pgrad_y = 0.5 * (src[+yo] - src[-yo]) ;
      pgrad_y += gradWidthStride;
      src++;
    }

    /* last pixel of the middle row */
    *pgrad_x =        src[0]   - src[-xo] ;
    pgrad_x += gradWidthStride;
    *pgrad_y = 0.5 * (src[+yo] - src[-yo]) ;
    pgrad_y += gradWidthStride;
    src++;

    xGradient += gradHeightStride;
    pgrad_x = xGradient;
    yGradient += gradHeightStride;
    pgrad_y = yGradient;
    image += yo;
    src = image;
  }

  /* first pixel of the last row */
  *pgrad_x = src[+xo] - src[0] ;
  pgrad_x += gradWidthStride;
  *pgrad_y = src[  0] - src[-yo] ;
  pgrad_y += gradWidthStride;
  src++;

  /* middle pixels of the last row */
  end = (src - 1) + w - 1 ;
  while (src < end) {
    *pgrad_x = 0.5 * (src[+xo] - src[-xo]) ;
    pgrad_x += gradWidthStride;
    *pgrad_y =        src[0]   - src[-yo] ;
    pgrad_y += gradWidthStride;
    src++;
  }

  /* last pixel of the last row */
  *pgrad_x = src[0]   - src[-xo] ;
  *pgrad_y = src[0]   - src[-yo] ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %r8, %r13
movq 0x40(%rsp), %r10
movq 0x38(%rsp), %rax
movq %rax, -0x18(%rsp)
movss 0x4(%r8), %xmm0
subss (%r8), %xmm0
leaq 0x4(%r8), %rax
movss %xmm0, (%rdi)
leaq (%r8,%r10,4), %r15
movss (%r15), %xmm0
subss (%r8), %xmm0
movss %xmm0, (%rsi)
movq %r9, -0x20(%rsp)
leaq -0x4(%r8,%r9,4), %r8
leaq (,%rdx,4), %r11
movss 0x15b02(%rip), %xmm0    # 0x2d328
movq %r11, %r14
movq %rax, -0x28(%rsp)
movq %rax, %r9
cmpq %r8, %r9
jae 0x17866
movss 0x4(%r9), %xmm1
subss -0x4(%r9), %xmm1
mulss %xmm0, %xmm1
movss %xmm1, (%rdi,%r14)
movss (%r9,%r10,4), %xmm1
subss (%r9), %xmm1
addq $0x4, %r9
movss %xmm1, (%rsi,%r14)
addq %r11, %r14
jmp 0x17831
movss (%r9), %xmm1
subss -0x4(%r9), %xmm1
movss %xmm1, (%rdi,%r14)
leaq (,%r10,4), %rbx
movss (%r9,%r10,4), %xmm1
subss (%r9), %xmm1
movss %xmm1, (%rsi,%r14)
decq -0x18(%rsp)
movq %r10, %rax
negq %rax
movq %rax, -0x30(%rsp)
leaq (,%rcx,4), %r12
shlq $0x2, %rdx
movq %rcx, -0x10(%rsp)
leaq (%rdx,%rcx,4), %rax
movq %rax, -0x8(%rsp)
movabsq $0x1, %rbp
leaq (%rsi,%r12), %r11
movss 0x4(%r15), %xmm1
subss (%r15), %xmm1
movss %xmm1, (%rdi,%r12)
cmpq -0x18(%rsp), %rbp
jae 0x179a6
leaq (%rdi,%r12), %r9
leaq (%r15,%r10,4), %rcx
movss (%rcx), %xmm1
movq -0x30(%rsp), %rax
subss (%r15,%rax,4), %xmm1
mulss %xmm0, %xmm1
movss %xmm1, (%r11)
movq -0x20(%rsp), %r8
leaq (%r15,%r8,4), %r14
addq $-0x4, %r14
movq -0x8(%rsp), %r15
movq %r13, %rax
movq %r13, %r8
leaq (%r8,%rbx), %r13
addq $0x4, %r13
cmpq %r14, %r13
jae 0x17960
movss 0x8(%r8,%r10,4), %xmm1
subss (%r8,%r10,4), %xmm1
mulss %xmm0, %xmm1
movss %xmm1, (%rdi,%r15)
movss 0x4(%r8,%r10,8), %xmm1
subss 0x4(%r8), %xmm1
addq $0x4, %r8
mulss %xmm0, %xmm1
movss %xmm1, (%rsi,%r15)
addq %rdx, %r15
jmp 0x1791c
movss 0x4(%r8,%r10,4), %xmm1
subss (%r8,%r10,4), %xmm1
movss %xmm1, (%rdi,%r15)
movss 0x4(%r8,%r10,8), %xmm1
subss 0x4(%r8), %xmm1
mulss %xmm0, %xmm1
movss %xmm1, (%rsi,%r15)
incq %rbp
addq %rbx, -0x28(%rsp)
movq %rax, %r13
addq %rbx, %r13
movq %r11, %rsi
movq %r9, %rdi
movq %rcx, %r15
jmp 0x178c4
movss (%r15), %xmm1
movq -0x30(%rsp), %rax
subss (%r15,%rax,4), %xmm1
leaq 0x4(%r15), %r9
movss %xmm1, (%r11)
movq -0x20(%rsp), %rcx
leaq (%r15,%rcx,4), %r8
addq $-0x4, %r8
movq -0x10(%rsp), %rcx
leaq (%rdx,%rcx,4), %rcx
movq -0x28(%rsp), %rax
cmpq %r8, %r9
jae 0x17a0f
movss 0x4(%r9), %xmm1
subss -0x4(%r9), %xmm1
mulss %xmm0, %xmm1
movss %xmm1, (%rdi,%rcx)
movss (%r9), %xmm1
addq $0x4, %r9
subss (%rax), %xmm1
movss %xmm1, (%rsi,%rcx)
addq $0x4, %rax
addq %rdx, %rcx
jmp 0x179da
movss (%r9), %xmm0
subss -0x4(%r9), %xmm0
movss %xmm0, (%rdi,%rcx)
movss (%r9), %xmm0
subss (%rax), %xmm0
movss %xmm0, (%rsi,%rcx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq