// File: /workspace/github_c_makefile_star2_O3/zpole[P]IICV/vl/pgm.c
// Function: vl_pgm_extract_head
VL_EXPORT int
vl_pgm_extract_head (FILE* f, VlPgmImage *im)
{
  char magic [2] ;
  int c ;
  int is_raw ;
  int width ;
  int height ;
  int max_value ;
  size_t sz ;
  vl_bool good ;

  /* -----------------------------------------------------------------
   *                                                check magic number
   * -------------------------------------------------------------- */
  sz = fread(magic, 1, 2, f) ;

  if (sz < 2) {
    return vl_set_last_error(VL_ERR_PGM_INV_HEAD, "Invalid PGM header") ;
  }

  good = magic [0] == 'P' ;

  switch (magic [1]) {
  case '2' : /* ASCII format */
    is_raw = 0 ;
    break ;

  case '5' : /* RAW format */
    is_raw = 1 ;
    break ;

  default :
    good = 0 ;
    break ;
  }

  if( ! good ) {
    return vl_set_last_error(VL_ERR_PGM_INV_HEAD, "Invalid PGM header") ;
  }

  /* -----------------------------------------------------------------
   *                                    parse width, height, max_value
   * -------------------------------------------------------------- */
  good = 1 ;

  c = remove_blanks(f) ;
  good &= c > 0 ;

  c = fscanf(f, "%d", &width) ;
  good &= c == 1 ;

  c = remove_blanks(f) ;
  good &= c > 0 ;

  c = fscanf(f, "%d", &height) ;
  good &= c == 1 ;

  c = remove_blanks(f) ;
  good &= c > 0 ;

  c = fscanf(f, "%d", &max_value) ;
  good &= c == 1 ;

  /* must end with a single blank */
  c = fgetc(f) ;
  good &=
    c == '\n' ||
    c == '\t' ||
    c == ' '  ||
    c == '\r' ;

  if(! good) {
    return vl_set_last_error(VL_ERR_PGM_INV_META, "Invalid PGM meta information");
  }

  if(! max_value >= 65536) {
    return vl_set_last_error(VL_ERR_PGM_INV_META, "Invalid PGM meta information");
  }

  /* exit */
  im-> width     = width ;
  im-> height    = height ;
  im-> max_value = max_value ;
  im-> is_raw    = is_raw ;
  return 0 ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0xe(%rsp), %rdi
movl $0x1, %esi
movl $0x2, %edx
movq %r14, %rcx
callq 0x91c0
cmpq $0x1, %rax
jbe 0x282fb
movb 0xe(%rsp), %al
movzbl 0xf(%rsp), %ecx
cmpl $0x32, %ecx
je 0x2821e
cmpl $0x35, %ecx
jne 0x282fb
movl $0x1, %ecx
jmp 0x28220
xorl %ecx, %ecx
cmpb $0x50, %al
jne 0x282fb
movl %ecx, 0x10(%rsp)
movq %r14, %rdi
callq 0x2833e
movl %eax, 0x18(%rsp)
leaq 0xb008(%rip), %r15      # 0x33247
leaq 0x24(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x9120
movl %eax, 0x14(%rsp)
movq %r14, %rdi
callq 0x2833e
movl %eax, %r12d
leaq 0x20(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x9120
movl %eax, %r13d
movq %r14, %rdi
callq 0x2833e
movl %eax, %ebp
leaq 0x1c(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x9120
movl %eax, %r15d
movq %r14, %rdi
callq 0x9420
cmpl $0x20, %eax
ja 0x2831c
movl %eax, %eax
movabsq $0x100002600, %rcx      # imm = 0x100002600
btq %rax, %rcx
jae 0x2831c
cmpl $0x0, 0x18(%rsp)
jle 0x2831c
cmpl $0x1, 0x14(%rsp)
jne 0x2831c
testl %r12d, %r12d
jle 0x2831c
cmpl $0x1, %r13d
jne 0x2831c
testl %ebp, %ebp
jle 0x2831c
cmpl $0x1, %r15d
jne 0x2831c
movslq 0x24(%rsp), %rax
movq %rax, (%rbx)
movslq 0x20(%rsp), %rax
movq %rax, 0x8(%rbx)
movslq 0x1c(%rsp), %rax
movq %rax, 0x10(%rbx)
movl 0x10(%rsp), %eax
movl %eax, 0x18(%rbx)
xorl %eax, %eax
jmp 0x2832f
leaq 0xaf32(%rip), %rsi      # 0x33234
movl $0x65, %edi
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9150
leaq 0xaf27(%rip), %rsi      # 0x3324a
movl $0x66, %edi
xorl %eax, %eax
callq 0x9150
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq