// File: /workspace/github_cpp_makefile_star2_O2/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 0x50814
leaq 0x3(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4690
movzbl (%rbx), %eax
movb $0x1, %bpl
cmpl $0x32, %eax
je 0x50592
cmpl $0x35, %eax
jne 0x5095b
xorl %ebp, %ebp
movq %r14, %rdi
callq 0x5040c
leaq 0x8(%rsp), %rsi
movq %rax, %rdi
callq 0x42c0
movq %rax, %rdi
callq 0x5040c
leaq 0x4(%rsp), %rsi
movq %rax, %rdi
callq 0x42c0
movq %rax, %rdi
callq 0x5040c
leaq 0xc(%rsp), %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x42c0
leaq 0xe0(%rsp), %rsi
movq %r14, %rdi
callq 0x4710
movl (%rbx), %r12d
cmpl $0x100, %r12d           # imm = 0x100
jge 0x50883
movq (%r14), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%r14,%rax)
jne 0x508f2
movslq 0x8(%rsp), %rax
movslq 0x4(%rsp), %rcx
imulq %rax, %rcx
movq %rcx, %r15
shlq $0x2, %r15
testl %ecx, %ecx
pushq $-0x1
popq %rdi
cmovnsq %r15, %rdi
callq 0x4040
movq %rax, %rbx
testb %bpl, %bpl
je 0x50684
cvtsi2ss %r12d, %xmm0
movss %xmm0, 0x10(%rsp)
xorl %r12d, %r12d
leaq 0x14(%rsp), %r13
cmpq %r12, %r15
je 0x5070f
movq %r14, %rdi
movq %r13, %rsi
callq 0x42c0
movq (%r14), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%r14,%rax)
jne 0x5073a
cvtsi2ssl 0x14(%rsp), %xmm0
divss 0x10(%rsp), %xmm0
movss %xmm0, (%rbx,%r12)
addq $0x4, %r12
jmp 0x50645
movq %r14, %rdi
callq 0x4940
movq %rax, %r12
movslq 0x8(%rsp), %rax
movslq 0x4(%rsp), %rbp
imulq %rax, %rbp
testl %ebp, %ebp
pushq $-0x1
popq %rax
cmovnsl %ebp, %eax
movslq %eax, %rdi
callq 0x4040
movq %rax, %r13
movq %r14, %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0x4640
movq (%r14), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%r14,%rax)
jne 0x509ca
movl 0x8(%rsp), %eax
movl 0x4(%rsp), %ecx
movl %ecx, %edx
imull %eax, %edx
movslq %edx, %rdx
shlq $0x2, %rdx
xorl %esi, %esi
movss 0x3b45(%rip), %xmm0     # 0x54234
cmpq %rsi, %rdx
je 0x50717
movzbl (%r13), %edi
cvtsi2ss %edi, %xmm1
incq %r13
divss %xmm0, %xmm1
movss %xmm1, (%rbx,%rsi)
addq $0x4, %rsi
jmp 0x506ef
movl 0x8(%rsp), %eax
movl 0x4(%rsp), %ecx
movq 0x18(%rsp), %rdx
movl %eax, (%rdx)
movl %ecx, 0x4(%rdx)
movq %rbx, 0x8(%rdx)
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 0x28ea6(%rip), %rsi     # 0x795f4
leaq 0xe0(%rsp), %rdi
callq 0x4520
movl 0x8(%rsp), %esi
movq %rax, %rdi
callq 0x4930
leaq 0x28ea5(%rip), %rsi     # 0x79613
movq %rax, %rdi
callq 0x4520
movl 0x4(%rsp), %esi
movq %rax, %rdi
callq 0x4930
leaq 0x28e93(%rip), %rsi     # 0x7961c
movq %rax, %rdi
callq 0x4520
movl 0xc(%rsp), %esi
movq %rax, %rdi
callq 0x4930
leaq 0x28e81(%rip), %rsi     # 0x79625
movq %rax, %rdi
callq 0x4520
sarq $0x2, %r12
movq %rax, %rdi
movq %r12, %rsi
callq 0x44e0
leaq 0x52c9(%rip), %rsi      # 0x55a8b
movq %rax, %rdi
callq 0x4520
pushq $0x20
popq %rdi
callq 0x4210
movq %rax, %r15
leaq 0xe8(%rsp), %rsi
leaq 0x40(%rsp), %rdi
callq 0x4880
movb $0x1, %bpl
leaq 0x40(%rsp), %rsi
movq %r15, %rdi
callq 0x4700
xorl %ebp, %ebp
leaq 0x3f568(%rip), %rsi     # 0x8fd68
leaq 0x2905(%rip), %rdx      # 0x5310c
movq %r15, %rdi
callq 0x4910
jmp 0x50b7a
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
callq 0x46b0
leaq 0x28d64(%rip), %rsi     # 0x7958f
movq %rbx, %rdi
callq 0x4520
pushq $0x20
popq %rdi
callq 0x4210
movq %rax, %r14
leaq 0xe8(%rsp), %rsi
leaq 0xc0(%rsp), %rdi
callq 0x4880
movb $0x1, %bpl
leaq 0xc0(%rsp), %rsi
movq %r14, %rdi
callq 0x4700
xorl %ebp, %ebp
leaq 0x3f4f9(%rip), %rsi     # 0x8fd68
leaq 0x2896(%rip), %rdx      # 0x5310c
movq %r14, %rdi
callq 0x4910
jmp 0x50b7a
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
callq 0x46b0
leaq 0x28d0f(%rip), %rsi     # 0x795a9
movq %rbx, %rdi
callq 0x4520
pushq $0x20
popq %rdi
callq 0x4210
movq %rax, %r14
leaq 0xe8(%rsp), %rsi
leaq 0x80(%rsp), %rdi
callq 0x4880
movb $0x1, %bpl
leaq 0x80(%rsp), %rsi
movq %r14, %rdi
callq 0x4700
xorl %ebp, %ebp
leaq 0x3f48a(%rip), %rsi     # 0x8fd68
leaq 0x2827(%rip), %rdx      # 0x5310c
movq %r14, %rdi
callq 0x4910
jmp 0x50b7a
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
callq 0x46b0
leaq 0x28cd2(%rip), %rsi     # 0x795db
movq %rbx, %rdi
callq 0x4520
pushq $0x20
popq %rdi
callq 0x4210
movq %rax, %r14
leaq 0xe8(%rsp), %rsi
leaq 0x60(%rsp), %rdi
callq 0x4880
movb $0x1, %bpl
leaq 0x60(%rsp), %rsi
movq %r14, %rdi
callq 0x4700
xorl %ebp, %ebp
leaq 0x3f421(%rip), %rsi     # 0x8fd68
leaq 0x27be(%rip), %rdx      # 0x5310c
movq %r14, %rdi
callq 0x4910
jmp 0x50b7a
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
callq 0x46b0
leaq 0x28c1d(%rip), %rsi     # 0x7958f
movq %rbx, %rdi
callq 0x4520
pushq $0x20
popq %rdi
callq 0x4210
movq %rax, %r14
leaq 0xe8(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
callq 0x4880
movb $0x1, %bpl
leaq 0xa0(%rsp), %rsi
movq %r14, %rdi
callq 0x4700
xorl %ebp, %ebp
leaq 0x3f3b2(%rip), %rsi     # 0x8fd68
leaq 0x274f(%rip), %rdx      # 0x5310c
movq %r14, %rdi
callq 0x4910
jmp 0x50b7a
leaq 0xe0(%rsp), %rdi
callq 0x46b0
leaq 0x28c16(%rip), %rsi     # 0x795f4
leaq 0xe0(%rsp), %rdi
callq 0x4520
movl 0x8(%rsp), %esi
movq %rax, %rdi
callq 0x4930
leaq 0x28c15(%rip), %rsi     # 0x79613
movq %rax, %rdi
callq 0x4520
movl 0x4(%rsp), %esi
movq %rax, %rdi
callq 0x4930
leaq 0x28c03(%rip), %rsi     # 0x7961c
movq %rax, %rdi
callq 0x4520
movl 0xc(%rsp), %esi
movq %rax, %rdi
callq 0x4930
leaq 0x28bf1(%rip), %rsi     # 0x79625
movq %rax, %rdi
callq 0x4520
movq %rax, %r15
movq %r14, %rdi
callq 0x4940
subq %r12, %rax
movq %r15, %rdi
movq %rax, %rsi
callq 0x44e0
leaq 0x502f(%rip), %rsi      # 0x55a8b
movq %rax, %rdi
callq 0x4520
pushq $0x20
popq %rdi
callq 0x4210
movq %rax, %r15
leaq 0xe8(%rsp), %rsi
leaq 0x20(%rsp), %rdi
callq 0x4880
movb $0x1, %bpl
leaq 0x20(%rsp), %rsi
movq %r15, %rdi
callq 0x4700
xorl %ebp, %ebp
leaq 0x3f2ce(%rip), %rsi     # 0x8fd68
leaq 0x266b(%rip), %rdx      # 0x5310c
movq %r15, %rdi
callq 0x4910
jmp 0x50b7a
movq %rax, %r14
leaq 0x20(%rsp), %rdi
jmp 0x50ac7
jmp 0x50ad3
jmp 0x50b4e
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x4aa8
testb %bpl, %bpl
jne 0x50ad6
jmp 0x50b51
movq %rax, %r14
movq %r15, %rdi
callq 0x4390
jmp 0x50b51
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
jmp 0x50b1b
jmp 0x50b27
jmp 0x50b4e
jmp 0x50b62
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
jmp 0x50b1b
jmp 0x50b27
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
jmp 0x50b1b
jmp 0x50b27
jmp 0x50b3a
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x4aa8
testb %bpl, %bpl
jne 0x50b2a
jmp 0x50b3d
movq %rax, %rbx
movq %r14, %rdi
callq 0x4390
jmp 0x50b3d
jmp 0x50b62
jmp 0x50b3a
jmp 0x50b3a
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x40c0
jmp 0x50b82
jmp 0x50b62
movq %rax, %r14
leaq 0xe0(%rsp), %rdi
callq 0x40c0
jmp 0x50b65
jmp 0x50b62
movq %rax, %r14
movq %r14, %rdi
callq 0x41d0
movq %rbx, %rdi
callq 0x4670
callq 0x4760
movq %rax, %rbx
callq 0x48d0
movq %rbx, %rdi
callq 0x4950
movq %rax, %rdi
callq 0x7f6f