// File: /workspace/github_cpp_makefile_star2_O2/nanjiangshu[P]calSOV/calSOV.cpp
// Function: ReadNextSeq_FASTA(_IO_FILE*, char*, int*, int, char*, int)
int ReadNextSeq_FASTA(FILE *fp, char* seq, int *pSeq_type /*= NULL*/, int maxlength /*= LONGEST_SEQ*/, char* annotationLine/*=NULL*/, int maxSizeAnnotationLine /*=50*/)/*{{{*/
    /****************************************************************************
     * ReadNextSeq_FASTA()
     * read in the fasta format sequence from the file stream 
     * return the length of the sequence if successful
     * return 0 or minus value if no more sequence can be read from the file stream
     * The leading white spaces are ignored
     * check the type (DNA or AA) of fasta sequence file based the annotation line 
     * Last modified, 2007-02-12, Nanjiang Shu
     * Updated 2010-04-22: the annotation line (without the leading ">") can be
     * read in, note that the maxSizeAnnotationLine must be supplied
     ***************************************************************************/
{
    int   c;
    int   i;

    do{  /* ignore the leading white spaces */ 
        c = getc(fp);
    }while(isspace(c));

    if(pSeq_type != NULL) 
        *pSeq_type = UNKNOWN_SEQ_TYPE; /* initializing sequence type*/

    if(c  == '>') 
    { 
        Array1D <char> line_1darray(maxSizeAnnotationLine +1);
        char *line = line_1darray.array1D;
        fgetline(fp,line,maxSizeAnnotationLine);
        if( pSeq_type != NULL)
        {
            if(strstr(line, "protein") != NULL)
                *pSeq_type = AA_SEQ;
            else if( strstr(line,"nucleic") != NULL)
                *pSeq_type = DNA_SEQ;
            else if( strstr(line,"shape") != NULL)
                *pSeq_type = SHAPE_SEQ;
            else
                *pSeq_type = UNKNOWN_SEQ_TYPE;
        }
        if (annotationLine != NULL)
        {
            my_strcpy(annotationLine,line, maxSizeAnnotationLine-1);  /*read in the annotation line*/ 
        }
    }
    else  
    {
        fseek(fp, -1, SEEK_CUR); /* backward 1 byte of file stream if there is no annotation line*/ 
    }

    i = 0 ;
    while((c = getc(fp)) != EOF) 
    {
        if(c == '>') 
        {
            fseek(fp, -1, SEEK_CUR); /* backward 1 byte of file stream*/
            break;  /* read in the first sequence if there are multiple sequences in the file*/ 
        }
        if(! isspace(c)) /* neglect white spaces and return characters in sequence region*/ 
        {
            seq[i] = c ; i ++ ;
            if(i >= maxlength)
            {
                fprintf(stderr,"Error, sequence longer then maxlength = %d\n", maxlength);
                return 1;

            }
        }
    }
    seq[i] = '\0' ;
    if(c == EOF && i == 0)
        return EOF;
    else
        return i; /* return the length of sequence*/ 
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, %r15d
movq %r8, %r12
movl %ecx, 0xc(%rsp)
movq %rdx, %r13
movq %rsi, 0x10(%rsp)
movq %rdi, %r14
movq %r14, %rdi
callq 0x20c0
movl %eax, %ebp
movl %eax, %edi
callq 0x2060
testl %eax, %eax
jne 0x28a1
testq %r13, %r13
je 0x28c0
orl $-0x1, (%r13)
cmpl $0x3e, %ebp
jne 0x2909
leal 0x1(%r15), %ebx
movq %rbx, %rdi
callq 0x2030
movq %rax, %rbp
movq %rax, 0x20(%rsp)
movl %ebx, 0x18(%rsp)
movq %r14, %rdi
movq %rax, %rsi
movl %r15d, %edx
callq 0x29fd
testq %r13, %r13
je 0x2952
leaq 0x4e7b(%rip), %rsi      # 0x7772
movq %rbp, %rdi
callq 0x20a0
testq %rax, %rax
je 0x291e
pushq $0x1
popq %rcx
jmp 0x294e
pushq $-0x1
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x2200
movq 0x10(%rsp), %r13
jmp 0x2977
leaq 0x4e55(%rip), %rsi      # 0x777a
movq %rbp, %rdi
callq 0x20a0
xorl %ecx, %ecx
testq %rax, %rax
jne 0x294e
leaq 0x4e47(%rip), %rsi      # 0x7782
movq %rbp, %rdi
callq 0x20a0
xorl %ecx, %ecx
cmpq $0x1, %rax
sbbl %ecx, %ecx
orl $0x2, %ecx
movl %ecx, (%r13)
testq %r12, %r12
movq 0x10(%rsp), %r13
je 0x296d
decl %r15d
movq %r12, %rdi
movq %rbp, %rsi
movl %r15d, %edx
callq 0x26b8
leaq 0x18(%rsp), %rdi
callq 0x5bf8
pushq $0x1
popq %rbp
xorl %ebx, %ebx
movq %r14, %rdi
callq 0x20c0
movl %eax, %r15d
movl %ebx, %r12d
cmpl $-0x1, %eax
je 0x29da
cmpl $0x3e, %r15d
je 0x29cc
movl %r15d, %edi
callq 0x2060
testl %eax, %eax
jne 0x297c
movb %r15b, (%r13,%r12)
incl %ebx
cmpl 0xc(%rsp), %ebx
jl 0x297c
movq 0x8623(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x4dc9(%rip), %rsi      # 0x7788
movl 0xc(%rsp), %edx
xorl %eax, %eax
callq 0x2290
jmp 0x29ec
pushq $-0x1
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x2200
movb $0x0, (%r13,%r12)
notl %r15d
orl %ebx, %r15d
pushq $-0x1
popq %rbp
cmovnel %ebx, %ebp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq