// File: /workspace/github_cpp_makefile_star2_O3/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 %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
leaq -0x88(%rbp), %rsi
movq %r14, (%rsi)
callq 0xb012
leaq 0x8(%rbx), %r8
leaq 0x3712(%rip), %r13      # 0x11302
movq %r13, (%rsp)
leaq 0x36cd(%rip), %rdi      # 0x112c8
leaq 0x36ec(%rip), %rcx      # 0x112ee
leaq 0x36f0(%rip), %r9       # 0x112f9
movl $0xae, %esi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x90eb
testb %al, %al
je 0xe1bd
leaq 0x18(%rbx), %r12
leaq -0x88(%rbp), %rsi
movq %r15, (%rsi)
movq %r12, %rdi
callq 0xb012
leaq 0x20(%rbx), %r8
movq %r13, (%rsp)
leaq 0x3683(%rip), %rdi      # 0x112c8
leaq 0x36a2(%rip), %rcx      # 0x112ee
leaq 0x36a6(%rip), %r9       # 0x112f9
movl $0xae, %esi
movq %r12, %rdx
xorl %eax, %eax
callq 0x90eb
testb %al, %al
je 0xe1bd
cmpb $0x1, 0x118(%rbx)
jne 0xdc7f
leaq 0xe0(%rbx), %rdi
callq 0xcbc9
leaq 0xe0(%rbx), %r15
movq %r15, %rdi
callq 0xcbc9
movq $0x0, 0xf0(%rbx)
movl $0x3, 0x108(%rbx)
movw $0x100, 0x10c(%rbx)     # imm = 0x100
leaq 0xf8(%rbx), %r13
movq 0xf8(%rbx), %rax
movl $0x1, -0x2c(%rbp)
movq %r13, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq *0x10(%rax)
movl $0x1, 0x108(%rbx)
movw $0x1, 0x10c(%rbx)
testb %al, %al
je 0xe18f
movl $0x1, -0x2c(%rbp)
movq %r13, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0xbcd8
movq %rax, %r14
movq %r13, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0xbcd8
movq %rax, %r12
movq %r13, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0xbc01
movq %r12, 0xf0(%rbx)
movq %r15, %rdi
movq %r12, %rsi
callq 0xa4d4
testb %al, %al
je 0xe19a
movb $0x1, 0x118(%rbx)
leaq -0x50(%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 -0x88(%rbp), %rsi
callq 0xe563
movl $0x1, -0x2c(%rbp)
testb %al, %al
jne 0xe19a
leaq -0x50(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0xeed9
testb %al, %al
je 0xe19a
leaq -0xa8(%rbp), %rdi
callq 0x8e1e
leaq -0xc0(%rbp), %rdi
callq 0x8e1e
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
je 0xe103
leaq 0x30(%rbx), %rax
movq %rax, -0xd8(%rbp)
leaq 0x48(%rbx), %rax
movq %rax, -0xd0(%rbp)
leaq 0x387c(%rip), %r14      # 0x1165a
leaq 0x384a(%rip), %r15      # 0x1162f
leaq -0x88(%rbp), %r13
movq -0xa8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0xb8(%rbp)
movb $0x1, -0x88(%rbp)
movq %r14, %rdi
movl $0xca, %esi
movq %r13, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0xb61f
testb %al, %al
je 0xe1bd
movq -0x48(%rbp), %rax
cmpb $0x3e, (%rax)
jne 0xe1b4
cmpq -0x40(%rbp), %rax
setne -0x88(%rbp)
movq %r14, %rdi
movl $0xbd, %esi
movq %r13, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0xb61f
testb %al, %al
je 0xe1bd
incq -0x48(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
movq %r13, %rdx
movl $0x1, %ecx
callq 0xf2d0
testl %eax, %eax
jne 0xe1af
movq -0x48(%rbp), %rax
movl $0x400, -0x2c(%rbp)     # imm = 0x400
cmpq -0x40(%rbp), %rax
je 0xe175
movb $0x1, -0x88(%rbp)
movq %r14, %rdi
movl $0xca, %esi
movq %r13, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0xb61f
testb %al, %al
je 0xe1bd
movq -0x48(%rbp), %r12
cmpb $0xa, (%r12)
je 0xdf0a
cmpq -0x40(%rbp), %r12
setne -0x88(%rbp)
movq %r14, %rdi
movl $0xbd, %esi
movq %r13, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0xb61f
testb %al, %al
je 0xe1bd
movq -0x48(%rbp), %rax
incq %rax
movq %rax, -0x48(%rbp)
jmp 0xde96
cmpq -0x40(%rbp), %r12
je 0xdf42
movb $0x1, -0x88(%rbp)
movq %r14, %rdi
movl $0xbd, %esi
movq %r13, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0xb61f
testb %al, %al
je 0xe1bd
movq -0x48(%rbp), %r12
incq %r12
movq %r12, -0x48(%rbp)
movq -0x50(%rbp), %rax
subq (%rax), %r12
leaq -0xa8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0xe2f6
testl $0xfffffbff, %eax       # imm = 0xFFFFFBFF
jne 0xe1af
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
movl (%rax), %edx
movl -0xa0(%rbp), %eax
subl -0xa8(%rbp), %eax
addl %r12d, %edx
movl %edx, -0x8c(%rbp)
movl %eax, -0x54(%rbp)
movl %eax, -0x2c(%rbp)
movq %rcx, -0xc8(%rbp)
cmpq -0x40(%rbp), %rcx
je 0xe046
movl -0x54(%rbp), %eax
movl %eax, -0x2c(%rbp)
movb $0x1, -0x88(%rbp)
movq %r14, %rdi
movl $0xca, %esi
movq %r13, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0xb61f
testb %al, %al
je 0xe1bd
movq %r15, %r13
movq %r14, %r15
movq -0x48(%rbp), %r14
movsbl (%r14), %edi
cmpl $0x3e, %edi
je 0xe039
callq 0x3060
cmpl $0x1, %eax
adcl $0x0, -0x2c(%rbp)
cmpq -0x40(%rbp), %r14
setne -0x88(%rbp)
movq %r15, %r14
movq %r15, %rdi
movl $0xbd, %esi
leaq -0x88(%rbp), %rdx
movq %r13, %r15
movq %r13, %rcx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0xb61f
testb %al, %al
leaq -0x88(%rbp), %r13
je 0xe1bd
movq -0x48(%rbp), %rax
incq %rax
movq %rax, -0x48(%rbp)
cmpq -0x40(%rbp), %rax
jne 0xdfa0
jmp 0xe046
movq %r15, %r14
movq %r13, %r15
leaq -0x88(%rbp), %r13
movq %r13, %rdi
callq 0x8e1e
leaq -0x70(%rbp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq %r13, %rdi
leaq -0xc0(%rbp), %rsi
callq 0xad82
leaq 0x328c(%rip), %rax      # 0x11302
movq %rax, (%rsp)
leaq 0x3247(%rip), %rdi      # 0x112c8
movl $0xb6, %esi
movq %r13, %rdx
leaq 0x325e(%rip), %rcx      # 0x112ee
leaq -0x80(%rbp), %r8
leaq 0x325e(%rip), %r9       # 0x112f9
xorl %eax, %eax
callq 0x90eb
testb %al, %al
je 0xe1bd
movq -0xc8(%rbp), %rcx
subl -0x8c(%rbp), %ecx
movl -0x2c(%rbp), %eax
movq %rax, -0x70(%rbp)
movq %r12, -0x68(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x60(%rbp)
movl %ecx, -0x5c(%rbp)
movq -0xd8(%rbp), %rdi
movq %r13, %rsi
callq 0xd93e
movq -0xd0(%rbp), %rdi
movq %r13, %rsi
callq 0xd3c7
movq -0x88(%rbp), %rdi
callq 0x32f0
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
jne 0xddec
leaq 0x88(%rbx), %r14
movq %r14, %rdi
callq 0xdb06
movq 0xc0(%rbx), %rax
movq 0x8(%rax), %rcx
cmpq (%rax), %rcx
je 0xe16e
movl $0x1, %r12d
xorl %eax, %eax
leaq -0x88(%rbp), %r15
movabsq $-0x5555555555555555, %r13 # imm = 0xAAAAAAAAAAAAAAAB
movq %rax, -0x88(%rbp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x9c34
movl %r12d, %eax
movq 0xc0(%rbx), %rcx
movq 0x8(%rcx), %rdx
subq (%rcx), %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
incl %r12d
cmpq %rax, %rdx
ja 0xe13b
movl $0x0, -0x2c(%rbp)
movq -0xc0(%rbp), %rdi
callq 0x32f0
movq -0xa8(%rbp), %rdi
callq 0x32f0
jmp 0xe19a
movq $0x0, 0xf0(%rbx)
movl -0x2c(%rbp), %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, -0x2c(%rbp)
jmp 0xe175
movl $0x1, -0x2c(%rbp)
jmp 0xe175
callq 0x31e0
jmp 0xe1e2
movq %rax, %rbx
jmp 0xe1f1
jmp 0xe1e2
movq %rax, %rbx
movq -0x88(%rbp), %rdi
callq 0x32f0
jmp 0xe1e5
jmp 0xe1e2
jmp 0xe1e2
jmp 0xe1e2
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
callq 0x32f0
movq -0xa8(%rbp), %rdi
callq 0x32f0
movq %rbx, %rdi
callq 0x35b0