// File: /workspace/github_c_makefile_star2_O3/zpole[P]IICV/vl/sift.c
// Function: vl_sift_process_first_octave
VL_EXPORT
int
vl_sift_process_first_octave (VlSiftFilt *f, vl_sift_pix const *im)
{
  int o, s, h, w ;
  double sa, sb ;
  vl_sift_pix *octave ;

  /* shortcuts */
  vl_sift_pix *temp   = f-> temp ;
  int width           = f-> width ;
  int height          = f-> height ;
  int o_min           = f-> o_min ;
  int s_min           = f-> s_min ;
  int s_max           = f-> s_max ;
  double sigma0       = f-> sigma0 ;
  double sigmak       = f-> sigmak ;
  double sigman       = f-> sigman ;
  double dsigma0      = f-> dsigma0 ;

  /* restart from the first */
  f->o_cur = o_min ;
  f->nkeys = 0 ;
  w = f-> octave_width  = VL_SHIFT_LEFT(f->width,  - f->o_cur) ;
  h = f-> octave_height = VL_SHIFT_LEFT(f->height, - f->o_cur) ;

  /* is there at least one octave? */
  if (f->O == 0)
    return VL_ERR_EOF ;

  /* ------------------------------------------------------------------
   *                     Compute the first sublevel of the first octave
   * --------------------------------------------------------------- */

  /*
   * If the first octave has negative index, we upscale the image; if
   * the first octave has positive index, we downscale the image; if
   * the first octave has index zero, we just copy the image.
   */

  octave = vl_sift_get_octave (f, s_min) ;

  if (o_min < 0) {
    /* double once */
    copy_and_upsample_rows (temp,   im,   width,      height) ;
    copy_and_upsample_rows (octave, temp, height, 2 * width ) ;

    /* double more */
    for(o = -1 ; o > o_min ; --o) {
      copy_and_upsample_rows (temp, octave,
                              width << -o,      height << -o ) ;
      copy_and_upsample_rows (octave, temp,
                              width << -o, 2 * (height << -o)) ;
    }
  }
  else if (o_min > 0) {
    /* downsample */
    copy_and_downsample (octave, im, width, height, o_min) ;
  }
  else {
    /* direct copy */
    memcpy(octave, im, sizeof(vl_sift_pix) * width * height) ;
  }

  /*
   * Here we adjust the smoothing of the first level of the octave.
   * The input image is assumed to have nominal smoothing equal to
   * f->simgan.
   */

  sa = sigma0 * pow (sigmak,   s_min) ;
  sb = sigman * pow (2.0,    - o_min) ;

  if (sa > sb) {
    double sd = sqrt (sa*sa - sb*sb) ;
    _vl_sift_smooth (f, octave, temp, octave, w, h, sd) ;
  }

  /* -----------------------------------------------------------------
   *                                          Compute the first octave
   * -------------------------------------------------------------- */

  for(s = s_min + 1 ; s <= s_max ; ++s) {
    double sd = dsigma0 * pow (sigmak, s) ;
    _vl_sift_smooth (f, vl_sift_get_octave(f, s), temp,
                     vl_sift_get_octave(f, s - 1), w, h, sd) ;
  }

  return VL_ERR_OK ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %rbx
movq 0x40(%rdi), %r15
movslq 0x20(%rdi), %r13
movl 0x24(%rdi), %r9d
movl 0x30(%rdi), %ebp
movl 0x34(%rdi), %eax
movl 0x38(%rdi), %r14d
movsd 0x10(%rdi), %xmm0
movups (%rdi), %xmm2
movsd 0x18(%rdi), %xmm1
movl %ebp, 0x3c(%rdi)
movl $0x0, 0x80(%rdi)
testl %ebp, %ebp
jle 0x2b5ab
movl %r13d, %edx
movl %ebp, %ecx
sarl %cl, %edx
movl %edx, 0x58(%rbx)
movl %r9d, %edi
sarl %cl, %edi
jmp 0x2b5bc
movl %ebp, %ecx
negb %cl
movl %r13d, %edx
shll %cl, %edx
movl %edx, 0x58(%rbx)
movl %r9d, %edi
shll %cl, %edi
movl %edi, 0x5c(%rbx)
cmpl $0x0, 0x28(%rbx)
je 0x2b657
movq 0x48(%rbx), %r12
testl %ebp, %ebp
movq %r15, 0x40(%rsp)
movq %r12, 0x8(%rsp)
movsd %xmm0, 0x48(%rsp)
movq %rax, 0x38(%rsp)
movsd %xmm1, 0x68(%rsp)
movaps %xmm2, 0x70(%rsp)
movl %edx, 0x18(%rsp)
movl %edi, 0x14(%rsp)
js 0x2b661
je 0x2b719
movl $0x1, %edx
movl %ebp, %ecx
shll %cl, %edx
testl %r9d, %r9d
jle 0x2b72f
movl %r13d, %eax
subl %edx, %eax
incl %eax
movslq %edx, %rcx
imulq %rcx, %r13
shlq $0x2, %r13
xorl %edx, %edx
movq 0x8(%rsp), %rdi
testl %eax, %eax
jle 0x2b647
xorl %r8d, %r8d
movss (%rsi,%r8,4), %xmm0
movss %xmm0, (%rdi)
addq $0x4, %rdi
addq %rcx, %r8
cmpl %eax, %r8d
jl 0x2b631
addq %rcx, %rdx
addq %r13, %rsi
cmpq %r9, %rdx
jl 0x2b62a
jmp 0x2b72f
movl $0x5, %eax
jmp 0x2b835
movq %r15, %rdi
movl %r13d, %edx
movl %r9d, %ecx
movq %r9, 0x20(%rsp)
callq 0x2b847
leal (,%r13,2), %ecx
movq %r12, %rdi
movq %r15, %rsi
movq 0x20(%rsp), %rdx
callq 0x2b847
movq 0x20(%rsp), %rax
cmpl $-0x1, %ebp
je 0x2b72f
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl $0x1, %r15d
movq %r14, 0x60(%rsp)
movl %ebp, 0x1c(%rsp)
movq %rbx, 0x58(%rsp)
movq %r13, 0x50(%rsp)
movl %r13d, %ebp
movl %r15d, %ecx
shll %cl, %ebp
movl %eax, %r13d
shll %cl, %r13d
movq 0x40(%rsp), %rbx
movq %rbx, %rdi
movq 0x8(%rsp), %r14
movq %r14, %rsi
movl %ebp, %edx
movl %r13d, %ecx
callq 0x2b847
addl %r13d, %r13d
movq %r14, %rdi
movq %rbx, %rsi
movq 0x58(%rsp), %rbx
movq 0x60(%rsp), %r14
movl %ebp, %edx
movl 0x1c(%rsp), %ebp
movl %r13d, %ecx
movq 0x50(%rsp), %r13
callq 0x2b847
movq 0x20(%rsp), %rax
decl %r12d
incl %r15d
cmpl %ebp, %r12d
jg 0x2b6b9
jmp 0x2b72f
movslq %r9d, %rax
imulq %rax, %r13
shlq $0x2, %r13
movq %r12, %rdi
movq %r13, %rdx
callq 0x95a0
xorps %xmm1, %xmm1
cvtsi2sdl 0x38(%rsp), %xmm1
movsd 0x48(%rsp), %xmm0
callq 0x9270
movaps %xmm0, 0x20(%rsp)
negl %ebp
movsd 0x6b1e(%rip), %xmm0     # 0x32270
movl %ebp, %edi
callq 0x90c0
unpcklpd 0x20(%rsp), %xmm0       # xmm0 = xmm0[0],mem[0]
movapd 0x70(%rsp), %xmm1
mulpd %xmm0, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
ucomisd %xmm1, %xmm0
movslq 0x18(%rsp), %r12
movslq 0x14(%rsp), %r13
movq 0x40(%rsp), %r15
jbe 0x2b7c0
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
subsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x2b7a2
sqrtsd %xmm0, %xmm0
jmp 0x2b7a7
callq 0x9990
movq %rbx, %rdi
movq 0x8(%rsp), %rcx
movq %rcx, %rsi
movq %r15, %rdx
movq %r12, %r8
movq %r13, %r9
callq 0x2b8d8
xorl %eax, %eax
movq 0x38(%rsp), %rbp
cmpl %r14d, %ebp
jge 0x2b835
negl %r14d
incl %ebp
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
movsd 0x48(%rsp), %xmm0
callq 0x9270
mulsd 0x68(%rsp), %xmm0
movl 0x5c(%rbx), %eax
imull 0x58(%rbx), %eax
movq 0x48(%rbx), %rcx
movl %ebp, %edx
subl 0x34(%rbx), %edx
movl %edx, %esi
imull %eax, %esi
movslq %esi, %rsi
leaq (%rcx,%rsi,4), %rsi
decl %edx
imull %eax, %edx
movslq %edx, %rax
leaq (%rcx,%rax,4), %rcx
movq %rbx, %rdi
movq %r15, %rdx
movq %r12, %r8
movq %r13, %r9
callq 0x2b8d8
leal (%r14,%rbp), %eax
incl %eax
movl %ebp, %ecx
incl %ecx
movl %ecx, %ebp
cmpl $0x1, %eax
jne 0x2b7d1
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq