// File: /workspace/github_cpp_makefile_star2_O1/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 0x4b88
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 0x4938
movl %eax, %ebx
testb %al, %al
jne 0x43c4
movq 0x8(%rsp), %rax
movq %rax, 0x18(%r15)
movq 0x38(%rsp), %rcx
movq 0x8(%rsp), %rax
lock
cmpxchgq %r15, 0x18(%rcx)
je 0x442d
movq %rax, 0x8(%rsp)
jmp 0x437a
movq 0x28(%r15), %rsi
movq 0x8(%rsp), %rax
xchgq %rsi, 0x28(%rax)
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rdx
movaps %xmm0, (%rdx)
leaq 0xddb(%rip), %rax       # 0x51be
movq %rax, 0x18(%rdx)
leaq 0xde4(%rip), %rax       # 0x51d2
movq %rax, 0x10(%rdx)
movq 0x30(%rsp), %rdi
callq 0x4bae
movq 0x50(%rsp), %rax
testq %rax, %rax
je 0x4415
leaq 0x40(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq $0x0, 0x28(%r15)
testq %r15, %r15
je 0x449a
movq (%r15), %rax
movq %r15, %rdi
callq *0x10(%rax)
jmp 0x449a
movl $0x1, %eax
lock
xaddq %rax, 0x8(%r14)
movq (%r14), %rcx
movl $0x1, %edx
shll %cl, %edx
cvtsi2ss %edx, %xmm0
incq %rax
mulss 0x1bb7(%rip), %xmm0     # 0x6008
testq %rax, %rax
js 0x445d
cvtsi2ss %rax, %xmm1
jmp 0x4472
movq %rax, %rdx
shrq %rdx
andl $0x1, %eax
orq %rdx, %rax
cvtsi2ss %rax, %xmm1
addss %xmm1, %xmm1
ucomiss %xmm0, %xmm1
jbe 0x449a
leaq 0x1(%rcx), %rdx
movq %rcx, %rax
lock
cmpxchgq %rdx, (%r14)
jne 0x449a
movq (%r14), %rcx
movl $0x1, %eax
shll %cl, %eax
cltq
cmpq %rax, 0x64c0(%rip)      # 0xa958
jb 0x44ca
xorb $0x1, %bl
movq 0x10(%rsp), %rdi
movl 0x18(%rsp), %esi
callq 0x4dc8
movq 0x20(%rsp), %rdi
movl 0x28(%rsp), %esi
callq 0x4dc8
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1e63(%rip), %rdi      # 0x6334
leaq 0x1e7c(%rip), %rsi      # 0x6354
leaq 0x1e8c(%rip), %rcx      # 0x636b
movl $0x200, %edx            # imm = 0x200
callq 0x20c0
jmp 0x4509
movq %rax, %rbx
movq 0x50(%rsp), %rax
testq %rax, %rax
je 0x4516
leaq 0x40(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x4516
movq %rax, %rdi
callq 0x3584
jmp 0x4513
movq %rax, %rbx
movq 0x10(%rsp), %rdi
movl 0x18(%rsp), %esi
callq 0x4dc8
movq 0x20(%rsp), %rdi
movl 0x28(%rsp), %esi
callq 0x4dc8
movq %rbx, %rdi
callq 0x2230