// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, %r12
movq %r8, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq %rdx, 0x28(%rsp)
movq %rsi, %r14
movq %rdi, 0x8(%rsp)
movq 0x90(%rsp), %r15
callq 0x4ab4
movq %rax, %rbx
movq %r14, 0x50(%rsp)
leaq 0x18(%r14), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %r14
movq (%r14), %rbp
movq (%r15), %rdi
movl 0x8(%r15), %esi
callq 0x4cf0
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x2514
movq %rbx, (%r15)
movl %eax, 0x8(%r15)
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x4cf0
movq (%r14), %rax
cmpq %rax, %rbp
jne 0x48d2
movq 0x20(%rsp), %rcx
movq 0x50(%rsp), %r13
testq %rbp, %rbp
je 0x4a41
movq 0x18(%rbp), %r14
testb $0x1, %r14b
jne 0x4983
movq (%rcx), %rax
cmpq %rax, %rbp
jne 0x48d2
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
movq 0x28(%rsp), %rdx
callq 0x4b68
testb %al, %al
jne 0x4a55
movq (%r15), %rdi
movl 0x8(%r15), %eax
movl $0xffffffff, 0x8(%r15)  # imm = 0xFFFFFFFF
movq (%r12), %rcx
movq %rcx, (%r15)
movl 0x8(%r12), %ecx
movl %ecx, 0x8(%r15)
movq %rdi, (%r12)
movl %eax, 0x8(%r12)
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x4cf0
movq %rbp, %r13
jmp 0x49fd
andq $-0x2, %r14
movq %rbp, %rax
lock
cmpxchgq %r14, (%rcx)
jne 0x48d2
movq $0x0, 0x38(%rsp)
leaq 0x1b7(%rip), %rax       # 0x4b5c
movq %rax, 0x30(%rsp)
leaq 0x6a5(%rip), %rax       # 0x5056
movq %rax, 0x48(%rsp)
leaq 0x6a1(%rip), %rax       # 0x505e
movq %rax, 0x40(%rsp)
movq %rbx, %rdi
movq %rbp, %rsi
leaq 0x30(%rsp), %rdx
callq 0x4ada
movq 0x40(%rsp), %rax
testq %rax, %rax
je 0x49eb
leaq 0x30(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq %rbx, %rdi
callq 0x2620
movq 0x8(%rsp), %rax
lock
decq 0x8(%rax)
movq (%r15), %rdi
movl 0x8(%r15), %esi
callq 0x4cf0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2514
movq %rbx, (%r15)
movl %eax, 0x8(%r15)
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x4cf0
leaq 0x18(%r13), %rcx
movq 0x18(%r13), %rax
movq %r14, %rbp
cmpq %rax, %r14
je 0x4917
jmp 0x48d2
movq 0x10(%rsp), %rax
movq %r13, (%rax)
movq 0x18(%rsp), %rax
movq %rbp, (%rax)
xorl %eax, %eax
jmp 0x4a77
movq 0x10(%rsp), %rax
movq %r13, (%rax)
movq 0x18(%rsp), %rax
movq %rbp, (%rax)
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
movq 0x28(%rsp), %rdx
callq 0x4bb4
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4aac
movq %rax, %rbx
movq 0x40(%rsp), %rax
testq %rax, %rax
je 0x4aa4
leaq 0x30(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq %rbx, %rdi
callq 0x2230
movq %rax, %rdi
callq 0x3504