// File: /workspace/github_c_makefile_star2_O3/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: pager_link_page
static int pager_link_page(Pager *pPager,Page *pPage)
{
	sxu32 nBucket;
	/* Install in the corresponding bucket */
	nBucket = PAGE_HASH(pPage->iPage) & (pPager->nSize - 1);
	pPage->pNextCollide = pPager->apHash[nBucket];
	if( pPager->apHash[nBucket] ){
		pPager->apHash[nBucket]->pPrevCollide = pPage;
	}
	pPager->apHash[nBucket] = pPage;
	/* Link to the list of active pages */
	MACRO_LD_PUSH(pPager->pAll,pPage);
	pPager->nPage++;
	if( (pPager->nPage >= pPager->nSize * 4)  && pPager->nPage < 100000 ){
		/* Grow the hashtable */
		sxu32 nNewSize = pPager->nSize << 1;
		Page *pEntry,**apNew;
		sxu32 n;
		apNew = (Page **)SyMemBackendAlloc(pPager->pAllocator, nNewSize * sizeof(Page *));
		if( apNew ){
			sxu32 iBucket;
			/* Zero the new table */
			SyZero((void *)apNew, nNewSize * sizeof(Page *));
			/* Rehash all entries */
			n = 0;
			pEntry = pPager->pAll;
			for(;;){
				/* Loop one */
				if( n >= pPager->nPage ){
					break;
				}
				pEntry->pNextCollide = pEntry->pPrevCollide = 0;
				/* Install in the new bucket */
				iBucket = PAGE_HASH(pEntry->iPage) & (nNewSize - 1);
				pEntry->pNextCollide = apNew[iBucket];
				if( apNew[iBucket] ){
					apNew[iBucket]->pPrevCollide = pEntry;
				}
				apNew[iBucket] = pEntry;
				/* Point to the next entry */
				pEntry = pEntry->pNext;
				n++;
			}
			/* Release the old table and reflect the change */
			SyMemBackendFree(pPager->pAllocator,(void *)pPager->apHash);
			pPager->apHash = apNew;
			pPager->nSize  = nNewSize;
		}
	}
	return UNQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
movl 0x250(%rdi), %r12d
leal -0x1(%r12), %eax
andl 0x10(%rsi), %eax
movq 0x248(%rdi), %rcx
movq (%rcx,%rax,8), %rdx
movq %rdx, 0x48(%rsi)
testq %rdx, %rdx
je 0x3b299
movq %rsi, 0x50(%rdx)
movq %rsi, (%rcx,%rax,8)
movq 0x228(%rbx), %rax
testq %rax, %rax
je 0x3b2b1
movq %rax, 0x28(%rsi)
movq %rsi, 0x30(%rax)
movq %rsi, 0x228(%rbx)
movl 0x254(%rbx), %eax
incl %eax
movl %eax, 0x254(%rbx)
leal (,%r12,4), %ecx
cmpl %ecx, %eax
setb %cl
cmpl $0x186a0, %eax          # imm = 0x186A0
setae %al
orb %cl, %al
jne 0x3b3a0
movq (%rbx), %rdi
movl %r12d, %r15d
shll $0x4, %r15d
movl %r15d, %esi
callq 0x33d86
testq %rax, %rax
je 0x3b3a0
movq %rax, %r14
testl %r15d, %r15d
je 0x3b33e
movl %r15d, %ecx
movq %r14, %rax
addq %rcx, %rax
movq %r14, %rcx
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x3b33e
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x3b33e
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x3b33e
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jb 0x3b312
addl %r12d, %r12d
movl 0x254(%rbx), %eax
testl %eax, %eax
je 0x3b383
leaq 0x228(%rbx), %rcx
leal -0x1(%r12), %edx
xorps %xmm0, %xmm0
movq (%rcx), %rcx
movups %xmm0, 0x48(%rcx)
movl 0x10(%rcx), %esi
andl %edx, %esi
movq (%r14,%rsi,8), %rdi
movq %rdi, 0x48(%rcx)
testq %rdi, %rdi
je 0x3b377
movq %rcx, 0x50(%rdi)
movq %rcx, (%r14,%rsi,8)
addq $0x28, %rcx
decl %eax
jne 0x3b35a
movq (%rbx), %rdi
movq 0x248(%rbx), %rsi
callq 0x3490d
movq %r14, 0x248(%rbx)
movl %r12d, 0x250(%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq