// File: bhhbazinga[P]LockFreeHashTable/./lockfree_hashtable.h
// Function: LockFreeHashTable<int, int, std::hash<int>>::SearchNode(LockFreeHashTable<int, int, std::hash<int>>::DummyNode*, LockFreeHashTable<int, int, std::hash<int>>::Node*, LockFreeHashTable<int, int, std::hash<int>>::Node**, LockFreeHashTable<int, int, std::hash<int>>::Node**, HazardPointer&, HazardPointer&)
bool LockFreeHashTable<K, V, Hash>::SearchNode(DummyNode* head,
                                               Node* search_node,
                                               Node** prev_ptr, Node** cur_ptr,
                                               HazardPointer& prev_hp,
                                               HazardPointer& cur_hp) {
  auto& reclaimer = TableReclaimer<K, V>::GetInstance();
try_again:
  Node* prev = head;
  Node* cur = prev->get_next();
  Node* next;
  while (true) {
    cur_hp.UnMark();
    cur_hp = HazardPointer(&reclaimer, cur);
    // Make sure prev is the predecessor of cur,
    // so that cur is properly marked as hazard.
    if (prev->get_next() != cur) goto try_again;

    if (nullptr == cur) {
      *prev_ptr = prev;
      *cur_ptr = cur;
      return false;
    }

    next = cur->get_next();
    if (is_marked_reference(next)) {
      if (!prev->next.compare_exchange_strong(cur,
                                              get_unmarked_reference(next)))
        goto try_again;

      reclaimer.ReclaimLater(cur, LockFreeHashTable<K, V, Hash>::OnDeleteNode);
      reclaimer.ReclaimNoHazardPointer();
      size_.fetch_sub(1, std::memory_order_relaxed);
      cur = get_unmarked_reference(next);
    } else {
      if (prev->get_next() != cur) goto try_again;

      // Can not get copy_cur after above invocation,
      // because prev may not be the predecessor of cur at this point.
      if (GreaterOrEquals(cur, search_node)) {
        *prev_ptr = prev;
        *cur_ptr = cur;
        return Equals(cur, search_node);
      }

      // Swap cur_hp and prev_hp.
      HazardPointer tmp = std::move(cur_hp);
      cur_hp = std::move(prev_hp);
      prev_hp = std::move(tmp);

      prev = cur;
      cur = next;
    }
  };

  assert(false);
  return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq 0x10(%rbp), %rax
movq %rdi, -0x38(%rbp)
movq %rsi, -0x40(%rbp)
movq %rdx, -0x48(%rbp)
movq %rcx, -0x50(%rbp)
movq %r8, -0x58(%rbp)
movq %r9, -0x60(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0xd8(%rbp)
callq 0xba40
movq %rax, -0x68(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
callq 0xbab0
movq %rax, -0x78(%rbp)
movq 0x10(%rbp), %rdi
callq 0xbae0
movq -0x68(%rbp), %rsi
movq -0x78(%rbp), %rdx
leaq -0x90(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0xbb10
movq -0xe0(%rbp), %rsi
movq 0x10(%rbp), %rdi
callq 0xbb50
jmp 0xb0c6
leaq -0x90(%rbp), %rdi
callq 0xba10
movq -0x70(%rbp), %rdi
callq 0xbab0
cmpq -0x78(%rbp), %rax
je 0xb106
jmp 0xb07b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0xba10
jmp 0xb3e7
xorl %eax, %eax
cmpq -0x78(%rbp), %rax
jne 0xb12d
movq -0x70(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, (%rax)
movq -0x78(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, (%rax)
movb $0x0, -0x29(%rbp)
jmp 0xb3d9
movq -0x78(%rbp), %rdi
callq 0xbab0
movq -0xd8(%rbp), %rdi
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rsi
callq 0xbb90
testb $0x1, %al
jne 0xb153
jmp 0xb306
movq -0xd8(%rbp), %rdi
movq -0x70(%rbp), %rax
addq $0x18, %rax
movq %rax, -0xe8(%rbp)
movq -0x80(%rbp), %rsi
callq 0xc160
movq -0xe8(%rbp), %rdi
movq %rax, %rdx
leaq -0x78(%rbp), %rsi
movl $0x5, %ecx
callq 0xbbb0
testb $0x1, %al
jne 0xb193
jmp 0xb07b
movq -0x68(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0xf8(%rbp)
leaq 0x1050(%rip), %rsi      # 0xc200
leaq -0xc0(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0xc230
movq -0x100(%rbp), %rdi
movq -0xf8(%rbp), %rsi
movq -0xf0(%rbp), %rdx
callq 0xc180
jmp 0xb1df
leaq -0xc0(%rbp), %rdi
callq 0x5750
movq -0x68(%rbp), %rdi
callq 0x2be0
movq -0xd8(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x8(%rbp)
movq $0x1, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x110(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
movq %rcx, -0x20(%rbp)
decl %eax
movl %eax, %ecx
movq %rcx, -0x108(%rbp)
subl $0x4, %eax
ja 0xb24f
movq -0x108(%rbp), %rax
leaq 0x5e92(%rip), %rcx      # 0x110d8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x110(%rbp), %rcx
movq -0x20(%rbp), %rax
negq %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0x28(%rbp)
jmp 0xb2ca
movq -0x110(%rbp), %rcx
movq -0x20(%rbp), %rax
negq %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0x28(%rbp)
jmp 0xb2ca
movq -0x110(%rbp), %rcx
movq -0x20(%rbp), %rax
negq %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0x28(%rbp)
jmp 0xb2ca
movq -0x110(%rbp), %rcx
movq -0x20(%rbp), %rax
negq %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0x28(%rbp)
jmp 0xb2ca
movq -0x110(%rbp), %rcx
movq -0x20(%rbp), %rax
negq %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0x28(%rbp)
movq -0xd8(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0xc160
movq %rax, -0x78(%rbp)
jmp 0xb3d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x5750
jmp 0xb3e7
movq -0x70(%rbp), %rdi
callq 0xbab0
cmpq -0x78(%rbp), %rax
je 0xb31a
jmp 0xb07b
movq -0xd8(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0xc2c0
testb $0x1, %al
jne 0xb334
jmp 0xb365
movq -0xd8(%rbp), %rdi
movq -0x70(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, (%rax)
movq -0x78(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, (%rax)
movq -0x78(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0xc2f0
andb $0x1, %al
movb %al, -0x29(%rbp)
jmp 0xb3d9
movq 0x10(%rbp), %rsi
leaq -0xd0(%rbp), %rdi
callq 0xc350
movq -0x60(%rbp), %rsi
movq 0x10(%rbp), %rdi
callq 0xbb50
jmp 0xb384
movq -0x60(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0xbb50
jmp 0xb396
movq -0x78(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0xba10
jmp 0xb3d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0xba10
jmp 0xb3e7
jmp 0xb090
movb -0x29(%rbp), %al
andb $0x1, %al
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0x98(%rbp), %rdi
callq 0x2230
nopw %cs:(%rax,%rax)
nopl (%rax)