// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %rcx
movq %rdi, 0x30(%rsp)
leaq 0x16643(%rip), %rax     # 0x33cc8
leaq 0x88(%rsp), %rsi
movq %rax, (%rsi)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rsi)
andq $0x0, 0x18(%rsi)
movq %rcx, 0x8(%rsp)
movq %rcx, %rdi
callq 0x6cf0
leaq 0xb6fd(%rip), %rsi      # 0x28dad
leaq 0x60(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0xd596
movq 0x8(%rsp), %rax
addq $0xd8, %rax
movq %rax, 0x38(%rsp)
leaq 0x88(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x80(%rsp)
movb $0x1, %al
movl %eax, 0x4(%rsp)
movq $0x0, 0x40(%rsp)
pushq $-0x1
popq %r14
movq %r14, %r13
xorl %r12d, %r12d
cmpq %r12, 0x80(%rsp)
je 0x1d880
orq $-0x1, 0x50(%rsp)
orq $-0x1, 0x48(%rsp)
orq $-0x1, 0x58(%rsp)
movq 0x8(%rsp), %rdi
pushq $0x1
popq %rsi
movq %r12, %rdx
leaq 0x50(%rsp), %rcx
leaq 0x48(%rsp), %r8
leaq 0x58(%rsp), %r9
callq 0x6738
movq 0x50(%rsp), %rbp
cmpq $-0x1, %rbp
je 0x1d76e
movq 0x48(%rsp), %rbx
movq 0x58(%rsp), %r15
cmpq %r15, %rbx
jae 0x1d76e
cmpq %rbp, %r14
jne 0x1d779
movq %r14, %rbp
movq %r13, %r15
movl 0x4(%rsp), %ecx
movq 0x40(%rsp), %rdx
jmp 0x1d7ee
movq %r14, %rbp
movq %r13, %r15
jmp 0x1d872
cmpq $-0x1, %r14
je 0x1d7d9
subq 0x68(%rsp), %r13
jbe 0x1d7ba
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
pushq $0x4e
popq %rdx
callq 0x4370
leaq 0x60(%rsp), %rdi
leaq 0x10(%rsp), %r13
movq %r13, %rsi
callq 0x46b0
movq %r13, %rdi
callq 0x46c8
movq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x140da
movq 0x30(%rsp), %rdi
movq %rax, %rsi
leaq 0x60(%rsp), %rdx
callq 0xa100
leaq 0x60(%rsp), %rdi
leaq 0xb5c8(%rip), %rsi      # 0x28dad
callq 0x4670
movb $0x1, %cl
xorl %edx, %edx
testq %rbx, %rbx
setne %al
andb %cl, %al
movzbl %al, %eax
movl %edx, %ecx
movq %rbx, %rsi
subq %rcx, %rsi
addq %rax, %rsi
cmpq $0x2, %rsi
leaq 0x10(%rsp), %r14
jb 0x1d83c
decq %rsi
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %r14, %rdi
pushq $0x4e
popq %rdx
callq 0x4370
leaq 0x60(%rsp), %rdi
movq %r14, %rsi
callq 0x46b0
movq %r14, %rdi
callq 0x46c8
leaq 0x88(%rsp), %rdi
movq %r12, %rsi
callq 0xe1f4
movsbq (%rax), %rax
leaq 0xa8fd(%rip), %rcx      # 0x28154
movsbl (%rax,%rcx), %esi
leaq 0x60(%rsp), %rdi
callq 0x4250
movl $0x0, 0x4(%rsp)
movq %rbx, 0x40(%rsp)
incq %r12
movq %rbp, %r14
movq %r15, %r13
jmp 0x1d6fc
movq 0x8(%rsp), %rax
cmpq 0xf0(%rax), %r14
jae 0x1d8e5
subq 0x68(%rsp), %r13
jbe 0x1d8c6
leaq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
movq %rax, (%rdi)
pushq $0x4e
popq %rdx
movq %r13, %rsi
callq 0x4370
leaq 0x60(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x46b0
leaq 0x10(%rsp), %rdi
callq 0x46c8
movq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x140da
leaq 0x60(%rsp), %rdx
movq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0xa100
leaq 0x60(%rsp), %rdi
callq 0x46c8
leaq 0x88(%rsp), %rdi
callq 0xe6f0
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1d91f
jmp 0x1d932
jmp 0x1d932
jmp 0x1d916
movq %rax, %rbx
jmp 0x1d93f
jmp 0x1d91f
jmp 0x1d932
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x46c8
jmp 0x1d935
jmp 0x1d932
jmp 0x1d932
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x46c8
leaq 0x88(%rsp), %rdi
callq 0xe6f0
movq %rbx, %rdi
callq 0x45e0