// File: 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:
subq $0xb78, %rsp            # imm = 0xB78
movq %rdi, 0xb70(%rsp)
movq %rsi, 0xb68(%rsp)
movq 0xb70(%rsp), %rdi
leaq 0xb53(%rsp), %rsi
callq 0x5690
movsbl 0xb53(%rsp), %eax
cmpl $0x50, %eax
je 0xc0262
leaq 0x9d8(%rsp), %rdi
movq %rdi, 0x120(%rsp)
callq 0x56b0
movq 0x120(%rsp), %rdi
leaq 0x2d37e(%rip), %rsi     # 0xed4ef
callq 0x5520
jmp 0xc0178
movb $0x1, 0x9a7(%rsp)
movl $0x20, %edi
callq 0x5240
movq %rax, 0x118(%rsp)
leaq 0x9a8(%rsp), %rdi
leaq 0x9d8(%rsp), %rsi
callq 0x5550
jmp 0xc01a9
movq 0x118(%rsp), %rdi
leaq 0x9a8(%rsp), %rsi
callq 0xc5840
jmp 0xc01c0
movq 0x118(%rsp), %rdi
movb $0x0, 0x9a7(%rsp)
leaq 0x3fb89(%rip), %rsi     # 0xffd60
leaq 0x5682(%rip), %rdx      # 0xc5860
callq 0x5920
jmp 0xc0e16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x9d0(%rsp)
movl %eax, 0x9cc(%rsp)
jmp 0xc0250
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x9d0(%rsp)
movl %eax, 0x9cc(%rsp)
jmp 0xc0235
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x9d0(%rsp)
movl %eax, 0x9cc(%rsp)
leaq 0x9a8(%rsp), %rdi
callq 0x5ae8
testb $0x1, 0x9a7(%rsp)
jne 0xc0241
jmp 0xc024e
movq 0x118(%rsp), %rdi
callq 0x53a0
jmp 0xc0250
leaq 0x9d8(%rsp), %rdi
callq 0x50e0
jmp 0xc0e01
movq 0xb70(%rsp), %rdi
leaq 0xb53(%rsp), %rsi
callq 0x5690
movsbl 0xb53(%rsp), %eax
movl %eax, 0x114(%rsp)
subl $0x32, %eax
je 0xc029b
jmp 0xc028d
movl 0x114(%rsp), %eax
subl $0x35, %eax
je 0xc02a8
jmp 0xc02b5
movb $0x1, 0x9a6(%rsp)
jmp 0xc03ca
movb $0x0, 0x9a6(%rsp)
jmp 0xc03ca
leaq 0x828(%rsp), %rdi
movq %rdi, 0x108(%rsp)
callq 0x56b0
movq 0x108(%rsp), %rdi
leaq 0x2d216(%rip), %rsi     # 0xed4ef
callq 0x5520
jmp 0xc02e0
movb $0x1, 0x807(%rsp)
movl $0x20, %edi
callq 0x5240
movq %rax, 0x100(%rsp)
leaq 0x808(%rsp), %rdi
leaq 0x828(%rsp), %rsi
callq 0x5550
jmp 0xc0311
movq 0x100(%rsp), %rdi
leaq 0x808(%rsp), %rsi
callq 0xc5840
jmp 0xc0328
movq 0x100(%rsp), %rdi
movb $0x0, 0x807(%rsp)
leaq 0x3fa21(%rip), %rsi     # 0xffd60
leaq 0x551a(%rip), %rdx      # 0xc5860
callq 0x5920
jmp 0xc0e16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x9d0(%rsp)
movl %eax, 0x9cc(%rsp)
jmp 0xc03b8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x9d0(%rsp)
movl %eax, 0x9cc(%rsp)
jmp 0xc039d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x9d0(%rsp)
movl %eax, 0x9cc(%rsp)
leaq 0x808(%rsp), %rdi
callq 0x5ae8
testb $0x1, 0x807(%rsp)
jne 0xc03a9
jmp 0xc03b6
movq 0x100(%rsp), %rdi
callq 0x53a0
jmp 0xc03b8
leaq 0x828(%rsp), %rdi
callq 0x50e0
jmp 0xc0e01
movq 0xb70(%rsp), %rdi
leaq 0x42f3c(%rip), %rsi     # 0x103315
callq 0xbff40
movq %rax, %rdi
leaq 0xb5c(%rsp), %rsi
callq 0x52e0
movq %rax, %rdi
leaq 0x42f1d(%rip), %rsi     # 0x103315
callq 0xbff40
movq %rax, %rdi
leaq 0xb58(%rsp), %rsi
callq 0x52e0
movq %rax, %rdi
leaq 0x42efe(%rip), %rsi     # 0x103315
callq 0xbff40
movq %rax, %rdi
leaq 0xb54(%rsp), %rsi
callq 0x52e0
movq 0xb70(%rsp), %rdi
leaq 0x806(%rsp), %rsi
callq 0x5700
cmpl $0xff, 0xb54(%rsp)
jle 0xc0567
leaq 0x688(%rsp), %rdi
movq %rdi, 0xf8(%rsp)
callq 0x56b0
movq 0xf8(%rsp), %rdi
leaq 0x2d093(%rip), %rsi     # 0xed509
callq 0x5520
jmp 0xc047d
movb $0x1, 0x667(%rsp)
movl $0x20, %edi
callq 0x5240
movq %rax, 0xf0(%rsp)
leaq 0x668(%rsp), %rdi
leaq 0x688(%rsp), %rsi
callq 0x5550
jmp 0xc04ae
movq 0xf0(%rsp), %rdi
leaq 0x668(%rsp), %rsi
callq 0xc5840
jmp 0xc04c5
movq 0xf0(%rsp), %rdi
movb $0x0, 0x667(%rsp)
leaq 0x3f884(%rip), %rsi     # 0xffd60
leaq 0x537d(%rip), %rdx      # 0xc5860
callq 0x5920
jmp 0xc0e16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x9d0(%rsp)
movl %eax, 0x9cc(%rsp)
jmp 0xc0555
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x9d0(%rsp)
movl %eax, 0x9cc(%rsp)
jmp 0xc053a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x9d0(%rsp)
movl %eax, 0x9cc(%rsp)
leaq 0x668(%rsp), %rdi
callq 0x5ae8
testb $0x1, 0x667(%rsp)
jne 0xc0546
jmp 0xc0553
movq 0xf0(%rsp), %rdi
callq 0x53a0
jmp 0xc0555
leaq 0x688(%rsp), %rdi
callq 0x50e0
jmp 0xc0e01
movq 0xb70(%rsp), %rdi
movq (%rdi), %rax
addq -0x18(%rax), %rdi
callq 0x5910
testb $0x1, %al
jne 0xc0698
leaq 0x4e8(%rsp), %rdi
movq %rdi, 0xe8(%rsp)
callq 0x56b0
movq 0xe8(%rsp), %rdi
leaq 0x2cf94(%rip), %rsi     # 0xed53b
callq 0x5520
jmp 0xc05ae
movb $0x1, 0x4c7(%rsp)
movl $0x20, %edi
callq 0x5240
movq %rax, 0xe0(%rsp)
leaq 0x4c8(%rsp), %rdi
leaq 0x4e8(%rsp), %rsi
callq 0x5550
jmp 0xc05df
movq 0xe0(%rsp), %rdi
leaq 0x4c8(%rsp), %rsi
callq 0xc5840
jmp 0xc05f6
movq 0xe0(%rsp), %rdi
movb $0x0, 0x4c7(%rsp)
leaq 0x3f753(%rip), %rsi     # 0xffd60
leaq 0x524c(%rip), %rdx      # 0xc5860
callq 0x5920
jmp 0xc0e16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x9d0(%rsp)
movl %eax, 0x9cc(%rsp)
jmp 0xc0686
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x9d0(%rsp)
movl %eax, 0x9cc(%rsp)
jmp 0xc066b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x9d0(%rsp)
movl %eax, 0x9cc(%rsp)
leaq 0x4c8(%rsp), %rdi
callq 0x5ae8
testb $0x1, 0x4c7(%rsp)
jne 0xc0677
jmp 0xc0684
movq 0xe0(%rsp), %rdi
callq 0x53a0
jmp 0xc0686
leaq 0x4e8(%rsp), %rdi
callq 0x50e0
jmp 0xc0e01
movl 0xb5c(%rsp), %eax
imull 0xb58(%rsp), %eax
cltq
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x5040
movq %rax, 0xb60(%rsp)
testb $0x1, 0x9a6(%rsp)
je 0xc09e8
movq 0xb60(%rsp), %rax
movq %rax, 0x4b8(%rsp)
movq 0x4b8(%rsp), %rax
movl 0xb5c(%rsp), %ecx
imull 0xb58(%rsp), %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, 0x4b0(%rsp)
cvtsi2ssl 0xb54(%rsp), %xmm0
movss %xmm0, 0x4ac(%rsp)
movq 0x4b8(%rsp), %rax
cmpq 0x4b0(%rsp), %rax
je 0xc09e3
movq 0xb70(%rsp), %rdi
leaq 0x4a8(%rsp), %rsi
callq 0x52e0
jmp 0xc0758
movq 0xb70(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x5910
movb %al, 0xdf(%rsp)
jmp 0xc0778
movb 0xdf(%rsp), %al
testb $0x1, %al
jne 0xc09b1
jmp 0xc0789
leaq 0x330(%rsp), %rdi
callq 0x56b0
jmp 0xc0798
leaq 0x2cdb5(%rip), %rsi     # 0xed554
leaq 0x330(%rsp), %rdi
callq 0x5520
movq %rax, 0xd0(%rsp)
jmp 0xc07b6
movq 0xd0(%rsp), %rdi
movl 0xb5c(%rsp), %esi
callq 0x5940
movq %rax, 0xc8(%rsp)
jmp 0xc07d4
movq 0xc8(%rsp), %rdi
leaq 0x2cd90(%rip), %rsi     # 0xed573
callq 0x5520
movq %rax, 0xc0(%rsp)
jmp 0xc07f2
movq 0xc0(%rsp), %rdi
movl 0xb58(%rsp), %esi
callq 0x5940
movq %rax, 0xb8(%rsp)
jmp 0xc0810
movq 0xb8(%rsp), %rdi
leaq 0x2cd5d(%rip), %rsi     # 0xed57c
callq 0x5520
movq %rax, 0xb0(%rsp)
jmp 0xc082e
movq 0xb0(%rsp), %rdi
movl 0xb54(%rsp), %esi
callq 0x5940
movq %rax, 0xa8(%rsp)
jmp 0xc084c
movq 0xa8(%rsp), %rdi
leaq 0x2cd2a(%rip), %rsi     # 0xed585
callq 0x5520
movq %rax, 0xa0(%rsp)
jmp 0xc086a
movq 0xa0(%rsp), %rdi
movq 0x4b8(%rsp), %rsi
movq 0xb60(%rsp), %rax
subq %rax, %rsi
sarq $0x2, %rsi
callq 0x5a00
movq %rax, 0x98(%rsp)
jmp 0xc0898
movq 0x98(%rsp), %rdi
leaq 0x9103(%rip), %rsi      # 0xc99aa
callq 0x5520
jmp 0xc08ae
movb $0x1, 0x30f(%rsp)
movl $0x20, %edi
callq 0x5240
movq %rax, 0x90(%rsp)
leaq 0x310(%rsp), %rdi
leaq 0x330(%rsp), %rsi
callq 0x5550
jmp 0xc08df
movq 0x90(%rsp), %rdi
leaq 0x310(%rsp), %rsi
callq 0xc5840
jmp 0xc08f6
movq 0x90(%rsp), %rdi
movb $0x0, 0x30f(%rsp)
leaq 0x3f453(%rip), %rsi     # 0xffd60
leaq 0x4f4c(%rip), %rdx      # 0xc5860
callq 0x5920
jmp 0xc0e16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x9d0(%rsp)
movl %eax, 0x9cc(%rsp)
jmp 0xc0cc3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x9d0(%rsp)
movl %eax, 0x9cc(%rsp)
jmp 0xc099f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x9d0(%rsp)
movl %eax, 0x9cc(%rsp)
jmp 0xc0984
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x9d0(%rsp)
movl %eax, 0x9cc(%rsp)
leaq 0x310(%rsp), %rdi
callq 0x5ae8
testb $0x1, 0x30f(%rsp)
jne 0xc0990
jmp 0xc099d
movq 0x90(%rsp), %rdi
callq 0x53a0
jmp 0xc099f
leaq 0x330(%rsp), %rdi
callq 0x50e0
jmp 0xc0cc3
cvtsi2ssl 0x4a8(%rsp), %xmm0
divss 0x4ac(%rsp), %xmm0
movq 0x4b8(%rsp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x4b8(%rsp)
movss %xmm0, (%rax)
jmp 0xc072b
jmp 0xc0d9b
movq 0xb70(%rsp), %rdi
callq 0x5950
movq %rdx, 0x80(%rsp)
movq %rax, 0x88(%rsp)
jmp 0xc0a07
movq 0x80(%rsp), %rax
movq 0x88(%rsp), %rcx
movq %rcx, 0x2f8(%rsp)
movq %rax, 0x300(%rsp)
movl 0xb5c(%rsp), %eax
movl 0xb58(%rsp), %ecx
imull %ecx, %eax
movslq %eax, %rdi
testq %rdi, %rdi
movq $-0x1, %rax
cmovsq %rax, %rdi
callq 0x5040
movq %rax, 0x78(%rsp)
jmp 0xc0a55
movq 0x78(%rsp), %rax
movq %rax, 0x2f0(%rsp)
movq 0xb70(%rsp), %rdi
movq 0x2f0(%rsp), %rsi
movl 0xb5c(%rsp), %eax
movl 0xb58(%rsp), %ecx
imull %ecx, %eax
movslq %eax, %rdx
callq 0x5650
jmp 0xc0a8d
movq 0xb70(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x5910
movb %al, 0x77(%rsp)
jmp 0xc0aaa
movb 0x77(%rsp), %al
testb $0x1, %al
jne 0xc0cf7
jmp 0xc0ab8
leaq 0x178(%rsp), %rdi
callq 0x56b0
jmp 0xc0ac7
leaq 0x2ca86(%rip), %rsi     # 0xed554
leaq 0x178(%rsp), %rdi
callq 0x5520
movq %rax, 0x68(%rsp)
jmp 0xc0ae2
movq 0x68(%rsp), %rdi
movl 0xb5c(%rsp), %esi
callq 0x5940
movq %rax, 0x60(%rsp)
jmp 0xc0afa
movq 0x60(%rsp), %rdi
leaq 0x2ca6d(%rip), %rsi     # 0xed573
callq 0x5520
movq %rax, 0x58(%rsp)
jmp 0xc0b12
movq 0x58(%rsp), %rdi
movl 0xb58(%rsp), %esi
callq 0x5940
movq %rax, 0x50(%rsp)
jmp 0xc0b2a
movq 0x50(%rsp), %rdi
leaq 0x2ca46(%rip), %rsi     # 0xed57c
callq 0x5520
movq %rax, 0x48(%rsp)
jmp 0xc0b42
movq 0x48(%rsp), %rdi
movl 0xb54(%rsp), %esi
callq 0x5940
movq %rax, 0x40(%rsp)
jmp 0xc0b5a
movq 0x40(%rsp), %rdi
leaq 0x2ca1f(%rip), %rsi     # 0xed585
callq 0x5520
movq %rax, 0x38(%rsp)
jmp 0xc0b72
movq 0xb70(%rsp), %rdi
callq 0x5950
movq %rdx, 0x28(%rsp)
movq %rax, 0x30(%rsp)
jmp 0xc0b8b
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, 0x168(%rsp)
movq %rax, 0x170(%rsp)
leaq 0x168(%rsp), %rdi
leaq 0x2f8(%rsp), %rsi
callq 0xc5870
movq %rax, 0x20(%rsp)
jmp 0xc0bc1
movq 0x20(%rsp), %rsi
movq 0x38(%rsp), %rdi
callq 0x5a00
movq %rax, 0x18(%rsp)
jmp 0xc0bd7
movq 0x18(%rsp), %rdi
leaq 0x8dc7(%rip), %rsi      # 0xc99aa
callq 0x5520
jmp 0xc0bea
movb $0x1, 0x147(%rsp)
movl $0x20, %edi
callq 0x5240
movq %rax, 0x10(%rsp)
leaq 0x148(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0x5550
jmp 0xc0c18
movq 0x10(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0xc5840
jmp 0xc0c2c
movq 0x10(%rsp), %rdi
movb $0x0, 0x147(%rsp)
leaq 0x3f120(%rip), %rsi     # 0xffd60
leaq 0x4c19(%rip), %rdx      # 0xc5860
callq 0x5920
jmp 0xc0e16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x9d0(%rsp)
movl %eax, 0x9cc(%rsp)
jmp 0xc0cb6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x9d0(%rsp)
movl %eax, 0x9cc(%rsp)
jmp 0xc0c9e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x9d0(%rsp)
movl %eax, 0x9cc(%rsp)
leaq 0x148(%rsp), %rdi
callq 0x5ae8
testb $0x1, 0x147(%rsp)
jne 0xc0caa
jmp 0xc0cb4
movq 0x10(%rsp), %rdi
callq 0x53a0
jmp 0xc0cb6
leaq 0x178(%rsp), %rdi
callq 0x50e0
movq 0x9d0(%rsp), %rdi
callq 0x51e0
movq 0xb60(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0xc0ced
movq 0x8(%rsp), %rdi
callq 0x5680
callq 0x5760
jmp 0xc0e16
movq 0xb60(%rsp), %rax
movq %rax, 0x138(%rsp)
movq 0x138(%rsp), %rax
movl 0xb5c(%rsp), %ecx
imull 0xb58(%rsp), %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, 0x130(%rsp)
movq 0x2f0(%rsp), %rax
movq %rax, 0x128(%rsp)
movq 0x138(%rsp), %rax
cmpq 0x130(%rsp), %rax
je 0xc0d99
movq 0x128(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x128(%rsp)
movzbl (%rax), %eax
cvtsi2ss %eax, %xmm0
movss 0x73bc(%rip), %xmm1     # 0xc8134
divss %xmm1, %xmm0
movq 0x138(%rsp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x138(%rsp)
movss %xmm0, (%rax)
jmp 0xc0d40
jmp 0xc0d9b
jmp 0xc0dba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x9d0(%rsp)
movl %eax, 0x9cc(%rsp)
callq 0x58d0
jmp 0xc0db8
jmp 0xc0e01
movl 0xb5c(%rsp), %ecx
movq 0xb68(%rsp), %rax
movl %ecx, (%rax)
movl 0xb58(%rsp), %ecx
movq 0xb68(%rsp), %rax
movl %ecx, 0x4(%rax)
movq 0xb60(%rsp), %rcx
movq 0xb68(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0xb70(%rsp), %rax
addq $0xb78, %rsp            # imm = 0xB78
retq
movq 0x9d0(%rsp), %rdi
callq 0x5970
movq %rax, %rdi
callq 0xcb20
nopw %cs:(%rax,%rax)