// File: /workspace/github_c_makefile_star2_O1/icebert[P]pblat/lib/fa.c
// Function: faReadMixedNext
boolean faReadMixedNext(FILE *f, boolean preserveCase, char *defaultName, 
    boolean mustStartWithComment, char **retCommentLine, struct dnaSeq **retSeq)
/* Read next sequence from .fa file. Return sequence in retSeq.  
 * If retCommentLine is non-null return the '>' line in retCommentLine.
 * The whole thing returns FALSE at end of file. 
 * Contains parameter to preserve mixed case. */
{
char lineBuf[1024];
int lineSize;
char *words[1];
int c;
off_t offset = ftello(f);
size_t dnaSize = 0;
DNA *dna, *sequence;
char *name = defaultName;

if (name == NULL)
    name = "";
dnaUtilOpen();
if (retCommentLine != NULL)
    *retCommentLine = NULL;
*retSeq = NULL;

/* Skip first lines until it starts with '>' */
for (;;)
    {
    if(fgets(lineBuf, sizeof(lineBuf), f) == NULL)
        {
        if (ferror(f))
            errnoAbort("read of fasta file failed");
        return FALSE;
        }
    lineSize = strlen(lineBuf);
    if (lineBuf[0] == '>')
        {
	if (retCommentLine != NULL)
            *retCommentLine = cloneString(lineBuf);
        offset = ftello(f);
        chopByWhite(lineBuf, words, ArraySize(words));
        name = words[0]+1;
        break;
        }
    else if (!mustStartWithComment)
        {
        if (fseeko(f, offset, SEEK_SET) < 0)
            errnoAbort("fseek on fasta file failed");
        break;
        }
    else
        offset += lineSize;
    }
/* Count up DNA. */
for (;;)
    {
    c = fgetc(f);
    if (c == EOF || c == '>')
        break;
    if (isalpha(c))
        {
        ++dnaSize;
        }
    }

if (dnaSize == 0)
    {
    warn("Invalid fasta format: sequence size == 0 for element %s",name);
    }

/* Allocate DNA and fill it up from file. */
dna = sequence = needHugeMem(dnaSize+1);
if (fseeko(f, offset, SEEK_SET) < 0)
    errnoAbort("fseek on fasta file failed");
for (;;)
    {
    c = fgetc(f);
    if (c == EOF || c == '>')
        break;
    if (isalpha(c))
        {
        /* check for non-DNA char */
        if (ntChars[c] == 0)
            {
            *dna++ = preserveCase ? 'N' : 'n';
            }
        else
            {
            *dna++ = preserveCase ? c : ntChars[c];
            }
        }
    }
if (c == '>')
    ungetc(c, f);
*dna = 0;

*retSeq = newDnaSeq(sequence, dnaSize, name);
if (ferror(f))
    errnoAbort("read of fasta file failed");    
return TRUE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x428, %rsp            # imm = 0x428
movq %r9, 0x10(%rsp)
movq %r8, %r13
movl %ecx, %ebp
movq %rdx, %rbx
movl %esi, 0x8(%rsp)
movq %rdi, %r14
callq 0x6b80
movq %rax, %r12
testq %rbx, %rbx
leaq 0x712f3(%rip), %r15     # 0x98360
cmovneq %rbx, %r15
xorl %eax, %eax
callq 0x25b5c
testq %r13, %r13
je 0x27085
movq $0x0, (%r13)
movq 0x10(%rsp), %rax
movq $0x0, (%rax)
leaq 0x20(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdx
callq 0x6c00
testq %rax, %rax
je 0x270cd
leaq 0x20(%rsp), %rbx
cmpb $0x3e, 0x20(%rsp)
je 0x270dc
testl %ebp, %ebp
je 0x27119
movq %rbx, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdx
callq 0x6c00
testq %rax, %rax
jne 0x270ad
movq %r14, %rdi
callq 0x6e00
xorl %ebx, %ebx
jmp 0x2723e
testq %r13, %r13
je 0x270ef
leaq 0x20(%rsp), %rdi
callq 0x1f9f6
movq %rax, (%r13)
movq %r14, %rdi
callq 0x6b80
movq %rax, %r12
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rbx
movq %rbx, %rsi
movl $0x1, %edx
callq 0x223ad
movq (%rbx), %r15
incq %r15
jmp 0x27138
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x6c90
testl %eax, %eax
jns 0x27138
leaq 0x69909(%rip), %rdi     # 0x90a3a
xorl %eax, %eax
callq 0x26c9f
xorl %r13d, %r13d
movq %r14, %rdi
callq 0x6bf0
cmpl $-0x1, %eax
je 0x27168
movl %eax, %ebx
cmpl $0x3e, %eax
je 0x27168
callq 0x6790
movq (%rax), %rax
movslq %ebx, %rcx
movzwl (%rax,%rcx,2), %eax
btl $0xa, %eax
adcq $0x0, %r13
jmp 0x2713b
testq %r13, %r13
jne 0x2717e
leaq 0x698e1(%rip), %rdi     # 0x90a55
movq %r15, %rsi
xorl %eax, %eax
callq 0x268ca
leaq 0x1(%r13), %rdi
callq 0x2dbbc
movq %rax, %rbp
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x6c90
testl %eax, %eax
jns 0x271a9
leaq 0x69898(%rip), %rdi     # 0x90a3a
xorl %eax, %eax
callq 0x26c9f
cmpl $0x0, 0x8(%rsp)
sete %al
shlb $0x5, %al
orb $0x4e, %al
movzbl %al, %eax
movl %eax, 0xc(%rsp)
movq %rbp, %rbx
movq %r14, %rdi
callq 0x6bf0
cmpl $-0x1, %eax
je 0x27218
movl %eax, %r12d
cmpl $0x3e, %eax
je 0x2720b
callq 0x6790
movq (%rax), %rcx
movslq %r12d, %rax
testb $0x4, 0x1(%rcx,%rax,2)
je 0x271c0
cmpl $0x0, 0x8(%rsp)
leaq 0x9a77d(%rip), %rcx     # 0xc1970
movzbl (%rcx,%rax), %eax
cmovel %eax, %r12d
testb %al, %al
cmovel 0xc(%rsp), %r12d
movb %r12b, (%rbx)
incq %rbx
jmp 0x271c0
movl $0x3e, %edi
movq %r14, %rsi
callq 0x6150
movb $0x0, (%rbx)
movq %rbp, %rdi
movl %r13d, %esi
movq %r15, %rdx
callq 0x249f8
movq 0x10(%rsp), %rcx
movq %rax, (%rcx)
movq %r14, %rdi
callq 0x6e00
movl $0x1, %ebx
testl %eax, %eax
je 0x27250
leaq 0x697d7(%rip), %rdi     # 0x90a20
xorl %eax, %eax
callq 0x26c9f
movl %ebx, %eax
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq