// File: /workspace/github_c_makefile_star2_O0/zpole[P]IICV/vl/covdet.c
// Function: vl_refine_local_extreum_2
VL_EXPORT vl_bool
vl_refine_local_extreum_2 (VlCovDetExtremum2 * refined,
                           float const * map,
                           vl_size width, vl_size height,
                           vl_index x, vl_index y)
{
  vl_size const xo = 1 ;
  vl_size const yo = width ;

  double Dx=0,Dy=0,Dxx=0,Dyy=0,Dxy=0;
  double A [2*2], b [2] ;

#define at(dx,dy) (*(pt + (dx)*xo + (dy)*yo ))
#define Aat(i,j) (A[(i)+(j)*2])

  float const * pt ;
  vl_index dx = 0 ;
  vl_index dy = 0 ;
  vl_index iter ;
  int err ;

  assert (map) ;
  assert (1 <= x && x <= (signed)width - 2) ;
  assert (1 <= y && y <= (signed)height - 2) ;

  for (iter = 0 ; iter < 5 ; ++iter) {
    x += dx ;
    y += dy ;
    pt = map + x*xo + y*yo  ;

    /* compute the gradient */
    Dx = 0.5 * (at(+1,0) - at(-1,0)) ;
    Dy = 0.5 * (at(0,+1) - at(0,-1));

    /* compute the Hessian */
    Dxx = (at(+1,0) + at(-1,0) - 2.0 * at(0,0)) ;
    Dyy = (at(0,+1) + at(0,-1) - 2.0 * at(0,0)) ;
    Dxy = 0.25 * (at(+1,+1) + at(-1,-1) - at(-1,+1) - at(+1,-1)) ;

    /* solve linear system */
    Aat(0,0) = Dxx ;
    Aat(1,1) = Dyy ;
    Aat(0,1) = Aat(1,0) = Dxy ;

    b[0] = - Dx ;
    b[1] = - Dy ;

    err = vl_solve_linear_system_2(b, A, b) ;

    if (err != VL_ERR_OK) {
      b[0] = 0 ;
      b[1] = 0 ;
      break ;
    }

    /* Keep going if there is sufficient translation */

    dx = (b[0] > 0.6 && x < (signed)width - 2 ?  1 : 0)
    + (b[0] < -0.6 && x > 1 ? -1 : 0) ;

    dy = (b[1] > 0.6 && y < (signed)height - 2 ?  1 : 0)
    + (b[1] < -0.6 && y > 1 ? -1 : 0) ;

    if (dx == 0 && dy == 0) break ;
  }

  /* check threshold and other conditions */
  {
    double peakScore = at(0,0) + 0.5 * (Dx * b[0] + Dy * b[1]) ;
    double alpha = (Dxx+Dyy)*(Dxx+Dyy) / (Dxx*Dyy - Dxy*Dxy) ;
    double edgeScore ;

    if (alpha < 0) {
      /* not an extremum */
      edgeScore = VL_INFINITY_D ;
    } else {
      edgeScore = (0.5*alpha - 1) + sqrt(VL_MAX(0.25*alpha - 1,0)*alpha) ;
    }

    refined->xi = x ;
    refined->yi = y ;
    refined->x = x + b[0] ;
    refined->y = y + b[1] ;
    refined->peakScore = peakScore ;
    refined->edgeScore = edgeScore ;

    return
    err == VL_ERR_OK &&
    vl_abs_d(b[0]) < 1.5 &&
    vl_abs_d(b[1]) < 1.5 &&
    0 <= refined->x && refined->x <= (signed)width - 1 &&
    0 <= refined->y && refined->y <= (signed)height - 1 ;
  }
#undef Aat
#undef at
}

// Assembly:
subq $0x108, %rsp            # imm = 0x108
movq %rdi, 0x100(%rsp)
movq %rsi, 0xf8(%rsp)
movq %rdx, 0xf0(%rsp)
movq %rcx, 0xe8(%rsp)
movq %r8, 0xe0(%rsp)
movq %r9, 0xd8(%rsp)
movq $0x1, 0xd0(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0xc8(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xc0(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xb8(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xb0(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xa8(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xa0(%rsp)
movq $0x0, 0x60(%rsp)
movq $0x0, 0x58(%rsp)
movq $0x0, 0x50(%rsp)
cmpq $0x5, 0x50(%rsp)
jge 0xd238
movq 0x60(%rsp), %rax
addq 0xe0(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq 0x58(%rsp), %rax
addq 0xd8(%rsp), %rax
movq %rax, 0xd8(%rsp)
movq 0xf8(%rsp), %rax
movq 0xe0(%rsp), %rcx
shlq $0x0, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq 0xd8(%rsp), %rcx
imulq 0xc8(%rsp), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rax
imulq $0x0, 0xc8(%rsp), %rcx
movss 0x4(%rax,%rcx,4), %xmm0
movq 0x68(%rsp), %rax
imulq $0x0, 0xc8(%rsp), %rcx
subss -0x4(%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x4c1c4(%rip), %xmm0    # 0x59080
mulsd %xmm1, %xmm0
movsd %xmm0, 0xc0(%rsp)
movq 0x68(%rsp), %rax
movq 0xc8(%rsp), %rcx
shlq $0x0, %rcx
movss (%rax,%rcx,4), %xmm0
movq 0x68(%rsp), %rax
imulq $-0x1, 0xc8(%rsp), %rcx
subss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x4c182(%rip), %xmm0    # 0x59080
mulsd %xmm1, %xmm0
movsd %xmm0, 0xb8(%rsp)
movq 0x68(%rsp), %rax
imulq $0x0, 0xc8(%rsp), %rcx
movss 0x4(%rax,%rcx,4), %xmm0
movq 0x68(%rsp), %rax
imulq $0x0, 0xc8(%rsp), %rcx
addss -0x4(%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movq 0x68(%rsp), %rax
imulq $0x0, 0xc8(%rsp), %rcx
movss (%rax,%rcx,4), %xmm1
cvtss2sd %xmm1, %xmm1
addsd %xmm1, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0xb0(%rsp)
movq 0x68(%rsp), %rax
movq 0xc8(%rsp), %rcx
shlq $0x0, %rcx
movss (%rax,%rcx,4), %xmm0
movq 0x68(%rsp), %rax
imulq $-0x1, 0xc8(%rsp), %rcx
addss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movq 0x68(%rsp), %rax
imulq $0x0, 0xc8(%rsp), %rcx
movss (%rax,%rcx,4), %xmm1
cvtss2sd %xmm1, %xmm1
addsd %xmm1, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0xa8(%rsp)
movq 0x68(%rsp), %rax
movq 0xc8(%rsp), %rcx
shlq $0x0, %rcx
movss 0x4(%rax,%rcx,4), %xmm0
movq 0x68(%rsp), %rax
imulq $-0x1, 0xc8(%rsp), %rcx
addss -0x4(%rax,%rcx,4), %xmm0
movq 0x68(%rsp), %rax
movq 0xc8(%rsp), %rcx
shlq $0x0, %rcx
subss -0x4(%rax,%rcx,4), %xmm0
movq 0x68(%rsp), %rax
imulq $-0x1, 0xc8(%rsp), %rcx
subss 0x4(%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x4c062(%rip), %xmm0    # 0x59078
mulsd %xmm1, %xmm0
movsd %xmm0, 0xa0(%rsp)
movsd 0xb0(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
movsd 0xa8(%rsp), %xmm0
movsd %xmm0, 0x98(%rsp)
movsd 0xa0(%rsp), %xmm0
movsd %xmm0, 0x88(%rsp)
movsd %xmm0, 0x90(%rsp)
movsd 0xc0(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, 0x70(%rsp)
movsd 0xb8(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, 0x78(%rsp)
leaq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0x70(%rsp), %rdx
callq 0x9a60
movl %eax, 0x4c(%rsp)
cmpl $0x0, 0x4c(%rsp)
je 0xd0e7
xorps %xmm0, %xmm0
movsd %xmm0, 0x70(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x78(%rsp)
jmp 0xd238
movsd 0x70(%rsp), %xmm0
xorl %eax, %eax
movsd 0x4bf91(%rip), %xmm1    # 0x59088
ucomisd %xmm1, %xmm0
movb %al, 0x2f(%rsp)
jbe 0xd121
movq 0xe0(%rsp), %rax
movq 0xf0(%rsp), %rcx
subl $0x2, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
setl %al
movb %al, 0x2f(%rsp)
movb 0x2f(%rsp), %dl
xorl %eax, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, 0x28(%rsp)
xorl %eax, %eax
movsd 0x4bf50(%rip), %xmm0    # 0x59090
ucomisd 0x70(%rsp), %xmm0
movb %al, 0x2e(%rsp)
jbe 0xd15c
cmpq $0x1, 0xe0(%rsp)
setg %al
movb %al, 0x2e(%rsp)
movl 0x28(%rsp), %eax
movb 0x2e(%rsp), %sil
xorl %ecx, %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
testb $0x1, %sil
cmovnel %edx, %ecx
addl %ecx, %eax
cltq
movq %rax, 0x60(%rsp)
movsd 0x78(%rsp), %xmm0
xorl %eax, %eax
movsd 0x4befc(%rip), %xmm1    # 0x59088
ucomisd %xmm1, %xmm0
movb %al, 0x27(%rsp)
jbe 0xd1b6
movq 0xd8(%rsp), %rax
movq 0xe8(%rsp), %rcx
subl $0x2, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
setl %al
movb %al, 0x27(%rsp)
movb 0x27(%rsp), %dl
xorl %eax, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, 0x20(%rsp)
xorl %eax, %eax
movsd 0x4bebb(%rip), %xmm0    # 0x59090
ucomisd 0x78(%rsp), %xmm0
movb %al, 0x26(%rsp)
jbe 0xd1f1
cmpq $0x1, 0xd8(%rsp)
setg %al
movb %al, 0x26(%rsp)
movl 0x20(%rsp), %eax
movb 0x26(%rsp), %sil
xorl %ecx, %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
testb $0x1, %sil
cmovnel %edx, %ecx
addl %ecx, %eax
cltq
movq %rax, 0x58(%rsp)
cmpq $0x0, 0x60(%rsp)
jne 0xd223
cmpq $0x0, 0x58(%rsp)
jne 0xd223
jmp 0xd238
jmp 0xd225
movq 0x50(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x50(%rsp)
jmp 0xce1a
movq 0x68(%rsp), %rax
imulq $0x0, 0xc8(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0xc0(%rsp), %xmm0
movsd 0x70(%rsp), %xmm3
movsd 0xb8(%rsp), %xmm2
mulsd 0x78(%rsp), %xmm2
mulsd %xmm3, %xmm0
addsd %xmm2, %xmm0
movsd 0x4be03(%rip), %xmm2    # 0x59080
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0xb0(%rsp), %xmm0
addsd 0xa8(%rsp), %xmm0
movsd 0xb0(%rsp), %xmm1
addsd 0xa8(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd 0xb0(%rsp), %xmm1
movsd 0xa8(%rsp), %xmm3
movsd 0xa0(%rsp), %xmm2
mulsd 0xa0(%rsp), %xmm2
movq %xmm2, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm2
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x38(%rsp)
xorps %xmm0, %xmm0
ucomisd 0x38(%rsp), %xmm0
jbe 0xd31e
movsd 0x4be8d(%rip), %xmm0    # 0x591a0
movsd %xmm0, 0x30(%rsp)
jmp 0xd3be
movsd 0x38(%rsp), %xmm0
movsd 0x4bd54(%rip), %xmm1    # 0x59080
mulsd %xmm1, %xmm0
movsd 0x4bd60(%rip), %xmm1    # 0x59098
addsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x38(%rsp), %xmm0
movsd 0x4bd28(%rip), %xmm1    # 0x59078
mulsd %xmm1, %xmm0
movsd 0x4bd3c(%rip), %xmm1    # 0x59098
addsd %xmm1, %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xd38f
movsd 0x38(%rsp), %xmm0
movsd 0x4bd01(%rip), %xmm1    # 0x59078
mulsd %xmm1, %xmm0
movsd 0x4bd15(%rip), %xmm1    # 0x59098
addsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
jmp 0xd39a
xorps %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
jmp 0xd39a
movsd 0x10(%rsp), %xmm0
mulsd 0x38(%rsp), %xmm0
callq 0x9b20
movaps %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0xe0(%rsp), %rcx
movq 0x100(%rsp), %rax
movq %rcx, (%rax)
movq 0xd8(%rsp), %rcx
movq 0x100(%rsp), %rax
movq %rcx, 0x8(%rax)
cvtsi2sdq 0xe0(%rsp), %xmm0
addsd 0x70(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movq 0x100(%rsp), %rax
movss %xmm0, 0x10(%rax)
cvtsi2sdq 0xd8(%rsp), %xmm0
addsd 0x78(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movq 0x100(%rsp), %rax
movss %xmm0, 0x14(%rax)
movsd 0x40(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movq 0x100(%rsp), %rax
movss %xmm0, 0x18(%rax)
movsd 0x30(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movq 0x100(%rsp), %rax
movss %xmm0, 0x1c(%rax)
xorl %eax, %eax
cmpl $0x0, 0x4c(%rsp)
movb %al, 0xf(%rsp)
jne 0xd535
movsd 0x70(%rsp), %xmm0
callq 0xcd50
movaps %xmm0, %xmm1
xorl %eax, %eax
movsd 0x4bc22(%rip), %xmm0    # 0x590a0
ucomisd %xmm1, %xmm0
movb %al, 0xf(%rsp)
jbe 0xd535
movsd 0x78(%rsp), %xmm0
callq 0xcd50
movaps %xmm0, %xmm1
xorl %eax, %eax
movsd 0x4bbfc(%rip), %xmm0    # 0x590a0
ucomisd %xmm1, %xmm0
movb %al, 0xf(%rsp)
jbe 0xd535
movq 0x100(%rsp), %rax
movss 0x10(%rax), %xmm0
xorl %eax, %eax
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
movb %al, 0xf(%rsp)
jb 0xd535
movq 0x100(%rsp), %rax
movss 0x10(%rax), %xmm1
movq 0xf0(%rsp), %rax
subl $0x1, %eax
cvtsi2ss %eax, %xmm0
xorl %eax, %eax
ucomiss %xmm1, %xmm0
movb %al, 0xf(%rsp)
jb 0xd535
movq 0x100(%rsp), %rax
movss 0x14(%rax), %xmm0
xorl %eax, %eax
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
movb %al, 0xf(%rsp)
jb 0xd535
movq 0x100(%rsp), %rax
movss 0x14(%rax), %xmm1
movq 0xe8(%rsp), %rax
subl $0x1, %eax
cvtsi2ss %eax, %xmm0
ucomiss %xmm1, %xmm0
setae %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
addq $0x108, %rsp            # imm = 0x108
retq
nopw %cs:(%rax,%rax)