// File: /workspace/github_cpp_makefile_star2_O3/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 $0x28, %rsp
movq %rdi, %rbx
movq 0x18(%rdi), %r15
subq 0x10(%rdi), %r15
sarq $0x2, %r15
leaq 0x24(%rsp), %r12
leaq 0x20(%rsp), %r13
movl %r15d, %esi
movq %r12, %rdx
movq %r13, %rcx
callq 0x7398
movl %eax, %ebp
movq %rbp, %rdi
callq 0x5030
movq %rax, %r14
movq %rax, %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x5240
movq %r14, 0x28(%rbx)
movl (%r12), %r12d
testq %r12, %r12
setne %al
movl (%r13), %ebp
testl %ebp, %ebp
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x7333
movq 0x10(%rbx), %rdi
movq 0x18(%rbx), %r8
cmpq %r8, %rdi
je 0x723b
movl 0x4(%rbx), %r9d
movl (%rdi), %esi
movl %esi, %eax
xorl %edx, %edx
divl %ebp
testl %r9d, %r9d
jle 0x7232
shll $0x6, %edx
addq %r14, %rdx
movl %esi, %eax
shrl $0x11, %eax
movl %r9d, %r10d
movl %esi, %ecx
andb $0x7, %cl
movl $0x1, %r11d
shll %cl, %r11d
movl %esi, %ecx
shrl $0x3, %ecx
andl $0x3f, %ecx
orb %r11b, (%rdx,%rcx)
addl %eax, %esi
decl %r10d
jne 0x7211
addq $0x4, %rdi
cmpq %r8, %rdi
jne 0x71f6
cmpq $0x2dc6bf, %r15         # imm = 0x2DC6BF
jbe 0x7333
movl %r12d, %esi
shrl $0x3, %esi
movl 0x4(%rbx), %edx
movq %r15, %rdi
callq 0xcf46
movsd %xmm0, 0x18(%rsp)
movl (%rbx), %eax
movl 0x4(%rbx), %edi
shll $0x10, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd 0x21e61(%rip), %xmm0    # 0x290d8
movsd %xmm0, 0x8(%rsp)
movl $0x200, %esi            # imm = 0x200
callq 0xf9f2
movsd %xmm0, 0x10(%rsp)
movsd 0x21e4b(%rip), %xmm0    # 0x290e0
callq 0x53a0
movsd 0x18(%rsp), %xmm1
movsd 0x8(%rsp), %xmm0
mulsd 0x21e3a(%rip), %xmm0    # 0x290e8
addsd 0x21e3a(%rip), %xmm0    # 0x290f0
movapd %xmm0, %xmm2
movsd 0x21e36(%rip), %xmm0    # 0x290f8
divsd %xmm2, %xmm0
addsd 0x10(%rsp), %xmm0
movsd 0x21e2c(%rip), %xmm2    # 0x29100
movapd %xmm0, %xmm3
addsd %xmm2, %xmm3
mulsd %xmm2, %xmm0
subsd %xmm0, %xmm3
movsd 0x21e1c(%rip), %xmm0    # 0x29108
mulsd %xmm3, %xmm0
ucomisd %xmm0, %xmm1
jb 0x7333
movq %r15, %xmm2
punpckldq 0x21e5d(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x21e65(%rip), %xmm2    # 0x29170
movapd %xmm2, %xmm0
unpckhpd %xmm2, %xmm0            # xmm0 = xmm0[1],xmm2[1]
addsd %xmm2, %xmm0
divsd 0x21df1(%rip), %xmm0    # 0x29110
movl (%rbx), %esi
divsd %xmm3, %xmm1
leaq 0x21ed1(%rip), %rdi     # 0x291fd
movb $0x2, %al
callq 0x5070
movb 0x4(%rbx), %al
shrl $0x3, %r12d
movb %al, (%r14,%r12)
movl %ebp, 0x1(%r14,%r12)
addl $0x4, %r12d
movl %r12d, 0xc(%rbx)
movq 0x10(%rbx), %rax
cmpq %rax, 0x18(%rbx)
je 0x7359
movq %rax, 0x18(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq