// File: /workspace/github_cpp_makefile_star2_O3/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 0x12e8c
testb %al, %al
je 0xaf40
movq (%r14), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%r14,%rax)
jne 0xaf5f
movl %r15d, 0xc(%rsp)
movq (%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%rbp,%rax)
jne 0xaf7e
movb 0x1(%rbx), %r13b
testb %r13b, %r13b
movl $0x1000000, %eax        # imm = 0x1000000
movl $0x1, %r15d
cmovnel %eax, %r15d
movq %rsp, %r12
movl %r15d, (%r12)
movl $0x4, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x4430
movl %r15d, (%r12)
movq %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)
movq %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)
movq %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)
movq %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)
movq %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)
movq %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)
movq %rsp, %rsi
movl $0x4, %edx
movq %r14, %rdi
callq 0x4430
cmpb $0x0, 0xc(%rsp)
jne 0xaf31
movq %rbp, %r15
movq %rbx, %rdi
callq 0xf948
testb %al, %al
je 0xaf9d
movq 0x80(%rbx), %rax
movq %rax, %rcx
bswapq %rcx
testb %r13b, %r13b
cmoveq %rax, %rcx
movq %rsp, %rsi
movq %rcx, (%rsi)
movl $0x8, %edx
movq %r14, %rdi
callq 0x4430
cmpq $0x0, 0x80(%rbx)
movq %r15, 0x10(%rsp)
je 0xad29
xorl %ebp, %ebp
movq %rsp, %r12
movq 0x90(%rbx), %rax
movq (%rax,%rbp,8), %rax
movq %rax, %rcx
bswapq %rcx
testb %r13b, %r13b
cmoveq %rax, %rcx
movq %rcx, (%rsp)
movl $0x8, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x4430
incq %rbp
movq 0x80(%rbx), %rcx
cmpq %rcx, %rbp
jb 0xacd5
movq 0x88(%rbx), %rax
cmpq %rcx, %rax
jb 0xafbc
leaq 0x88(%rbx), %r15
jmp 0xad37
leaq 0x88(%rbx), %r15
movq 0x88(%rbx), %rax
movq %rax, %rcx
bswapq %rcx
testb %r13b, %r13b
cmoveq %rax, %rcx
movq %rsp, %rsi
movq %rcx, (%rsi)
movl $0x8, %edx
movq %r14, %rdi
callq 0x4430
cmpq $0x0, (%r15)
je 0xada1
xorl %ebp, %ebp
movq %rsp, %r12
movq 0x98(%rbx), %rax
movq (%rax,%rbp,8), %rax
movq %rax, %rcx
bswapq %rcx
testb %r13b, %r13b
cmoveq %rax, %rcx
movq %rcx, (%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 0xad62
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
movq %rsp, %rsi
movq %rcx, (%rsi)
movl $0x8, %edx
movq %r14, %rdi
callq 0x4430
movq 0x168(%rbx), %rbp
testq %rbp, %rbp
movq 0x10(%rsp), %r12
je 0xae23
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, (%rsp)
movl $0x8, %edx
movq %r12, %rdi
movq %rsp, %rsi
callq 0x4430
incq %r15
cmpq %r15, %rbp
jne 0xadef
movl 0x178(%rbx), %ebp
testq %rbp, %rbp
je 0xae65
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, (%rsp)
movl $0x8, %edx
movq %r12, %rdi
movq %rsp, %rsi
callq 0x4430
incq %r15
cmpq %r15, %rbp
jne 0xae31
xorl %r12d, %r12d
movq %rsp, %r15
movq 0xa0(%rbx), %rax
movq (%rax,%r12,8), %rax
movq %rax, %rcx
bswapq %rcx
testb %r13b, %r13b
cmoveq %rax, %rcx
movq %rcx, (%rsp)
movl $0x8, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x4430
incq %r12
cmpq $0x5, %r12
jne 0xae6b
cmpq $0x0, 0x158(%rbx)
je 0xaee8
xorl %r12d, %r12d
movq %rsp, %r15
movq 0xa8(%rbx), %rax
movq (%rax,%r12,8), %rax
movq %rax, %rcx
bswapq %rcx
testb %r13b, %r13b
cmoveq %rax, %rcx
movq %rcx, (%rsp)
movl $0x8, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x4430
incq %r12
cmpq 0x158(%rbx), %r12
jb 0xaeb0
cmpl $0x0, 0x14c(%rbx)
je 0xaf31
xorl %r12d, %r12d
movq %rsp, %r15
movq 0xb0(%rbx), %rax
movq (%rax,%r12,8), %rax
movq %rax, %rcx
bswapq %rcx
testb %r13b, %r13b
cmoveq %rax, %rcx
movq %rcx, (%rsp)
movl $0x8, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x4430
incq %r12
movl 0x14c(%rbx), %eax
cmpq %rax, %r12
jb 0xaef7
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x21da4(%rip), %rdi     # 0x2cceb
leaq 0x2121c(%rip), %rsi     # 0x2c16a
leaq 0x21cf3(%rip), %rcx     # 0x2cc48
movl $0xe17, %edx            # imm = 0xE17
callq 0x41c0
leaq 0x21d1f(%rip), %rdi     # 0x2cc85
leaq 0x211fd(%rip), %rsi     # 0x2c16a
leaq 0x21cd4(%rip), %rcx     # 0x2cc48
movl $0xe19, %edx            # imm = 0xE19
callq 0x41c0
leaq 0x21d0c(%rip), %rdi     # 0x2cc91
leaq 0x211de(%rip), %rsi     # 0x2c16a
leaq 0x21cb5(%rip), %rcx     # 0x2cc48
movl $0xe1a, %edx            # imm = 0xE1A
callq 0x41c0
leaq 0x211b9(%rip), %rdi     # 0x2c15d
leaq 0x211bf(%rip), %rsi     # 0x2c16a
leaq 0x21c96(%rip), %rcx     # 0x2cc48
movl $0xe2b, %edx            # imm = 0xE2B
callq 0x41c0
movq 0x2bff5(%rip), %r14     # 0x36fb8
leaq 0x212e8(%rip), %rsi     # 0x2c2b2
movq %r14, %rdi
callq 0x4310
movq 0x88(%rbx), %rsi
movq %rax, %rdi
callq 0x40c0
leaq 0x212e1(%rip), %rsi     # 0x2c2c9
movq %rax, %rdi
callq 0x4310
movq 0x80(%rbx), %rsi
movq %rax, %rdi
callq 0x40c0
leaq 0x2339f(%rip), %rsi     # 0x2e3a5
movq %rax, %rdi
callq 0x4310
movq %rax, %rdi
callq 0x4150
leaq 0x2114d(%rip), %rbx     # 0x2c16a
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4310
leaq 0x22779(%rip), %rsi     # 0x2d7a8
movq %rax, %rdi
callq 0x4310
movq %rax, %rdi
movl $0xe32, %esi            # imm = 0xE32
callq 0x4610
movq %rax, %rdi
callq 0x4150
leaq 0x22635(%rip), %rdi     # 0x2d688
leaq 0x21bee(%rip), %rcx     # 0x2cc48
movq %rbx, %rsi
movl $0xe32, %edx            # imm = 0xE32
callq 0x41c0
nop