// File: /workspace/github_cpp_makefile_star2_O1/chahk0129[P]hash_bench/./index/cuckoo_hash.h
// Function: CuckooHash<char [32]>::resize()
bool CuckooHash<Key_t>::resize(void) {
  old_cap = capacity;
  old_tab = table;

  std::unique_lock<std::shared_mutex> *lock[nlocks];
  for(int i=0;i<nlocks;i++){
    lock[i] = new std::unique_lock<std::shared_mutex>(mutex[i]);
  }
  std::shared_mutex* old_mutex = mutex;

  int prev_nlocks = nlocks;

  bool success = true;
  size_t num_grows = 0;

  do {
    success = true;
    if (table != old_tab) delete [] table;
    capacity = capacity * kResizingFactor;
    table = new Pair<Key_t>[capacity];
    if (table == nullptr) {
      cerr << "error: memory allocation failed." << endl;
      exit(1);
    }

    for (unsigned i = 0; i < old_cap; ++i) {
	    if constexpr(sizeof(Key_t) > 8){
		    if(memcmp(old_tab[i].key, INVALID<Key_t>, sizeof(Key_t)) != 0){
			    if(!insert4resize(old_tab[i].key, old_tab[i].value)){
				    success = false;
				    break;
			    }
		    }
	    }
	    else{
		    if(memcmp(&old_tab[i].key, &INVALID<Key_t>, sizeof(Key_t)) != 0){
			    if(!insert4resize(old_tab[i].key, old_tab[i].value)){
				    success = false;
				    break;
			    }
		    }
	    }
    }
    ++num_grows;
  } while (!success && num_grows < kMaxGrows);

  for (int i = 0; i < prev_nlocks; ++i) {
    delete lock[i];
  }

  if (success) {
    nlocks = capacity/locksize+1;
    mutex = new std::shared_mutex[nlocks];
    delete old_mutex;
  } else {
    exit(1);
  }
  return success;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movdqu 0x30(%rdi), %xmm0
movdqu %xmm0, 0xb8(%rdi)
movl 0xd8(%rdi), %r13d
movq %rsp, %rcx
leaq 0xf(,%r13,8), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x30(%rbp)
movq %rcx, %rsp
testl %r13d, %r13d
jle 0xb459
xorl %r15d, %r15d
xorl %r12d, %r12d
movl $0x10, %edi
callq 0x21f0
movq %rax, %r14
movq 0xd0(%rbx), %rax
addq %r15, %rax
movq %rax, (%r14)
movb $0x0, 0x8(%r14)
movq %r14, %rdi
callq 0xa0ba
movb $0x1, 0x8(%r14)
movq -0x30(%rbp), %rax
movq %r14, (%rax,%r12,8)
incq %r12
movslq 0xd8(%rbx), %r13
addq $0x38, %r15
cmpq %r13, %r12
jl 0xb412
movq 0xd0(%rbx), %rax
movq %rax, -0x38(%rbp)
xorl %r12d, %r12d
movq 0x38(%rbx), %rdi
testq %rdi, %rdi
je 0xb47e
cmpq 0xc0(%rbx), %rdi
je 0xb47e
callq 0x2230
movq 0x30(%rbx), %rax
testq %rax, %rax
js 0xb491
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
jmp 0xb4a9
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
addss %xmm0, %xmm0
mulss 0x20(%rbx), %xmm0
cvttss2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subss 0x1bce(%rip), %xmm0     # 0xd090
cvttss2si %xmm0, %r15
andq %rcx, %r15
orq %rax, %r15
movq %r15, %rax
movl $0x28, %ecx
mulq %rcx
movq %r15, 0x30(%rbx)
movq $-0x1, %rcx
cmovoq %rcx, %rax
movq %rax, %rdi
callq 0x2030
testq %r15, %r15
xorps %xmm0, %xmm0
je 0xb513
shlq $0x3, %r15
leaq (%r15,%r15,4), %rcx
xorl %edx, %edx
movups %xmm0, 0x10(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
addq $0x28, %rdx
cmpq %rdx, %rcx
jne 0xb501
movq %rax, 0x38(%rbx)
cmpq $0x0, 0xb8(%rbx)
setne %r14b
je 0xb599
movl $0x1, %r15d
xorl %eax, %eax
movq 0xc0(%rbx), %rcx
leaq (%rax,%rax,4), %rax
movdqu (%rcx,%rax,8), %xmm0
movdqu 0x10(%rcx,%rax,8), %xmm1
pcmpeqb 0x8d95(%rip), %xmm1     # 0x142e0
pcmpeqb 0x8d7d(%rip), %xmm0     # 0x142d0
pand %xmm1, %xmm0
pmovmskb %xmm0, %edx
cmpl $0xffff, %edx           # imm = 0xFFFF
je 0xb577
leaq (%rcx,%rax,8), %rsi
movq 0x20(%rsi), %rdx
movq %rbx, %rdi
callq 0xc3fc
testb %al, %al
je 0xb58c
movl %r15d, %eax
incl %r15d
cmpq %rax, 0xb8(%rbx)
seta %r14b
ja 0xb52d
jmp 0xb599
incq %r12
cmpq 0x28(%rbx), %r12
jb 0xb467
testl %r13d, %r13d
jle 0xb5ce
movl %r13d, %r12d
xorl %r13d, %r13d
movq -0x30(%rbp), %rax
movq (%rax,%r13,8), %r15
testq %r15, %r15
je 0xb5c6
movq %r15, %rdi
callq 0x9de6
movl $0x10, %esi
movq %r15, %rdi
callq 0x2200
incq %r13
cmpq %r13, %r12
jne 0xb5a4
testb $0x1, %r14b
jne 0xb671
movq 0x30(%rbx), %rax
movslq 0xdc(%rbx), %rcx
xorl %edx, %edx
divq %rcx
movq %rax, %r12
incl %eax
movl %eax, 0xd8(%rbx)
movslq %eax, %r15
movl $0x38, %ecx
movq %r15, %rax
mulq %rcx
movq $-0x1, %rdi
cmovnoq %rax, %rdi
callq 0x2030
incl %r12d
je 0xb646
imulq $0x38, %r15, %rdx
movq %rax, %rcx
addq %rdx, %rcx
pxor %xmm0, %xmm0
movq %rax, %rdx
movdqu %xmm0, 0x20(%rdx)
movdqu %xmm0, 0x10(%rdx)
movdqu %xmm0, (%rdx)
movq $0x0, 0x30(%rdx)
addq $0x38, %rdx
cmpq %rcx, %rdx
jne 0xb627
movq %rax, 0xd0(%rbx)
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0xb660
movl $0x38, %esi
callq 0x2200
movb $0x1, %al
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %edi
callq 0x2220
movq %rax, %rbx
movl $0x10, %esi
movq %r14, %rdi
callq 0x2200
movq %rbx, %rdi
callq 0x2330
nop