// File: /workspace/github_cpp_makefile_star2_O2/chahk0129[P]hash_bench/./index/cuckoo_hash.h
// Function: CuckooHash<char [32]>::insert4resize(char (&) [32], long)
bool CuckooHash<Key_t>::insert4resize(Key_t& key, Value_t value) {
  size_t f_hash, s_hash;
  if constexpr(sizeof(Key_t) > 8){
      f_hash = hash_funcs[0](key, sizeof(Key_t), _seed);
      s_hash = hash_funcs[1](key, sizeof(Key_t), _seed);
  }
  else{
      f_hash = hash_funcs[0](&key, sizeof(Key_t), _seed);
      s_hash = hash_funcs[1](&key, sizeof(Key_t), _seed);
  }

  auto f_idx = f_hash % capacity;
  auto s_idx = s_hash % capacity;

  if constexpr(sizeof(Key_t) > 8){
      if(memcmp(table[f_idx].key, INVALID<Key_t>, sizeof(Key_t)) == 0){
	  memcpy(table[f_idx].key, key, sizeof(Key_t));
	  memcpy(&table[f_idx].value, &value, sizeof(Value_t));
      }
      else if(memcmp(table[s_idx].key, INVALID<Key_t>, sizeof(Key_t)) == 0){
	  memcpy(table[s_idx].key, key, sizeof(Key_t));
	  memcpy(&table[s_idx].value, &value, sizeof(Value_t));
      }
      else{
	  auto path1 = find_path(f_idx, true);
	  auto path2 = find_path(s_idx, true);
	  memcpy(pushed[0].key, key, sizeof(Key_t));
	  memcpy(&pushed[0].value, &value, sizeof(Value_t));
	  if(path1.size() == 0 && path2.size() == 0)
		  return false;
	  else{
		  if(path1.size() == 0)
			  execute_path(path2, true);
		  else if(path2.size() == 0)
			  execute_path(path1, true);
		  else if(path1.size() < path2.size())
			  execute_path(path1, true);
		  else
			  execute_path(path2, true);
	  }
      }
  }
  else{
      if(memcmp(&table[f_idx].key, &INVALID<Key_t>, sizeof(Key_t)) == 0){
	  memcpy(&table[f_idx].key, &key, sizeof(Key_t));
	  memcpy(&table[f_idx].value, &value, sizeof(Value_t));
      }
      else if(memcmp(&table[s_idx].key, &INVALID<Key_t>, sizeof(Key_t)) == 0){
	  memcpy(&table[s_idx].key, &key, sizeof(Key_t));
	  memcpy(&table[s_idx].value, &value, sizeof(Value_t));
      }
      else{
	  auto path1 = find_path(f_idx);
	  auto path2 = find_path(s_idx);
	  memcpy(&pushed[0].key, &key, sizeof(Key_t));
	  memcpy(&pushed[0].value, &value, sizeof(Value_t));
	  if(path1.size() == 0 && path2.size() == 0)
		  return false;
	  else{
		  if(path1.size() == 0)
			  execute_path(path2);
		  else if(path2.size() == 0)
			  execute_path(path1);
		  else if(path1.size() < path2.size())
			  execute_path(path1);
		  else
			  execute_path(path2);
	  }
      }
  }

  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, 0x8(%rsp)
movq %rsi, %r15
movq %rdi, %rbx
movq 0x8(%rdi), %rdx
pushq $0x20
popq %r14
movq %rsi, %rdi
movq %r14, %rsi
callq 0x2040
movq %rax, %r13
movq 0x8(%rbx), %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x82f2
movq %rax, %rcx
movq 0x30(%rbx), %rsi
movq 0x38(%rbx), %r12
movq %r13, %rax
xorl %edx, %edx
divq %rsi
movq %rdx, %rbp
movq %rcx, %rax
xorl %edx, %edx
divq %rsi
movq %rdx, 0x10(%rsp)
imulq $0x28, %rbp, %r14
leaq (%r12,%r14), %r13
leaq 0x97c6(%rip), %rsi      # 0x142e0
movq %r13, %rdi
pushq $0x20
popq %rdx
callq 0x2200
testl %eax, %eax
je 0xabc8
movq 0x8(%rsp), %r13
imulq $0x28, 0x10(%rsp), %r14
addq %r14, %r12
leaq 0x979e(%rip), %rsi      # 0x142e0
pushq $0x20
popq %rdx
movq %r12, %rdi
callq 0x2200
testl %eax, %eax
je 0xabeb
leaq 0x18(%rsp), %r12
pushq $0x1
popq %r14
movq %r12, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movl %r14d, %ecx
callq 0x97d6
leaq 0x30(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
movq 0x10(%rsp), %rdx
movl %r14d, %ecx
callq 0x97d6
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups %xmm1, 0x50(%rbx)
movups %xmm0, 0x40(%rbx)
movq %r13, 0x60(%rbx)
movq 0x20(%rsp), %rax
movq 0x30(%rsp), %rdx
movq 0x38(%rsp), %rcx
subq 0x18(%rsp), %rax
je 0xac0a
subq %rdx, %rcx
je 0xac12
cmpq %rcx, %rax
leaq 0x18(%rsp), %rax
cmovbq %rax, %rbp
movq %rbp, %r12
jmp 0xac12
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups %xmm1, 0x10(%r13)
movups %xmm0, (%r13)
movq 0x38(%rbx), %rax
movq 0x8(%rsp), %rcx
movq %rcx, 0x20(%rax,%r14)
jmp 0xac34
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups %xmm1, 0x10(%r12)
movups %xmm0, (%r12)
movq 0x38(%rbx), %rax
movq %r13, 0x20(%rax,%r14)
jmp 0xac34
movq %rbp, %r12
cmpq %rdx, %rcx
je 0xac45
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0xac82
leaq 0x30(%rsp), %rdi
callq 0x9e38
leaq 0x18(%rsp), %rdi
callq 0x9e38
movb $0x1, %al
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x30(%rsp), %rdi
callq 0x9e38
leaq 0x18(%rsp), %rdi
callq 0x9e38
xorl %eax, %eax
jmp 0xac36
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x9e38
jmp 0xac6f
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x9e38
movq %rbx, %rdi
callq 0x2340
nop