// File: /workspace/github_c_makefile_star2_O1/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)
jne 0x392dd
movq (%r12), %rdi
addq $0x8, %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x343ed
testq %rax, %rax
je 0x3941d
movq $-0x4, %rcx
movl $0x0, 0x4(%rax,%rcx)
addq $0x4, %rcx
cmpq $0xfc, %rcx
jb 0x392ba
movq %rax, 0x20(%r12)
movl $0x20, 0x3c(%r12)
movl 0x3c(%r12), %r13d
leal -0x1(%r13), %eax
andl (%rbx), %eax
movq 0x20(%r12), %rcx
movq (%rcx,%rax,8), %rdx
movq %rdx, 0x70(%rbx)
movq (%rcx,%rax,8), %rdx
testq %rdx, %rdx
je 0x39302
movq %rbx, 0x78(%rdx)
movq %rbx, (%rcx,%rax,8)
leaq 0x28(%r12), %rax
cmpq $0x0, 0x30(%r12)
je 0x39325
movq (%rax), %rcx
testq %rcx, %rcx
je 0x39330
movq %rcx, 0x60(%rbx)
addq $0x68, %rcx
jmp 0x3932d
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 %ebx, %ebx
orb %cl, %al
jne 0x39422
movq (%r12), %rdi
addq $0x8, %rdi
movl %r13d, %r15d
shll $0x4, %r15d
movl %r15d, %esi
callq 0x343ed
testq %rax, %rax
je 0x39422
movq %rax, %r14
testl %r15d, %r15d
je 0x393bb
movl %r15d, %ecx
movq %r14, %rax
addq %rcx, %rax
movq %r14, %rcx
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x393bb
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x393bb
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x393bb
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jb 0x3938f
addl %r13d, %r13d
movl 0x38(%r12), %eax
testl %eax, %eax
je 0x393ff
leaq 0x28(%r12), %rcx
leal -0x1(%r13), %edx
xorps %xmm0, %xmm0
movq (%rcx), %rcx
movups %xmm0, 0x70(%rcx)
movl (%rcx), %esi
andl %edx, %esi
movq (%r14,%rsi,8), %rdi
movq %rdi, 0x70(%rcx)
movq (%r14,%rsi,8), %rdi
testq %rdi, %rdi
je 0x393f3
movq %rcx, 0x78(%rdi)
movq %rcx, (%r14,%rsi,8)
addq $0x60, %rcx
decl %eax
jne 0x393d3
movq (%r12), %rdi
movq 0x20(%r12), %rsi
addq $0x8, %rdi
callq 0x3503f
movq %r14, 0x20(%r12)
movl %r13d, 0x3c(%r12)
jmp 0x39422
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq