// File: /workspace/github_c_makefile_star2_O3/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 0x33d86
testq %rax, %rax
je 0x3662f
movq %rax, %r15
testl %r12d, %r12d
je 0x36542
movl %r12d, %ecx
movq %r15, %rax
addq %rcx, %rax
movq %r15, %rcx
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x36542
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x36542
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x36542
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jb 0x36516
addl %r13d, %r13d
movl 0xd0(%rbx), %eax
testl %eax, %eax
je 0x36612
leaq 0xe8(%rbx), %rsi
leal -0x1(%r13), %ecx
xorl %edx, %edx
xorps %xmm0, %xmm0
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 0x36580
movq %rsi, 0x48(%r8)
movq %rsi, (%r15,%rdi,8)
leal 0x1(%rdx), %edi
cmpl %eax, %edi
jae 0x36612
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 0x365ad
movq %rsi, 0x48(%r8)
movq %rsi, (%r15,%rdi,8)
leal 0x2(%rdx), %edi
cmpl %eax, %edi
jae 0x36612
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 0x365d6
movq %rsi, 0x48(%r8)
movq %rsi, (%r15,%rdi,8)
leal 0x3(%rdx), %edi
cmpl %eax, %edi
jae 0x36612
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 0x365ff
movq %rsi, 0x48(%r8)
movq %rsi, (%r15,%rdi,8)
addq $0x30, %rsi
addl $0x4, %edx
cmpl %eax, %edx
jb 0x36563
movq 0xd8(%rbx), %rsi
movq %r14, %rdi
callq 0x3490d
movq %r15, 0xd8(%rbx)
movl %r13d, 0xd4(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq