// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
leaq 0x2e(%rsp), %rdi
movq 0x38(%rsp), %rcx
movl $0x1, %esi
movl $0x2, %edx
callq 0x91e0
movq %rax, 0x10(%rsp)
cmpq $0x2, 0x10(%rsp)
jae 0x46740
movl $0x65, %edi
leaq 0x13904(%rip), %rsi     # 0x5a034
movb $0x0, %al
callq 0x9160
movl %eax, 0x44(%rsp)
jmp 0x4698c
movb 0x2e(%rsp), %al
subb $0x50, %al
sete %al
movzbl %al, %eax
movl %eax, 0xc(%rsp)
movsbl 0x2f(%rsp), %eax
movl %eax, 0x8(%rsp)
subl $0x32, %eax
je 0x4676b
jmp 0x46760
movl 0x8(%rsp), %eax
subl $0x35, %eax
je 0x46775
jmp 0x4677f
movl $0x0, 0x24(%rsp)
jmp 0x46787
movl $0x1, 0x24(%rsp)
jmp 0x46787
movl $0x0, 0xc(%rsp)
cmpl $0x0, 0xc(%rsp)
jne 0x467aa
movl $0x65, %edi
leaq 0x1389a(%rip), %rsi     # 0x5a034
movb $0x0, %al
callq 0x9160
movl %eax, 0x44(%rsp)
jmp 0x4698c
movl $0x1, 0xc(%rsp)
movq 0x38(%rsp), %rdi
callq 0x469a0
movl %eax, 0x28(%rsp)
cmpl $0x0, 0x28(%rsp)
setg %al
andb $0x1, %al
movzbl %al, %eax
andl 0xc(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x38(%rsp), %rdi
leaq 0x13866(%rip), %rsi     # 0x5a047
leaq 0x20(%rsp), %rdx
movb $0x0, %al
callq 0x9120
movl %eax, 0x28(%rsp)
cmpl $0x1, 0x28(%rsp)
sete %al
andb $0x1, %al
movzbl %al, %eax
andl 0xc(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x38(%rsp), %rdi
callq 0x469a0
movl %eax, 0x28(%rsp)
cmpl $0x0, 0x28(%rsp)
setg %al
andb $0x1, %al
movzbl %al, %eax
andl 0xc(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x38(%rsp), %rdi
leaq 0x13812(%rip), %rsi     # 0x5a047
leaq 0x1c(%rsp), %rdx
movb $0x0, %al
callq 0x9120
movl %eax, 0x28(%rsp)
cmpl $0x1, 0x28(%rsp)
sete %al
andb $0x1, %al
movzbl %al, %eax
andl 0xc(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x38(%rsp), %rdi
callq 0x469a0
movl %eax, 0x28(%rsp)
cmpl $0x0, 0x28(%rsp)
setg %al
andb $0x1, %al
movzbl %al, %eax
andl 0xc(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x38(%rsp), %rdi
leaq 0x137be(%rip), %rsi     # 0x5a047
leaq 0x18(%rsp), %rdx
movb $0x0, %al
callq 0x9120
movl %eax, 0x28(%rsp)
cmpl $0x1, 0x28(%rsp)
sete %al
andb $0x1, %al
movzbl %al, %eax
andl 0xc(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x38(%rsp), %rdi
callq 0x94b0
movl %eax, 0x28(%rsp)
movb $0x1, %al
cmpl $0xa, 0x28(%rsp)
movb %al, 0x7(%rsp)
je 0x468ef
movb $0x1, %al
cmpl $0x9, 0x28(%rsp)
movb %al, 0x7(%rsp)
je 0x468ef
movb $0x1, %al
cmpl $0x20, 0x28(%rsp)
movb %al, 0x7(%rsp)
je 0x468ef
cmpl $0xd, 0x28(%rsp)
sete %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
andl 0xc(%rsp), %eax
movl %eax, 0xc(%rsp)
cmpl $0x0, 0xc(%rsp)
jne 0x46920
movl $0x66, %edi
leaq 0x13737(%rip), %rsi     # 0x5a04a
movb $0x0, %al
callq 0x9160
movl %eax, 0x44(%rsp)
jmp 0x4698c
cmpl $0x0, 0x18(%rsp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x10000, %eax          # imm = 0x10000
jl 0x4694f
movl $0x66, %edi
leaq 0x13708(%rip), %rsi     # 0x5a04a
movb $0x0, %al
callq 0x9160
movl %eax, 0x44(%rsp)
jmp 0x4698c
movslq 0x20(%rsp), %rcx
movq 0x30(%rsp), %rax
movq %rcx, (%rax)
movslq 0x1c(%rsp), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x8(%rax)
movslq 0x18(%rsp), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x10(%rax)
movl 0x24(%rsp), %ecx
movq 0x30(%rsp), %rax
movl %ecx, 0x18(%rax)
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)