// File: /workspace/github_cpp_makefile_star2_O1/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 0x155be(%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 0x721c
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0xc661(%rip), %rdx      # 0x2dd8a
leaq 0x28(%rsp), %rdi
movq %rdx, %rsi
callq 0x21c14
movq 0x50(%rsp), %rax
addq $0xd8, %rax
movq %rax, 0x68(%rsp)
movq 0xa0(%rsp), %rax
movq $-0x1, 0x58(%rsp)
movq %rax, 0x80(%rsp)
testq %rax, %rax
je 0x21951
xorl %r13d, %r13d
movb $0x1, %al
movl %eax, 0x4(%rsp)
movq $0x0, 0x48(%rsp)
movq $-0x1, %rbp
movq $-0x1, %r12
movq $-0x1, %rax
movq %rax, 0x78(%rsp)
movq %rax, 0x70(%rsp)
movq %rax, 0x58(%rsp)
movl $0x1, %esi
movq 0x50(%rsp), %rdi
movq %r13, %rdx
leaq 0x78(%rsp), %rcx
leaq 0x70(%rsp), %r8
leaq 0x58(%rsp), %r9
callq 0x6c32
movq 0x78(%rsp), %rbx
cmpq $-0x1, %rbx
je 0x217e9
movq 0x70(%rsp), %r15
movq 0x58(%rsp), %r14
cmpq %r14, %r15
jae 0x217e9
cmpq %rbx, %r12
jne 0x217f4
movq %r12, %rbx
movq %rbp, %r14
jmp 0x21896
movq %r12, %rbx
movq %rbp, %r14
jmp 0x21938
cmpq $-0x1, %r12
je 0x2186c
subq 0x30(%rsp), %rbp
jbe 0x2184d
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x8(%rsp), %rdi
movq %rbp, %rsi
movl $0x4e, %edx
callq 0x43c0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0x28(%rsp), %rdi
callq 0x4110
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x2184d
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x68(%rsp), %rdi
movq %r12, %rsi
callq 0x17b9e
movq 0x60(%rsp), %rdi
movq %rax, %rsi
leaq 0x28(%rsp), %rdx
callq 0xb331
movb $0x1, %al
movl %eax, 0x4(%rsp)
movq $0x0, 0x48(%rsp)
movq 0x30(%rsp), %rdx
leaq 0x28(%rsp), %rdi
xorl %esi, %esi
leaq 0xc4fc(%rip), %rcx      # 0x2dd8a
xorl %r8d, %r8d
callq 0x4530
testq %r15, %r15
setne %al
andb 0x4(%rsp), %al
movzbl %al, %eax
movl 0x48(%rsp), %ecx
movq %r15, %rsi
subq %rcx, %rsi
addq %rax, %rsi
cmpq $0x2, %rsi
jb 0x21902
decq %rsi
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x8(%rsp), %rdi
movl $0x4e, %edx
callq 0x43c0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0x28(%rsp), %rdi
callq 0x4110
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x21902
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4340
leaq 0x88(%rsp), %rdi
movq %r13, %rsi
callq 0x10648
movsbq (%rax), %rax
leaq 0xb814(%rip), %rcx      # 0x2d131
movsbl (%rax,%rcx), %esi
leaq 0x28(%rsp), %rdi
callq 0x4290
movl $0x0, 0x4(%rsp)
movq %r15, 0x48(%rsp)
incq %r13
movq %r14, %rbp
movq %rbx, %r12
cmpq %r13, 0x80(%rsp)
jne 0x21788
jmp 0x2195f
movq $-0x1, %rbx
movq $-0x1, %r14
movq 0x50(%rsp), %rax
cmpq 0xf0(%rax), %rbx
jae 0x219d9
subq 0x30(%rsp), %r14
jbe 0x219ba
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
movl $0x4e, %edx
callq 0x43c0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0x28(%rsp), %rdi
callq 0x4110
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x219ba
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x68(%rsp), %rdi
movq %rbx, %rsi
callq 0x17b9e
leaq 0x28(%rsp), %rdx
movq 0x60(%rsp), %rdi
movq %rax, %rsi
callq 0xb331
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x219f5
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x4340
leaq 0x88(%rsp), %rdi
callq 0x10b48
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
jne 0x21a44
jmp 0x21a5a
jmp 0x21a57
jmp 0x21a32
jmp 0x21a57
jmp 0x21a57
jmp 0x21a2d
movq %rax, %rbx
jmp 0x21a76
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x21a5a
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4340
jmp 0x21a5a
jmp 0x21a57
jmp 0x21a57
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x21a76
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x4340
leaq 0x88(%rsp), %rdi
callq 0x10b48
movq %rbx, %rdi
callq 0x4620
nop