// File: /workspace/github_cpp_makefile_star2_O3/nmmmnu[P]HM3/hm3/diskfile/diskfilebuilder_impl.h
// Function: bool hm3::diskfile::DiskFileBuilder::_writeIteratorToFile<hm3::LinkList::Iterator>(hm3::LinkList::Iterator const&, hm3::LinkList::Iterator const&, std::basic_ofstream<char, std::char_traits<char>>&, std::basic_ofstream<char, std::char_traits<char>>&, std::basic_ofstream<char, std::char_traits<char>>&, bool) const
bool DiskFileBuilder::_writeIteratorToFile(const ITERATOR &begin, const ITERATOR &end,
			std::ofstream &file_meta,
			std::ofstream &file_indx,
			std::ofstream &file_data,
			bool const keepTombstones) const{
	uint64_t be;

	size_t current = 0;

	size_t datacount = 0;
	size_t tombstones = 0;
	uint64_t createdMin = 0;
	uint64_t createdMax = 0;

	bool first_created = true;

	for(ITERATOR it = begin; it != end; ++it){
		const auto &pair = *it;

		if (! pair )
			continue;

		if (pair.isTombstone()){
			if (keepTombstones == false)
					continue;

			++tombstones;
		}

		if (first_created){
			uint64_t const created = pair.getCreated();

			createdMin = created;
			createdMax = created;

			first_created = false;
		}else{
			uint64_t const created = pair.getCreated();

			if (created < createdMin)
				createdMin = created;

			if (created > createdMax)
				createdMax = created;
		}

		// write the index
		be = htobe64(current);
		file_indx.write( (const char *) & be, sizeof(uint64_t));

		// write the data
		pair.fwrite(file_data);

		current += pair.getBytes();
		++datacount;

	//	pair.print();
	}

	// now we miraculasly have the datacount.

	// write table header
	DiskFileHeader head{datacount, true, tombstones, createdMin, createdMax};
	return head.writeToFile(file_meta);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r9, 0x40(%rsp)
movq %r8, 0x38(%rsp)
movq %rcx, 0x28(%rsp)
movq %rdx, %r14
movq (%rsi), %rax
leaq 0x50(%rsp), %rdi
movq %rax, (%rdi)
movq %rdx, %rsi
callq 0x5d5a
testb %al, %al
je 0x45e2
xorl %r12d, %r12d
xorl %ebp, %ebp
movq $0x0, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
jmp 0x46e3
movb $0x1, %al
movl %eax, 0xc(%rsp)
movq $0x0, 0x20(%rsp)
leaq 0x50(%rsp), %rbx
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
xorl %ebp, %ebp
xorl %r12d, %r12d
movq %r14, 0x30(%rsp)
movq %rbx, %rdi
callq 0x5d56
cmpq $0x0, (%rax)
je 0x46c8
movq %rax, %r15
movq %rax, %rdi
callq 0x6ae8
testb %al, %al
je 0x4646
cmpb $0x0, 0xc0(%rsp)
je 0x46c8
incq 0x10(%rsp)
movq %r15, %rdi
callq 0x6a5a
movq %rax, %r13
movq %rax, %r14
testb $0x1, 0xc(%rsp)
jne 0x466f
cmpq %r12, %r13
cmovbq %r13, %r12
cmpq %rbp, %r13
cmovaq %r13, %rbp
movq %r12, %r13
movq %rbp, %r14
movq 0x20(%rsp), %r12
movq %r12, %rax
bswapq %rax
movq %rax, 0x48(%rsp)
movl $0x8, %edx
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x2280
movq %r15, %rdi
movq 0x40(%rsp), %rsi
callq 0x6b4c
movq %r15, %rdi
callq 0x6b10
addq %rax, %r12
movq %r12, 0x20(%rsp)
incq 0x18(%rsp)
movl $0x0, 0xc(%rsp)
movq %r13, %r12
movq %r14, %rbp
movq 0x30(%rsp), %r14
movq %rbx, %rdi
callq 0x5d48
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5d5a
testb %al, %al
je 0x4612
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movl $0x1, %edx
movq 0x10(%rsp), %rcx
movq %r12, %r8
movq %rbp, %r9
callq 0x82bc
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
callq 0x84fa
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq