// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: unqlitePagerRollback
UNQLITE_PRIVATE int unqlitePagerRollback(Pager *pPager,int bResetKvEngine)
{
	int rc = UNQLITE_OK;
	if( pPager->iState < PAGER_WRITER_LOCKED ){
		/* A write transaction must be opened */
		return UNQLITE_OK;
	}
	if( pPager->is_mem ){
		/* As of this release 1.1.6: Transactions are not supported for in-memory databases */
		return UNQLITE_OK;
	}
	if( pPager->is_rdonly ){
		/* Read-Only DB */
		unqliteGenError(pPager->pDb,"Read-Only database");
		return UNQLITE_READ_ONLY;
	}
	if( pPager->iState >= PAGER_WRITER_CACHEMOD ){
		if( !pPager->no_jrnl ){
			/* Close any outstanding joural file */
			if( pPager->pjfd ){
				/* Sync the journal file */
				unqliteOsSync(pPager->pjfd,UNQLITE_SYNC_NORMAL);
			}
			unqliteOsCloseFree(pPager->pAllocator,pPager->pjfd);
			pPager->pjfd = 0;
			if( pPager->iFlags & (PAGER_CTRL_COMMIT_ERR|PAGER_CTRL_DIRTY_COMMIT) ){
				/* Perform the rollback */
				rc = pager_journal_rollback(pPager,0);
				if( rc != UNQLITE_OK ){
					/* Set the auto-commit flag */
					pPager->pDb->iFlags |= UNQLITE_FL_DISABLE_AUTO_COMMIT;
					return rc;
				}
			}
		}
		/* Unlink the journal file */
		unqliteOsDelete(pPager->pVfs,pPager->zJournal,1);
		/* Reset the pager state */
		rc = pager_reset_state(pPager,bResetKvEngine);
		if( rc != UNQLITE_OK ){
			/* Mostly an unlikely scenario */
			pPager->pDb->iFlags |= UNQLITE_FL_DISABLE_AUTO_COMMIT; /* Set the auto-commit flag */
			unqliteGenError(pPager->pDb,"Error while reseting pager to its initial state");
			return rc;
		}
	}else{
		/* Downgrade to shared lock */
		pager_unlock_db(pPager,SHARED_LOCK);
		pPager->iState = PAGER_READER;
	}
	return UNQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x2, 0x1f0(%rax)
jge 0x5a29f
movl $0x0, -0x4(%rbp)
jmp 0x5a417
movq -0x10(%rbp), %rax
cmpl $0x0, 0x1fc(%rax)
je 0x5a2b8
movl $0x0, -0x4(%rbp)
jmp 0x5a417
movq -0x10(%rbp), %rax
cmpl $0x0, 0x200(%rax)
je 0x5a2e5
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x6bf43(%rip), %rsi     # 0xc6217
callq 0x58950
movl $0xffffffb5, -0x4(%rbp) # imm = 0xFFFFFFB5
jmp 0x5a417
movq -0x10(%rbp), %rax
cmpl $0x3, 0x1f0(%rax)
jl 0x5a3f4
movq -0x10(%rbp), %rax
cmpl $0x0, 0x204(%rax)
jne 0x5a390
movq -0x10(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x5a324
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movl $0x2, %esi
callq 0x695e0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
callq 0x697c0
movq -0x10(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x10(%rbp), %rax
movl 0x1f8(%rax), %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0x5a38e
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x68f20
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x5a38c
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x10c(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x10c(%rax)
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5a417
jmp 0x5a38e
jmp 0x5a390
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
movl $0x1, %edx
callq 0x69810
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0xae8e0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x5a3f2
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x10c(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x10c(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x6beb7(%rip), %rsi     # 0xc629c
callq 0x58950
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5a417
jmp 0x5a410
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x693c0
movq -0x10(%rbp), %rax
movl $0x1, 0x1f0(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq