// File: /workspace/github_cpp_makefile_star2_O1/chahk0129[P]hash_bench/./index/cuckoo_hash.h
// Function: CuckooHash<unsigned long>::find_path(unsigned long)
vector<pair<size_t,Key_t>> CuckooHash<Key_t>::find_path(size_t target) {
  vector<pair<size_t,Key_t>> path;
  path.reserve(kCuckooThreshold);
  path.emplace_back(target, table[target].key);
  auto cur = target;
  auto i = 0;
  do {
    Key_t* key;
    size_t f_hash, s_hash;
    key = &table[cur].key;
    if(memcmp(key, &INVALID<Key_t>, sizeof(Key_t)) == 0) break;
    f_hash = hash_funcs[0](key, sizeof(Key_t), _seed);
    s_hash = hash_funcs[1](key, sizeof(Key_t), _seed);

    auto f_idx = f_hash % capacity;
    auto s_idx = s_hash % capacity;

    if (f_idx == cur) {
      path.emplace_back(s_idx, table[s_idx].key);
      cur = s_idx;
    } else if (s_idx == cur) {
      path.emplace_back(f_idx, table[f_idx].key);
      cur = f_idx;
    } else {  // something terribly wrong
      cout << "E: " << f_idx << " " << s_idx << " " << cur << " " << target << endl;
      cout << *key << endl;
      exit(1);
    }
    i++;
  } while (i < kCuckooThreshold);

  if (i == kCuckooThreshold) {
    path.resize(0);
  }

  return move(path);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r15
movq %rdi, 0x40(%rsp)
movq %rdx, 0x8(%rsp)
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq 0x10(%rsi), %rsi
callq 0xb07e
leaq 0x8(%rsp), %rsi
movq (%rsi), %rdx
shlq $0x4, %rdx
addq 0x38(%r15), %rdx
leaq 0x10(%rsp), %rdi
callq 0xb126
xorl %r13d, %r13d
movq 0x8(%rsp), %r12
movq 0x38(%r15), %r14
movq %r12, %rax
shlq $0x4, %rax
movq (%r14,%rax), %rcx
xorl %ebp, %ebp
cmpq 0x974d(%rip), %rcx      # 0x14298
setne %bl
je 0xac13
addq %rax, %r14
movq 0x8(%r15), %rdx
movl $0x8, %esi
movq %r14, %rdi
callq 0x2050
movl 0x8(%r15), %ecx
xorl $0x8, %ecx
xorl %edx, %edx
imull $0x5bd1e995, (%r14,%rdx), %esi # imm = 0x5BD1E995
movl %esi, %edi
shrl $0x18, %edi
xorl %esi, %edi
imull $0x5bd1e995, %edi, %esi # imm = 0x5BD1E995
imull $0x5bd1e995, %ecx, %ecx # imm = 0x5BD1E995
xorl %esi, %ecx
addq $0x4, %rdx
cmpq $0x8, %rdx
jne 0xab71
movl %ecx, %edx
shrl $0xd, %edx
xorl %ecx, %edx
imull $0x5bd1e995, %edx, %ecx # imm = 0x5BD1E995
movl %ecx, %esi
shrl $0xf, %esi
xorl %ecx, %esi
movq 0x30(%r15), %rdi
xorl %edx, %edx
divq %rdi
movq %rdx, %rcx
movq %rdx, 0x38(%rsp)
movq %rsi, %rax
xorl %edx, %edx
divq %rdi
movq %rdx, 0x30(%rsp)
cmpq %r12, %rcx
jne 0xabeb
shlq $0x4, %rdx
addq 0x38(%r15), %rdx
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %r14
movq %r14, %rsi
callq 0xb126
jmp 0xac0d
cmpq %r12, %rdx
jne 0xac67
shlq $0x4, %rcx
addq 0x38(%r15), %rcx
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %r14
movq %r14, %rsi
movq %rcx, %rdx
callq 0xb126
movq (%r14), %r12
incl %r13d
movb %bl, %bpl
movslq %r13d, %rax
testl %ebp, %ebp
je 0xac27
cmpq %rax, 0x10(%r15)
ja 0xab33
cmpq %rax, 0x10(%r15)
jne 0xac39
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0xb164
movq 0x10(%rsp), %rcx
movq 0x40(%rsp), %rax
movq %rcx, (%rax)
movq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rax)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x9352(%rip), %rdi      # 0x13fc0
leaq 0x2789(%rip), %rsi      # 0xd3fe
movl $0x3, %edx
callq 0x21d0
movq 0x38(%rsp), %rsi
movq 0x9335(%rip), %rdi      # 0x13fc0
callq 0x2100
movq %rax, %rbx
leaq 0x27a6(%rip), %rsi      # 0xd440
movl $0x1, %edx
movq %rax, %rdi
callq 0x21d0
movq 0x30(%rsp), %rsi
movq %rbx, %rdi
callq 0x2100
movq %rax, %rbx
leaq 0x2782(%rip), %rsi      # 0xd440
movl $0x1, %edx
movq %rax, %rdi
callq 0x21d0
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2100
movq %rax, %rbx
leaq 0x2760(%rip), %rsi      # 0xd440
movl $0x1, %edx
movq %rax, %rdi
callq 0x21d0
movq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x20b0
movq (%r14), %rsi
movq 0x92b4(%rip), %rdi      # 0x13fc0
callq 0x2100
movq %rax, %rdi
callq 0x20b0
movl $0x1, %edi
callq 0x21e0
jmp 0xad2b
jmp 0xad2b
jmp 0xad2b
jmp 0xad2b
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xad45
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq %rbx, %rdi
callq 0x22e0
nop