// File: /workspace/github_cpp_makefile_star2_O1/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
subq $0x18, %rsp
movq %rcx, %rbp
movq %rdx, %r14
movl %esi, %r15d
movq %rdi, %rbx
addq $0x108, %rdi            # imm = 0x108
callq 0x13086
testb %al, %al
je 0xb09b
movq (%r14), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%r14,%rax)
jne 0xb0ba
movl %r15d, 0x14(%rsp)
movq (%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%rbp,%rax)
jne 0xb0d9
movb 0x1(%rbx), %r13b
testb %r13b, %r13b
movl $0x1000000, %eax        # imm = 0x1000000
movl $0x1, %r15d
cmovnel %eax, %r15d
leaq 0x8(%rsp), %r12
movl %r15d, (%r12)
movl $0x4, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x4430
movl %r15d, (%r12)
leaq 0x8(%rsp), %r12
movl $0x4, %edx
movq %rbp, %rdi
movq %r12, %rsi
callq 0x4430
movq 0x108(%rbx), %rax
movq %rax, %rcx
bswapq %rcx
testb %r13b, %r13b
cmoveq %rax, %rcx
movq %rcx, (%r12)
leaq 0x8(%rsp), %r12
movl $0x8, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x4430
testb %r13b, %r13b
movl 0x128(%rbx), %eax
movl %eax, %ecx
bswapl %ecx
cmovel %eax, %ecx
movl %ecx, (%r12)
leaq 0x8(%rsp), %r12
movl $0x4, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x4430
testb %r13b, %r13b
movl 0x12c(%rbx), %eax
movl %eax, %ecx
bswapl %ecx
cmovel %eax, %ecx
movl %ecx, (%r12)
leaq 0x8(%rsp), %r12
movl $0x4, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x4430
testb %r13b, %r13b
movl 0x134(%rbx), %eax
movl %eax, %ecx
bswapl %ecx
cmovel %eax, %ecx
movl %ecx, (%r12)
leaq 0x8(%rsp), %r12
movl $0x4, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x4430
testb %r13b, %r13b
movl 0x148(%rbx), %eax
movl %eax, %ecx
bswapl %ecx
cmovel %eax, %ecx
movl %ecx, (%r12)
leaq 0x8(%rsp), %r12
movl $0x4, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x4430
movzbl 0x1c0(%rbx), %eax
decl %eax
orl $-0x5, %eax
testb %r13b, %r13b
movl %eax, %ecx
bswapl %ecx
cmovel %eax, %ecx
movl %ecx, (%r12)
leaq 0x8(%rsp), %rsi
movl $0x4, %edx
movq %r14, %rdi
callq 0x4430
cmpb $0x0, 0x14(%rsp)
jne 0xb08c
movq %rbp, %r15
movq %rbx, %rdi
callq 0xfb60
testb %al, %al
je 0xb0f8
movq 0x80(%rbx), %rax
movq %rax, %rcx
bswapq %rcx
testb %r13b, %r13b
cmoveq %rax, %rcx
leaq 0x8(%rsp), %rsi
movq %rcx, (%rsi)
movl $0x8, %edx
movq %r14, %rdi
callq 0x4430
movq 0x80(%rbx), %rax
testq %rax, %rax
je 0xae6a
xorl %ebp, %ebp
leaq 0x8(%rsp), %r12
movq 0x90(%rbx), %rax
movq (%rax,%rbp,8), %rax
movq %rax, %rcx
bswapq %rcx
testb %r13b, %r13b
cmoveq %rax, %rcx
movq %rcx, 0x8(%rsp)
movl $0x8, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x4430
incq %rbp
movq 0x80(%rbx), %rax
cmpq %rax, %rbp
jb 0xae2e
movq 0x88(%rbx), %rcx
cmpq %rax, %rcx
jb 0xb117
movq %rcx, %rax
bswapq %rax
testb %r13b, %r13b
cmoveq %rcx, %rax
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
movl $0x8, %edx
movq %r14, %rdi
callq 0x4430
cmpq $0x0, 0x88(%rbx)
je 0xaeed
xorl %ebp, %ebp
leaq 0x8(%rsp), %r12
movq 0x98(%rbx), %rax
movq (%rax,%rbp,8), %rax
movq %rax, %rcx
bswapq %rcx
testb %r13b, %r13b
cmoveq %rax, %rcx
movq %rcx, 0x8(%rsp)
movl $0x8, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x4430
incq %rbp
movq 0x88(%rbx), %rax
leaq (%rax,%rax,2), %rax
cmpq %rax, %rbp
jb 0xaead
movq 0xc8(%rbx), %rsi
movq 0x1b0(%rbx), %rdx
movq %r14, %rdi
callq 0x4430
movq 0x68(%rbx), %rax
movq %rax, %rcx
bswapq %rcx
testb %r13b, %r13b
cmoveq %rax, %rcx
leaq 0x8(%rsp), %rsi
movq %rcx, (%rsi)
movl $0x8, %edx
movq %r14, %rdi
callq 0x4430
movq 0x168(%rbx), %rbp
testq %rbp, %rbp
movq %r15, %r12
je 0xaf72
xorl %r15d, %r15d
movq 0xb8(%rbx), %rax
movq (%rax,%r15,8), %rax
movq %rax, %rcx
bswapq %rcx
testb %r13b, %r13b
cmoveq %rax, %rcx
movq %rcx, 0x8(%rsp)
movl $0x8, %edx
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
callq 0x4430
incq %r15
cmpq %r15, %rbp
jne 0xaf3b
movl 0x178(%rbx), %ebp
testq %rbp, %rbp
je 0xafb7
xorl %r15d, %r15d
movq 0xc0(%rbx), %rax
movq (%rax,%r15,8), %rax
movq %rax, %rcx
bswapq %rcx
testb %r13b, %r13b
cmoveq %rax, %rcx
movq %rcx, 0x8(%rsp)
movl $0x8, %edx
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
callq 0x4430
incq %r15
cmpq %r15, %rbp
jne 0xaf80
xorl %r12d, %r12d
leaq 0x8(%rsp), %r15
movq 0xa0(%rbx), %rax
movq (%rax,%r12,8), %rax
movq %rax, %rcx
bswapq %rcx
testb %r13b, %r13b
cmoveq %rax, %rcx
movq %rcx, 0x8(%rsp)
movl $0x8, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x4430
incq %r12
cmpq $0x5, %r12
jne 0xafbf
cmpq $0x0, 0x158(%rbx)
je 0xb040
xorl %r12d, %r12d
leaq 0x8(%rsp), %r15
movq 0xa8(%rbx), %rax
movq (%rax,%r12,8), %rax
movq %rax, %rcx
bswapq %rcx
testb %r13b, %r13b
cmoveq %rax, %rcx
movq %rcx, 0x8(%rsp)
movl $0x8, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x4430
incq %r12
cmpq 0x158(%rbx), %r12
jb 0xb007
cmpl $0x0, 0x14c(%rbx)
je 0xb08c
xorl %r12d, %r12d
leaq 0x8(%rsp), %r15
movq 0xb0(%rbx), %rax
movq (%rax,%r12,8), %rax
movq %rax, %rcx
bswapq %rcx
testb %r13b, %r13b
cmoveq %rax, %rcx
movq %rcx, 0x8(%rsp)
movl $0x8, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x4430
incq %r12
movl 0x14c(%rbx), %eax
cmpq %rax, %r12
jb 0xb051
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x22bb9(%rip), %rdi     # 0x2dc5b
leaq 0x22031(%rip), %rsi     # 0x2d0da
leaq 0x22b08(%rip), %rcx     # 0x2dbb8
movl $0xe17, %edx            # imm = 0xE17
callq 0x41c0
leaq 0x22b34(%rip), %rdi     # 0x2dbf5
leaq 0x22012(%rip), %rsi     # 0x2d0da
leaq 0x22ae9(%rip), %rcx     # 0x2dbb8
movl $0xe19, %edx            # imm = 0xE19
callq 0x41c0
leaq 0x22b21(%rip), %rdi     # 0x2dc01
leaq 0x21ff3(%rip), %rsi     # 0x2d0da
leaq 0x22aca(%rip), %rcx     # 0x2dbb8
movl $0xe1a, %edx            # imm = 0xE1A
callq 0x41c0
leaq 0x21fce(%rip), %rdi     # 0x2d0cd
leaq 0x21fd4(%rip), %rsi     # 0x2d0da
leaq 0x22aab(%rip), %rcx     # 0x2dbb8
movl $0xe2b, %edx            # imm = 0xE2B
callq 0x41c0
movq 0x2be9a(%rip), %r14     # 0x36fb8
leaq 0x220fd(%rip), %rsi     # 0x2d222
movq %r14, %rdi
callq 0x4310
movq 0x88(%rbx), %rsi
movq %rax, %rdi
callq 0x40c0
leaq 0x220f6(%rip), %rsi     # 0x2d239
movq %rax, %rdi
callq 0x4310
movq 0x80(%rbx), %rsi
movq %rax, %rdi
callq 0x40c0
leaq 0x241b4(%rip), %rsi     # 0x2f315
movq %rax, %rdi
callq 0x4310
movq %rax, %rdi
callq 0x4150
leaq 0x21f62(%rip), %rbx     # 0x2d0da
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4310
leaq 0x2358e(%rip), %rsi     # 0x2e718
movq %rax, %rdi
callq 0x4310
movq %rax, %rdi
movl $0xe32, %esi            # imm = 0xE32
callq 0x4610
movq %rax, %rdi
callq 0x4150
leaq 0x2344a(%rip), %rdi     # 0x2e5f8
leaq 0x22a03(%rip), %rcx     # 0x2dbb8
movq %rbx, %rsi
movl $0xe32, %edx            # imm = 0xE32
callq 0x41c0