// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %rsi
pushq $0x2
popq %rdx
movq %r14, %rcx
callq 0x91c0
cmpq $0x1, %rax
jbe 0x23bf7
movb 0xe(%rsp), %al
movzbl 0xf(%rsp), %ecx
cmpl $0x32, %ecx
je 0x23b1a
cmpl $0x35, %ecx
jne 0x23bf7
cmpb $0x50, %al
jne 0x23bf7
pushq $0x1
popq %rcx
jmp 0x23b24
xorl %ecx, %ecx
cmpb $0x50, %al
jne 0x23bf7
movl %ecx, 0x10(%rsp)
movq %r14, %rdi
callq 0x23c36
movl %eax, 0x18(%rsp)
leaq 0xa68c(%rip), %r15      # 0x2e1c7
leaq 0x24(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x9120
movl %eax, 0x14(%rsp)
movq %r14, %rdi
callq 0x23c36
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 0x23c36
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 0x9440
cmpl $0x20, %eax
ja 0x23c16
movl %eax, %eax
movabsq $0x100002600, %rcx      # imm = 0x100002600
btq %rax, %rcx
jae 0x23c16
cmpl $0x0, 0x18(%rsp)
jle 0x23c16
cmpl $0x1, 0x14(%rsp)
jne 0x23c16
testl %r12d, %r12d
jle 0x23c16
cmpl $0x1, %r13d
jne 0x23c16
testl %ebp, %ebp
jle 0x23c16
cmpl $0x1, %r15d
jne 0x23c16
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 0x23c27
leaq 0xa5b6(%rip), %rsi      # 0x2e1b4
pushq $0x65
popq %rdi
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9150
leaq 0xa5ad(%rip), %rsi      # 0x2e1ca
pushq $0x66
popq %rdi
xorl %eax, %eax
callq 0x9150
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq