// File: ekg[P]fastahack/Fasta.cpp
// Function: FastaReference::getSequence(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
string FastaReference::getSequence(string seqname) {
    FastaIndexEntry entry = index->entry(seqname);
    int bytes_per_newline = entry.line_len - entry.line_blen;
    int newline_bytes_in_sequence = entry.length / entry.line_blen * bytes_per_newline;
    int seqlen = newline_bytes_in_sequence + entry.length;
    char* seq = (char*) calloc (seqlen + 1, sizeof(char));
    fseek64(file, entry.offset, SEEK_SET);
    string s;
    if (fread(seq, sizeof(char), seqlen, file)) {
        seq[seqlen] = '\0';
        char* pbegin = seq;
        char* pend = seq + (seqlen/sizeof(char));
        pend = remove(pbegin, pend, '\r');
        pend = remove(pbegin, pend, '\n');
        pend = remove(pbegin, pend, '\0');
        s = seq;
        free(seq);
        s.resize((pend - pbegin)/sizeof(char));
    }
    return s;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdx, -0xe0(%rbp)
movq %rsi, %rax
movq -0xe0(%rbp), %rsi
movq %rdi, -0xd8(%rbp)
movq %rdi, %rcx
movq %rcx, -0xd0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rax, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq 0x40(%rax), %rax
movq %rax, -0xc0(%rbp)
leaq -0x70(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0x3130
movq -0xc0(%rbp), %rsi
movq -0xb8(%rbp), %rdx
leaq -0x50(%rbp), %rdi
callq 0x4b30
jmp 0x50b8
leaq -0x70(%rbp), %rdi
callq 0x31a0
movl -0x20(%rbp), %ecx
movl -0x1c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x80(%rbp)
movl -0x30(%rbp), %eax
movl -0x20(%rbp), %ecx
cltd
idivl %ecx
movl -0x80(%rbp), %ecx
imull %ecx, %eax
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %eax
movl -0x30(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x88(%rbp)
movl -0x88(%rbp), %eax
incl %eax
movslq %eax, %rdi
movl $0x1, %esi
callq 0x31c0
movq %rax, %rcx
movq -0xc8(%rbp), %rax
movq %rcx, -0x90(%rbp)
movq 0x28(%rax), %rdi
movq -0x28(%rbp), %rsi
xorl %edx, %edx
callq 0x3190
jmp 0x5129
movq -0xd8(%rbp), %rdi
movb $0x0, -0x91(%rbp)
callq 0x3430
movq -0xc8(%rbp), %rax
movq -0x90(%rbp), %rdi
movslq -0x88(%rbp), %rdx
movq 0x28(%rax), %rcx
movl $0x1, %esi
callq 0x3460
movq %rax, -0xe8(%rbp)
jmp 0x5168
movq -0xe8(%rbp), %rax
cmpq $0x0, %rax
je 0x52da
movq -0x90(%rbp), %rax
movslq -0x88(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x90(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x90(%rbp), %rax
movslq -0x88(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0xa8(%rbp)
movq -0xa0(%rbp), %rdi
movq -0xa8(%rbp), %rsi
movb $0xd, -0xa9(%rbp)
leaq -0xa9(%rbp), %rdx
callq 0x6300
movq %rax, -0xf0(%rbp)
jmp 0x51db
movq -0xf0(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa0(%rbp), %rdi
movq -0xa8(%rbp), %rsi
movb $0xa, -0xaa(%rbp)
leaq -0xaa(%rbp), %rdx
callq 0x6300
movq %rax, -0xf8(%rbp)
jmp 0x5213
movq -0xf8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa0(%rbp), %rdi
movq -0xa8(%rbp), %rsi
movb $0x0, -0xab(%rbp)
leaq -0xab(%rbp), %rdx
callq 0x6300
movq %rax, -0x100(%rbp)
jmp 0x524b
movq -0xd8(%rbp), %rdi
movq -0x100(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x90(%rbp), %rsi
callq 0x3410
jmp 0x526e
movq -0x90(%rbp), %rdi
callq 0x3390
movq -0xd8(%rbp), %rdi
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rax
subq %rax, %rsi
callq 0x3420
jmp 0x5299
jmp 0x52da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x31a0
jmp 0x5318
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x530f
movq -0xd8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
callq 0x31a0
jmp 0x530f
movb $0x1, -0x91(%rbp)
testb $0x1, -0x91(%rbp)
jne 0x52f6
movq -0xd8(%rbp), %rdi
callq 0x31a0
leaq -0x50(%rbp), %rdi
callq 0x3840
movq -0xd0(%rbp), %rax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
leaq -0x50(%rbp), %rdi
callq 0x3840
movq -0x78(%rbp), %rdi
callq 0x3540
nopw %cs:(%rax,%rax)