// File: /workspace/github_c_makefile_star2_O1/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 0x343ed
testq %rax, %rax
je 0x36d5a
movq %rax, %r15
testl %r12d, %r12d
je 0x36c5d
movl %r12d, %ecx
movq %r15, %rax
addq %rcx, %rax
movq %r15, %rcx
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x36c5d
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x36c5d
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x36c5d
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jb 0x36c31
addl %r13d, %r13d
movl 0xd0(%rbx), %eax
testl %eax, %eax
je 0x36d3d
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)
movq (%r15,%rdi,8), %r8
testq %r8, %r8
je 0x36c9f
movq %rsi, 0x48(%r8)
movq %rsi, (%r15,%rdi,8)
leal 0x1(%rdx), %edi
cmpl %eax, %edi
jae 0x36d3d
movq 0x30(%rsi), %rsi
movups %xmm0, 0x40(%rsi)
movl 0x8(%rsi), %edi
andl %ecx, %edi
movq (%r15,%rdi,8), %r8
movq %r8, 0x40(%rsi)
movq (%r15,%rdi,8), %r8
testq %r8, %r8
je 0x36cd0
movq %rsi, 0x48(%r8)
movq %rsi, (%r15,%rdi,8)
leal 0x2(%rdx), %edi
cmpl %eax, %edi
jae 0x36d3d
movq 0x30(%rsi), %rsi
movups %xmm0, 0x40(%rsi)
movl 0x8(%rsi), %edi
andl %ecx, %edi
movq (%r15,%rdi,8), %r8
movq %r8, 0x40(%rsi)
movq (%r15,%rdi,8), %r8
testq %r8, %r8
je 0x36cfd
movq %rsi, 0x48(%r8)
movq %rsi, (%r15,%rdi,8)
leal 0x3(%rdx), %edi
cmpl %eax, %edi
jae 0x36d3d
movq 0x30(%rsi), %rsi
movups %xmm0, 0x40(%rsi)
movl 0x8(%rsi), %edi
andl %ecx, %edi
movq (%r15,%rdi,8), %r8
movq %r8, 0x40(%rsi)
movq (%r15,%rdi,8), %r8
testq %r8, %r8
je 0x36d2a
movq %rsi, 0x48(%r8)
movq %rsi, (%r15,%rdi,8)
addq $0x30, %rsi
addl $0x4, %edx
cmpl %eax, %edx
jb 0x36c7e
movq 0xd8(%rbx), %rsi
movq %r14, %rdi
callq 0x3503f
movq %r15, 0xd8(%rbx)
movl %r13d, 0xd4(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq