// File: /workspace/github_cpp_makefile_star2_O2/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, 0x48(%rsp)
movq %r8, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
movq %rsi, %r13
movq %rdi, %r12
movq 0x90(%rsp), %r14
callq 0x4902
movq %rax, %rbx
leaq 0x28(%rsp), %r15
movq %r13, 0x50(%rsp)
movq 0x18(%r13), %rax
movq %rax, (%rsp)
movq %r13, 0x20(%rsp)
addq $0x18, %r13
movq %r14, %rdi
callq 0x4960
movq (%rsp), %rsi
movq %rbx, 0x28(%rsp)
movq %rbx, %rdi
callq 0x2472
movq 0x28(%rsp), %rcx
movq %rcx, (%r14)
movl %eax, 0x8(%r14)
orl $-0x1, 0x30(%rsp)
movq %r15, %rdi
callq 0x48f2
movq (%r13), %rcx
movq (%rsp), %rax
cmpq %rcx, %rax
jne 0x4885
testq %rcx, %rcx
je 0x488f
movq 0x18(%rax), %rbp
testb $0x1, %bpl
je 0x4824
andq $-0x2, %rbp
movq %r13, %rdi
movq %rsp, %rsi
movq %rbp, %rdx
pushq $0x5
popq %rcx
callq 0x496e
testb %al, %al
je 0x4885
andq $0x0, 0x30(%rsp)
movq (%rsp), %rsi
leaq 0x23d(%rip), %rax       # 0x4a1a
movq %rax, 0x28(%rsp)
leaq 0x759(%rip), %rax       # 0x4f42
movq %rax, 0x40(%rsp)
leaq 0x755(%rip), %rax       # 0x4f4a
movq %rax, 0x38(%rsp)
movq %rbx, %rdi
movq %r15, %rdx
callq 0x49c6
movq %r15, %rdi
callq 0x36a4
movq %rbx, %rdi
callq 0x2558
lock
decq 0x8(%r12)
movq %rbp, (%rsp)
jmp 0x4759
movq (%r13), %rax
movq (%rsp), %rsi
cmpq %rax, %rsi
jne 0x4885
movq %r12, %rdi
movq 0x8(%rsp), %rdx
callq 0x4a26
testb %al, %al
jne 0x48b5
movq (%r14), %rax
movq %rax, 0x28(%rsp)
movl 0x8(%r14), %ecx
orl $-0x1, 0x8(%r14)
movq 0x48(%rsp), %rsi
movq (%rsi), %rdx
movq %rdx, (%r14)
movl 0x8(%rsi), %edx
movl %edx, 0x8(%r14)
movq %rax, (%rsi)
movl %ecx, 0x8(%rsi)
orl $-0x1, 0x30(%rsp)
movq (%rsp), %r13
movq %rbp, (%rsp)
movq %r15, %rdi
callq 0x48f2
jmp 0x4750
movq 0x50(%rsp), %r13
jmp 0x4748
movq 0x10(%rsp), %rcx
movq 0x20(%rsp), %rdx
movq %rdx, (%rcx)
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
movq %rcx, (%rax)
movq (%rsp), %rsi
movq 0x18(%rsp), %rax
movq %rsi, (%rax)
movq %r12, %rdi
movq 0x8(%rsp), %rdx
callq 0x4a30
jmp 0x48a6
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x36a4
movq %rbx, %rdi
callq 0x2230