// File: BenLangmead[P]bowtie/bowtie_inspect.cpp
// Function: void print_index_sequences<SString<char>>(std::ostream&, Ebwt&, BitPairReference const&)
void print_index_sequences(
	ostream& fout,
	Ebwt& ebwt,
	const BitPairReference& refs)
{
	EList<string>* refnames = &(ebwt.refnames());

	TStr cat_ref;
	ebwt.restore(cat_ref);

	TIndexOffU curr_ref = OFF_MASK;
	string curr_ref_seq = "";
	TIndexOffU curr_ref_len = OFF_MASK;
	uint32_t last_text_off = 0;
	size_t orig_len = cat_ref.length();
	TIndexOffU tlen = OFF_MASK;
	bool first = true;
	for(size_t i = 0; i < orig_len; i++) {
		TIndexOffU tidx = OFF_MASK;
		TIndexOffU textoff = OFF_MASK;
		tlen = OFF_MASK;

		ebwt.joinedToTextOff(1 /* qlen */, (TIndexOffU)i, tidx, textoff, tlen);

		if (tidx != OFF_MASK && textoff < tlen)
		{
			if (curr_ref != tidx)
			{
				if (curr_ref != OFF_MASK)
				{
					// Add trailing gaps, if any exist
					if(curr_ref_seq.length() < curr_ref_len) {
						curr_ref_seq += string(curr_ref_len - curr_ref_seq.length(), 'N');
					}
					print_fasta_record(fout, (*refnames)[curr_ref], curr_ref_seq);
				}
				curr_ref = tidx;
				curr_ref_seq = "";
				curr_ref_len = tlen;
				last_text_off = 0;
				first = true;
			}

			TIndexOffU textoff_adj = textoff;
			if(first && textoff > 0) textoff_adj++;
			if (textoff_adj - last_text_off > 1)
				curr_ref_seq += string(textoff_adj - last_text_off - 1, 'N');

			curr_ref_seq.push_back("ACGT"[(int)cat_ref[i]]);
			last_text_off = textoff;
			first = false;
		}
	}
	if (curr_ref < refnames->size())
	{
		// Add trailing gaps, if any exist
		if(curr_ref_seq.length() < curr_ref_len) {
			curr_ref_seq += string(curr_ref_len - curr_ref_seq.length(), 'N');
		}
		print_fasta_record(fout, (*refnames)[curr_ref], curr_ref_seq);
	}

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x30350
movq %rax, -0x20(%rbp)
leaq -0x40(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0x19450
movq -0x148(%rbp), %rsi
movq -0x10(%rbp), %rdi
callq 0x8e60
jmp 0x2fc06
movq $-0x1, -0x58(%rbp)
leaq -0x79(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x5780
movq -0x150(%rbp), %rdx
leaq 0x10198(%rip), %rsi     # 0x3fdc4
leaq -0x78(%rbp), %rdi
callq 0x17fb0
jmp 0x2fc37
leaq -0x79(%rbp), %rdi
callq 0x53f0
movq $-0x1, -0x88(%rbp)
movl $0x0, -0x8c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x195b0
movq %rax, -0x158(%rbp)
jmp 0x2fc67
movq -0x158(%rbp), %rax
movq %rax, -0x98(%rbp)
movq $-0x1, -0xa0(%rbp)
movb $0x1, -0xa1(%rbp)
movq $0x0, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
cmpq -0x98(%rbp), %rax
jae 0x30022
movq $-0x1, -0xb8(%rbp)
movq $-0x1, -0xc0(%rbp)
movq $-0x1, -0xa0(%rbp)
movq -0x10(%rbp), %rdi
movq -0xb0(%rbp), %rdx
movl $0x1, %esi
leaq -0xb8(%rbp), %rcx
leaq -0xc0(%rbp), %r8
leaq -0xa0(%rbp), %r9
callq 0x8720
jmp 0x2fcf3
cmpq $-0x1, -0xb8(%rbp)
je 0x30009
movq -0xc0(%rbp), %rax
cmpq -0xa0(%rbp), %rax
jae 0x30009
movq -0x58(%rbp), %rax
cmpq -0xb8(%rbp), %rax
je 0x2febd
cmpq $-0x1, -0x58(%rbp)
je 0x2fe81
leaq -0x78(%rbp), %rdi
callq 0x5610
cmpq -0x88(%rbp), %rax
jae 0x2fe45
movq -0x88(%rbp), %rax
movq %rax, -0x170(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x5610
movq %rax, %rcx
movq -0x170(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x168(%rbp)
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x5780
movq -0x168(%rbp), %rsi
movq -0x160(%rbp), %rcx
leaq -0xe0(%rbp), %rdi
movl $0x4e, %edx
callq 0x30370
jmp 0x2fda6
leaq -0x78(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x5500
jmp 0x2fdb8
leaq -0xe0(%rbp), %rdi
callq 0x5888
leaq -0xe1(%rbp), %rdi
callq 0x53f0
jmp 0x2fe45
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x3018b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x79(%rbp), %rdi
callq 0x53f0
jmp 0x3018b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x30182
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x2fe34
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x5888
leaq -0xe1(%rbp), %rdi
callq 0x53f0
jmp 0x30182
movq -0x8(%rbp), %rax
movq %rax, -0x180(%rbp)
movq -0x20(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x22060
movq %rax, -0x178(%rbp)
jmp 0x2fe66
movq -0x178(%rbp), %rsi
movq -0x180(%rbp), %rdi
leaq -0x78(%rbp), %rdx
callq 0xedc0
jmp 0x2fe7f
jmp 0x2fe81
movq -0xb8(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq 0xff31(%rip), %rsi      # 0x3fdc4
leaq -0x78(%rbp), %rdi
callq 0x5570
jmp 0x2fe9e
movq -0xa0(%rbp), %rax
movq %rax, -0x88(%rbp)
movl $0x0, -0x8c(%rbp)
movb $0x1, -0xa1(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0xf0(%rbp)
testb $0x1, -0xa1(%rbp)
je 0x2fef0
cmpq $0x0, -0xc0(%rbp)
jbe 0x2fef0
movq -0xf0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rax
movl -0x8c(%rbp), %ecx
subq %rcx, %rax
cmpq $0x1, %rax
jbe 0x2ffbb
movq -0xf0(%rbp), %rcx
movl -0x8c(%rbp), %eax
notq %rax
addq %rcx, %rax
movq %rax, -0x190(%rbp)
leaq -0x111(%rbp), %rdi
movq %rdi, -0x188(%rbp)
callq 0x5780
movq -0x190(%rbp), %rsi
movq -0x188(%rbp), %rcx
leaq -0x110(%rbp), %rdi
movl $0x4e, %edx
callq 0x30370
jmp 0x2ff58
leaq -0x78(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x5500
jmp 0x2ff6a
leaq -0x110(%rbp), %rdi
callq 0x5888
leaq -0x111(%rbp), %rdi
callq 0x53f0
jmp 0x2ffbb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x2ffaa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x5888
leaq -0x111(%rbp), %rdi
callq 0x53f0
jmp 0x30182
movq -0xb0(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x18f90
movq %rax, -0x198(%rbp)
jmp 0x2ffd4
movq -0x198(%rbp), %rax
movsbq (%rax), %rax
leaq 0xf12e(%rip), %rcx      # 0x3f114
movsbl (%rax,%rcx), %esi
leaq -0x78(%rbp), %rdi
callq 0x52d0
jmp 0x2fff5
movq -0xc0(%rbp), %rax
movl %eax, -0x8c(%rbp)
movb $0x0, -0xa1(%rbp)
jmp 0x3000b
movq -0xb0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xb0(%rbp)
jmp 0x2fc92
movq -0x58(%rbp), %rax
movq %rax, -0x1a8(%rbp)
movq -0x20(%rbp), %rdi
callq 0x1aaa0
movq %rax, -0x1a0(%rbp)
jmp 0x3003f
movq -0x1a8(%rbp), %rax
movq -0x1a0(%rbp), %rcx
cmpq %rcx, %rax
jae 0x30167
leaq -0x78(%rbp), %rdi
callq 0x5610
cmpq -0x88(%rbp), %rax
jae 0x3012b
movq -0x88(%rbp), %rax
movq %rax, -0x1c0(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x5610
movq %rax, %rcx
movq -0x1c0(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x1b8(%rbp)
leaq -0x139(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
callq 0x5780
movq -0x1b8(%rbp), %rsi
movq -0x1b0(%rbp), %rcx
leaq -0x138(%rbp), %rdi
movl $0x4e, %edx
callq 0x30370
jmp 0x300cb
leaq -0x78(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x5500
jmp 0x300dd
leaq -0x138(%rbp), %rdi
callq 0x5888
leaq -0x139(%rbp), %rdi
callq 0x53f0
jmp 0x3012b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x3011d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x5888
leaq -0x139(%rbp), %rdi
callq 0x53f0
jmp 0x30182
movq -0x8(%rbp), %rax
movq %rax, -0x1d0(%rbp)
movq -0x20(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x22060
movq %rax, -0x1c8(%rbp)
jmp 0x3014c
movq -0x1c8(%rbp), %rsi
movq -0x1d0(%rbp), %rdi
leaq -0x78(%rbp), %rdx
callq 0xedc0
jmp 0x30165
jmp 0x30167
leaq -0x78(%rbp), %rdi
callq 0x5888
leaq -0x40(%rbp), %rdi
callq 0x196d0
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
leaq -0x78(%rbp), %rdi
callq 0x5888
leaq -0x40(%rbp), %rdi
callq 0x196d0
movq -0x48(%rbp), %rdi
callq 0x5760
nopl (%rax)