// File: /workspace/github_cpp_makefile_star2_O1/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
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, %ebp
cmovbq %rsi, %rbp
movq %rsi, 0x8(%rsp)
testq %rsi, %rsi
movq %rdi, 0x10(%rsp)
movq %rbp, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
je 0xe5ff
movl %edx, %r13d
shrl $0x6, %r13d
cmpq $0x1, %rbp
adcq $0x0, %rbp
xorl %r15d, %r15d
movq 0x30(%r14), %rax
movq (%rax), %r12
callq 0xe760
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,%r15,4)
shrq $0x20, %r12
movl %r12d, 0x48(%rsp,%r15,4)
incq %r15
cmpq %r15, %rbp
jne 0xe5bf
jmp 0xe602
xorl %r15d, %r15d
cmpq 0x8(%rsp), %r15
movq 0x18(%rsp), %rbp
jae 0xe69f
shrl $0x6, %ebp
movl %r15d, %r13d
andl $0x7, %r13d
movl 0x4(%r14), %eax
testl %eax, %eax
jle 0xe657
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 0xe633
movq 0x30(%r14), %rax
movq (%rax), %r12
callq 0xe760
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 0xe615
cmpq $0x0, 0x8(%rsp)
movq 0x20(%rsp), %r9
je 0xe6f5
cmpq $0x1, %r9
adcq $0x0, %r9
xorl %eax, %eax
movl 0x4(%r14), %edx
testl %edx, %edx
jle 0xe6ed
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 0xe6c9
incq %rax
cmpq %r9, %rax
jne 0xe6b6
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq