// File: /workspace/github_c_makefile_star2_O0/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
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movl 0x8(%rax), %esi
callq 0x6d960
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x8(%rbp), %rcx
movl 0xdc(%rcx), %ecx
subl $0x1, %ecx
andl %ecx, %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x130(%rax)
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rax
movl -0x1c(%rbp), %ecx
cmpq $0x0, (%rax,%rcx,8)
je 0x6df80
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rax
movl -0x1c(%rbp), %edx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x138(%rax)
movq -0x10(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rax
movl -0x1c(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
cmpq $0x0, 0xd0(%rax)
jne 0x6dfb5
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0xd0(%rax)
jmp 0x6dff0
movq -0x8(%rbp), %rax
movq 0xd0(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x120(%rax)
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq 0xd0(%rax), %rax
movq %rcx, 0x128(%rax)
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0xd0(%rax)
movq -0x8(%rbp), %rax
movl 0xd8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xd8(%rax)
movq -0x8(%rbp), %rax
movl 0xd8(%rax), %eax
movq -0x8(%rbp), %rcx
movl 0xdc(%rcx), %ecx
shll $0x2, %ecx
cmpl %ecx, %eax
jb 0x6e172
movq -0x8(%rbp), %rax
cmpl $0x2710, 0xd8(%rax)     # imm = 0x2710
jae 0x6e172
movq -0x8(%rbp), %rax
movl 0xdc(%rax), %eax
shll %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
movl -0x20(%rbp), %eax
shlq $0x3, %rax
movl %eax, %esi
callq 0x5bf70
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x6e170
movq -0x30(%rbp), %rdi
movl -0x20(%rbp), %eax
shlq $0x3, %rax
movl %eax, %esi
callq 0x54280
movl $0x0, -0x34(%rbp)
movq -0x8(%rbp), %rax
movq 0xd0(%rax), %rax
movq %rax, -0x28(%rbp)
movl -0x34(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0xd8(%rcx), %eax
jb 0x6e0a6
jmp 0x6e13c
movq -0x28(%rbp), %rax
movq $0x0, 0x138(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x130(%rax)
movq -0x28(%rbp), %rax
movl 0x18(%rax), %eax
movl -0x20(%rbp), %ecx
subl $0x1, %ecx
andl %ecx, %eax
movl %eax, -0x1c(%rbp)
movq -0x30(%rbp), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x130(%rax)
movq -0x30(%rbp), %rax
movl -0x1c(%rbp), %ecx
cmpq $0x0, (%rax,%rcx,8)
je 0x6e110
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movl -0x1c(%rbp), %edx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x138(%rax)
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rax
movl -0x1c(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
movq 0x120(%rax), %rax
movq %rax, -0x28(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x6e092
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rsi
callq 0x5d6b0
movq -0x30(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0xc8(%rax)
movl -0x20(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xdc(%rax)
jmp 0x6e172
xorl %eax, %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)