// File: 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
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x98(%rbp)
movq %rdi, %rax
movq %rax, -0x90(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0x80(%rbp)
callq 0x1f480
movq -0x88(%rbp), %rax
movq -0x80(%rbp), %rdi
movq 0x10(%rax), %rsi
callq 0x1f4a0
jmp 0x1e6a6
movq -0x88(%rbp), %rax
movq 0x38(%rax), %rdx
movq -0x18(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdx
leaq -0x30(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x1f5a0
jmp 0x1e6cb
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movq -0x88(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x48(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq (%rax), %rax
movq 0x3d516(%rip), %rcx     # 0x5bc18
subq %rcx, %rax
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x1e72f
jmp 0x1e970
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x1f420
jmp 0x1e9bb
movq -0x88(%rbp), %rcx
movq 0x3ccc3(%rip), %rax     # 0x5b400
movq -0x58(%rbp), %rdi
movq 0x8(%rcx), %rdx
movl $0x8, %esi
callq *%rax
movq %rax, -0xa0(%rbp)
jmp 0x1e755
movq -0x88(%rbp), %rcx
movq -0xa0(%rbp), %rax
movq %rax, -0x60(%rbp)
movq 0x3cc9a(%rip), %rax     # 0x5b408
movq -0x58(%rbp), %rdi
movq 0x8(%rcx), %rdx
movl $0x8, %esi
callq *%rax
movq %rax, -0xa8(%rbp)
jmp 0x1e786
movq -0x88(%rbp), %rcx
movq -0xa8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rax
xorl %edx, %edx
divq 0x30(%rcx)
movq %rdx, -0x70(%rbp)
movq -0x68(%rbp), %rax
xorl %edx, %edx
divq 0x30(%rcx)
movq %rdx, -0x78(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x1e7f0
movq -0x88(%rbp), %rax
movq 0x38(%rax), %rdx
movq -0x78(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdx
leaq -0x30(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x1f5a0
jmp 0x1e7e3
movq -0x78(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x1e952
movq -0x78(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x1e82c
movq -0x88(%rbp), %rax
movq 0x38(%rax), %rdx
movq -0x70(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdx
leaq -0x30(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x1f5a0
jmp 0x1e81f
movq -0x70(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x1e950
movq 0x3c785(%rip), %rdi     # 0x5afb8
leaq 0x23ba4(%rip), %rsi     # 0x423de
callq 0x5390
movq %rax, -0xb0(%rbp)
jmp 0x1e848
movq -0xb0(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0x50a0
movq %rax, -0xb8(%rbp)
jmp 0x1e861
movq -0xb8(%rbp), %rdi
leaq 0x251b7(%rip), %rsi     # 0x43a26
callq 0x5390
movq %rax, -0xc0(%rbp)
jmp 0x1e87d
movq -0xc0(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x50a0
movq %rax, -0xc8(%rbp)
jmp 0x1e896
movq -0xc8(%rbp), %rdi
leaq 0x25182(%rip), %rsi     # 0x43a26
callq 0x5390
movq %rax, -0xd0(%rbp)
jmp 0x1e8b2
movq -0xd0(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x50a0
movq %rax, -0xd8(%rbp)
jmp 0x1e8cb
movq -0xd8(%rbp), %rdi
leaq 0x2514d(%rip), %rsi     # 0x43a26
callq 0x5390
movq %rax, -0xe0(%rbp)
jmp 0x1e8e7
movq -0xe0(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x50a0
movq %rax, -0xe8(%rbp)
jmp 0x1e900
movq -0xe8(%rbp), %rdi
movq 0x3c692(%rip), %rsi     # 0x5afa0
callq 0x53f0
jmp 0x1e915
movq -0x58(%rbp), %rax
movq (%rax), %rsi
movq 0x3c695(%rip), %rdi     # 0x5afb8
callq 0x50a0
movq %rax, -0xf0(%rbp)
jmp 0x1e931
movq -0xf0(%rbp), %rdi
movq 0x3c661(%rip), %rsi     # 0x5afa0
callq 0x53f0
jmp 0x1e946
movl $0x1, %edi
callq 0x5460
jmp 0x1e952
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movq -0x88(%rbp), %rcx
movslq -0x4c(%rbp), %rax
cmpq 0x10(%rcx), %rax
jb 0x1e6da
movq -0x88(%rbp), %rcx
movslq -0x4c(%rbp), %rax
cmpq 0x10(%rcx), %rax
jne 0x1e992
xorl %eax, %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0x1f620
jmp 0x1e990
jmp 0x1e992
movq -0x98(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1f6b0
leaq -0x30(%rbp), %rdi
callq 0x1f420
movq -0x90(%rbp), %rax
addq $0xf0, %rsp
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x56c0
nopw %cs:(%rax,%rax)
nop