// File: /workspace/github_cpp_makefile_star2_O1/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 0x2ad6
testq %rbp, %rbp
je 0x2af8
movl $0xffffffff, (%rbp)     # imm = 0xFFFFFFFF
cmpl $0x3e, %r13d
jne 0x2b92
leal 0x1(%r12), %edi
callq 0x2030
movq %rax, %r13
movq %r14, %rdi
movq %rax, %rsi
movl %r12d, %edx
callq 0x2c50
testq %rbp, %rbp
je 0x2b6e
leaq 0x4c4c(%rip), %rsi      # 0x7775
movq %r13, %rdi
callq 0x20a0
movl $0x1, %ecx
testq %rax, %rax
jne 0x2b6b
leaq 0x4c3b(%rip), %rsi      # 0x777d
movq %r13, %rdi
callq 0x20a0
xorl %ecx, %ecx
testq %rax, %rax
jne 0x2b6b
leaq 0x4c2d(%rip), %rsi      # 0x7785
movq %r13, %rdi
callq 0x20a0
xorl %ecx, %ecx
cmpq $0x1, %rax
sbbl %ecx, %ecx
orl $0x2, %ecx
movl %ecx, (%rbp)
testq %r15, %r15
je 0x2bba
movslq %r12d, %rbp
decq %rbp
cmpl $0xc8, %r12d
jg 0x2ba8
movslq %ebp, %rdx
movq %r15, %rdi
movq %r13, %rsi
callq 0x20f0
jmp 0x2bb5
movq %r14, %rdi
movq $-0x1, %rsi
movl $0x1, %edx
callq 0x21c0
jmp 0x2bc2
movl %ebp, %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x2130
movb $0x0, (%r15,%rbp)
movq %r13, %rdi
callq 0x2220
xorl %r15d, %r15d
movq %r14, %rdi
callq 0x20c0
movl %eax, %ebp
cmpl $-0x1, %eax
je 0x2c2c
cmpl $0x3e, %ebp
je 0x2c18
movl %ebp, %edi
callq 0x2060
testl %eax, %eax
jne 0x2bc5
movl %r15d, %eax
movb %bpl, (%rbx,%rax)
incl %r15d
cmpl 0x4(%rsp), %r15d
jl 0x2bc5
movq 0x83dc(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x4b85(%rip), %rsi      # 0x778b
movl 0x4(%rsp), %edx
xorl %eax, %eax
callq 0x2240
movl $0x1, %eax
jmp 0x2c41
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