// File: /workspace/github_c_makefile_star2_O0/zpole[P]IICV/vl/covdet.c
// Function: vl_covdet_extract_laplacian_scales_for_frame
VlCovDetFeatureLaplacianScale *
vl_covdet_extract_laplacian_scales_for_frame (VlCovDet * self,
                                              vl_size * numScales,
                                              VlFrameOrientedEllipse frame)
{
  /*
   We try to explore one octave, with the nominal detection scale 1.0
   (in the patch reference frame) in the middle. Thus the goal is to sample
   the response of the tr-Laplacian operator at logarithmically
   spaced scales in 1/sqrt(2), sqrt(2).

   To this end, the patch is warped with a smoothing of at most
   sigmaImage = 1 / sqrt(2) (beginning of the scale), sampled at
   roughly twice the Nyquist frequency (so step = 1 / (2*sqrt(2))).
   This maes it possible to approximate the Laplacian operator at
   that scale by simple finite differences.

   */
  int err ;
  double const sigmaImage = 1.0 / sqrt(2.0) ;
  double const step = 0.5 * sigmaImage ;
  double actualSigmaImage ;
  vl_size const resolution = VL_COVDET_LAP_PATCH_RESOLUTION ;
  vl_size const num = 2 * resolution + 1 ;
  double extent = step * resolution ;
  double scores [VL_COVDET_LAP_NUM_LEVELS] ;
  double factor = 1.0 ;
  float const * pt ;
  vl_index k ;

  double A[2*2] = {frame.a11, frame.a21, frame.a12, frame.a22} ;
  double T[2] = {frame.x, frame.y} ;
  double D[4], U[4], V[4] ;
  double sigma1, sigma2 ;

  assert(self) ;
  assert(numScales) ;

  *numScales = 0 ;

  vl_svd2(D, U, V, A) ;

  err = vl_covdet_extract_patch_helper
  (self, &sigma1, &sigma2, self->lapPatch, resolution, extent, sigmaImage, A, T, D[0], D[3]) ;
  if (err) return NULL ;

  /* the actual smoothing after warping is never the target one */
  if (sigma1 == sigma2) {
    actualSigmaImage = sigma1 ;
  } else {
    /* here we could compensate */
    actualSigmaImage = sqrt(sigma1*sigma2) ;
  }

  /* now multiply by the bank of Laplacians */
  pt = self->laplacians ;
  for (k = 0 ; k < VL_COVDET_LAP_NUM_LEVELS ; ++k) {
    vl_index q ;
    double score = 0 ;
    double sigmaLap = pow(2.0, -0.5 + (double)k / (VL_COVDET_LAP_NUM_LEVELS - 1)) ;
    /* note that the sqrt argument cannot be negative since by construction
     sigmaLap >= sigmaImage */
    sigmaLap = sqrt(sigmaLap*sigmaLap
                    - sigmaImage*sigmaImage
                    + actualSigmaImage*actualSigmaImage) ;

    for (q = 0 ; q < (signed)(num * num) ; ++q) {
      score += (*pt++) * self->lapPatch[q] ;
    }
    scores[k] = score * sigmaLap * sigmaLap ;
  }

  /* find and interpolate maxima */
  for (k = 1 ; k < VL_COVDET_LAP_NUM_LEVELS - 1 ; ++k) {
    double a = scores[k-1] ;
    double b = scores[k] ;
    double c = scores[k+1] ;
    double t = self->lapPeakThreshold ;

    if ((((b > a) && (b > c)) || ((b < a) && (b < c))) && (vl_abs_d(b) >= t)) {
      double dk = - 0.5 * (c - a) / (c + a - 2 * b) ;
      double s = k + dk ;
      double sigmaLap = pow(2.0, -0.5 + s / (VL_COVDET_LAP_NUM_LEVELS - 1)) ;
      double scale ;
      sigmaLap = sqrt(sigmaLap*sigmaLap
                      - sigmaImage*sigmaImage
                      + actualSigmaImage*actualSigmaImage) ;
      scale = sigmaLap / 1.0 ;
      /*
       VL_PRINTF("** k:%d, s:%f, sigmaLapFilter:%f, sigmaLap%f, scale:%f (%f %f %f)\n",
       k,s,sigmaLapFilter,sigmaLap,scale,a,b,c) ;
       */
      if (*numScales < VL_COVDET_MAX_NUM_LAPLACIAN_SCALES) {
        self->scales[*numScales].scale = scale * factor ;
        self->scales[*numScales].score = b + 0.5 * (c - a) * dk ;
        *numScales += 1 ;
      }
    }
  }
  return self->scales ;
}

// Assembly:
subq $0x1d8, %rsp            # imm = 0x1D8
leaq 0x1e0(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %rdi, 0x1c8(%rsp)
movq %rsi, 0x1c0(%rsp)
movsd 0x460f4(%rip), %xmm0    # 0x590e0
callq 0x9b20
movq 0x10(%rsp), %rax
movaps %xmm0, %xmm1
movsd 0x460d7(%rip), %xmm0    # 0x590d8
divsd %xmm1, %xmm0
movsd %xmm0, 0x1b0(%rsp)
movsd 0x4606a(%rip), %xmm0    # 0x59080
mulsd 0x1b0(%rsp), %xmm0
movsd %xmm0, 0x1a8(%rsp)
movq $0x10, 0x198(%rsp)
movq $0x21, 0x190(%rsp)
movsd 0x46100(%rip), %xmm0    # 0x59148
mulsd 0x1a8(%rsp), %xmm0
movsd %xmm0, 0x188(%rsp)
movsd 0x46076(%rip), %xmm0    # 0x590d8
movsd %xmm0, 0x128(%rsp)
movss 0x8(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xf0(%rsp)
movss 0x10(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xf8(%rsp)
movss 0xc(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x100(%rsp)
movss 0x14(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x108(%rsp)
movss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xe0(%rsp)
movss 0x4(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xe8(%rsp)
movq 0x1c0(%rsp), %rax
movq $0x0, (%rax)
leaq 0xc0(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
leaq 0x80(%rsp), %rdx
leaq 0xf0(%rsp), %rcx
callq 0x9730
movq 0x1c8(%rsp), %rdi
movq 0x1c8(%rsp), %rcx
addq $0x6a14, %rcx           # imm = 0x6A14
movsd 0x188(%rsp), %xmm0
movsd 0x1b0(%rsp), %xmm1
leaq 0xf0(%rsp), %r9
leaq 0xe0(%rsp), %rax
movsd 0xc0(%rsp), %xmm2
movsd 0xd8(%rsp), %xmm3
leaq 0x78(%rsp), %rsi
leaq 0x70(%rsp), %rdx
movl $0x10, %r8d
movq %rax, (%rsp)
callq 0xfdd0
movl %eax, 0x1bc(%rsp)
cmpl $0x0, 0x1bc(%rsp)
je 0x13190
movq $0x0, 0x1d0(%rsp)
jmp 0x135eb
movsd 0x78(%rsp), %xmm0
ucomisd 0x70(%rsp), %xmm0
jne 0x131b1
jp 0x131b1
movsd 0x78(%rsp), %xmm0
movsd %xmm0, 0x1a0(%rsp)
jmp 0x131cb
movsd 0x78(%rsp), %xmm0
mulsd 0x70(%rsp), %xmm0
callq 0x9b20
movsd %xmm0, 0x1a0(%rsp)
movq 0x1c8(%rsp), %rax
addq $0x7b18, %rax           # imm = 0x7B18
movq %rax, 0x120(%rsp)
movq $0x0, 0x118(%rsp)
cmpq $0xa, 0x118(%rsp)
jge 0x1333d
xorps %xmm0, %xmm0
movsd %xmm0, 0x60(%rsp)
cvtsi2sdq 0x118(%rsp), %xmm0
movsd 0x45ed9(%rip), %xmm1    # 0x590f0
divsd %xmm1, %xmm0
movsd 0x45ec5(%rip), %xmm1    # 0x590e8
addsd %xmm0, %xmm1
movsd 0x45eb1(%rip), %xmm0    # 0x590e0
callq 0x92b0
movsd %xmm0, 0x58(%rsp)
movsd 0x58(%rsp), %xmm1
movsd 0x58(%rsp), %xmm2
movsd 0x1b0(%rsp), %xmm0
mulsd 0x1b0(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x1a0(%rsp), %xmm0
movsd 0x1a0(%rsp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x9b20
movsd %xmm0, 0x58(%rsp)
movq $0x0, 0x68(%rsp)
cmpq $0x441, 0x68(%rsp)      # imm = 0x441
jge 0x13301
movq 0x120(%rsp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x120(%rsp)
movss (%rax), %xmm0
movq 0x1c8(%rsp), %rax
movq 0x68(%rsp), %rcx
mulss 0x6a14(%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
addsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movq 0x68(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x68(%rsp)
jmp 0x132a5
movsd 0x60(%rsp), %xmm0
mulsd 0x58(%rsp), %xmm0
mulsd 0x58(%rsp), %xmm0
movq 0x118(%rsp), %rax
movsd %xmm0, 0x130(%rsp,%rax,8)
movq 0x118(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x118(%rsp)
jmp 0x131ed
movq $0x1, 0x118(%rsp)
cmpq $0x9, 0x118(%rsp)
jge 0x135d5
movq 0x118(%rsp), %rax
subq $0x1, %rax
movsd 0x130(%rsp,%rax,8), %xmm0
movsd %xmm0, 0x50(%rsp)
movq 0x118(%rsp), %rax
movsd 0x130(%rsp,%rax,8), %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x118(%rsp), %rax
movsd 0x138(%rsp,%rax,8), %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x1c8(%rsp), %rax
movsd 0x28(%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x48(%rsp), %xmm0
ucomisd 0x50(%rsp), %xmm0
jbe 0x133d0
movsd 0x48(%rsp), %xmm0
ucomisd 0x40(%rsp), %xmm0
ja 0x133fc
movsd 0x48(%rsp), %xmm1
movsd 0x50(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x135ba
movsd 0x48(%rsp), %xmm1
movsd 0x40(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x135ba
movsd 0x48(%rsp), %xmm0
callq 0xcd50
ucomisd 0x38(%rsp), %xmm0
jb 0x135ba
movsd 0x40(%rsp), %xmm1
subsd 0x50(%rsp), %xmm1
movsd 0x45cc1(%rip), %xmm0    # 0x590e8
mulsd %xmm1, %xmm0
movsd 0x40(%rsp), %xmm1
addsd 0x50(%rsp), %xmm1
movsd 0x48(%rsp), %xmm2
addsd %xmm2, %xmm2
subsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
cvtsi2sdq 0x118(%rsp), %xmm0
addsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x28(%rsp), %xmm0
movsd 0x45c7d(%rip), %xmm1    # 0x590f0
divsd %xmm1, %xmm0
movsd 0x45c69(%rip), %xmm1    # 0x590e8
addsd %xmm0, %xmm1
movsd 0x45c55(%rip), %xmm0    # 0x590e0
callq 0x92b0
movsd %xmm0, 0x20(%rsp)
movsd 0x20(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
movsd 0x1b0(%rsp), %xmm0
mulsd 0x1b0(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x1a0(%rsp), %xmm0
movsd 0x1a0(%rsp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x9b20
movsd %xmm0, 0x20(%rsp)
movsd 0x20(%rsp), %xmm0
movsd 0x45bd2(%rip), %xmm1    # 0x590d8
divsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x1c0(%rsp), %rax
cmpq $0x4, (%rax)
jae 0x135b8
movsd 0x18(%rsp), %xmm0
mulsd 0x128(%rsp), %xmm0
movq 0x1c8(%rsp), %rax
addq $0xc0, %rax
movq 0x1c0(%rsp), %rcx
movq (%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, (%rax)
movsd 0x48(%rsp), %xmm1
movsd 0x40(%rsp), %xmm2
subsd 0x50(%rsp), %xmm2
movsd 0x45b11(%rip), %xmm0    # 0x59080
mulsd %xmm2, %xmm0
movsd 0x30(%rsp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x1c8(%rsp), %rax
addq $0xc0, %rax
movq 0x1c0(%rsp), %rcx
movq (%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movq 0x1c0(%rsp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x135ba
jmp 0x135bc
movq 0x118(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x118(%rsp)
jmp 0x13349
movq 0x1c8(%rsp), %rax
addq $0xc0, %rax
movq %rax, 0x1d0(%rsp)
movq 0x1d0(%rsp), %rax
addq $0x1d8, %rsp            # imm = 0x1D8
retq
nopl (%rax,%rax)