// File: 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:
subq $0xc8, %rsp
movq %rdi, 0xc0(%rsp)
movq %rsi, 0xb8(%rsp)
movl %edx, 0xb4(%rsp)
movq 0xc0(%rsp), %rdi
movq %rdi, 0x30(%rsp)
addq $0x20, %rdi
callq 0x14280
movq %rax, 0xa8(%rsp)
movq $0x7, 0xa0(%rsp)
movq $0x0, 0x58(%rsp)
xorl %eax, %eax
cmpq $0x7, 0x58(%rsp)
movb %al, 0x2f(%rsp)
ja 0x149d3
movq 0x58(%rsp), %rax
cmpq 0xa8(%rsp), %rax
setb %al
movb %al, 0x2f(%rsp)
movb 0x2f(%rsp), %al
testb $0x1, %al
jne 0x149e0
jmp 0x14a87
movq 0x30(%rsp), %rdi
addq $0x20, %rdi
callq 0x14c70
movq 0x30(%rsp), %rdi
movq (%rax), %rax
movq %rax, 0x50(%rsp)
addq $0x20, %rdi
callq 0x14ca0
movq 0x50(%rsp), %rdi
callq 0x14d70
movl %eax, 0x18(%rsp)
movl 0xb4(%rsp), %eax
movl %eax, 0x1c(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x58(%rsp), %rsi
leaq 0x60(%rsp), %rdi
callq 0x14d80
movl 0x18(%rsp), %edi
movl 0x1c(%rsp), %esi
movq 0x20(%rsp), %rdx
movq %rax, %rcx
callq 0x14d10
movq 0x50(%rsp), %rdi
callq 0x14db0
movl %eax, 0x28(%rsp)
movq 0x58(%rsp), %rsi
leaq 0x80(%rsp), %rdi
callq 0x14d80
movl 0x28(%rsp), %ecx
movl %ecx, (%rax)
movq 0x58(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x58(%rsp)
jmp 0x149b1
jmp 0x14a89
movq 0x58(%rsp), %rax
cmpq 0xa8(%rsp), %rax
jae 0x14b67
movq 0x58(%rsp), %rsi
andq $0x7, %rsi
leaq 0x80(%rsp), %rdi
callq 0x14d80
movq %rax, 0x48(%rsp)
movq 0x58(%rsp), %rsi
andq $0x7, %rsi
leaq 0x60(%rsp), %rdi
callq 0x14d80
movq %rax, %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x40(%rsp)
movq 0x48(%rsp), %rcx
movl (%rcx), %edi
movl 0x4(%rax), %esi
movq 0xb8(%rsp), %rdx
movq 0x40(%rsp), %rax
movl (%rax), %eax
addq %rax, %rdx
callq 0x14dc0
movq 0x30(%rsp), %rdi
addq $0x20, %rdi
callq 0x14c70
movq 0x30(%rsp), %rdi
movq (%rax), %rax
movq %rax, 0x38(%rsp)
addq $0x20, %rdi
callq 0x14ca0
movq 0x38(%rsp), %rdi
callq 0x14d70
movl %eax, %edi
movl 0xb4(%rsp), %esi
movq 0xb8(%rsp), %rdx
movq 0x40(%rsp), %rcx
callq 0x14d10
movq 0x38(%rsp), %rdi
callq 0x14db0
movl %eax, %ecx
movq 0x48(%rsp), %rax
movl %ecx, (%rax)
movq 0x58(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x58(%rsp)
jmp 0x14a89
movq $0x0, 0x58(%rsp)
xorl %eax, %eax
cmpq $0x7, 0x58(%rsp)
movb %al, 0x17(%rsp)
ja 0x14b92
movq 0x58(%rsp), %rax
cmpq 0xa8(%rsp), %rax
setb %al
movb %al, 0x17(%rsp)
movb 0x17(%rsp), %al
testb $0x1, %al
jne 0x14b9c
jmp 0x14c07
movq 0x58(%rsp), %rsi
leaq 0x80(%rsp), %rdi
callq 0x14d80
movq %rax, %rcx
movq 0x30(%rsp), %rax
movl (%rcx), %ecx
movl %ecx, 0xc(%rsp)
movl 0x4(%rax), %eax
movl %eax, 0x10(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, (%rsp)
movq 0x58(%rsp), %rsi
leaq 0x60(%rsp), %rdi
callq 0x14d80
movq (%rsp), %rdx
movl 0xc(%rsp), %edi
movl 0x10(%rsp), %esi
movl (%rax), %eax
addq %rax, %rdx
callq 0x14dc0
movq 0x58(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x58(%rsp)
jmp 0x14b70
addq $0xc8, %rsp
retq
nop