// File: /workspace/github_cpp_makefile_star2_O1/manikandan5[P]Image-Matching-Stitching-Warping/siftpp/sift.cpp
// Function: VL::extractPgm(std::istream&, VL::PgmBuffer&)
std::istream& 
extractPgm(std::istream& in, PgmBuffer& buffer)
{
  pixel_t* im_pt ;
  int      width ;
  int      height ;
  int      maxval ;

  char c ;
  in>>c ;
  if( c != 'P') VL_THROW("File is not in PGM format") ;
  
  bool is_ascii ;
  in>>c ;
  switch( c ) {
  case '2' : is_ascii = true ; break ;
  case '5' : is_ascii = false ; break ;
  default  : VL_THROW("File is not in PGM format") ;
  }
  
  in >> Detail::cmnt
     >> width
     >> Detail::cmnt 
     >> height
     >> Detail::cmnt
     >> maxval ;

  // after maxval no more comments, just a whitespace or newline
  {char trash ; in.get(trash) ;}

  if(maxval > 255)
    VL_THROW("Only <= 8-bit per channel PGM files are supported") ;

  if(! in.good()) 
    VL_THROW("PGM header parsing error") ;
  
  im_pt = new pixel_t [ width*height ];
  
  try {
    if( is_ascii ) {
      pixel_t* start = im_pt ;
      pixel_t* end   = start + width*height ; 
      pixel_t  norm  = pixel_t( maxval ) ;
      
      while( start != end ) {        
        int i ;
        in >> i ;	
        if( ! in.good() ) VL_THROW
                            ("PGM parsing error file (width="<<width
                             <<" height="<<height
                             <<" maxval="<<maxval
                             <<" at pixel="<<start-im_pt<<")") ;    
        *start++ = pixel_t( i ) / norm ;        
      }
    } else {
      std::streampos beg = in.tellg() ;
      char* buffer = new char [width*height] ;
      in.read(buffer, width*height) ;
      if( ! in.good() ) VL_THROW
			  ("PGM parsing error file (width="<<width
			   <<" height="<<height
			   <<" maxval="<<maxval
			   <<" at pixel="<<in.tellg()-beg<<")") ;
      
      pixel_t* start = im_pt ;
      pixel_t* end   = start + width*height ; 
      uint8_t* src = reinterpret_cast<uint8_t*>(buffer) ;      
      while( start != end ) *start++ = *src++ / 255.0f ;
    }       
  } catch(...) {
    delete [] im_pt ; 
    throw ;
  }
  
  buffer.width  = width ;
  buffer.height = height ;
  buffer.data   = im_pt ;

  return in ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movq %rsi, 0x18(%rsp)
movq %rdi, %r14
leaq 0x3(%rsp), %rbx
movq %rbx, %rsi
callq 0x4690
cmpb $0x50, (%rbx)
jne 0x6d30c
leaq 0x3(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4690
movzbl (%rbx), %eax
movb $0x1, %bpl
cmpl $0x32, %eax
je 0x6d03a
cmpl $0x35, %eax
jne 0x6d4a4
xorl %ebp, %ebp
movq %r14, %rdi
callq 0x6ce64
leaq 0x8(%rsp), %rsi
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
callq 0x6ce64
leaq 0x4(%rsp), %rsi
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
callq 0x6ce64
leaq 0xc(%rsp), %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x42d0
leaq 0xe0(%rsp), %rsi
movq %r14, %rdi
callq 0x4700
movl (%rbx), %r12d
cmpl $0x100, %r12d           # imm = 0x100
jge 0x6d397
movq (%r14), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%r14,%rax)
jne 0x6d422
movslq 0x8(%rsp), %rax
movslq 0x4(%rsp), %r13
imulq %rax, %r13
movq %r13, %r15
shlq $0x2, %r15
testl %r13d, %r13d
movq $-0x1, %rdi
cmovnsq %r15, %rdi
callq 0x4040
movq %rax, %rbx
testb %bpl, %bpl
je 0x6d13c
testl %r13d, %r13d
je 0x6d1cc
cvtsi2ss %r12d, %xmm0
movss %xmm0, 0x10(%rsp)
xorl %r12d, %r12d
leaq 0x14(%rsp), %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x42d0
movq (%r14), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%r14,%rax)
jne 0x6d1f7
xorps %xmm0, %xmm0
cvtsi2ssl 0x14(%rsp), %xmm0
divss 0x10(%rsp), %xmm0
movss %xmm0, (%rbx,%r12)
addq $0x4, %r12
cmpq %r12, %r15
jne 0x6d0fb
jmp 0x6d1cc
movq %r14, %rdi
callq 0x4930
movq %rax, %r12
movslq 0x8(%rsp), %rax
movslq 0x4(%rsp), %rbp
imulq %rax, %rbp
testl %ebp, %ebp
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovnsl %ebp, %eax
movslq %eax, %rdi
callq 0x4040
movq %rax, %r13
movq %r14, %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0x4650
movq (%r14), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%r14,%rax)
jne 0x6d52f
movslq 0x8(%rsp), %rcx
movslq 0x4(%rsp), %rax
imulq %rcx, %rax
testl %eax, %eax
je 0x6d1cc
shlq $0x2, %rax
xorl %ecx, %ecx
movss 0x4119(%rip), %xmm0     # 0x712c4
movzbl (%r13), %edx
incq %r13
xorps %xmm1, %xmm1
cvtsi2ss %edx, %xmm1
divss %xmm0, %xmm1
movss %xmm1, (%rbx,%rcx)
addq $0x4, %rcx
cmpq %rcx, %rax
jne 0x6d1ab
movl 0x8(%rsp), %eax
movq 0x18(%rsp), %rcx
movl %eax, (%rcx)
movl 0x4(%rsp), %eax
movl %eax, 0x4(%rcx)
movq %rbx, 0x8(%rcx)
movq %r14, %rax
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xe0(%rsp), %rdi
callq 0x46b0
leaq 0x2af49(%rip), %rsi     # 0x98154
leaq 0xe0(%rsp), %rdi
movl $0x1e, %edx
callq 0x45a0
movl 0x8(%rsp), %esi
leaq 0xe0(%rsp), %rdi
callq 0x4920
movq %rax, %r14
leaq 0x2af3b(%rip), %rsi     # 0x98173
movl $0x8, %edx
movq %rax, %rdi
callq 0x45a0
movl 0x4(%rsp), %esi
movq %r14, %rdi
callq 0x4920
movq %rax, %r14
leaq 0x2af21(%rip), %rsi     # 0x9817c
movl $0x8, %edx
movq %rax, %rdi
callq 0x45a0
movl 0xc(%rsp), %esi
movq %r14, %rdi
callq 0x4920
movq %rax, %r14
leaq 0x2af07(%rip), %rsi     # 0x98185
movl $0xa, %edx
movq %rax, %rdi
callq 0x45a0
sarq $0x2, %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x44f0
leaq 0x733a(%rip), %rsi      # 0x745db
movl $0x1, %edx
movq %rax, %rdi
callq 0x45a0
movl $0x20, %edi
callq 0x4210
movq %rax, %r15
leaq 0xe8(%rsp), %rsi
leaq 0x40(%rsp), %rdi
callq 0x4870
movq %r15, %rax
addq $0x10, %rax
movq %rax, (%r15)
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
addq %rsi, %rdx
movb $0x1, %bpl
movq %r15, %rdi
callq 0x39158
xorl %ebp, %ebp
leaq 0x3fa60(%rip), %rsi     # 0xacd58
leaq 0x336f(%rip), %rdx      # 0x7066e
movq %r15, %rdi
callq 0x4900
jmp 0x6d764
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
callq 0x46b0
leaq 0x2adcc(%rip), %rsi     # 0x980ef
movl $0x19, %edx
movq %rbx, %rdi
callq 0x45a0
movl $0x20, %edi
callq 0x4210
movq %rax, %r14
leaq 0xe8(%rsp), %rsi
leaq 0xc0(%rsp), %rdi
callq 0x4870
movq %r14, %rax
addq $0x10, %rax
movq %rax, (%r14)
movq 0xc0(%rsp), %rsi
movq 0xc8(%rsp), %rdx
addq %rsi, %rdx
movb $0x1, %bpl
movq %r14, %rdi
callq 0x39158
xorl %ebp, %ebp
leaq 0x3f9d5(%rip), %rsi     # 0xacd58
leaq 0x32e4(%rip), %rdx      # 0x7066e
movq %r14, %rdi
callq 0x4900
jmp 0x6d764
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
callq 0x46b0
leaq 0x2ad5b(%rip), %rsi     # 0x98109
movl $0x31, %edx
movq %rbx, %rdi
callq 0x45a0
movl $0x20, %edi
callq 0x4210
movq %rax, %r14
leaq 0xe8(%rsp), %rsi
leaq 0x80(%rsp), %rdi
callq 0x4870
movq %r14, %rax
addq $0x10, %rax
movq %rax, (%r14)
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
addq %rsi, %rdx
movb $0x1, %bpl
movq %r14, %rdi
callq 0x39158
xorl %ebp, %ebp
leaq 0x3f94a(%rip), %rsi     # 0xacd58
leaq 0x3259(%rip), %rdx      # 0x7066e
movq %r14, %rdi
callq 0x4900
jmp 0x6d764
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
callq 0x46b0
leaq 0x2ad02(%rip), %rsi     # 0x9813b
movl $0x18, %edx
movq %rbx, %rdi
callq 0x45a0
movl $0x20, %edi
callq 0x4210
movq %rax, %r14
leaq 0xe8(%rsp), %rsi
leaq 0x60(%rsp), %rdi
callq 0x4870
movq %r14, %rax
addq $0x10, %rax
movq %rax, (%r14)
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
addq %rsi, %rdx
movb $0x1, %bpl
movq %r14, %rdi
callq 0x39158
xorl %ebp, %ebp
leaq 0x3f8c8(%rip), %rsi     # 0xacd58
leaq 0x31d7(%rip), %rdx      # 0x7066e
movq %r14, %rdi
callq 0x4900
jmp 0x6d764
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
callq 0x46b0
leaq 0x2ac34(%rip), %rsi     # 0x980ef
movl $0x19, %edx
movq %rbx, %rdi
callq 0x45a0
movl $0x20, %edi
callq 0x4210
movq %rax, %r14
leaq 0xe8(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
callq 0x4870
movq %r14, %rax
addq $0x10, %rax
movq %rax, (%r14)
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
addq %rsi, %rdx
movb $0x1, %bpl
movq %r14, %rdi
callq 0x39158
xorl %ebp, %ebp
leaq 0x3f83d(%rip), %rsi     # 0xacd58
leaq 0x314c(%rip), %rdx      # 0x7066e
movq %r14, %rdi
callq 0x4900
jmp 0x6d764
leaq 0xe0(%rsp), %rdi
callq 0x46b0
leaq 0x2ac11(%rip), %rsi     # 0x98154
leaq 0xe0(%rsp), %rdi
movl $0x1e, %edx
callq 0x45a0
movl 0x8(%rsp), %esi
leaq 0xe0(%rsp), %rdi
callq 0x4920
movq %rax, %r15
leaq 0x2ac03(%rip), %rsi     # 0x98173
movl $0x8, %edx
movq %rax, %rdi
callq 0x45a0
movl 0x4(%rsp), %esi
movq %r15, %rdi
callq 0x4920
movq %rax, %r15
leaq 0x2abe9(%rip), %rsi     # 0x9817c
movl $0x8, %edx
movq %rax, %rdi
callq 0x45a0
movl 0xc(%rsp), %esi
movq %r15, %rdi
callq 0x4920
movq %rax, %r15
leaq 0x2abcf(%rip), %rsi     # 0x98185
movl $0xa, %edx
movq %rax, %rdi
callq 0x45a0
movq %r14, %rdi
callq 0x4930
subq %r12, %rax
movq %r15, %rdi
movq %rax, %rsi
callq 0x44f0
leaq 0x6ffb(%rip), %rsi      # 0x745db
movl $0x1, %edx
movq %rax, %rdi
callq 0x45a0
movl $0x20, %edi
callq 0x4210
movq %rax, %r15
leaq 0xe8(%rsp), %rsi
leaq 0x20(%rsp), %rdi
callq 0x4870
movq %r15, %rax
addq $0x10, %rax
movq %rax, (%r15)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
addq %rsi, %rdx
movb $0x1, %bpl
movq %r15, %rdi
callq 0x39158
xorl %ebp, %ebp
leaq 0x3f721(%rip), %rsi     # 0xacd58
leaq 0x3030(%rip), %rdx      # 0x7066e
movq %r15, %rdi
callq 0x4900
jmp 0x6d764
movq %rax, %r14
leaq 0x30(%rsp), %rax
jmp 0x6d664
jmp 0x6d674
jmp 0x6d724
movq %rax, %r14
leaq 0x50(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6d67a
callq 0x44e0
jmp 0x6d67a
movq %rax, %r14
movb $0x1, %bpl
testb %bpl, %bpl
je 0x6d727
movq %r15, %rdi
callq 0x43b0
jmp 0x6d727
movq %rax, %rbx
leaq 0xb0(%rsp), %rax
jmp 0x6d6d1
jmp 0x6d6e1
jmp 0x6d724
jmp 0x6d74c
movq %rax, %rbx
leaq 0x70(%rsp), %rax
jmp 0x6d6d1
jmp 0x6d6e1
movq %rax, %rbx
leaq 0x90(%rsp), %rax
jmp 0x6d6d1
jmp 0x6d6e1
jmp 0x6d6fc
movq %rax, %rbx
leaq 0xd0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6d6e7
callq 0x44e0
jmp 0x6d6e7
movq %rax, %rbx
movb $0x1, %bpl
testb %bpl, %bpl
je 0x6d6ff
movq %r14, %rdi
callq 0x43b0
jmp 0x6d6ff
jmp 0x6d74c
jmp 0x6d6fc
jmp 0x6d6fc
movq %rax, %rbx
movq 0x3f8aa(%rip), %rsi     # 0xacfb0
leaq 0xe0(%rsp), %rdi
callq 0x4260
leaq 0x150(%rsp), %rdi
callq 0x4170
jmp 0x6d76c
jmp 0x6d74c
movq %rax, %r14
movq 0x3f882(%rip), %rsi     # 0xacfb0
leaq 0xe0(%rsp), %rdi
callq 0x4260
leaq 0x150(%rsp), %rdi
callq 0x4170
jmp 0x6d74f
jmp 0x6d74c
movq %rax, %r14
movq %r14, %rdi
callq 0x41d0
movq %rbx, %rdi
callq 0x4680
callq 0x4750
movq %rax, %rbx
callq 0x48c0
movq %rbx, %rdi
callq 0x4950
movq %rax, %rdi
callq 0xa08f