// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %rax
movl %r9d, %r12d
movq %r8, %r15
movl %ecx, 0x4(%rsp)
movq %rdx, %rbp
movq %rsi, %rbx
movq %rdi, %r14
movq %r14, %rdi
callq 0x20c0
movl %eax, %r13d
movl %eax, %edi
callq 0x2060
testl %eax, %eax
jne 0x2ad5
testq %rbp, %rbp
je 0x2af7
movl $0xffffffff, (%rbp)     # imm = 0xFFFFFFFF
cmpl $0x3e, %r13d
jne 0x2b93
leal 0x1(%r12), %edi
callq 0x2030
movq %rax, %r13
movq %r14, %rdi
movq %rax, %rsi
movl %r12d, %edx
callq 0x2c55
testq %rbp, %rbp
je 0x2b6d
leaq 0x4ca2(%rip), %rsi      # 0x77ca
movq %r13, %rdi
callq 0x20a0
movl $0x1, %ecx
testq %rax, %rax
jne 0x2b6a
leaq 0x4c91(%rip), %rsi      # 0x77d2
movq %r13, %rdi
callq 0x20a0
xorl %ecx, %ecx
testq %rax, %rax
jne 0x2b6a
leaq 0x4c83(%rip), %rsi      # 0x77da
movq %r13, %rdi
callq 0x20a0
xorl %ecx, %ecx
cmpq $0x1, %rax
sbbl %ecx, %ecx
orl $0x2, %ecx
movl %ecx, (%rbp)
testq %r15, %r15
je 0x2bbf
leal -0x1(%r12), %eax
cmpl $0xc8, %r12d
jg 0x2ba9
movslq %eax, %r12
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x20f0
jmp 0x2bba
movq %r14, %rdi
movq $-0x1, %rsi
movl $0x1, %edx
callq 0x21c0
jmp 0x2bc7
movl %eax, %r12d
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x2130
movb $0x0, (%r15,%r12)
movq %r13, %rdi
callq 0x2220
xorl %r15d, %r15d
movq %r14, %rdi
callq 0x20c0
movl %eax, %ebp
cmpl $-0x1, %eax
je 0x2c31
cmpl $0x3e, %ebp
je 0x2c1d
movl %ebp, %edi
callq 0x2060
testl %eax, %eax
jne 0x2bca
movl %r15d, %eax
movb %bpl, (%rbx,%rax)
incl %r15d
cmpl 0x4(%rsp), %r15d
jl 0x2bca
movq 0x83d7(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x4bd5(%rip), %rsi      # 0x77e0
movl 0x4(%rsp), %edx
xorl %eax, %eax
callq 0x2240
movl $0x1, %eax
jmp 0x2c46
movq %r14, %rdi
movq $-0x1, %rsi
movl $0x1, %edx
callq 0x21c0
movl %r15d, %eax
movb $0x0, (%rbx,%rax)
notl %ebp
orl %r15d, %ebp
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovnel %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq