// File: /workspace/github_c_makefile_star2_O1/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 0x3e3b3
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)
movq (%rax,%rcx,8), %rdx
testq %rdx, %rdx
je 0x3e698
movq %r14, 0x138(%rdx)
movq %r14, (%rax,%rcx,8)
movq 0xd0(%rbx), %rax
testq %rax, %rax
je 0x3e6b6
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 0x3e7b8
leaq 0x8(%rbx), %r14
movl %r13d, %r12d
shll $0x4, %r12d
movq %r14, %rdi
movl %r12d, %esi
callq 0x343ed
testq %rax, %rax
je 0x3e7b8
movq %rax, %r15
testl %r12d, %r12d
je 0x3e747
movl %r12d, %ecx
movq %r15, %rax
addq %rcx, %rax
movq %r15, %rcx
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x3e747
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x3e747
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x3e747
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jb 0x3e71b
addl %r13d, %r13d
movl 0xd8(%rbx), %eax
testl %eax, %eax
je 0x3e79b
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)
movq (%r15,%rsi,8), %rdi
testq %rdi, %rdi
je 0x3e78c
movq %rcx, 0x138(%rdi)
movq %rcx, (%r15,%rsi,8)
addq $0x120, %rcx            # imm = 0x120
decl %eax
jne 0x3e762
movq 0xc8(%rbx), %rsi
movq %r14, %rdi
callq 0x3503f
movq %r15, 0xc8(%rbx)
movl %r13d, 0xdc(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq