// File: nmmmnu[P]HM3/hm3/hashindex/hashindexbuilder_impl.h
// Function: bool hm3::hashindex::HashIndexBuilder::createFromList<hm3::DiskTable>(StringRef const&, hm3::DiskTable const&, bool) const
bool HashIndexBuilder::createFromList(const StringRef &filename2, const LIST &list, bool const stats) const{
	size_t const hashtableSize = list.getCount() * growFactor_;
	size_t const sizeBin       = hashtableSize * sizeof(uint64_t);

	const std::string filename = filenameIndx(filename2);

	// create file

	if ( ! MMAPFile::createFile(filename, sizeBin) ){
		return false;
	}

	// open file

	MMAPFile mmap{ MADV_RANDOM };
	if ( ! mmap.openRW(filename) ){
		return false;
	}

	uint64_t *hashtable = (uint64_t *) mmap.mem();

	// memset is not good, because it needs size to be int
	log__("Set hashtable to zeroes.");
	std::fill(hashtable, hashtable + hashtableSize, htobe64(BUCKET_EMPTY));

	// process

	size_t const collisions = createFromList_(hashtable, hashtableSize, list);

	if (stats)
		printStats_(list.getCount(), collisions);

	return true;
}

// Assembly:
subq $0x108, %rsp            # imm = 0x108
movb %cl, %al
movq %rdi, 0xf8(%rsp)
movq %rsi, 0xf0(%rsp)
movq %rdx, 0xe8(%rsp)
andb $0x1, %al
movb %al, 0xe7(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0xe8(%rsp), %rdi
callq 0x3030
movq 0x40(%rsp), %rcx
movq (%rcx), %rcx
imulq %rcx, %rax
movq %rax, 0xd8(%rsp)
movq 0xd8(%rsp), %rax
shlq $0x3, %rax
movq %rax, 0xd0(%rsp)
movq 0xf0(%rsp), %rsi
leaq 0xb0(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x3040
movq 0x48(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
callq 0x30c0
jmp 0x2c1a
movq 0xd0(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
callq 0x83a0
movb %al, 0x3f(%rsp)
jmp 0x2c35
movb 0x3f(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2c41
jmp 0x2c72
movb $0x0, 0x107(%rsp)
movl $0x1, 0x90(%rsp)
jmp 0x2de8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
jmp 0x2e06
leaq 0x78(%rsp), %rdi
movl $0x1, %esi
callq 0x2eb0
jmp 0x2c83
leaq 0x68(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x30c0
jmp 0x2c97
leaq 0x78(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x8310
movb %al, 0x3e(%rsp)
jmp 0x2cac
movb 0x3e(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2cb8
jmp 0x2cf3
movb $0x0, 0x107(%rsp)
movl $0x1, 0x90(%rsp)
jmp 0x2dde
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x2f00
jmp 0x2e06
leaq 0x78(%rsp), %rdi
callq 0x3110
movq %rax, 0x30(%rsp)
jmp 0x2d04
movq 0x30(%rsp), %rax
movq %rax, 0x60(%rsp)
leaq 0x6426(%rip), %rdi      # 0x913b
callq 0x2860
jmp 0x2d1c
movq 0x60(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0xd8(%rsp), %rcx
leaq (%rax,%rcx,8), %rax
movq %rax, 0x20(%rsp)
movq $-0x1, %rdi
callq 0x2890
movq %rax, 0x28(%rsp)
jmp 0x2d4a
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdi
movq 0x28(%rsp), %rax
movq %rax, 0x58(%rsp)
leaq 0x58(%rsp), %rdx
callq 0x3120
jmp 0x2d6a
movq 0x40(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0xd8(%rsp), %rdx
movq 0xe8(%rsp), %rcx
callq 0x3150
movq %rax, 0x10(%rsp)
jmp 0x2d90
movq 0x10(%rsp), %rax
movq %rax, 0x50(%rsp)
testb $0x1, 0xe7(%rsp)
je 0x2dcb
movq 0xe8(%rsp), %rdi
callq 0x3030
movq %rax, 0x8(%rsp)
jmp 0x2db8
movq 0x8(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0x2550
jmp 0x2dc9
jmp 0x2dcb
movb $0x1, 0x107(%rsp)
movl $0x1, 0x90(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x2f00
leaq 0xb0(%rsp), %rdi
callq 0x2110
movb 0x107(%rsp), %al
andb $0x1, %al
addq $0x108, %rsp            # imm = 0x108
retq
leaq 0xb0(%rsp), %rdi
callq 0x2110
movq 0x98(%rsp), %rdi
callq 0x22c0