// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
movq %r8, 0x20(%rsp)
movq %rcx, 0x18(%rsp)
movq %rdx, 0x28(%rsp)
movq %rsi, %rbp
movq %rdi, 0x10(%rsp)
movq 0x90(%rsp), %r15
callq 0x4b88
movq %rax, %r14
leaq 0x18(%rbp), %rax
movq %rax, 0x50(%rsp)
movl %eax, 0x4(%rsp)
movq %rbp, 0x8(%rsp)
movq 0x18(%rbp), %r12
movq (%r15), %rdi
movl 0x8(%r15), %esi
callq 0x4dc8
movq %r14, %rdi
movq %r12, %rsi
callq 0x2514
movq %r14, (%r15)
movl %eax, 0x8(%r15)
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x4dc8
movq 0x18(%rbp), %rax
movb $0x1, %cl
cmpq %rax, %r12
jne 0x4b3d
movq 0x50(%rsp), %rcx
testq %r12, %r12
je 0x4af6
movq 0x18(%r12), %r13
testb $0x1, %r13b
jne 0x4a30
movq (%rcx), %rax
cmpq %rax, %r12
jne 0x4aed
movq 0x10(%rsp), %rdi
movq %r12, %rsi
movq 0x28(%rsp), %rdx
callq 0x4c3c
testb %al, %al
jne 0x4b10
movq (%r15), %rdi
movl 0x8(%r15), %eax
movl $0xffffffff, 0x8(%r15)  # imm = 0xFFFFFFFF
movq (%rbx), %rcx
movq %rcx, (%r15)
movl 0x8(%rbx), %ecx
movl %ecx, 0x8(%r15)
movq %rdi, (%rbx)
movl %eax, 0x8(%rbx)
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x4dc8
movq %r12, %rbp
jmp 0x4aae
andq $-0x2, %r13
movq %r12, %rax
lock
cmpxchgq %r13, (%rcx)
jne 0x4aed
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x40(%rsp)
leaq 0x1da(%rip), %rax       # 0x4c30
movq %rax, 0x30(%rsp)
leaq 0x732(%rip), %rax       # 0x5194
movq %rax, 0x48(%rsp)
leaq 0x72e(%rip), %rax       # 0x519c
movq %rax, 0x40(%rsp)
movq %r14, %rdi
movq %r12, %rsi
leaq 0x30(%rsp), %rdx
callq 0x4bae
movq 0x40(%rsp), %rax
testq %rax, %rax
je 0x4a9c
leaq 0x30(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq %r14, %rdi
callq 0x263e
movq 0x10(%rsp), %rax
lock
decq 0x8(%rax)
movq (%r15), %rdi
movl 0x8(%r15), %esi
callq 0x4dc8
movq %r14, %rdi
movq %r13, %rsi
callq 0x2514
movq %r14, (%r15)
movl %eax, 0x8(%r15)
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x4dc8
leaq 0x18(%rbp), %rcx
movq 0x18(%rbp), %rax
movq %r13, %r12
cmpq %rax, %r13
je 0x49c5
movq 0x8(%rsp), %rbp
movb $0x1, %cl
jmp 0x4b3d
movq 0x18(%rsp), %rax
movq %rbp, (%rax)
movq 0x20(%rsp), %rax
movq %r12, (%rax)
movl $0x0, 0x4(%rsp)
jmp 0x4b36
movq 0x18(%rsp), %rax
movq %rbp, (%rax)
movq 0x20(%rsp), %rax
movq %r12, (%rax)
movq 0x10(%rsp), %rdi
movq %r12, %rsi
movq 0x28(%rsp), %rdx
callq 0x4c88
movl %eax, 0x4(%rsp)
xorl %ecx, %ecx
movq 0x8(%rsp), %rbp
testb %cl, %cl
jne 0x4982
movl 0x4(%rsp), %eax
andb $0x1, %al
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4b80
movq %rax, %rbx
movq 0x40(%rsp), %rax
testq %rax, %rax
je 0x4b78
leaq 0x30(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq %rbx, %rdi
callq 0x2230
movq %rax, %rdi
callq 0x3584