// File: /workspace/github_c_makefile_star2_O3/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, %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 (,%r9,4), %r8
movq %r8, -0x18(%rsp)
leaq (%rsi,%rdx,4), %r14
leaq (%rdi,%rdx,4), %r15
cmpq $0x3, %r9
jl 0x193c0
leaq (%rbx,%r9,4), %r13
addq $-0x4, %r13
leaq (,%rdx,4), %rbp
movss 0x18fd9(%rip), %xmm0    # 0x32360
leaq 0x4(%r11), %r12
movss 0x4(%r11), %xmm1
subss -0x4(%r11), %xmm1
mulss %xmm0, %xmm1
movss %xmm1, (%r15)
movss (%r11,%rax,4), %xmm1
subss (%r11), %xmm1
movss %xmm1, (%r14)
addq %rbp, %r15
addq %rbp, %r14
movq %r12, %r11
cmpq %r13, %r12
jb 0x19387
jmp 0x193c3
movq %r11, %r12
leaq (%rbx,%rax,4), %r11
movss (%r12), %xmm0
subss -0x4(%r12), %xmm0
movss %xmm0, (%r15)
movss (%r12,%rax,4), %xmm0
subss (%r12), %xmm0
movss %xmm0, (%r14)
decq %r10
leaq (%rsi,%rcx,4), %r14
leaq (%rdi,%rcx,4), %rdi
movq %rax, %r8
negq %r8
addq $-0x4, -0x18(%rsp)
movq %r10, -0x8(%rsp)
cmpq $0x2, %r10
movq %r8, -0x10(%rsp)
jb 0x19518
shlq $0x2, %rcx
leaq (,%rdx,4), %r15
leaq (,%rax,4), %r12
movl $0x1, %r13d
movss 0x18f29(%rip), %xmm0    # 0x32360
movss 0x4(%r11), %xmm1
subss (%r11), %xmm1
movss %xmm1, (%rdi)
movss (%r11,%rax,4), %xmm1
subss (%r11,%r8,4), %xmm1
mulss %xmm0, %xmm1
movss %xmm1, (%r14)
cmpq $0x3, %r9
jl 0x194c7
movq -0x18(%rsp), %r8
leaq (%r11,%r8), %r10
movq %rbx, %rsi
movq %rbx, %r8
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), %rbx
addq $0x4, %r8
mulss %xmm0, %xmm1
movss %xmm1, (%r14,%rbp)
addq %r15, %rbp
cmpq %r10, %rbx
jb 0x19473
leaq (%rdi,%rbp), %rbx
addq %r14, %rbp
leaq (%r8,%r12), %r10
addq $0x4, %r10
movq -0x10(%rsp), %r8
jmp 0x194d6
movq %rbx, %rsi
leaq 0x4(%r11), %r10
leaq (%r14,%rdx,4), %rbp
leaq (%rdi,%rdx,4), %rbx
movss (%r10), %xmm1
subss -0x4(%r10), %xmm1
movss %xmm1, (%rbx)
movss (%r10,%rax,4), %xmm1
subss (%r10,%r8,4), %xmm1
leaq (%r11,%rax,4), %r11
mulss %xmm0, %xmm1
movss %xmm1, (%rbp)
incq %r13
addq %rcx, %r14
addq %rcx, %rdi
movq %rsi, %rbx
addq %r12, %rbx
cmpq -0x8(%rsp), %r13
jne 0x19437
movq %r8, %rcx
leaq 0x4(%r11), %r8
movss 0x4(%r11), %xmm0
subss (%r11), %xmm0
movss %xmm0, (%rdi)
movss (%r11), %xmm0
subss (%r11,%rcx,4), %xmm0
movss %xmm0, (%r14)
leaq (%r14,%rdx,4), %rcx
leaq (%rdi,%rdx,4), %rdi
cmpq $0x3, %r9
jl 0x1959b
addq -0x18(%rsp), %r11
shlq $0x2, %rdx
shlq $0x2, %rax
negq %rax
movss 0x18dfc(%rip), %xmm0    # 0x32360
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, (%rcx)
addq %rdx, %rdi
addq %rdx, %rcx
movq %r9, %r8
cmpq %r11, %r9
jb 0x19564
jmp 0x1959e
movq %r8, %r9
movss (%r9), %xmm0
subss -0x4(%r9), %xmm0
movss %xmm0, (%rdi)
movss (%r9), %xmm0
movq -0x10(%rsp), %rax
subss (%r9,%rax,4), %xmm0
movss %xmm0, (%rcx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq