// File: /workspace/github_cpp_makefile_star2_O2/BU-DiSC[P]BF-Shared-Hashing/./FastLocalBF.h
// Function: FastLocalBF::AddAllEntries(char*, unsigned int)
void AddAllEntries(char* data, uint32_t len) {
    // Simple version without prefetching:
    //
    // for (auto h : hash_entries_) {
    //   FastLocalBloomImpl::AddHash(Lower32of64(h), Upper32of64(h), len,
    //                               num_probes_, data);
    // }

    const size_t num_entries = hash_entries_.size();
    constexpr size_t kBufferMask = 7;
    static_assert(((kBufferMask + 1) & kBufferMask) == 0,
                  "Must be power of 2 minus 1");

    std::array<uint32_t, kBufferMask + 1> hashes;
    std::array<uint32_t, kBufferMask + 1> byte_offsets;

    // Prime the buffer
    size_t i = 0;
    for (; i <= kBufferMask && i < num_entries; ++i) {
      uint64_t h = hash_entries_.front();
      hash_entries_.pop_front();
      FastLocalBloomImpl::PrepareHash(Lower32of64(h), len, data,
                                      /*out*/ &byte_offsets[i]);
	//cout << byte_offsets[i] << endl;
      hashes[i] = Upper32of64(h);
    }

    // Process and buffer
    for (; i < num_entries; ++i) {
      uint32_t& hash_ref = hashes[i & kBufferMask];
      uint32_t& byte_offset_ref = byte_offsets[i & kBufferMask];
      // Process (add)
      FastLocalBloomImpl::AddHashPrepared(hash_ref, num_probes_,
                                          data + byte_offset_ref);
      // And buffer
      uint64_t h = hash_entries_.front();
      hash_entries_.pop_front();
      FastLocalBloomImpl::PrepareHash(Lower32of64(h), len, data,
                                      /*out*/ &byte_offset_ref);
	//cout << byte_offset_ref << endl;
      hash_ref = Upper32of64(h);
    }

    // Finish processing
    for (i = 0; i <= kBufferMask && i < num_entries; ++i) {
      FastLocalBloomImpl::AddHashPrepared(hashes[i], num_probes_,
                                          data + byte_offsets[i]);
    }
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %edx, %r15d
movq %rsi, %rbx
movq %rdi, %r14
addq $0x20, %rdi
movq %rdi, (%rsp)
callq 0xc394
movq %rax, %r13
cmpq $0x8, %rax
pushq $0x8
popq %r12
cmovbq %rax, %r12
shrl $0x6, %r15d
movq %r15, 0x8(%rsp)
leal (%r12,%r12), %eax
subq %rax, %r13
xorl %r15d, %r15d
cmpq %r15, %r12
je 0xc5a6
movq 0x30(%r14), %rax
movq (%rax), %rbp
movq (%rsp), %rdi
callq 0xc66c
movl %ebp, %eax
imulq 0x8(%rsp), %rax
shrq $0x1a, %rax
andl $-0x40, %eax
prefetcht2 (%rbx,%rax)
prefetcht2 0x3f(%rbx,%rax)
movl %eax, 0x18(%rsp,%r15,4)
shrq $0x20, %rbp
movl %ebp, 0x38(%rsp,%r15,4)
incq %r15
jmp 0xc566
addq %r15, %r13
movq %r12, %r15
movq %r14, 0x10(%rsp)
subq $0x1, %r13
jb 0xc61a
movl %r15d, %ebp
andl $0x7, %ebp
shll $0x2, %ebp
movl 0x38(%rsp,%rbp), %edi
movl 0x4(%r14), %esi
movl 0x18(%rsp,%rbp), %edx
addq %rbx, %rdx
callq 0xc68a
movq 0x30(%r14), %rax
movq %r12, %r14
movq (%rax), %r12
movq (%rsp), %rdi
callq 0xc66c
movl %r12d, %eax
imulq 0x8(%rsp), %rax
shrq $0x1a, %rax
andl $-0x40, %eax
prefetcht2 (%rbx,%rax)
prefetcht2 0x3f(%rbx,%rax)
movl %eax, 0x18(%rsp,%rbp)
shrq $0x20, %r12
movl %r12d, 0x38(%rsp,%rbp)
movq %r14, %r12
movq 0x10(%rsp), %r14
incq %r15
jmp 0xc5b1
xorl %r15d, %r15d
cmpq %r15, %r12
je 0xc63d
movl 0x38(%rsp,%r15,4), %edi
movl 0x4(%r14), %esi
movl 0x18(%rsp,%r15,4), %edx
addq %rbx, %rdx
callq 0xc68a
incq %r15
jmp 0xc61d
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq