// File: /workspace/github_c_makefile_star2_O1/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 0x28504
cmpb $0x50, 0xe(%rsp)
sete %al
movzbl 0xf(%rsp), %ecx
cmpl $0x32, %ecx
je 0x28426
cmpl $0x35, %ecx
jne 0x2842a
movl $0x1, %ecx
jmp 0x2842c
xorl %ecx, %ecx
jmp 0x2842c
xorl %eax, %eax
testb %al, %al
je 0x28504
movl %ecx, 0x10(%rsp)
movq %r14, %rdi
callq 0x28547
movl %eax, 0x18(%rsp)
leaq 0xbe0c(%rip), %r15      # 0x34257
leaq 0x24(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x9120
movl %eax, 0x14(%rsp)
movq %r14, %rdi
callq 0x28547
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 0x28547
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
movl $0xffffd9ff, %edx       # imm = 0xFFFFD9FF
movl %eax, %ecx
shrq %cl, %rdx
cmpl $0x0, 0x18(%rsp)
jle 0x28525
cmpl $0x1, 0x14(%rsp)
jne 0x28525
testl %r12d, %r12d
jle 0x28525
cmpl $0x1, %r13d
jne 0x28525
testl %ebp, %ebp
jle 0x28525
cmpl $0x1, %r15d
jne 0x28525
cmpl $0x20, %eax
ja 0x28525
testb $0x1, %dl
jne 0x28525
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 0x28538
leaq 0xbd39(%rip), %rsi      # 0x34244
movl $0x65, %edi
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9150
leaq 0xbd2e(%rip), %rsi      # 0x3425a
movl $0x66, %edi
xorl %eax, %eax
callq 0x9150
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq