// File: /workspace/github_c_makefile_star2_O1/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 0x40(%rsp), %rax
movq 0x38(%rsp), %r10
leaq 0x4(%r8), %r11
movss 0x4(%r8), %xmm0
subss (%r8), %xmm0
movss %xmm0, (%rdi)
movss (%r8,%rax,4), %xmm0
subss (%r8), %xmm0
movss %xmm0, (%rsi)
leaq (%rsi,%rdx,4), %rbx
leaq (%rdi,%rdx,4), %r14
cmpq $0x3, %r9
jl 0x194dd
leaq (%r8,%r9,4), %r12
addq $-0x4, %r12
leaq (,%rdx,4), %r13
movss 0x19eab(%rip), %xmm0    # 0x33350
leaq 0x4(%r11), %r15
movss 0x4(%r11), %xmm1
subss -0x4(%r11), %xmm1
mulss %xmm0, %xmm1
movss %xmm1, (%r14)
movss (%r11,%rax,4), %xmm1
subss (%r11), %xmm1
movss %xmm1, (%rbx)
addq %r13, %r14
addq %r13, %rbx
movq %r15, %r11
cmpq %r12, %r15
jb 0x194a5
jmp 0x194e0
movq %r11, %r15
movq %rdx, -0x18(%rsp)
leaq (%r8,%rax,4), %r11
movss (%r15), %xmm0
subss -0x4(%r15), %xmm0
movss %xmm0, (%r14)
movss (%r15,%rax,4), %xmm0
subss (%r15), %xmm0
movss %xmm0, (%rbx)
decq %r10
leaq (%rsi,%rcx,4), %rsi
leaq (%rdi,%rcx,4), %rdi
movq %r10, -0x8(%rsp)
cmpq $0x2, %r10
jb 0x1963f
movq %rcx, %rbx
movq %rax, %rdx
negq %rdx
leaq -0x4(,%r9,4), %rcx
movq %rcx, -0x10(%rsp)
shlq $0x2, %rbx
movq -0x18(%rsp), %rcx
leaq (,%rcx,4), %r15
leaq (,%rax,4), %r12
movl $0x1, %r13d
movss 0x19df1(%rip), %xmm0    # 0x33350
movss 0x4(%r11), %xmm1
subss (%r11), %xmm1
movss %xmm1, (%rdi)
movss (%r11,%rax,4), %xmm1
subss (%r11,%rdx,4), %xmm1
mulss %xmm0, %xmm1
movss %xmm1, (%rsi)
cmpq $0x3, %r9
jl 0x195ee
movq %rbx, %rcx
movq -0x10(%rsp), %r10
leaq (%r11,%r10), %r14
movq %r8, %rbx
movq %r15, %rbp
movss 0x8(%r8,%rax,4), %xmm1
subss (%r8,%rax,4), %xmm1
mulss %xmm0, %xmm1
movss %xmm1, (%rdi,%rbp)
movss 0x4(%r8,%rax,8), %xmm1
subss 0x4(%r8), %xmm1
leaq 0x8(%r8,%r12), %r10
addq $0x4, %r8
mulss %xmm0, %xmm1
movss %xmm1, (%rsi,%rbp)
addq %r15, %rbp
cmpq %r14, %r10
jb 0x1959a
leaq (%rdi,%rbp), %r10
addq %rsi, %rbp
leaq (%r8,%r12), %r14
addq $0x4, %r14
movq %rbx, %r8
movq %rcx, %rbx
jmp 0x195ff
leaq 0x4(%r11), %r14
movq -0x18(%rsp), %rcx
leaq (%rsi,%rcx,4), %rbp
leaq (%rdi,%rcx,4), %r10
movss (%r14), %xmm1
subss -0x4(%r14), %xmm1
movss %xmm1, (%r10)
movss (%r14,%rax,4), %xmm1
subss (%r14,%rdx,4), %xmm1
leaq (%r11,%rax,4), %r11
mulss %xmm0, %xmm1
movss %xmm1, (%rbp)
incq %r13
addq %rbx, %rsi
addq %rbx, %rdi
addq %r12, %r8
cmpq -0x8(%rsp), %r13
jne 0x1955f
leaq 0x4(%r11), %r8
movss 0x4(%r11), %xmm0
subss (%r11), %xmm0
movss %xmm0, (%rdi)
movss (%r11), %xmm0
movq %rax, %rcx
negq %rcx
shlq $0x2, %rax
negq %rax
subss (%r11,%rax), %xmm0
movss %xmm0, (%rsi)
movq -0x18(%rsp), %rdx
leaq (%rsi,%rdx,4), %rsi
leaq (%rdi,%rdx,4), %rdi
cmpq $0x3, %r9
jl 0x196cc
leaq (%r11,%r9,4), %r10
addq $-0x4, %r10
shlq $0x2, %rdx
movss 0x19cbb(%rip), %xmm0    # 0x33350
leaq 0x4(%r8), %r9
movss 0x4(%r8), %xmm1
subss -0x4(%r8), %xmm1
mulss %xmm0, %xmm1
movss %xmm1, (%rdi)
movss (%r8), %xmm1
subss (%r8,%rax), %xmm1
movss %xmm1, (%rsi)
addq %rdx, %rdi
addq %rdx, %rsi
movq %r9, %r8
cmpq %r10, %r9
jb 0x19695
jmp 0x196cf
movq %r8, %r9
movss (%r9), %xmm0
subss -0x4(%r9), %xmm0
movss %xmm0, (%rdi)
movss (%r9), %xmm0
subss (%r9,%rcx,4), %xmm0
movss %xmm0, (%rsi)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq