// File: /workspace/github_c_makefile_star2_O3/mmayer[P]pcal/src/pcalutil.c
// Function: get_pcal_line
int get_pcal_line (FILE *fp, char *buf, int *pline)
{
   register char *cp;
   register int c, c2;
   int in_comment;   /* comments: from '#' to end-of-line */
   char tmpbuf[LINSIZ];   /* temporary buffer to accumulate line */

   cp = tmpbuf;
   *buf = '\0';   /* in case of premature EOF */
   
   do {
      in_comment = FALSE;
      while ((c = getc(fp)) != '\n' && c != EOF) {
         if (c == COMMENT_CHAR) in_comment = TRUE;
         
         if (isspace(c)) c = ' ';   /* whitespace => blank */
         
         /* ignore comments and leading white space */
         if (in_comment || (cp == tmpbuf && c == ' ')) continue;
         
         /* only handle escape newlines and '#' here; other escapes are now
            handled by cvt_escape() or loadwords() (q.v.)
         */
         if (c == '\\') {
            if ((c2 = getc(fp)) == EOF) return FALSE;

            if (c2 == '\n') {
               c = ' ';
               (*pline)++;
            }
            else if (c2 == COMMENT_CHAR) c = '#';
            else ungetc(c2, fp);
         }
         
         /* 
            Crudely prevent buffer overflow to prevent exploit by malicious
            calendar input file.
         */
         if ((cp - tmpbuf) < (LINSIZ - 1)) *cp++ = c;
         else return FALSE;
      }

      if (c == EOF) {
         /* 
            15 Dec 2007: 

            Prior to the 4.11.0 release, the code just returned 'FALSE' here,
            with no other test being performed.

            That was causing a bug whereby the last line of a configuration
            file was silently ignored if it ended without a 'line feed' (ASCII
            10 character).

            Adding a test, as done below, to see if anything is in the line
            buffer (before deciding to return 'FALSE') fixes this bug.

         */
         if ((cp - tmpbuf) == 0) return FALSE;    /* no more input lines */
      }

      (*pline)++;   /* bump line number */
      
   } while (cp == tmpbuf);   /* ignore empty lines */

   *cp = '\0';
   cvt_escape(buf, tmpbuf);   /* convert escape sequences */
   return TRUE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movq %rdx, (%rsp)
movq %rdi, %r15
movq %rsi, 0x8(%rsp)
movb $0x0, (%rsi)
leaq 0x10(%rsp), %rax
movq %rax, %rbx
xorl %r14d, %r14d
movq %r15, %rdi
callq 0x5320
movl %eax, %ebp
cmpl $0x23, %eax
je 0xb668
cmpl $-0x1, %ebp
je 0xb70e
cmpl $0xa, %ebp
jne 0xb66e
jmp 0xb6d3
movl $0x1, %r14d
movq %rbx, %r12
leaq 0x10(%rsp), %rax
subq %rax, %r12
sete %r13b
callq 0x5340
movq (%rax), %rax
movslq %ebp, %rcx
testb $0x20, 0x1(%rax,%rcx,2)
je 0xb694
movl $0x20, %ebp
cmpl $0x20, %ebp
sete %al
testl %r14d, %r14d
jne 0xb649
andb %al, %r13b
jne 0xb649
cmpl $0x5c, %ebp
jne 0xb6f7
movq %r15, %rdi
callq 0x5320
cmpl $0xa, %eax
je 0xb6ec
movl %eax, %ebp
cmpl $0x23, %eax
je 0xb6f7
cmpl $-0x1, %ebp
je 0xb737
movl %ebp, %edi
movq %r15, %rsi
callq 0x5260
movl $0x5c, %ebp
jmp 0xb6f7
movq (%rsp), %rax
incl (%rax)
leaq 0x10(%rsp), %rcx
movq %rcx, %rax
cmpq %rcx, %rbx
je 0xb643
jmp 0xb71e
movq (%rsp), %rax
incl (%rax)
movl $0x20, %ebp
cmpq $0x1fe, %r12            # imm = 0x1FE
jg 0xb737
movb %bpl, (%rbx)
incq %rbx
movq %rbx, %rax
jmp 0xb643
leaq 0x10(%rsp), %rax
cmpq %rax, %rbx
je 0xb737
movq (%rsp), %rax
incl (%rax)
movb $0x0, (%rbx)
leaq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0xb1ce
movl $0x1, %eax
jmp 0xb739
xorl %eax, %eax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq