// File: /workspace/github_cpp_makefile_star2_O2/mshabbirhasan[P]ups-indel/include/seqan/seq_io/fai_index.h
// Function: seqan::build(seqan::FaiIndex&, char const*, char const*)
inline int build(FaiIndex & index, char const * seqFilename, char const * faiFilename)
{
    index.fastaFilename = seqFilename;
    index.faiFilename = faiFilename;
    
    if (index.mmapStringOpen)
        close(index.mmapString);
    if (!open(index.mmapString, toCString(seqFilename), OPEN_RDONLY))
        return 1;  // Could not open file.
    index.mmapStringOpen = true;

    typedef String<char, MMap<> > TMMapString;
    RecordReader<TMMapString, SinglePass<StringReader> > reader(index.mmapString);
    // Get file format, must be FASTA for FAI.
    AutoSeqStreamFormat tagSelector;
    if (!guessStreamFormat(reader, tagSelector))
        return 1;  // Invalid format.

    if (!isEqual(tagSelector, seqan::Fasta()))
        return 1;  // Invalid format, not FASTA.

    // Re-using the FASTA/FASTQ parsing code from read_fasta_fastq is not really feasible here.  We roll our own
    // mini-parser from scratch.
    CharString line;
    CharString seqName;
    __uint32 seqLength = 0;
    __uint64 seqOffset = 0;
    __uint32 lineLength = 0;
    __uint32 lineSize = 0;
    while (!atEnd(reader))
    {
        clear(line);
        clear(seqName);

        if (value(reader) != '>')
            return 1;  // Must be >.

        goNext(reader);

        int res = readUntilWhitespace(seqName, reader);
        if (res != 0)
            return res;  // Error reading.

        res = skipLine(reader);
        if (res != 0)
            return res;  // Error reading.

        seqOffset = reader._current - begin(reader._string, Standard());

        res = readLine(line, reader);
        if (res != 0 && res != EOF_BEFORE_SUCCESS)
            return res;  // Error reading.

        lineSize = reader._current - begin(reader._string, Standard()) - seqOffset;
        lineLength = length(line);
        seqLength = lineLength;

        while (!atEnd(reader))
        {
            char c = value(reader);
            if (c == '>')
                break;
            if (!isspace(c))
                seqLength += 1;
            goNext(reader);
        }

        FaiIndexEntry_ entry;
        entry.name = seqName;
        entry.sequenceLength = seqLength;
        entry.offset = seqOffset;
        entry.lineLength = lineLength;
        entry.overallLineLength = lineSize;
        appendValue(index.indexEntryStore, entry);
        appendValue(index.refNameStore, entry.name);
    }

    // Refresh name store cache.
    refresh(index.refNameStoreCache);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdi, %rbx
leaq -0xa8(%rbp), %rax
movq %rsi, (%rax)
leaq -0xe0(%rbp), %r14
movq %rdx, (%r14)
movq %rax, %rsi
callq 0x9d50
leaq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0x9d50
cmpb $0x1, 0x118(%rbx)
jne 0xb10b
leaq 0xe0(%rbx), %rdi
callq 0x9da4
leaq 0xe0(%rbx), %r15
movq -0xa8(%rbp), %rsi
pushq $0x1
popq %r14
movq %r15, %rdi
movl %r14d, %edx
callq 0x9df0
testb %al, %al
je 0xb32c
movb $0x1, 0x118(%rbx)
leaq -0x70(%rbp), %rdi
movq %r15, (%rdi)
movq 0xe0(%rbx), %rax
movq %rax, 0x8(%rdi)
movq 0xe8(%rbx), %rax
movq %rax, 0x10(%rdi)
movq $0x2000, 0x18(%rdi)     # imm = 0x2000
leaq -0x34(%rbp), %rsi
orl $-0x1, (%rsi)
callq 0xb38c
pushq $0x1
popq %rcx
movl %ecx, -0x2c(%rbp)
testb %al, %al
je 0xb328
cmpl $0x0, -0x34(%rbp)
jne 0xb328
leaq -0x50(%rbp), %rdi
callq 0x6e2e
leaq -0x88(%rbp), %rdi
callq 0x6e2e
leaq 0x30(%rbx), %rax
movq %rax, -0xa0(%rbp)
movq %rbx, -0x90(%rbp)
leaq 0x48(%rbx), %rax
movq %rax, -0x98(%rbp)
leaq -0x70(%rbp), %r13
pushq $0x1
popq %rax
movl %eax, -0x2c(%rbp)
leaq -0xd8(%rbp), %r14
movq -0x68(%rbp), %rax
cmpq -0x60(%rbp), %rax
je 0xb2f9
movq -0x50(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x80(%rbp)
movq %r13, %rdi
callq 0xb3d7
cmpb $0x3e, %al
jne 0xb313
movq %r13, %rdi
callq 0xb41d
leaq -0x88(%rbp), %rdi
movq %r13, %rsi
callq 0xb463
testl %eax, %eax
jne 0xb2f4
movq %r13, %rdi
callq 0xb47a
testl %eax, %eax
jne 0xb2f4
movq -0x70(%rbp), %rax
movq -0x68(%rbp), %r12
subq (%rax), %r12
leaq -0x50(%rbp), %rdi
movq %r13, %rsi
callq 0xb4b6
testl $0xfffffbff, %eax       # imm = 0xFFFFFBFF
jne 0xb2f4
movl -0x68(%rbp), %ecx
movq -0x70(%rbp), %rax
movl (%rax), %eax
addl %r12d, %eax
subl %eax, %ecx
movl %ecx, -0x30(%rbp)
movl -0x48(%rbp), %ebx
subl -0x50(%rbp), %ebx
movl %ebx, %r15d
movq -0x68(%rbp), %rax
cmpq -0x60(%rbp), %rax
je 0xb28e
movq %r13, %rdi
callq 0xb3d7
cmpb $0x3e, %al
je 0xb28e
movsbl %al, %edi
callq 0x3070
cmpl $0x1, %eax
adcl $0x0, %r15d
movq %r13, %rdi
callq 0xb41d
jmp 0xb25f
movq %r14, %rdi
callq 0x9ece
movq %r14, %rdi
leaq -0x88(%rbp), %rsi
callq 0xb544
movl %r15d, %eax
movq %rax, -0xc0(%rbp)
movq %r12, -0xb8(%rbp)
movl %ebx, -0xb0(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0xac(%rbp)
movq -0xa0(%rbp), %rdi
movq %r14, %rsi
callq 0xae2e
movq -0x98(%rbp), %rdi
movq %r14, %rsi
callq 0xa586
movq -0xd8(%rbp), %rdi
callq 0x32e0
jmp 0xb1c3
movl %eax, -0x2c(%rbp)
jmp 0xb313
movq -0x90(%rbp), %rdi
addq $0x88, %rdi
movl $0x0, -0x2c(%rbp)
callq 0xa0e0
movq -0x88(%rbp), %rdi
callq 0x32e0
movq -0x50(%rbp), %rdi
callq 0x32e0
movl -0x2c(%rbp), %r14d
movl %r14d, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xb35f
movq %rax, %rbx
jmp 0xb36e
jmp 0xb35f
jmp 0xb35f
movq %rax, %rbx
movq -0xd8(%rbp), %rdi
callq 0x32e0
jmp 0xb362
jmp 0xb35f
movq %rax, %rbx
movq -0x88(%rbp), %rdi
callq 0x32e0
movq -0x50(%rbp), %rdi
callq 0x32e0
movq %rbx, %rdi
callq 0x3590