// File: /workspace/github_cpp_makefile_star2_O3/bhhbazinga[P]LockFreeHashTable/./lockfree_hashtable.h
// Function: LockFreeHashTable<int, int, std::hash<int>>::InsertRegularNode(LockFreeHashTable<int, int, std::hash<int>>::DummyNode*, LockFreeHashTable<int, int, std::hash<int>>::RegularNode*)
bool LockFreeHashTable<K, V, Hash>::InsertRegularNode(DummyNode* head,
                                                      RegularNode* new_node) {
  Node* prev;
  Node* cur;
  HazardPointer prev_hp, cur_hp;
  auto& reclaimer = TableReclaimer<K, V>::GetInstance();
  do {
    if (SearchNode(head, new_node, &prev, &cur, prev_hp, cur_hp)) {
      V* new_value = new_node->value.load(std::memory_order_consume);
      V* old_value = static_cast<RegularNode*>(cur)->value.exchange(
          new_value, std::memory_order_release);
      reclaimer.ReclaimLater(old_value,
                             [](void* ptr) { delete static_cast<V*>(ptr); });
      new_node->value.store(nullptr, std::memory_order_release);
      delete new_node;
      return false;
    }
    new_node->next.store(cur, std::memory_order_release);
  } while (!prev->next.compare_exchange_weak(
      cur, new_node, std::memory_order_release, std::memory_order_relaxed));

  size_t size = size_.fetch_add(1, std::memory_order_relaxed) + 1;
  size_t power = power_of_2_.load(std::memory_order_relaxed);
  if ((1 << power) * kLoadFactor < size) {
    if (power_of_2_.compare_exchange_strong(power, power + 1,
                                            std::memory_order_release)) {
      assert(bucket_size() <=
             kMaxBucketSize);  // Out of memory or you can change the kMaxLevel
                               // and kSegmentSize.
    }
  }
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, %r15
movq %rsi, %r13
movq %rdi, %r14
xorl %eax, %eax
movq %rax, 0x20(%rsp)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %ecx, 0x28(%rsp)
movq %rax, 0x10(%rsp)
movl %ecx, 0x18(%rsp)
callq 0x4ab4
movq %rax, 0x30(%rsp)
leaq 0x8(%rsp), %r12
leaq 0x20(%rsp), %rbp
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
leaq 0x38(%rsp), %rcx
movq %r12, %r8
movq %rbp, %r9
callq 0x488c
movl %eax, %ebx
testb %al, %al
jne 0x432d
movq 0x8(%rsp), %rax
movq %rax, 0x18(%r15)
movq 0x38(%rsp), %rcx
lock
cmpxchgq %r15, 0x18(%rcx)
je 0x4391
movq %rax, 0x8(%rsp)
jmp 0x42e8
movq 0x28(%r15), %rsi
movq 0x8(%rsp), %rax
xchgq %rsi, 0x28(%rax)
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rdx
movaps %xmm0, (%rdx)
leaq 0xd34(%rip), %rax       # 0x5080
movq %rax, 0x18(%rdx)
leaq 0xd37(%rip), %rax       # 0x508e
movq %rax, 0x10(%rdx)
movq 0x30(%rsp), %rdi
callq 0x4ada
movq 0x50(%rsp), %rax
testq %rax, %rax
je 0x437e
leaq 0x40(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq $0x0, 0x28(%r15)
movq (%r15), %rax
movq %r15, %rdi
callq *0x10(%rax)
jmp 0x43fe
movl $0x1, %eax
lock
xaddq %rax, 0x8(%r14)
movq (%r14), %rcx
movl $0x1, %edx
shll %cl, %edx
cvtsi2ss %edx, %xmm0
incq %rax
mulss 0x1c53(%rip), %xmm0     # 0x6008
testq %rax, %rax
js 0x43c1
cvtsi2ss %rax, %xmm1
jmp 0x43d6
movq %rax, %rdx
shrq %rdx
andl $0x1, %eax
orq %rdx, %rax
cvtsi2ss %rax, %xmm1
addss %xmm1, %xmm1
ucomiss %xmm0, %xmm1
jbe 0x43fe
leaq 0x1(%rcx), %rdx
movq %rcx, %rax
lock
cmpxchgq %rdx, (%r14)
jne 0x43fe
movq (%r14), %rcx
movl $0x1, %eax
shll %cl, %eax
cltq
cmpq %rax, 0x655c(%rip)      # 0xa958
jb 0x442e
xorb $0x1, %bl
movq 0x10(%rsp), %rdi
movl 0x18(%rsp), %esi
callq 0x4cf0
movq 0x20(%rsp), %rdi
movl 0x28(%rsp), %esi
callq 0x4cf0
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1eff(%rip), %rdi      # 0x6334
leaq 0x1f18(%rip), %rsi      # 0x6354
leaq 0x1f28(%rip), %rcx      # 0x636b
movl $0x200, %edx            # imm = 0x200
callq 0x20c0
jmp 0x446d
movq %rax, %rbx
movq 0x50(%rsp), %rax
testq %rax, %rax
je 0x447a
leaq 0x40(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x447a
movq %rax, %rdi
callq 0x3504
jmp 0x4477
movq %rax, %rbx
movq 0x10(%rsp), %rdi
movl 0x18(%rsp), %esi
callq 0x4cf0
movq 0x20(%rsp), %rdi
movl 0x28(%rsp), %esi
callq 0x4cf0
movq %rbx, %rdi
callq 0x2230