// File: /workspace/github_cpp_makefile_star2_O3/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 $0x268, %rsp            # imm = 0x268
movq %rsi, %r15
movq %rdi, %r14
leaq 0x7(%rsp), %rbx
movq %rbx, %rsi
callq 0x46a0
cmpb $0x50, (%rbx)
jne 0x6a279
leaq 0x7(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x46a0
movzbl (%rbx), %eax
movb $0x1, %r13b
cmpl $0x32, %eax
je 0x69f89
cmpl $0x35, %eax
jne 0x6a411
xorl %r13d, %r13d
movq %r14, %rdi
callq 0x69db4
leaq 0xc(%rsp), %rsi
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
callq 0x69db4
leaq 0x8(%rsp), %rsi
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
callq 0x69db4
leaq 0x14(%rsp), %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x42d0
leaq 0xf0(%rsp), %rsi
movq %r14, %rdi
callq 0x4710
movl (%rbx), %eax
cmpl $0x100, %eax            # imm = 0x100
jge 0x6a304
movl %eax, 0x10(%rsp)
movq %r15, 0x28(%rsp)
movq (%r14), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%r14,%rax)
jne 0x6a38f
movl 0xc(%rsp), %r12d
movl 0x8(%rsp), %ebx
movl %ebx, %r15d
imull %r12d, %r15d
movslq %r15d, %rax
leaq (,%rax,4), %rbp
testl %eax, %eax
movq $-0x1, %rdi
cmovnsq %rbp, %rdi
callq 0x4040
movq %rax, 0x18(%rsp)
testb %r13b, %r13b
je 0x6a0a7
testl %r15d, %r15d
movq 0x18(%rsp), %r15
je 0x6a140
cvtsi2ssl 0x10(%rsp), %xmm0
movss %xmm0, 0x10(%rsp)
xorl %r12d, %r12d
leaq 0x24(%rsp), %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x42d0
movq (%r14), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%r14,%rax)
jne 0x6a164
xorps %xmm0, %xmm0
cvtsi2ssl 0x24(%rsp), %xmm0
divss 0x10(%rsp), %xmm0
movss %xmm0, (%r15,%r12)
addq $0x4, %r12
cmpq %r12, %rbp
jne 0x6a05d
movl 0xc(%rsp), %r12d
movl 0x8(%rsp), %ebx
jmp 0x6a140
movq %r14, %rdi
callq 0x4940
movq %rax, %r12
movslq 0xc(%rsp), %rax
movslq 0x8(%rsp), %rbp
imulq %rax, %rbp
testl %ebp, %ebp
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovnsl %ebp, %eax
movslq %eax, %rdi
movq 0x18(%rsp), %r15
callq 0x4040
movq %rax, %r13
movq %r14, %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0x4660
movq (%r14), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%r14,%rax)
jne 0x6a49c
movl 0xc(%rsp), %r12d
movl 0x8(%rsp), %ebx
movl %ebx, %eax
imull %r12d, %eax
testl %eax, %eax
je 0x6a140
cltq
shlq $0x2, %rax
xorl %ecx, %ecx
movss 0x41a6(%rip), %xmm0     # 0x6e2c4
movzbl (%r13), %edx
incq %r13
xorps %xmm1, %xmm1
cvtsi2ss %edx, %xmm1
divss %xmm0, %xmm1
movss %xmm1, (%r15,%rcx)
addq $0x4, %rcx
cmpq %rcx, %rax
jne 0x6a11e
movq 0x28(%rsp), %rax
movl %r12d, (%rax)
movl %ebx, 0x4(%rax)
movq %r15, 0x8(%rax)
movq %r14, %rax
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf0(%rsp), %rdi
callq 0x46c0
leaq 0x293cc(%rip), %rsi     # 0x93544
leaq 0xf0(%rsp), %rdi
movl $0x1e, %edx
callq 0x45b0
movl 0xc(%rsp), %esi
leaq 0xf0(%rsp), %rdi
callq 0x4930
movq %rax, %r14
leaq 0x293be(%rip), %rsi     # 0x93563
movl $0x8, %edx
movq %rax, %rdi
callq 0x45b0
movl 0x8(%rsp), %esi
movq %r14, %rdi
callq 0x4930
movq %rax, %r14
leaq 0x293a4(%rip), %rsi     # 0x9356c
movl $0x8, %edx
movq %rax, %rdi
callq 0x45b0
movl 0x14(%rsp), %esi
movq %r14, %rdi
callq 0x4930
movq %rax, %r14
leaq 0x2938a(%rip), %rsi     # 0x93575
movl $0xa, %edx
movq %rax, %rdi
callq 0x45b0
sarq $0x2, %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x4500
leaq 0x58fd(%rip), %rsi      # 0x6fb0b
movl $0x1, %edx
movq %rax, %rdi
callq 0x45b0
movl $0x20, %edi
callq 0x4210
movq %rax, %r15
leaq 0xf8(%rsp), %rsi
leaq 0x50(%rsp), %rdi
callq 0x4880
movq %r15, %rax
addq $0x10, %rax
movq %rax, (%r15)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
movb $0x1, %bpl
movq %r15, %rdi
callq 0x374b4
xorl %ebp, %ebp
leaq 0x3daf3(%rip), %rsi     # 0xa7d58
leaq 0x3388(%rip), %rdx      # 0x6d5f4
movq %r15, %rdi
callq 0x4910
jmp 0x6a6cf
leaq 0xf0(%rsp), %rbx
movq %rbx, %rdi
callq 0x46c0
leaq 0x2924f(%rip), %rsi     # 0x934df
movl $0x19, %edx
movq %rbx, %rdi
callq 0x45b0
movl $0x20, %edi
callq 0x4210
movq %rax, %r14
leaq 0xf8(%rsp), %rsi
leaq 0xd0(%rsp), %rdi
callq 0x4880
movq %r14, %rax
addq $0x10, %rax
movq %rax, (%r14)
movq 0xd0(%rsp), %rsi
movq 0xd8(%rsp), %rdx
addq %rsi, %rdx
movb $0x1, %bpl
movq %r14, %rdi
callq 0x374b4
xorl %ebp, %ebp
leaq 0x3da68(%rip), %rsi     # 0xa7d58
leaq 0x32fd(%rip), %rdx      # 0x6d5f4
movq %r14, %rdi
callq 0x4910
jmp 0x6a6cf
leaq 0xf0(%rsp), %rbx
movq %rbx, %rdi
callq 0x46c0
leaq 0x291de(%rip), %rsi     # 0x934f9
movl $0x31, %edx
movq %rbx, %rdi
callq 0x45b0
movl $0x20, %edi
callq 0x4210
movq %rax, %r14
leaq 0xf8(%rsp), %rsi
leaq 0x90(%rsp), %rdi
callq 0x4880
movq %r14, %rax
addq $0x10, %rax
movq %rax, (%r14)
movq 0x90(%rsp), %rsi
movq 0x98(%rsp), %rdx
addq %rsi, %rdx
movb $0x1, %bpl
movq %r14, %rdi
callq 0x374b4
xorl %ebp, %ebp
leaq 0x3d9dd(%rip), %rsi     # 0xa7d58
leaq 0x3272(%rip), %rdx      # 0x6d5f4
movq %r14, %rdi
callq 0x4910
jmp 0x6a6cf
leaq 0xf0(%rsp), %rbx
movq %rbx, %rdi
callq 0x46c0
leaq 0x29185(%rip), %rsi     # 0x9352b
movl $0x18, %edx
movq %rbx, %rdi
callq 0x45b0
movl $0x20, %edi
callq 0x4210
movq %rax, %r14
leaq 0xf8(%rsp), %rsi
leaq 0x70(%rsp), %rdi
callq 0x4880
movq %r14, %rax
addq $0x10, %rax
movq %rax, (%r14)
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
addq %rsi, %rdx
movb $0x1, %bpl
movq %r14, %rdi
callq 0x374b4
xorl %ebp, %ebp
leaq 0x3d95b(%rip), %rsi     # 0xa7d58
leaq 0x31f0(%rip), %rdx      # 0x6d5f4
movq %r14, %rdi
callq 0x4910
jmp 0x6a6cf
leaq 0xf0(%rsp), %rbx
movq %rbx, %rdi
callq 0x46c0
leaq 0x290b7(%rip), %rsi     # 0x934df
movl $0x19, %edx
movq %rbx, %rdi
callq 0x45b0
movl $0x20, %edi
callq 0x4210
movq %rax, %r14
leaq 0xf8(%rsp), %rsi
leaq 0xb0(%rsp), %rdi
callq 0x4880
movq %r14, %rax
addq $0x10, %rax
movq %rax, (%r14)
movq 0xb0(%rsp), %rsi
movq 0xb8(%rsp), %rdx
addq %rsi, %rdx
movb $0x1, %bpl
movq %r14, %rdi
callq 0x374b4
xorl %ebp, %ebp
leaq 0x3d8d0(%rip), %rsi     # 0xa7d58
leaq 0x3165(%rip), %rdx      # 0x6d5f4
movq %r14, %rdi
callq 0x4910
jmp 0x6a6cf
leaq 0xf0(%rsp), %rdi
callq 0x46c0
leaq 0x29094(%rip), %rsi     # 0x93544
leaq 0xf0(%rsp), %rdi
movl $0x1e, %edx
callq 0x45b0
movl 0xc(%rsp), %esi
leaq 0xf0(%rsp), %rdi
callq 0x4930
movq %rax, %r15
leaq 0x29086(%rip), %rsi     # 0x93563
movl $0x8, %edx
movq %rax, %rdi
callq 0x45b0
movl 0x8(%rsp), %esi
movq %r15, %rdi
callq 0x4930
movq %rax, %r15
leaq 0x2906c(%rip), %rsi     # 0x9356c
movl $0x8, %edx
movq %rax, %rdi
callq 0x45b0
movl 0x14(%rsp), %esi
movq %r15, %rdi
callq 0x4930
movq %rax, %r15
leaq 0x29052(%rip), %rsi     # 0x93575
movl $0xa, %edx
movq %rax, %rdi
callq 0x45b0
movq %r14, %rdi
callq 0x4940
subq %r12, %rax
movq %r15, %rdi
movq %rax, %rsi
callq 0x4500
leaq 0x55be(%rip), %rsi      # 0x6fb0b
movl $0x1, %edx
movq %rax, %rdi
callq 0x45b0
movl $0x20, %edi
callq 0x4210
movq %rax, %r15
leaq 0xf8(%rsp), %rsi
leaq 0x30(%rsp), %rdi
callq 0x4880
movq %r15, %rax
addq $0x10, %rax
movq %rax, (%r15)
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
addq %rsi, %rdx
movb $0x1, %bpl
movq %r15, %rdi
callq 0x374b4
xorl %ebp, %ebp
leaq 0x3d7b4(%rip), %rsi     # 0xa7d58
leaq 0x3049(%rip), %rdx      # 0x6d5f4
movq %r15, %rdi
callq 0x4910
jmp 0x6a6cf
movq %rax, %r14
leaq 0x40(%rsp), %rax
jmp 0x6a5d1
jmp 0x6a5e9
jmp 0x6a68d
movq %rax, %r14
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6a5df
callq 0x44f0
testb %bpl, %bpl
jne 0x6a5ec
jmp 0x6a690
movq %rax, %r14
movq %r15, %rdi
callq 0x43c0
jmp 0x6a690
movq %rax, %rbx
leaq 0xc0(%rsp), %rax
jmp 0x6a63d
jmp 0x6a652
jmp 0x6a68d
jmp 0x6a6b5
movq %rax, %rbx
leaq 0x80(%rsp), %rax
jmp 0x6a63d
jmp 0x6a652
movq %rax, %rbx
leaq 0xa0(%rsp), %rax
jmp 0x6a63d
jmp 0x6a652
jmp 0x6a665
movq %rax, %rbx
leaq 0xe0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6a64b
callq 0x44f0
testb %bpl, %bpl
jne 0x6a655
jmp 0x6a668
movq %rax, %rbx
movq %r14, %rdi
callq 0x43c0
jmp 0x6a668
jmp 0x6a6b5
jmp 0x6a665
jmp 0x6a665
movq %rax, %rbx
movq 0x3d941(%rip), %rsi     # 0xa7fb0
leaq 0xf0(%rsp), %rdi
callq 0x4260
leaq 0x160(%rsp), %rdi
callq 0x4170
jmp 0x6a6d7
jmp 0x6a6b5
movq %rax, %r14
movq 0x3d919(%rip), %rsi     # 0xa7fb0
leaq 0xf0(%rsp), %rdi
callq 0x4260
leaq 0x160(%rsp), %rdi
callq 0x4170
jmp 0x6a6b8
jmp 0x6a6b5
movq %rax, %r14
movq %r14, %rdi
callq 0x41d0
movq 0x18(%rsp), %rdi
callq 0x4690
callq 0x4760
movq %rax, %rbx
callq 0x48d0
movq %rbx, %rdi
callq 0x4960
movq %rax, %rdi
callq 0xa02c