// File: /workspace/github_cpp_makefile_star2_O3/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 $0x68, %rsp
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
addq $0x20, %rdi
movq 0x68(%r14), %rax
movq %rax, %rcx
subq 0x48(%r14), %rcx
shrq $0x3, %rcx
cmpq $0x1, %rax
adcq $-0x1, %rcx
shlq $0x6, %rcx
movq 0x50(%r14), %rax
subq 0x58(%r14), %rax
movq 0x40(%r14), %rsi
sarq $0x3, %rax
subq 0x30(%r14), %rsi
sarq $0x3, %rsi
addq %rax, %rsi
addq %rcx, %rsi
cmpq $0x8, %rsi
movl $0x8, %r15d
cmovbq %rsi, %r15
movq %rsi, 0x8(%rsp)
testq %rsi, %rsi
movq %rdi, 0x10(%rsp)
movq %r15, 0x20(%rsp)
je 0xe4ef
movq %rbp, 0x18(%rsp)
movl %ebp, %r13d
shrl $0x6, %r13d
cmpq $0x1, %r15
adcq $0x0, %r15
xorl %ebp, %ebp
movq 0x30(%r14), %rax
movq (%rax), %r12
callq 0xe64c
movq 0x10(%rsp), %rdi
movl %r12d, %eax
imulq %r13, %rax
shrq $0x1a, %rax
andl $-0x40, %eax
prefetcht2 (%rbx,%rax)
prefetcht2 0x3f(%rbx,%rax)
movl %eax, 0x28(%rsp,%rbp,4)
shrq $0x20, %r12
movl %r12d, 0x48(%rsp,%rbp,4)
incq %rbp
cmpq %rbp, %r15
jne 0xe4ab
movq 0x18(%rsp), %rbp
jmp 0xe4f2
xorl %r15d, %r15d
cmpq 0x8(%rsp), %r15
jae 0xe58a
shrl $0x6, %ebp
movl %r15d, %r13d
andl $0x7, %r13d
movl 0x4(%r14), %eax
testl %eax, %eax
jle 0xe542
movl %r13d, %ecx
movl 0x28(%rsp,%rcx,4), %edx
addq %rbx, %rdx
movl 0x48(%rsp,%r13,4), %esi
movl %esi, %ecx
shrl $0x17, %ecx
andb $0x7, %cl
movl $0x1, %r8d
shll %cl, %r8d
imull $0x9e3779b9, %esi, %ecx # imm = 0x9E3779B9
shrl $0x1a, %esi
orb %r8b, (%rdx,%rsi)
movl %ecx, %esi
decl %eax
jne 0xe51e
movq 0x30(%r14), %rax
movq (%rax), %r12
callq 0xe64c
movq 0x10(%rsp), %rdi
movl %r12d, %eax
imulq %rbp, %rax
shrq $0x1a, %rax
andl $-0x40, %eax
prefetcht2 (%rbx,%rax)
prefetcht2 0x3f(%rbx,%rax)
shll $0x2, %r13d
movl %eax, 0x28(%rsp,%r13)
shrq $0x20, %r12
movl %r12d, 0x48(%rsp,%r13)
incq %r15
cmpq 0x8(%rsp), %r15
jb 0xe500
cmpq $0x0, 0x8(%rsp)
movq 0x20(%rsp), %r9
je 0xe5e0
cmpq $0x1, %r9
adcq $0x0, %r9
xorl %eax, %eax
movl 0x4(%r14), %edx
testl %edx, %edx
jle 0xe5d8
movl 0x28(%rsp,%rax,4), %esi
addq %rbx, %rsi
movl 0x48(%rsp,%rax,4), %edi
movl %edi, %ecx
shrl $0x17, %ecx
andb $0x7, %cl
movl $0x1, %r8d
shll %cl, %r8d
imull $0x9e3779b9, %edi, %ecx # imm = 0x9E3779B9
shrl $0x1a, %edi
orb %r8b, (%rsi,%rdi)
movl %ecx, %edi
decl %edx
jne 0xe5b4
incq %rax
cmpq %r9, %rax
jne 0xe5a1
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop