// File: /workspace/github_cpp_makefile_star2_O1/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, %r14
movq %rsi, %r15
movq %rdi, %rbx
leaq -0x90(%rbp), %rsi
movq %r15, (%rsi)
callq 0xb2bc
leaq 0x8(%rbx), %r8
leaq 0x2ef0(%rip), %r13      # 0x11302
movq %r13, (%rsp)
leaq 0x2eab(%rip), %rdi      # 0x112c8
leaq 0x2eca(%rip), %rcx      # 0x112ee
leaq 0x2ece(%rip), %r9       # 0x112f9
movl $0xae, %esi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x91c5
testb %al, %al
je 0xe906
leaq 0x18(%rbx), %r12
leaq -0x90(%rbp), %rsi
movq %r14, (%rsi)
movq %r12, %rdi
callq 0xb2bc
leaq 0x20(%rbx), %r8
movq %r13, (%rsp)
leaq 0x2e61(%rip), %rdi      # 0x112c8
leaq 0x2e80(%rip), %rcx      # 0x112ee
leaq 0x2e84(%rip), %r9       # 0x112f9
movl $0xae, %esi
movq %r12, %rdx
xorl %eax, %eax
callq 0x91c5
testb %al, %al
je 0xe906
cmpb $0x1, 0x118(%rbx)
jne 0xe4a1
leaq 0xe0(%rbx), %rdi
callq 0xce5a
leaq 0xe0(%rbx), %r12
movq %r12, %rdi
callq 0xce5a
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 %r15, %rsi
movl $0x1, %edx
callq *0x10(%rax)
movl %eax, %r15d
movl $0x1, 0x108(%rbx)
movw $0x1, 0x10c(%rbx)
testb %al, %al
je 0xe540
movq %r13, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0xbf5c
movq %rax, -0x58(%rbp)
movq %r13, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0xbf5c
movq %rax, %r14
movq %r13, %rdi
movq -0x58(%rbp), %rsi
xorl %edx, %edx
callq 0xbe84
jmp 0xe543
xorl %r14d, %r14d
movq %r14, 0xf0(%rbx)
testb %r15b, %r15b
je 0xe8f1
movq %r12, %rdi
movq %r14, %rsi
callq 0xa7b8
testb %al, %al
je 0xe8f1
movb $0x1, 0x118(%rbx)
leaq -0x50(%rbp), %rdi
movq %r12, (%rdi)
movq 0xe0(%rbx), %rax
movq %rax, 0x8(%rdi)
movq 0xe8(%rbx), %rax
movq %rax, 0x10(%rdi)
movq $0x2000, 0x18(%rdi)     # imm = 0x2000
leaq -0x90(%rbp), %rsi
callq 0xeca4
movl $0x1, -0x2c(%rbp)
testb %al, %al
jne 0xe8f1
leaq -0x50(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0xf5fd
testb %al, %al
je 0xe8f1
leaq -0xb0(%rbp), %rdi
callq 0x8ef8
leaq -0xc8(%rbp), %rdi
callq 0x8ef8
leaq 0x30(%rbx), %rax
movq %rax, -0xd8(%rbp)
leaq 0x48(%rbx), %rax
movq %rax, -0xd0(%rbp)
leaq 0x309a(%rip), %r13      # 0x11694
leaq 0x302e(%rip), %r14      # 0x1162f
leaq -0x90(%rbp), %r12
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
je 0xe85e
movq -0xb0(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, -0xc0(%rbp)
movb $0x1, -0x90(%rbp)
movq %r13, %rdi
movl $0xca, %esi
movq %r12, %rdx
movq %r14, %rcx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0xb89e
testb %al, %al
je 0xe906
movq -0x48(%rbp), %rax
cmpb $0x3e, (%rax)
jne 0xe8d2
cmpq -0x40(%rbp), %rax
setne -0x90(%rbp)
movq %r13, %rdi
movl $0xbd, %esi
movq %r12, %rdx
movq %r14, %rcx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0xb89e
testb %al, %al
je 0xe906
incq -0x48(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
movq %r12, %rdx
movl $0x1, %ecx
callq 0xf9fb
testl %eax, %eax
jne 0xe6e7
leaq -0x50(%rbp), %rdi
callq 0xe94c
testl %eax, %eax
jne 0xe6e7
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
subq (%rax), %rcx
movq %rcx, -0x98(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0xea54
testl $0xfffffbff, %eax       # imm = 0xFFFFFBFF
je 0xe6f9
xorl %ecx, %ecx
movl %eax, -0x2c(%rbp)
testb %cl, %cl
jne 0xe608
jmp 0xe8d9
movl -0x48(%rbp), %ecx
movq -0x50(%rbp), %rax
movl (%rax), %eax
addl -0x98(%rbp), %eax
subl %eax, %ecx
movl %ecx, -0x60(%rbp)
movl -0xa8(%rbp), %eax
subl -0xb0(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl %eax, -0x30(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
je 0xe7a8
movb $0x1, -0x90(%rbp)
movq %r13, %rdi
movl $0xca, %esi
movq %r12, %rdx
movq %r14, %rcx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0xb89e
testb %al, %al
je 0xe906
movq -0x48(%rbp), %r15
movsbl (%r15), %edi
cmpl $0x3e, %edi
je 0xe79e
movl %edi, -0x58(%rbp)
callq 0x3060
cmpl $0x1, %eax
adcl $0x0, -0x30(%rbp)
cmpq -0x40(%rbp), %r15
setne -0x90(%rbp)
movq %r13, %rdi
movl $0xbd, %esi
movq %r12, %rdx
movq %r14, %rcx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0xb89e
testb %al, %al
je 0xe906
incq -0x48(%rbp)
movl -0x58(%rbp), %edi
cmpb $0x3e, %dil
jne 0xe71f
movq %r12, %rdi
callq 0x8ef8
leaq -0x78(%rbp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq %r12, %rdi
leaq -0xc8(%rbp), %rsi
callq 0xb03c
leaq 0x2b2a(%rip), %rax      # 0x11302
movq %rax, (%rsp)
leaq 0x2ae5(%rip), %rdi      # 0x112c8
movl $0xb6, %esi
movq %r12, %rdx
leaq 0x2afc(%rip), %rcx      # 0x112ee
leaq -0x88(%rbp), %r8
leaq 0x2af9(%rip), %r9       # 0x112f9
xorl %eax, %eax
callq 0x91c5
testb %al, %al
je 0xe906
movl -0x30(%rbp), %eax
movq %rax, -0x78(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x70(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x60(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0xd8(%rbp), %rdi
movq %r12, %rsi
callq 0xe172
movq -0xd0(%rbp), %rdi
movq %r12, %rsi
callq 0xd65a
movq -0x90(%rbp), %rdi
callq 0x32f0
movb $0x1, %cl
jmp 0xe6ec
leaq 0x88(%rbx), %r14
movq %r14, %rdi
callq 0xe328
movq 0xc0(%rbx), %rax
movq 0x8(%rax), %rcx
cmpq (%rax), %rcx
je 0xe8c9
movl $0x1, %r12d
xorl %eax, %eax
leaq -0x90(%rbp), %r15
movabsq $-0x5555555555555555, %r13 # imm = 0xAAAAAAAAAAAAAAAB
movq %rax, -0x90(%rbp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x9d08
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 0xe896
movl $0x0, -0x2c(%rbp)
jmp 0xe8d9
movl $0x1, -0x2c(%rbp)
movq -0xc8(%rbp), %rdi
callq 0x32f0
movq -0xb0(%rbp), %rdi
callq 0x32f0
movl -0x2c(%rbp), %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x31e0
jmp 0xe929
movq %rax, %rbx
jmp 0xe938
movq %rax, %rbx
movq -0x90(%rbp), %rdi
callq 0x32f0
jmp 0xe92c
jmp 0xe929
jmp 0xe929
jmp 0xe929
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
callq 0x32f0
movq -0xb0(%rbp), %rdi
callq 0x32f0
movq %rbx, %rdi
callq 0x35b0