// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: lhInstallCell
static int lhInstallCell(lhcell *pCell)
{
	lhpage *pPage = pCell->pPage->pMaster;
	sxu32 iBucket;
	if( pPage->nCell < 1 ){
		sxu32 nTableSize = 32; /* Must be a power of two */
		lhcell **apTable;
		/* Allocate a new cell table */
		apTable = (lhcell **)SyMemBackendAlloc(&pPage->pHash->sAllocator, nTableSize * sizeof(lhcell *));
		if( apTable == 0 ){
			return UNQLITE_NOMEM;
		}
		/* Zero the new table */
		SyZero((void *)apTable, nTableSize * sizeof(lhcell *));
		/* Install it */
		pPage->apCell = apTable;
		pPage->nCellSize = nTableSize;
	}
	iBucket = pCell->nHash & (pPage->nCellSize - 1);
	pCell->pNextCol = pPage->apCell[iBucket];
	if( pPage->apCell[iBucket] ){
		pPage->apCell[iBucket]->pPrevCol = pCell;
	}
	pPage->apCell[iBucket] = pCell;
	if( pPage->pFirst == 0 ){
		pPage->pFirst = pPage->pList = pCell;
	}else{
		MACRO_LD_PUSH(pPage->pList,pCell);
	}
	pPage->nCell++;
	if( (pPage->nCell >= pPage->nCellSize * 3) && pPage->nCell < 100000 ){
		/* Allocate a new larger table */
		sxu32 nNewSize = pPage->nCellSize << 1;
		lhcell *pEntry;
		lhcell **apNew;
		sxu32 n;
		
		apNew = (lhcell **)SyMemBackendAlloc(&pPage->pHash->sAllocator, nNewSize * sizeof(lhcell *));
		if( apNew ){
			/* Zero the new table */
			SyZero((void *)apNew, nNewSize * sizeof(lhcell *));
			/* Rehash all entries */
			n = 0;
			pEntry = pPage->pList;
			for(;;){
				/* Loop one */
				if( n >= pPage->nCell ){
					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(&pPage->pHash->sAllocator,(void *)pPage->apCell);
			pPage->apCell = apNew;
			pPage->nCellSize  = 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
movq 0x20(%rdi), %rax
movq 0x40(%rax), %r12
cmpl $0x0, 0x38(%r12)
je 0x3120f
movl 0x3c(%r12), %r13d
movq 0x20(%r12), %r14
jmp 0x3124c
movq (%r12), %rdi
addq $0x8, %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x2ca19
testq %rax, %rax
je 0x3134a
movq %rax, %r14
movq %rax, %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x27aea
movq %r14, 0x20(%r12)
movl $0x20, 0x3c(%r12)
pushq $0x20
popq %r13
leal -0x1(%r13), %eax
andl (%rbx), %eax
movq (%r14,%rax,8), %rcx
movq %rcx, 0x70(%rbx)
testq %rcx, %rcx
je 0x31263
movq %rbx, 0x78(%rcx)
movq %rbx, (%r14,%rax,8)
leaq 0x28(%r12), %rax
cmpq $0x0, 0x30(%r12)
je 0x31286
movq (%rax), %rcx
testq %rcx, %rcx
je 0x31291
movq %rcx, 0x60(%rbx)
addq $0x68, %rcx
jmp 0x3128e
movq %rax, %rcx
leaq 0x30(%r12), %rax
movq %rbx, (%rcx)
movq %rbx, (%rax)
movl 0x38(%r12), %eax
incl %eax
movl %eax, 0x38(%r12)
leal (%r13,%r13,2), %ecx
cmpl %ecx, %eax
setb %cl
cmpl $0x186a0, %eax          # imm = 0x186A0
setae %al
xorl %r14d, %r14d
orb %cl, %al
jne 0x3134e
movq (%r12), %rdi
addq $0x8, %rdi
movl %r13d, %r15d
shll $0x4, %r15d
movl %r15d, %esi
callq 0x2ca19
testq %rax, %rax
je 0x3134e
movq %rax, %rbx
addl %r13d, %r13d
movq %rax, %rdi
movl %r15d, %esi
callq 0x27aea
leaq 0x28(%r12), %rax
movl 0x38(%r12), %ecx
leal -0x1(%r13), %edx
xorl %esi, %esi
xorps %xmm0, %xmm0
cmpl %ecx, %esi
jae 0x31329
movq (%rax), %rax
movups %xmm0, 0x70(%rax)
movl (%rax), %edi
andl %edx, %edi
movq (%rbx,%rdi,8), %r8
movq %r8, 0x70(%rax)
testq %r8, %r8
je 0x3131d
movq %rax, 0x78(%r8)
movq %rax, (%rbx,%rdi,8)
addq $0x60, %rax
incl %esi
jmp 0x312fd
movq (%r12), %rdi
movq 0x20(%r12), %rsi
addq $0x8, %rdi
callq 0x2d420
movq %rbx, 0x20(%r12)
movl %r13d, 0x3c(%r12)
xorl %r14d, %r14d
jmp 0x3134e
pushq $-0x1
popq %r14
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq