// File: BenLangmead[P]bowtie/./ebwt.h
// Function: Ebwt::writeFromMemory(bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) const
void Ebwt::writeFromMemory(bool justHeader,
			   const string& out1,
			   const string& out2) const
{
	assert(isInMemory());
	assert(this->_eh.repOk());

	ofstream fout1(out1.c_str(), ios::binary);
	ofstream fout2(out2.c_str(), ios::binary);
	writeFromMemory(justHeader, fout1, fout2);
	fout1.close();
	fout2.close();

	// Read the file back in and assert that all components match
	// TODO: revisit this block
	if(_sanity) {
#if 0
		if(_verbose)
			cout << "Re-reading \"" << out1 << "\"/\"" << out2 << "\" for sanity check" << endl;
		Ebwt copy(out1, out2, _verbose, _sanity);
		assert(!isInMemory());
		copy.loadIntoMemory(eh._color ? 1 : 0, -1, false, false);
		assert(isInMemory());
	    assert_eq(eh._lineRate,     copy.eh()._lineRate);
	    assert_eq(eh._linesPerSide, copy.eh()._linesPerSide);
	    assert_eq(eh._offRate,      copy.eh()._offRate);
	    assert_eq(eh._isaRate,      copy.eh()._isaRate);
	    assert_eq(eh._ftabChars,    copy.eh()._ftabChars);
	    assert_eq(eh._len,          copy.eh()._len);
	    assert_eq(_zOff,             copy.zOff());
	    assert_eq(_zEbwtBpOff,       copy.zEbwtBpOff());
	    assert_eq(_zEbwtByteOff,     copy.zEbwtByteOff());
		assert_eq(_nPat,             copy.nPat());
		for(TIndexOffU i = 0; i < _nPat; i++)
			assert_eq(this->_plen[i], copy.plen()[i]);
		assert_eq(this->_nFrag, copy.nFrag());
		for(TIndexOffU i = 0; i < this->_nFrag*3; i++) {
			assert_eq(this->_rstarts[i], copy.rstarts()[i]);
		}
		for(uint32_t i = 0; i < 5; i++)
			assert_eq(this->_fchr[i], copy.fchr()[i]);
		for(TIndexOffU i = 0; i < eh._ftabLen; i++)
			assert_eq(this->ftab()[i], copy.ftab()[i]);
		for(TIndexOffU i = 0; i < eh._eftabLen; i++)
			assert_eq(this->eftab()[i], copy.eftab()[i]);
		for(TIndexOffU i = 0; i < eh._offsLen; i++)
			assert_eq(this->_offs[i], copy.offs()[i]);
		for(TIndexOffU i = 0; i < eh._isaLen; i++)
			assert_eq(this->_isa[i], copy.isa()[i]);
		for(TIndexOffU i = 0; i < eh._ebwtTotLen; i++)
			assert_eq(this->ebwt()[i], copy.ebwt()[i]);
		//copy.sanityCheckAll();
		if(_verbose)
			cout << "Read-in check passed for \"" << out1 << "\"/\"" << out2 << "\"" << endl;
#endif
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x440, %rsp            # imm = 0x440
movb %sil, %al
movq %rdi, -0x8(%rbp)
andb $0x1, %al
movb %al, -0x9(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x438(%rbp)
callq 0x18060
testb $0x1, %al
jne 0xec65
jmp 0xec67
jmp 0xec86
leaq 0x30442(%rip), %rdi     # 0x3f0b0
leaq 0x30448(%rip), %rsi     # 0x3f0bd
movl $0xe60, %edx            # imm = 0xE60
leaq 0x30f6f(%rip), %rcx     # 0x3fbf0
callq 0x51e0
movq -0x438(%rbp), %rdi
addq $0x108, %rdi            # imm = 0x108
callq 0x1bfc0
testb $0x1, %al
jne 0xec9f
jmp 0xeca1
jmp 0xecc0
leaq 0x30f8f(%rip), %rdi     # 0x3fc37
leaq 0x3040e(%rip), %rsi     # 0x3f0bd
movl $0xe61, %edx            # imm = 0xE61
leaq 0x30f35(%rip), %rcx     # 0x3fbf0
callq 0x51e0
movq -0x18(%rbp), %rdi
callq 0x5150
movq %rax, %rsi
leaq -0x220(%rbp), %rdi
movl $0x4, %edx
movl %edx, -0x43c(%rbp)
callq 0x5400
movq -0x20(%rbp), %rdi
callq 0x5150
movl -0x43c(%rbp), %edx
movq %rax, %rsi
leaq -0x420(%rbp), %rdi
callq 0x5400
jmp 0xed03
movq -0x438(%rbp), %rdi
movzbl -0x9(%rbp), %esi
andl $0x1, %esi
leaq -0x220(%rbp), %rdx
leaq -0x420(%rbp), %rcx
callq 0xe5a0
jmp 0xed26
leaq -0x220(%rbp), %rdi
callq 0x55b0
jmp 0xed34
leaq -0x420(%rbp), %rdi
callq 0x55b0
jmp 0xed42
movq -0x438(%rbp), %rax
testb $0x1, 0xe(%rax)
je 0xed85
jmp 0xed85
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x428(%rbp)
movl %eax, -0x42c(%rbp)
jmp 0xeda6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x428(%rbp)
movl %eax, -0x42c(%rbp)
leaq -0x420(%rbp), %rdi
callq 0x55f0
jmp 0xeda6
leaq -0x420(%rbp), %rdi
callq 0x55f0
leaq -0x220(%rbp), %rdi
callq 0x55f0
addq $0x440, %rsp            # imm = 0x440
popq %rbp
retq
leaq -0x220(%rbp), %rdi
callq 0x55f0
movq -0x428(%rbp), %rdi
callq 0x5760
nop