// File: manikandan5[P]Image-Matching-Stitching-Warping/siftpp/sift.cpp
// Function: VL::Sift::prepareGrad(int)
void
Sift::prepareGrad(int o)
{ 
  int const ow = getOctaveWidth(o) ;
  int const oh = getOctaveHeight(o) ;
  int const xo = 1 ;
  int const yo = ow ;
  int const so = oh*ow ;

  if( ! tempIsGrad || tempOctave != o ) {

    // compute dx/dy
    for(int s = smin+1 ; s <= smax-2 ; ++s) {
      for(int y = 1 ; y < oh-1 ; ++y ) {
        pixel_t* src  = getLevel(o, s) + xo + yo*y ;        
        pixel_t* end  = src + ow - 1 ;
        pixel_t* grad = 2 * (xo + yo*y + (s - smin -1)*so) + temp ;
        while(src != end) {
          VL::float_t Gx = 0.5 * ( *(src+xo) - *(src-xo) ) ;
          VL::float_t Gy = 0.5 * ( *(src+yo) - *(src-yo) ) ;
          VL::float_t m = fast_sqrt( Gx*Gx + Gy*Gy ) ;
          VL::float_t t = fast_mod_2pi( fast_atan2(Gy, Gx) + VL::float_t(2*M_PI) );
          *grad++ = pixel_t( m ) ;
          *grad++ = pixel_t( t ) ;
          ++src ;
        }
      }
    }
  }
  
  tempIsGrad = true ;
  tempOctave = o ;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movl %esi, 0x4c(%rsp)
movq 0x50(%rsp), %rdi
movq %rdi, (%rsp)
movl 0x4c(%rsp), %esi
callq 0xc5d40
movq (%rsp), %rdi
movl %eax, 0x48(%rsp)
movl 0x4c(%rsp), %esi
callq 0xc5df0
movl %eax, %ecx
movq (%rsp), %rax
movl %ecx, 0x44(%rsp)
movl $0x1, 0x40(%rsp)
movl 0x48(%rsp), %ecx
movl %ecx, 0x3c(%rsp)
movl 0x44(%rsp), %ecx
imull 0x48(%rsp), %ecx
movl %ecx, 0x38(%rsp)
testb $0x1, 0x3c(%rax)
je 0xc41be
movq (%rsp), %rax
movl 0x40(%rax), %eax
cmpl 0x4c(%rsp), %eax
je 0xc43ba
movq (%rsp), %rax
movl 0x18(%rax), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
movq (%rsp), %rcx
movl 0x34(%rsp), %eax
movl 0x1c(%rcx), %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jg 0xc43b8
movl $0x1, 0x30(%rsp)
movl 0x30(%rsp), %eax
movl 0x44(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0xc43a6
movq (%rsp), %rdi
movl 0x4c(%rsp), %esi
movl 0x34(%rsp), %edx
callq 0xc5ea0
movq %rax, %rcx
movq (%rsp), %rax
addq $0x4, %rcx
movl 0x3c(%rsp), %edx
imull 0x30(%rsp), %edx
movslq %edx, %rdx
shlq $0x2, %rdx
addq %rdx, %rcx
movq %rcx, 0x28(%rsp)
movq 0x28(%rsp), %rcx
movslq 0x48(%rsp), %rdx
shlq $0x2, %rdx
addq %rdx, %rcx
addq $-0x4, %rcx
movq %rcx, 0x20(%rsp)
movl 0x3c(%rsp), %ecx
imull 0x30(%rsp), %ecx
addl $0x1, %ecx
movl 0x34(%rsp), %edx
subl 0x18(%rax), %edx
subl $0x1, %edx
imull 0x38(%rsp), %edx
addl %edx, %ecx
shll %ecx
movq 0x30(%rax), %rax
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, 0x18(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x20(%rsp), %rax
je 0xc4394
movq 0x28(%rsp), %rax
movss 0x4(%rax), %xmm0
movq 0x28(%rsp), %rax
subss -0x4(%rax), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x3d9b(%rip), %xmm0     # 0xc8048
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x14(%rsp)
movq 0x28(%rsp), %rax
movslq 0x3c(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
movq 0x28(%rsp), %rax
movslq 0x3c(%rsp), %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
subss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x3d5e(%rip), %xmm0     # 0xc8048
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x10(%rsp)
movss 0x14(%rsp), %xmm0
movss 0x14(%rsp), %xmm2
movss 0x10(%rsp), %xmm1
mulss 0x10(%rsp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
callq 0xc62f0
movss %xmm0, 0xc(%rsp)
movss 0x10(%rsp), %xmm0
movss 0x14(%rsp), %xmm1
callq 0xc6380
movss 0x29118(%rip), %xmm1    # 0xed454
addss %xmm1, %xmm0
callq 0xc6310
movss %xmm0, 0x8(%rsp)
movss 0xc(%rsp), %xmm0
movq 0x18(%rsp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x18(%rsp)
movss %xmm0, (%rax)
movss 0x8(%rsp), %xmm0
movq 0x18(%rsp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x18(%rsp)
movss %xmm0, (%rax)
movq 0x28(%rsp), %rax
addq $0x4, %rax
movq %rax, 0x28(%rsp)
jmp 0xc427d
jmp 0xc4396
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0xc41ea
jmp 0xc43a8
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0xc41cc
jmp 0xc43ba
movq (%rsp), %rax
movb $0x1, 0x3c(%rax)
movl 0x4c(%rsp), %ecx
movl %ecx, 0x40(%rax)
addq $0x58, %rsp
retq
nop