// File: /workspace/github_cpp_makefile_star2_O3/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, 0x60(%rsp)
leaq 0x15aee(%rip), %rax     # 0x36cb0
leaq 0x88(%rsp), %rsi
movq %rax, (%rsi)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rsi)
movq $0x0, 0x18(%rsi)
movq %rcx, 0x50(%rsp)
movq %rcx, %rdi
callq 0x7256
leaq 0x40(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xbc21(%rip), %rdx      # 0x2ce1a
leaq 0x30(%rsp), %rdi
movq %rdx, %rsi
callq 0x216a8
movq 0xa0(%rsp), %rax
movq %rax, 0x80(%rsp)
testq %rax, %rax
je 0x21474
movq 0x50(%rsp), %rax
addq $0xd8, %rax
movq %rax, 0x58(%rsp)
xorl %r12d, %r12d
movb $0x1, %r15b
xorl %ebx, %ebx
movq $-0x1, 0x20(%rsp)
movq $-0x1, 0x28(%rsp)
movq $-0x1, %rax
movq %rax, 0x70(%rsp)
movq %rax, 0x68(%rsp)
movq %rax, 0x78(%rsp)
movl $0x1, %esi
movq 0x50(%rsp), %rdi
movq %r12, %rdx
leaq 0x70(%rsp), %rcx
leaq 0x68(%rsp), %r8
leaq 0x78(%rsp), %r9
callq 0x6c86
movq 0x70(%rsp), %r14
cmpq $-0x1, %r14
je 0x213e2
movq 0x68(%rsp), %rbp
movq 0x78(%rsp), %r13
cmpq %r13, %rbp
jae 0x213e2
movq 0x28(%rsp), %rax
cmpq %r14, %rax
jne 0x212b9
movq %rax, %r14
movq 0x20(%rsp), %r13
jmp 0x2134b
cmpq $-0x1, %rax
je 0x2132b
movq 0x20(%rsp), %rsi
subq 0x38(%rsp), %rsi
jbe 0x2130a
leaq 0x10(%rsp), %r15
movq %r15, (%rsp)
movq %rsp, %rdi
movl $0x4e, %edx
callq 0x43c0
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
leaq 0x30(%rsp), %rdi
callq 0x4110
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x2130a
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x58(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x179c4
movq 0x60(%rsp), %rdi
movq %rax, %rsi
leaq 0x30(%rsp), %rdx
callq 0xb1d7
movb $0x1, %r15b
xorl %ebx, %ebx
movq 0x38(%rsp), %rdx
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
leaq 0xbad7(%rip), %rcx      # 0x2ce1a
xorl %r8d, %r8d
callq 0x4530
testq %rbp, %rbp
setne %al
andb %r15b, %al
movzbl %al, %eax
movl %ebx, %ecx
movq %rbp, %rsi
subq %rcx, %rsi
addq %rax, %rsi
cmpq $0x2, %rsi
jb 0x213aa
decq %rsi
leaq 0x10(%rsp), %r15
movq %r15, (%rsp)
movq %rsp, %rdi
movl $0x4e, %edx
callq 0x43c0
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
leaq 0x30(%rsp), %rdi
callq 0x4110
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x213aa
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4340
leaq 0x88(%rsp), %rdi
movq %r12, %rsi
callq 0x10430
movsbq (%rax), %rax
leaq 0xadfc(%rip), %rcx      # 0x2c1c1
movsbl (%rax,%rcx), %esi
leaq 0x30(%rsp), %rdi
callq 0x4290
xorl %r15d, %r15d
movq %r14, 0x28(%rsp)
movq %r13, 0x20(%rsp)
movl %ebp, %ebx
incq %r12
cmpq %r12, 0x80(%rsp)
jne 0x21249
movq 0x50(%rsp), %rax
movq 0x28(%rsp), %r15
cmpq 0xf0(%rax), %r15
leaq 0x40(%rsp), %rbx
jae 0x21474
movq 0x20(%rsp), %rsi
subq 0x38(%rsp), %rsi
jbe 0x21455
movq %rsp, %rdi
leaq 0x10(%rsp), %r14
movq %r14, (%rdi)
movl $0x4e, %edx
callq 0x43c0
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
leaq 0x30(%rsp), %rdi
callq 0x4110
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x21455
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x58(%rsp), %rdi
movq %r15, %rsi
callq 0x179c4
leaq 0x30(%rsp), %rdx
movq 0x60(%rsp), %rdi
movq %rax, %rsi
callq 0xb1d7
movq 0x30(%rsp), %rdi
cmpq %rbx, %rdi
je 0x2148b
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4340
leaq 0x88(%rsp), %rdi
callq 0x1092e
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r14, %rdi
jne 0x214d3
jmp 0x214e9
jmp 0x214e6
jmp 0x214e6
jmp 0x214c7
jmp 0x214e6
jmp 0x214c2
movq %rax, %rbx
jmp 0x21505
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x214e9
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4340
jmp 0x214e9
jmp 0x214e6
jmp 0x214e6
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x21505
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4340
leaq 0x88(%rsp), %rdi
callq 0x1092e
movq %rbx, %rdi
callq 0x4620