// File: /workspace/github_c_makefile_star2_O0/zpole[P]IICV/vl/pgm.c
// Function: vl_pgm_extract_data
VL_EXPORT
int
vl_pgm_extract_data (FILE* f, VlPgmImage const *im, void *data)
{
  vl_size bpp = vl_pgm_get_bpp(im) ;
  vl_size data_size = vl_pgm_get_npixels(im) ;
  vl_bool good = 1 ;
  size_t c ;

  /* -----------------------------------------------------------------
   *                                                         read data
   * -------------------------------------------------------------- */

  /*
     In RAW mode we read directly an array of bytes or shorts.  In
     the latter case, however, we must take care of the
     endianess. PGM files are sorted in big-endian format. If our
     architecture is little endian, we must do a conversion.
  */
  if (im->is_raw) {

    c = fread( data,
               bpp,
               data_size,
               f ) ;
    good = (c == data_size) ;

    /* adjust endianess */
#if defined(VL_ARCH_LITTLE_ENDIAN)
    if (bpp == 2) {
      vl_uindex i ;
      vl_uint8 *pt = (vl_uint8*) data ;
      for(i = 0 ; i < 2 * data_size ; i += 2) {
        vl_uint8 tmp = pt [i] ;
        pt [i]   = pt [i+1] ;
        pt [i+1] = tmp ;
      }
    }
#endif
  }
  /*
     In ASCII mode we read a sequence of decimal numbers separated
     by whitespaces.
  */
  else {
    vl_uindex i ;
    int unsigned v ;
    for(good = 1, i = 0 ;
        i < data_size && good ;
        ++i) {
      c = fscanf(f, " %ud", &v) ;
      if (bpp == 1) {
        * ((vl_uint8* )  data + i) = (vl_uint8)  v ;
      } else {
        * ((vl_uint16*)  data + i) = (vl_uint16) v ;
      }
      good &= c == 1 ;
    }
  }

  if(! good ) {
    return vl_set_last_error(VL_ERR_PGM_INV_DATA, "Invalid PGM data") ;
  }
  return 0 ;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq %rsi, 0x50(%rsp)
movq %rdx, 0x48(%rsp)
movq 0x50(%rsp), %rdi
callq 0x9770
movq %rax, 0x40(%rsp)
movq 0x50(%rsp), %rdi
callq 0x9760
movq %rax, 0x38(%rsp)
movl $0x1, 0x34(%rsp)
movq 0x50(%rsp), %rax
cmpl $0x0, 0x18(%rax)
je 0x46b4e
movq 0x48(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x58(%rsp), %rcx
callq 0x91e0
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x38(%rsp), %rax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x34(%rsp)
cmpq $0x2, 0x40(%rsp)
jne 0x46b49
movq 0x48(%rsp), %rax
movq %rax, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq 0x38(%rsp), %rcx
shlq %rcx
cmpq %rcx, %rax
jae 0x46b47
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
movb (%rax,%rcx), %al
movb %al, 0x17(%rsp)
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
movb 0x1(%rax,%rcx), %dl
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
movb %dl, (%rax,%rcx)
movb 0x17(%rsp), %dl
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
movb %dl, 0x1(%rax,%rcx)
movq 0x20(%rsp), %rax
addq $0x2, %rax
movq %rax, 0x20(%rsp)
jmp 0x46ae7
jmp 0x46b49
jmp 0x46c03
movl $0x1, 0x34(%rsp)
movq $0x0, 0x8(%rsp)
movq 0x8(%rsp), %rcx
xorl %eax, %eax
cmpq 0x38(%rsp), %rcx
movb %al, 0x3(%rsp)
jae 0x46b7d
cmpl $0x0, 0x34(%rsp)
setne %al
movb %al, 0x3(%rsp)
movb 0x3(%rsp), %al
testb $0x1, %al
jne 0x46b87
jmp 0x46c01
movq 0x58(%rsp), %rdi
leaq 0x134d4(%rip), %rsi     # 0x5a067
leaq 0x4(%rsp), %rdx
movb $0x0, %al
callq 0x9120
cltq
movq %rax, 0x28(%rsp)
cmpq $0x1, 0x40(%rsp)
jne 0x46bc3
movl 0x4(%rsp), %eax
movb %al, %dl
movq 0x48(%rsp), %rax
movq 0x8(%rsp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x46bd8
movl 0x4(%rsp), %eax
movw %ax, %dx
movq 0x48(%rsp), %rax
movq 0x8(%rsp), %rcx
movw %dx, (%rax,%rcx,2)
cmpq $0x1, 0x28(%rsp)
sete %al
andb $0x1, %al
movzbl %al, %eax
andl 0x34(%rsp), %eax
movl %eax, 0x34(%rsp)
movq 0x8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x8(%rsp)
jmp 0x46b5f
jmp 0x46c03
cmpl $0x0, 0x34(%rsp)
jne 0x46c23
movl $0x67, %edi
leaq 0x13456(%rip), %rsi     # 0x5a06c
movb $0x0, %al
callq 0x9160
movl %eax, 0x64(%rsp)
jmp 0x46c2b
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)