// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: pager_reset_state
static int pager_reset_state(Pager *pPager,int bResetKvEngine)
{
	unqlite_kv_engine *pEngine = pPager->pEngine;
	Page *pNext,*pPtr = pPager->pAll;
	const unqlite_kv_io *pIo;
	int rc;
	/* Remove stale flags */
	pPager->iFlags &= ~(PAGER_CTRL_COMMIT_ERR|PAGER_CTRL_DIRTY_COMMIT);
	pPager->iJournalOfft = 0;
	pPager->nRec = 0;
	/* Database original size */
	pPager->dbSize = pPager->dbOrigSize;
	/* Discard all in-memory pages */
	for(;;){
		if( pPtr == 0 ){
			break;
		}
		pNext = pPtr->pNext; /* Reverse link */
		/* Remove stale flags */
		pPtr->flags &= ~(PAGE_DIRTY|PAGE_DONT_WRITE|PAGE_NEED_SYNC|PAGE_IN_JOURNAL|PAGE_HOT_DIRTY);
		/* Release the page */
		pager_release_page(pPager,pPtr);
		/* Point to the next page */
		pPtr = pNext;
	}
	pPager->pAll = 0;
	pPager->nPage = 0;
	pPager->pDirty = pPager->pFirstDirty = 0;
	pPager->pHotDirty = pPager->pFirstHot = 0;
	pPager->nHot = 0;
	if( pPager->apHash ){
		/* Zero the table */
		SyZero((void *)pPager->apHash,sizeof(Page *) * pPager->nSize);
	}
	if( pPager->pVec ){
		unqliteBitvecDestroy(pPager->pVec);
		pPager->pVec = 0;
	}
	/* Switch back to shared lock */
	pager_unlock_db(pPager,SHARED_LOCK);
	pPager->iState = PAGER_READER;
	if( bResetKvEngine ){
		/* Reset the underlying KV engine */
		pIo = pEngine->pIo;
		if( pIo->pMethods->xRelease ){
			/* Call the release callback */
			pIo->pMethods->xRelease(pEngine);
		}
		/* Zero the structure */
		SyZero(pEngine,(sxu32)pIo->pMethods->szKv);
		/* Fill in */
		pEngine->pIo = pIo;
		if( pIo->pMethods->xInit ){
			/* Call the init method */
			rc = pIo->pMethods->xInit(pEngine,pPager->iPageSize);
			if( rc != UNQLITE_OK ){
				return rc;
			}
		}
		if( pIo->pMethods->xOpen ){
			/* Call the xOpen method */
			rc = pIo->pMethods->xOpen(pEngine,pPager->dbSize);
			if( rc != UNQLITE_OK ){
				return rc;
			}
		}
	}
	/* All done */
	return UNQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x228(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0x1f8(%rax), %ecx
andl $-0x4, %ecx
movl %ecx, 0x1f8(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x170(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x60(%rax)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
cmpq $0x0, -0x30(%rbp)
jne 0xae950
jmp 0xae980
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
movl 0x20(%rax), %ecx
andl $-0x6f, %ecx
movl %ecx, 0x20(%rax)
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x6af80
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0xae947
movq -0x10(%rbp), %rax
movq $0x0, 0x228(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x254(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x218(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x220(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x238(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x230(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x240(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x248(%rax)
je 0xaea15
movq -0x10(%rbp), %rax
movq 0x248(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x250(%rax), %eax
shlq $0x3, %rax
movl %eax, %esi
callq 0x54280
movq -0x10(%rbp), %rax
cmpq $0x0, 0x198(%rax)
je 0xaea42
movq -0x10(%rbp), %rax
movq 0x198(%rax), %rdi
callq 0x6bb80
movq -0x10(%rbp), %rax
movq $0x0, 0x198(%rax)
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x693c0
movq -0x10(%rbp), %rax
movl $0x1, 0x1f0(%rax)
cmpl $0x0, -0x14(%rbp)
je 0xaeb2f
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
cmpq $0x0, 0x20(%rax)
je 0xaea94
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rdi
callq *%rax
movq -0x20(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x8(%rax), %esi
callq 0x54280
movq -0x38(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
cmpq $0x0, 0x18(%rax)
je 0xaeaf1
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl 0x208(%rcx), %esi
callq *%rax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0xaeaef
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xaeb36
jmp 0xaeaf1
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
cmpq $0x0, 0x30(%rax)
je 0xaeb2d
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x30(%rax), %rax
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rcx
movq 0x40(%rcx), %rsi
callq *%rax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0xaeb2b
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xaeb36
jmp 0xaeb2d
jmp 0xaeb2f
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop