// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: lhMapInstallBucket
static int lhMapInstallBucket(lhash_kv_engine *pEngine,pgno iLogic,pgno iReal)
{
	lhash_bmap_rec *pRec;
	sxu32 iBucket;
	/* Allocate a new instance */
	pRec = (lhash_bmap_rec *)SyMemBackendPoolAlloc(&pEngine->sAllocator,sizeof(lhash_bmap_rec));
	if( pRec == 0 ){
		return UNQLITE_NOMEM;
	}
	/* Zero the structure */
	SyZero(pRec,sizeof(lhash_bmap_rec));
	/* Fill in the structure */
	pRec->iLogic = iLogic;
	pRec->iReal = iReal;
	iBucket = iLogic & (pEngine->nBuckSize - 1);
	pRec->pNextCol = pEngine->apMap[iBucket];
	if( pEngine->apMap[iBucket] ){
		pEngine->apMap[iBucket]->pPrevCol = pRec;
	}
	pEngine->apMap[iBucket] = pRec;
	/* Link */
	if( pEngine->pFirst == 0 ){
		pEngine->pFirst = pEngine->pList = pRec;
	}else{
		MACRO_LD_PUSH(pEngine->pList,pRec);
	}
	pEngine->nBuckRec++;
	if( (pEngine->nBuckRec >= pEngine->nBuckSize * 3) && pEngine->nBuckRec < 100000 ){
		/* Allocate a new larger table */
		sxu32 nNewSize = pEngine->nBuckSize << 1;
		lhash_bmap_rec *pEntry;
		lhash_bmap_rec **apNew;
		sxu32 n;
		
		apNew = (lhash_bmap_rec **)SyMemBackendAlloc(&pEngine->sAllocator, nNewSize * sizeof(lhash_bmap_rec *));
		if( apNew ){
			/* Zero the new table */
			SyZero((void *)apNew, nNewSize * sizeof(lhash_bmap_rec *));
			/* Rehash all entries */
			n = 0;
			pEntry = pEngine->pList;
			for(;;){
				/* Loop one */
				if( n >= pEngine->nBuckRec ){
					break;
				}
				pEntry->pNextCol = pEntry->pPrevCol = 0;
				/* Install in the new bucket */
				iBucket = pEntry->iLogic & (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(&pEngine->sAllocator,(void *)pEngine->apMap);
			pEngine->apMap = apNew;
			pEngine->nBuckSize  = nNewSize;
		}
	}
	return UNQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
movl $0x30, %esi
callq 0x541f0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x61fbd
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x62255
movq -0x28(%rbp), %rdi
movl $0x30, %esi
callq 0x54280
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0xe4(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
andq %rcx, %rax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq 0xd8(%rax), %rax
movl -0x2c(%rbp), %ecx
movq (%rax,%rcx,8), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0xd8(%rax), %rax
movl -0x2c(%rbp), %ecx
cmpq $0x0, (%rax,%rcx,8)
je 0x62044
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0xd8(%rax), %rax
movl -0x2c(%rbp), %edx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x28(%rax)
movq -0x28(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0xd8(%rax), %rax
movl -0x2c(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
cmpq $0x0, 0xf0(%rax)
jne 0x62084
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xe8(%rax)
movq -0x10(%rbp), %rax
movq %rcx, 0xf0(%rax)
jmp 0x620da
movq -0x10(%rbp), %rax
cmpq $0x0, 0xe8(%rax)
jne 0x620a3
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xe8(%rax)
jmp 0x620d8
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rax
movq %rcx, 0x18(%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xe8(%rax)
jmp 0x620da
movq -0x10(%rbp), %rax
movl 0xe0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xe0(%rax)
movq -0x10(%rbp), %rax
movl 0xe0(%rax), %eax
movq -0x10(%rbp), %rcx
imull $0x3, 0xe4(%rcx), %ecx
cmpl %ecx, %eax
jb 0x6224e
movq -0x10(%rbp), %rax
cmpl $0x186a0, 0xe0(%rax)    # imm = 0x186A0
jae 0x6224e
movq -0x10(%rbp), %rax
movl 0xe4(%rax), %eax
shll %eax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
movl -0x30(%rbp), %eax
shlq $0x3, %rax
movl %eax, %esi
callq 0x5bf70
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x6224c
movq -0x40(%rbp), %rdi
movl -0x30(%rbp), %eax
shlq $0x3, %rax
movl %eax, %esi
callq 0x54280
movl $0x0, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rax
movq %rax, -0x38(%rbp)
movl -0x44(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xe0(%rcx), %eax
jb 0x6218e
jmp 0x62218
movq -0x38(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl -0x30(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
andq %rcx, %rax
movl %eax, -0x2c(%rbp)
movq -0x40(%rbp), %rax
movl -0x2c(%rbp), %ecx
movq (%rax,%rcx,8), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x40(%rbp), %rax
movl -0x2c(%rbp), %ecx
cmpq $0x0, (%rax,%rcx,8)
je 0x621ef
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %rax
movl -0x2c(%rbp), %edx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x28(%rax)
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rax
movl -0x2c(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x6217a
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
movq -0x10(%rbp), %rax
movq 0xd8(%rax), %rsi
callq 0x5d6b0
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xd8(%rax)
movl -0x30(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xe4(%rax)
jmp 0x6224e
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop