// File: /workspace/github_c_makefile_star2_O3/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: unqliteVmInstallCollection
static int unqliteVmInstallCollection(
	unqlite_vm *pVm,  /* Target VM */
	unqlite_col *pCol /* Collection to install */
	)
{
	SyString *pName = &pCol->sName;
	sxu32 iBucket;
	/* Hash the collection name */
	pCol->nHash = SyBinHash((const void *)pName->zString,pName->nByte);
	/* Install it in the corresponding bucket */
	iBucket = pCol->nHash & (pVm->iColSize - 1);
	pCol->pNextCol = pVm->apCol[iBucket];
	if( pVm->apCol[iBucket] ){
		pVm->apCol[iBucket]->pPrevCol = pCol;
	}
	pVm->apCol[iBucket] = pCol;
	/* Link to the list of active collections */
	MACRO_LD_PUSH(pVm->pCol,pCol);
	pVm->iCol++;
	if( (pVm->iCol >= pVm->iColSize * 4) && pVm->iCol < 10000 ){
		/* Grow the hashtable */
		sxu32 nNewSize = pVm->iColSize << 1;
		unqlite_col *pEntry;
		unqlite_col **apNew;
		sxu32 n;
		
		apNew = (unqlite_col **)SyMemBackendAlloc(&pVm->sAlloc, nNewSize * sizeof(unqlite_col *));
		if( apNew ){
			/* Zero the new table */
			SyZero((void *)apNew, nNewSize * sizeof(unqlite_col *));
			/* Rehash all entries */
			n = 0;
			pEntry = pVm->pCol;
			for(;;){
				/* Loop one */
				if( n >= pVm->iCol ){
					break;
				}
				pEntry->pNextCol = pEntry->pPrevCol = 0;
				/* Install in the new bucket */
				iBucket = pEntry->nHash & (nNewSize - 1);
				pEntry->pNextCol = apNew[iBucket];
				if( apNew[iBucket]  ){
					apNew[iBucket]->pPrevCol = pEntry;
				}
				apNew[iBucket] = pEntry;
				/* Point to the next entry */
				pEntry = pEntry->pNext;
				n++;
			}
			/* Release the old table and reflect the change */
			SyMemBackendFree(&pVm->sAlloc,(void *)pVm->apCol);
			pVm->apCol = apNew;
			pVm->iColSize  = nNewSize;
		}
	}
	return UNQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movq 0x8(%rsi), %rdi
movl 0x10(%rsi), %esi
callq 0x3d9e9
movl %eax, 0x18(%r14)
movl 0xdc(%rbx), %r13d
leal -0x1(%r13), %ecx
andl %eax, %ecx
movq 0xc8(%rbx), %rax
movq (%rax,%rcx,8), %rdx
movq %rdx, 0x130(%r14)
testq %rdx, %rdx
je 0x3dc9c
movq %r14, 0x138(%rdx)
movq %r14, (%rax,%rcx,8)
movq 0xd0(%rbx), %rax
testq %rax, %rax
je 0x3dcba
movq %rax, 0x120(%r14)
movq %r14, 0x128(%rax)
movq %r14, 0xd0(%rbx)
movl 0xd8(%rbx), %eax
incl %eax
movl %eax, 0xd8(%rbx)
leal (,%r13,4), %ecx
cmpl %ecx, %eax
setb %cl
cmpl $0x2710, %eax           # imm = 0x2710
setae %al
orb %cl, %al
jne 0x3ddb8
leaq 0x8(%rbx), %r14
movl %r13d, %r12d
shll $0x4, %r12d
movq %r14, %rdi
movl %r12d, %esi
callq 0x33d86
testq %rax, %rax
je 0x3ddb8
movq %rax, %r15
testl %r12d, %r12d
je 0x3dd4b
movl %r12d, %ecx
movq %r15, %rax
addq %rcx, %rax
movq %r15, %rcx
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x3dd4b
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x3dd4b
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x3dd4b
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jb 0x3dd1f
addl %r13d, %r13d
movl 0xd8(%rbx), %eax
testl %eax, %eax
je 0x3dd9b
leaq 0xd0(%rbx), %rcx
leal -0x1(%r13), %edx
xorps %xmm0, %xmm0
movq (%rcx), %rcx
movups %xmm0, 0x130(%rcx)
movl 0x18(%rcx), %esi
andl %edx, %esi
movq (%r15,%rsi,8), %rdi
movq %rdi, 0x130(%rcx)
testq %rdi, %rdi
je 0x3dd8c
movq %rcx, 0x138(%rdi)
movq %rcx, (%r15,%rsi,8)
addq $0x120, %rcx            # imm = 0x120
decl %eax
jne 0x3dd66
movq 0xc8(%rbx), %rsi
movq %r14, %rdi
callq 0x3490d
movq %r15, 0xc8(%rbx)
movl %r13d, 0xdc(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq