// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: MemHashGrowTable
static int MemHashGrowTable(mem_hash_kv_engine *pEngine)
{
	sxu32 nNewSize = pEngine->nBucket << 1;
	mem_hash_record *pEntry;
	mem_hash_record **apNew;
	sxu32 n,iBucket;
	/* Allocate a new larger table */
	apNew = (mem_hash_record **)SyMemBackendAlloc(&pEngine->sAlloc, nNewSize * sizeof(mem_hash_record *));
	if( apNew == 0 ){
		/* Not so fatal, simply a performance hit */
		return UNQLITE_OK;
	}
	/* Zero the new table */
	SyZero((void *)apNew, nNewSize * sizeof(mem_hash_record *));
	/* Rehash all entries */
	n = 0;
	pEntry = pEngine->pLast;
	for(;;){
		
		/* Loop one */
		if( n >= pEngine->nRecord ){
			break;
		}
		pEntry->pNextHash = pEntry->pPrevHash = 0;
		/* Install in the new bucket */
		iBucket = pEntry->nHash & (nNewSize - 1);
		pEntry->pNextHash = apNew[iBucket];
		if( apNew[iBucket] ){
			apNew[iBucket]->pPrevHash = pEntry;
		}
		apNew[iBucket] = pEntry;
		/* Point to the next entry */
		pEntry = pEntry->pNext;
		n++;

		/* Loop two */
		if( n >= pEngine->nRecord ){
			break;
		}
		pEntry->pNextHash = pEntry->pPrevHash = 0;
		/* Install in the new bucket */
		iBucket = pEntry->nHash & (nNewSize - 1);
		pEntry->pNextHash = apNew[iBucket];
		if( apNew[iBucket] ){
			apNew[iBucket]->pPrevHash = pEntry;
		}
		apNew[iBucket] = pEntry;
		/* Point to the next entry */
		pEntry = pEntry->pNext;
		n++;

		/* Loop three */
		if( n >= pEngine->nRecord ){
			break;
		}
		pEntry->pNextHash = pEntry->pPrevHash = 0;
		/* Install in the new bucket */
		iBucket = pEntry->nHash & (nNewSize - 1);
		pEntry->pNextHash = apNew[iBucket];
		if( apNew[iBucket] ){
			apNew[iBucket]->pPrevHash = pEntry;
		}
		apNew[iBucket] = pEntry;
		/* Point to the next entry */
		pEntry = pEntry->pNext;
		n++;

		/* Loop four */
		if( n >= pEngine->nRecord ){
			break;
		}
		pEntry->pNextHash = pEntry->pPrevHash = 0;
		/* Install in the new bucket */
		iBucket = pEntry->nHash & (nNewSize - 1);
		pEntry->pNextHash = apNew[iBucket];
		if( apNew[iBucket] ){
			apNew[iBucket]->pPrevHash = pEntry;
		}
		apNew[iBucket] = pEntry;
		/* Point to the next entry */
		pEntry = pEntry->pNext;
		n++;
	}
	/* Release the old table and reflect the change */
	SyMemBackendFree(&pEngine->sAlloc,(void *)pEngine->apBucket);
	pEngine->apBucket = apNew;
	pEngine->nBucket  = nNewSize;
	return UNQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0xd4(%rdi), %r13d
leaq 0x8(%rdi), %r14
movl %r13d, %r12d
shll $0x4, %r12d
movq %r14, %rdi
movl %r12d, %esi
callq 0x2ca19
testq %rax, %rax
je 0x2ee49
movq %rax, %r15
addl %r13d, %r13d
movq %rax, %rdi
movl %r12d, %esi
callq 0x27aea
leaq 0xe8(%rbx), %rsi
movl 0xd0(%rbx), %eax
leal -0x1(%r13), %ecx
xorl %edx, %edx
xorps %xmm0, %xmm0
cmpl %eax, %edx
jae 0x2ee2c
movq (%rsi), %rsi
movups %xmm0, 0x40(%rsi)
movl 0x8(%rsi), %edi
andl %ecx, %edi
movq (%r15,%rdi,8), %r8
movq %r8, 0x40(%rsi)
testq %r8, %r8
je 0x2eda5
movq %rsi, 0x48(%r8)
movq %rsi, (%r15,%rdi,8)
incl %edx
cmpl %eax, %edx
jae 0x2ee2c
movq 0x30(%rsi), %rsi
movups %xmm0, 0x40(%rsi)
movl 0x8(%rsi), %edi
andl %ecx, %edi
movq (%r15,%rdi,8), %r8
movq %r8, 0x40(%rsi)
testq %r8, %r8
je 0x2edcd
movq %rsi, 0x48(%r8)
movq %rsi, (%r15,%rdi,8)
incl %edx
cmpl %eax, %edx
jae 0x2ee2c
movq 0x30(%rsi), %rsi
movups %xmm0, 0x40(%rsi)
movl 0x8(%rsi), %edi
andl %ecx, %edi
movq (%r15,%rdi,8), %r8
movq %r8, 0x40(%rsi)
testq %r8, %r8
je 0x2edf5
movq %rsi, 0x48(%r8)
movq %rsi, (%r15,%rdi,8)
incl %edx
cmpl %eax, %edx
jae 0x2ee2c
movq 0x30(%rsi), %rsi
movups %xmm0, 0x40(%rsi)
movl 0x8(%rsi), %edi
andl %ecx, %edi
movq (%r15,%rdi,8), %r8
movq %r8, 0x40(%rsi)
testq %r8, %r8
je 0x2ee1d
movq %rsi, 0x48(%r8)
movq %rsi, (%r15,%rdi,8)
addq $0x30, %rsi
incl %edx
jmp 0x2ed80
movq 0xd8(%rbx), %rsi
movq %r14, %rdi
callq 0x2d420
movq %r15, 0xd8(%rbx)
movl %r13d, 0xd4(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq