// File: /workspace/github_cpp_makefile_star2_O2/BU-DiSC[P]BF-Shared-Hashing/./LegacyBF.h
// Function: LegacyBF::Finish()
void LegacyBF::Finish() {
  uint32_t total_bits, num_lines;
  size_t num_entries = hash_entries_.size();
  char* data =
      ReserveSpace(static_cast<int>(num_entries), &total_bits, &num_lines);
  data_ = data;
  assert(data);
  if (total_bits != 0 && num_lines != 0) {
    for (auto h : hash_entries_) {
      AddHash(h, data, num_lines, total_bits);
    }

    // Check for excessive entries for 32-bit hash function
    if (num_entries >= /* minimum of 3 million */ 3000000U) {
      // More specifically, we can detect that the 32-bit hash function
      // is causing significant increase in FP rate by comparing current
      // estimated FP rate to what we would get with a normal number of
      // keys at same memory ratio.
      double est_fp_rate = LegacyBloomImpl::EstimatedFpRate(
          num_entries, total_bits / 8, num_probes_);
      double vs_fp_rate = LegacyBloomImpl::EstimatedFpRate(
          1U << 16, (1U << 16) * bits_per_key_ / 8, num_probes_);

      if (est_fp_rate >= 1.50 * vs_fp_rate) {
        // For more details, see
        // https://github.com/facebook/rocksdb/wiki/RocksDB-Bloom-Filter
        printf(
            "Using legacy SST/BBT Bloom filter with excessive key count "
            "(%.1fM @ %dbpk), causing estimated %.1fx higher filter FP rate. "
            "Consider using new Bloom with format_version>=5, smaller SST "
            "file size, or partitioned filters.",
            num_entries / 1000000.0, bits_per_key_, est_fp_rate / vs_fp_rate);
      }
    }
  }
  // See BloomFilterPolicy::GetFilterBitsReader for metadata
  data[total_bits / 8] = static_cast<char>(num_probes_);
  EncodeFixed32(data + total_bits / 8 + 1, static_cast<uint32_t>(num_lines));
  space_ = (total_bits >> 3) + 4;


  hash_entries_.clear();

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0x18(%rdi), %r12
subq 0x10(%rdi), %r12
sarq $0x2, %r12
leaq 0x14(%rsp), %r15
leaq 0x10(%rsp), %r13
movl %r12d, %esi
movq %r15, %rdx
movq %r13, %rcx
callq 0x7be8
movq %rax, %r14
movq %rax, 0x28(%rbx)
movl (%r15), %r15d
testq %r15, %r15
setne %al
movl (%r13), %ebp
testl %ebp, %ebp
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x7bb2
movq %r12, 0x8(%rsp)
movq 0x10(%rbx), %r13
movq 0x18(%rbx), %r12
cmpq %r12, %r13
je 0x7b1d
movl (%r13), %esi
movq %rbx, %rdi
movq %r14, %rdx
movl %ebp, %ecx
movl %r15d, %r8d
callq 0xb168
addq $0x4, %r13
jmp 0x7afe
movq 0x8(%rsp), %r12
cmpq $0x2dc6bf, %r12         # imm = 0x2DC6BF
jbe 0x7bb2
movl %r15d, %esi
shrl $0x3, %esi
movl 0x4(%rbx), %edx
movq %r12, %rdi
callq 0xb1a8
movsd %xmm0, (%rsp)
movl (%rbx), %eax
movl 0x4(%rbx), %edx
movzwl %ax, %esi
shll $0xd, %esi
movl $0x10000, %edi          # imm = 0x10000
callq 0xb1a8
movsd (%rsp), %xmm1
movsd 0x1a549(%rip), %xmm2    # 0x220b0
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jb 0x7bb2
movq %r12, %xmm2
punpckldq 0x1a592(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x1a59a(%rip), %xmm2    # 0x22120
movapd %xmm2, %xmm3
unpckhpd %xmm2, %xmm3            # xmm3 = xmm3[1],xmm2[1]
addsd %xmm2, %xmm3
divsd 0x1a51e(%rip), %xmm3    # 0x220b8
movl (%rbx), %esi
divsd %xmm0, %xmm1
leaq 0x1a5d6(%rip), %rdi     # 0x2217d
movapd %xmm3, %xmm0
movb $0x2, %al
callq 0x6060
movb 0x4(%rbx), %al
shrl $0x3, %r15d
movb %al, (%r14,%r15)
movl %ebp, 0x1(%r14,%r15)
addl $0x4, %r15d
movl %r15d, 0xc(%rbx)
movq 0x10(%rbx), %rax
cmpq %rax, 0x18(%rbx)
je 0x7bd8
movq %rax, 0x18(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop