// File: 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
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x132a0
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
leaq -0x20(%rbp), %rsi
callq 0x132a0
movq -0x10(%rbp), %rax
testb $0x1, 0x118(%rax)
je 0x162e2
movq -0x10(%rbp), %rdi
addq $0xe0, %rdi
callq 0x13310
movq -0x10(%rbp), %rax
addq $0xe0, %rax
movq %rax, -0xe0(%rbp)
movq -0x18(%rbp), %rdi
callq 0x12a90
movq -0xe0(%rbp), %rdi
movq %rax, %rsi
movl $0x1, %edx
callq 0x13380
testb $0x1, %al
jne 0x16320
movl $0x1, -0x4(%rbp)
jmp 0x1671e
movq -0x10(%rbp), %rax
movb $0x1, 0x118(%rax)
movq -0x10(%rbp), %rsi
addq $0xe0, %rsi
leaq -0x40(%rbp), %rdi
callq 0x16770
leaq -0x44(%rbp), %rdi
callq 0x167e0
leaq -0x40(%rbp), %rdi
leaq -0x44(%rbp), %rsi
callq 0x16800
testb $0x1, %al
jne 0x16365
movl $0x1, -0x4(%rbp)
jmp 0x1671e
leaq -0x44(%rbp), %rdi
leaq -0x45(%rbp), %rsi
callq 0x16880
xorb $-0x1, %al
testb $0x1, %al
jne 0x1637a
jmp 0x16386
movl $0x1, -0x4(%rbp)
jmp 0x1671e
leaq -0x60(%rbp), %rdi
callq 0xb3a0
leaq -0x78(%rbp), %rdi
callq 0xb3a0
jmp 0x1639a
movl $0x0, -0x88(%rbp)
movq $0x0, -0x90(%rbp)
movl $0x0, -0x94(%rbp)
movl $0x0, -0x98(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x168a0
movb %al, -0xe1(%rbp)
jmp 0x163d4
movb -0xe1(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x163e5
jmp 0x166d3
leaq -0x60(%rbp), %rdi
callq 0x13670
jmp 0x163f0
leaq -0x78(%rbp), %rdi
callq 0x13670
jmp 0x163fb
leaq -0x40(%rbp), %rdi
callq 0x168c0
movb %al, -0xe2(%rbp)
jmp 0x1640c
movb -0xe2(%rbp), %al
movsbl %al, %eax
cmpl $0x3e, %eax
je 0x16458
movl $0x1, -0x4(%rbp)
movl $0x1, -0x9c(%rbp)
jmp 0x166f6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x16713
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x1670a
leaq -0x40(%rbp), %rdi
callq 0x16920
jmp 0x16463
leaq -0x78(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x16990
movl %eax, -0xe8(%rbp)
jmp 0x16478
movl -0xe8(%rbp), %eax
movl %eax, -0xa0(%rbp)
cmpl $0x0, -0xa0(%rbp)
je 0x164a5
movl -0xa0(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x9c(%rbp)
jmp 0x166f6
leaq -0x40(%rbp), %rdi
callq 0x169c0
movl %eax, -0xec(%rbp)
jmp 0x164b6
movl -0xec(%rbp), %eax
movl %eax, -0xa0(%rbp)
cmpl $0x0, -0xa0(%rbp)
je 0x164e3
movl -0xa0(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x9c(%rbp)
jmp 0x166f6
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
movq %rax, -0xf8(%rbp)
callq 0xe9b0
movq %rax, %rcx
movq -0xf8(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x90(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x16a20
movl %eax, -0xf0(%rbp)
jmp 0x16520
movl -0xf0(%rbp), %eax
movl %eax, -0xa0(%rbp)
cmpl $0x0, -0xa0(%rbp)
je 0x16559
cmpl $0x400, -0xa0(%rbp)     # imm = 0x400
je 0x16559
movl -0xa0(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x9c(%rbp)
jmp 0x166f6
movl -0x38(%rbp), %eax
movl %eax, -0x104(%rbp)
movq -0x40(%rbp), %rdi
callq 0xe9b0
movq %rax, %rcx
movl -0x104(%rbp), %eax
subl %ecx, %eax
movl -0x90(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x98(%rbp)
leaq -0x60(%rbp), %rdi
callq 0xd920
movq %rax, -0x100(%rbp)
jmp 0x16596
movq -0x100(%rbp), %rax
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %eax
movl %eax, -0x88(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x168a0
movb %al, -0x105(%rbp)
jmp 0x165c0
movb -0x105(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x165ce
jmp 0x16626
leaq -0x40(%rbp), %rdi
callq 0x168c0
movb %al, -0x106(%rbp)
jmp 0x165df
movb -0x106(%rbp), %al
movb %al, -0xa3(%rbp)
movsbl -0xa3(%rbp), %eax
cmpl $0x3e, %eax
jne 0x165f9
jmp 0x16626
movsbl -0xa3(%rbp), %edi
callq 0x40a0
cmpl $0x0, %eax
jne 0x16619
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x16920
jmp 0x16624
jmp 0x165af
leaq -0xd8(%rbp), %rdi
callq 0x13500
jmp 0x16634
leaq -0xd8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x16b40
jmp 0x16646
movl -0x88(%rbp), %eax
movq %rax, -0xc0(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0xb8(%rbp)
movl -0x94(%rbp), %eax
movl %eax, -0xb0(%rbp)
movl -0x98(%rbp), %eax
movl %eax, -0xac(%rbp)
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
leaq -0xd8(%rbp), %rsi
callq 0x13900
jmp 0x1668f
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
leaq -0xd8(%rbp), %rsi
callq 0x13580
jmp 0x166a5
leaq -0xd8(%rbp), %rdi
callq 0x12a20
jmp 0x163c3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x12a20
jmp 0x1670a
movq -0x10(%rbp), %rdi
addq $0x88, %rdi
callq 0x13930
jmp 0x166e5
movl $0x0, -0x4(%rbp)
movl $0x1, -0x9c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0xb7b0
leaq -0x60(%rbp), %rdi
callq 0xb7b0
jmp 0x1671e
leaq -0x78(%rbp), %rdi
callq 0xb7b0
leaq -0x60(%rbp), %rdi
callq 0xb7b0
jmp 0x1672a
movl -0x4(%rbp), %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0x80(%rbp), %rdi
callq 0x4770
nopw %cs:(%rax,%rax)
nopl (%rax)