// File: 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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rcx
movq %rcx, -0x88(%rbp)
movq 0x36537(%rip), %rax     # 0x5a480
movq -0x18(%rbp), %rdi
movq 0x8(%rcx), %rdx
movl $0x20, %esi
callq *%rax
movq -0x88(%rbp), %rcx
movq %rax, -0x28(%rbp)
movq 0x3651e(%rip), %rax     # 0x5a488
movq -0x18(%rbp), %rdi
movq 0x8(%rcx), %rdx
movl $0x20, %esi
callq *%rax
movq -0x88(%rbp), %rcx
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
xorl %edx, %edx
divq 0x30(%rcx)
movq %rdx, -0x38(%rbp)
movq -0x30(%rbp), %rax
xorl %edx, %edx
divq 0x30(%rcx)
movq -0x88(%rbp), %rax
movq %rdx, -0x40(%rbp)
movq 0x38(%rax), %rdi
imulq $0x28, -0x38(%rbp), %rax
addq %rax, %rdi
leaq 0x36ce6(%rip), %rsi     # 0x5aca0
movl $0x20, %edx
callq 0x6190
cmpl $0x0, %eax
jne 0x24017
movq -0x88(%rbp), %rax
movq 0x38(%rax), %rcx
imulq $0x28, -0x38(%rbp), %rdx
addq %rdx, %rcx
movq -0x18(%rbp), %rdx
movq (%rdx), %rsi
movq %rsi, (%rcx)
movq 0x8(%rdx), %rsi
movq %rsi, 0x8(%rcx)
movq 0x10(%rdx), %rsi
movq %rsi, 0x10(%rcx)
movq 0x18(%rdx), %rdx
movq %rdx, 0x18(%rcx)
movq 0x38(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movq -0x20(%rbp), %rcx
movq %rcx, 0x20(%rax)
jmp 0x2423a
movq -0x88(%rbp), %rax
movq 0x38(%rax), %rdi
imulq $0x28, -0x40(%rbp), %rax
addq %rax, %rdi
leaq 0x36c6f(%rip), %rsi     # 0x5aca0
movl $0x20, %edx
callq 0x6190
cmpl $0x0, %eax
jne 0x2408e
movq -0x88(%rbp), %rax
movq 0x38(%rax), %rcx
imulq $0x28, -0x40(%rbp), %rdx
addq %rdx, %rcx
movq -0x18(%rbp), %rdx
movq (%rdx), %rsi
movq %rsi, (%rcx)
movq 0x8(%rdx), %rsi
movq %rsi, 0x8(%rcx)
movq 0x10(%rdx), %rsi
movq %rsi, 0x10(%rcx)
movq 0x18(%rdx), %rdx
movq %rdx, 0x18(%rcx)
movq 0x38(%rax), %rax
imulq $0x28, -0x40(%rbp), %rcx
addq %rcx, %rax
movq -0x20(%rbp), %rcx
movq %rcx, 0x20(%rax)
jmp 0x24238
movq -0x88(%rbp), %rsi
movq -0x38(%rbp), %rdx
leaq -0x58(%rbp), %rdi
movl $0x1, %ecx
movl %ecx, -0x8c(%rbp)
callq 0x1f600
movq -0x88(%rbp), %rsi
movl -0x8c(%rbp), %ecx
movq -0x40(%rbp), %rdx
leaq -0x70(%rbp), %rdi
callq 0x1f600
jmp 0x240c9
movq -0x88(%rbp), %rax
movq -0x18(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, 0x40(%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x48(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x50(%rax)
movq 0x18(%rcx), %rcx
movq %rcx, 0x58(%rax)
movq -0x20(%rbp), %rcx
movq %rcx, 0x60(%rax)
leaq -0x58(%rbp), %rdi
callq 0x1fb60
cmpq $0x0, %rax
jne 0x2413a
leaq -0x70(%rbp), %rdi
callq 0x1fb60
cmpq $0x0, %rax
jne 0x2413a
movb $0x0, -0x1(%rbp)
movl $0x1, -0x80(%rbp)
jmp 0x2420e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x2422d
leaq -0x58(%rbp), %rdi
callq 0x1fb60
cmpq $0x0, %rax
jne 0x2417f
movq -0x88(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl $0x1, %edx
callq 0x24260
jmp 0x24160
jmp 0x24205
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x206d0
jmp 0x2422d
leaq -0x70(%rbp), %rdi
callq 0x1fb60
cmpq $0x0, %rax
jne 0x241a7
movq -0x88(%rbp), %rdi
leaq -0x58(%rbp), %rsi
movl $0x1, %edx
callq 0x24260
jmp 0x241a5
jmp 0x24203
leaq -0x58(%rbp), %rdi
callq 0x1fb60
movq %rax, -0x98(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x1fb60
movq %rax, %rcx
movq -0x98(%rbp), %rax
cmpq %rcx, %rax
jae 0x241e8
movq -0x88(%rbp), %rdi
leaq -0x58(%rbp), %rsi
movl $0x1, %edx
callq 0x24260
jmp 0x241e6
jmp 0x24201
movq -0x88(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl $0x1, %edx
callq 0x24260
jmp 0x241ff
jmp 0x24201
jmp 0x24203
jmp 0x24205
jmp 0x24207
movl $0x0, -0x80(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x206d0
leaq -0x58(%rbp), %rdi
callq 0x206d0
movl -0x80(%rbp), %eax
testl %eax, %eax
je 0x2422b
jmp 0x24229
jmp 0x2423e
jmp 0x24238
leaq -0x58(%rbp), %rdi
callq 0x206d0
jmp 0x2424c
jmp 0x2423a
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xa0, %rsp
popq %rbp
retq
movq -0x78(%rbp), %rdi
callq 0x6780
nopw %cs:(%rax,%rax)
nop