// File: /workspace/github_cpp_makefile_star2_O2/BenLangmead[P]bowtie/./ebwt.h
// Function: Ebwt::writeFromMemory(bool, std::ostream&, std::ostream&) const
void Ebwt::writeFromMemory(bool justHeader,
			   ostream& out1,
			   ostream& out2) const
{
	const EbwtParams& eh = this->_eh;
	assert(eh.repOk());
	uint32_t be = this->toBe();
	assert(out1.good());
	assert(out2.good());

	// When building an Ebwt, these header parameters are known
	// "up-front", i.e., they can be written to disk immediately,
	// before we join() or buildToDisk()
	writeI<int32_t>(out1, 1, be); // endian hint for priamry stream
	writeI<int32_t>(out2, 1, be); // endian hint for secondary stream
	writeU<TIndexOffU>(out1, eh._len,          be); // length of string (and bwt and suffix array)
	writeI<int32_t>(out1, eh._lineRate,     be); // 2^lineRate = size in bytes of 1 line
	writeI<int32_t>(out1, eh._linesPerSide, be); // not used
	writeI<int32_t>(out1, eh._offRate,      be); // every 2^offRate chars is "marked"
	writeI<int32_t>(out1, eh._ftabChars,    be); // number of 2-bit chars used to address ftab
	int32_t flags = 1;
	if(eh._entireReverse) flags |= EBWT_ENTIRE_REV;
	writeI<int32_t>(out1, -flags, be); // BTL: chunkRate is now deprecated

	if(!justHeader) {
		assert(isInMemory());
		// These Ebwt parameters are known after the inputs strings have
		// been joined() but before they have been built().  These can
		// written to the disk next and then discarded from memory.
		writeU<TIndexOffU>(out1, this->_nPat,      be);
		for(TIndexOffU i = 0; i < this->_nPat; i++)
			writeU<TIndexOffU>(out1, this->_plen[i], be);
		assert_geq(this->_nFrag, this->_nPat);
		writeU<TIndexOffU>(out1, this->_nFrag, be);
		for(TIndexOffU i = 0; i < this->_nFrag*3; i++)
			writeU<TIndexOffU>(out1, this->_rstarts[i], be);

		// These Ebwt parameters are discovered only as the Ebwt is being
		// built (in buildToDisk()).  Of these, only 'offs' and 'ebwt' are
		// terribly large.  'ebwt' is written to the primary file and then
		// discarded from memory as it is built; 'offs' is similarly
		// written to the secondary file and discarded.
		out1.write((const char *)this->ebwt(), eh._ebwtTotLen);
		writeU<TIndexOffU>(out1, this->zOff(), be);
		TIndexOffU offsLen = eh._offsLen;
		for(TIndexOffU i = 0; i < offsLen; i++)
			writeU<TIndexOffU>(out2, this->_offs[i], be);
		uint32_t isaLen = eh._isaLen;
		for(TIndexOffU i = 0; i < isaLen; i++)
			writeU<TIndexOffU>(out2, this->_isa[i], be);

		// 'fchr', 'ftab' and 'eftab' are not fully determined until the
		// loop is finished, so they are written to the primary file after
		// all of 'ebwt' has already been written and only then discarded
		// from memory.
		for(int i = 0; i < 5; i++)
			writeU<TIndexOffU>(out1, this->_fchr[i], be);
		for(TIndexOffU i = 0; i < eh._ftabLen; i++)
			writeU<TIndexOffU>(out1, this->ftab()[i], be);
		for(TIndexOffU i = 0; i < eh._eftabLen; i++)
			writeU<TIndexOffU>(out1, this->eftab()[i], be);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r15
movq %rdx, %r14
movl %esi, %r12d
movq %rdi, %rbx
addq $0x108, %rdi            # imm = 0x108
callq 0xffd2
testb %al, %al
je 0x9e87
movq (%r14), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%r14,%rax)
jne 0x9ea6
movq (%r15), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%r15,%rax)
jne 0x9ec5
movzbl 0x1(%rbx), %ebp
pushq $0x1
popq %r13
movq %r14, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0x9fae
movq %r15, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0x9fae
movq 0x108(%rbx), %rsi
movq %r14, %rdi
movl %ebp, %edx
callq 0x9fc9
movl 0x128(%rbx), %esi
movq %r14, %rdi
movl %ebp, %edx
callq 0x9fae
movl 0x12c(%rbx), %esi
movq %r14, %rdi
movl %ebp, %edx
callq 0x9fae
movl 0x134(%rbx), %esi
movq %r14, %rdi
movl %ebp, %edx
callq 0x9fae
movl 0x148(%rbx), %esi
movq %r14, %rdi
movl %ebp, %edx
callq 0x9fae
movzbl 0x1c0(%rbx), %esi
decl %esi
orl $-0x5, %esi
movq %r14, %rdi
movl %ebp, %edx
callq 0x9fae
testb %r12b, %r12b
je 0x9d0e
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0xd5d2
testb %al, %al
je 0x9ee4
movq 0x80(%rbx), %rsi
movq %r14, %rdi
movl %ebp, %edx
callq 0x9fc9
xorl %r12d, %r12d
movq 0x80(%rbx), %rax
cmpq %rax, %r12
jae 0x9d58
movq 0x90(%rbx), %rax
movq (%rax,%r12,8), %rsi
movq %r14, %rdi
movl %ebp, %edx
callq 0x9fc9
incq %r12
jmp 0x9d32
movq 0x88(%rbx), %rsi
cmpq %rax, %rsi
jb 0x9f03
movq %r14, %rdi
movl %ebp, %edx
callq 0x9fc9
xorl %r12d, %r12d
imulq $0x3, 0x88(%rbx), %rax
cmpq %rax, %r12
jae 0x9d9c
movq 0x98(%rbx), %rax
movq (%rax,%r12,8), %rsi
movq %r14, %rdi
movl %ebp, %edx
callq 0x9fc9
incq %r12
jmp 0x9d75
movq 0xc8(%rbx), %rsi
movq 0x1b0(%rbx), %rdx
movq %r14, %rdi
callq 0x43f0
movq 0x68(%rbx), %rsi
movq %r14, %rdi
movl %ebp, %edx
callq 0x9fc9
movq 0x168(%rbx), %r12
xorl %r13d, %r13d
cmpq %r13, %r12
je 0x9de9
movq 0xb8(%rbx), %rax
movq (%rax,%r13,8), %rsi
movq %r15, %rdi
movl %ebp, %edx
callq 0x9fc9
incq %r13
jmp 0x9dca
movl 0x178(%rbx), %r12d
xorl %r13d, %r13d
cmpq %r13, %r12
je 0x9e12
movq 0xc0(%rbx), %rax
movq (%rax,%r13,8), %rsi
movq %r15, %rdi
movl %ebp, %edx
callq 0x9fc9
incq %r13
jmp 0x9df3
xorl %r15d, %r15d
cmpq $0x5, %r15
je 0x9e35
movq 0xa0(%rbx), %rax
movq (%rax,%r15,8), %rsi
movq %r14, %rdi
movl %ebp, %edx
callq 0x9fc9
incq %r15
jmp 0x9e15
xorl %r15d, %r15d
cmpq 0x158(%rbx), %r15
jae 0x9e5b
movq 0xa8(%rbx), %rax
movq (%rax,%r15,8), %rsi
movq %r14, %rdi
movl %ebp, %edx
callq 0x9fc9
incq %r15
jmp 0x9e38
xorl %r15d, %r15d
movl 0x14c(%rbx), %eax
cmpq %rax, %r15
jae 0x9cff
movq 0xb0(%rbx), %rax
movq (%rax,%r15,8), %rsi
movq %r14, %rdi
movl %ebp, %edx
callq 0x9fc9
incq %r15
jmp 0x9e5e
leaq 0x1edf0(%rip), %rdi     # 0x28c7e
leaq 0x1e268(%rip), %rsi     # 0x280fd
leaq 0x1ed3f(%rip), %rcx     # 0x28bdb
movl $0xe17, %edx            # imm = 0xE17
callq 0x4190
leaq 0x1ed6b(%rip), %rdi     # 0x28c18
leaq 0x1e249(%rip), %rsi     # 0x280fd
leaq 0x1ed20(%rip), %rcx     # 0x28bdb
movl $0xe19, %edx            # imm = 0xE19
callq 0x4190
leaq 0x1ed58(%rip), %rdi     # 0x28c24
leaq 0x1e22a(%rip), %rsi     # 0x280fd
leaq 0x1ed01(%rip), %rcx     # 0x28bdb
movl $0xe1a, %edx            # imm = 0xE1A
callq 0x4190
leaq 0x1e205(%rip), %rdi     # 0x280f0
leaq 0x1e20b(%rip), %rsi     # 0x280fd
leaq 0x1ece2(%rip), %rcx     # 0x28bdb
movl $0xe2b, %edx            # imm = 0xE2B
callq 0x4190
movq 0x2a0ae(%rip), %r14     # 0x33fb8
leaq 0x1e334(%rip), %rsi     # 0x28245
movq %r14, %rdi
callq 0x42d0
movq 0x88(%rbx), %rsi
movq %rax, %rdi
callq 0x40b0
leaq 0x1e32d(%rip), %rsi     # 0x2825c
movq %rax, %rdi
callq 0x42d0
movq 0x80(%rbx), %rsi
movq %rax, %rdi
callq 0x40b0
leaq 0x204cb(%rip), %rsi     # 0x2a418
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
callq 0x4130
leaq 0x1e199(%rip), %rbx     # 0x280fd
movq %r14, %rdi
movq %rbx, %rsi
callq 0x42d0
leaq 0x1f7c5(%rip), %rsi     # 0x2973b
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
movl $0xe32, %esi            # imm = 0xE32
callq 0x45d0
movq %rax, %rdi
callq 0x4130
leaq 0x1f681(%rip), %rdi     # 0x2961b
leaq 0x1ec3a(%rip), %rcx     # 0x28bdb
movq %rbx, %rsi
movl $0xe32, %edx            # imm = 0xE32
callq 0x4190