// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl 0x1f0(%rdi), %eax
xorl %ebx, %ebx
cmpl $0x2, %eax
jl 0x32ec0
movq %rdi, %r14
cmpl $0x0, 0x1fc(%rdi)
jne 0x32ec0
cmpl $0x0, 0x200(%r14)
je 0x32c3b
movq 0x8(%r14), %rdi
leaq 0x45112(%rip), %rsi     # 0x77d3e
callq 0x31537
movl $0xffffffb5, %ebx       # imm = 0xFFFFFFB5
jmp 0x32ec0
cmpl $0x2, %eax
jne 0x32c74
cmpl $0x0, 0x1f4(%r14)
je 0x32c64
movq 0x30(%r14), %rdi
movq (%rdi), %rax
movl $0x1, %esi
callq *0x40(%rax)
movl $0x1, 0x1f4(%r14)
movl $0x1, 0x1f0(%r14)
jmp 0x32ec0
movl %esi, %r12d
cmpl $0x0, 0x204(%r14)
je 0x32e57
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdi
movl $0x1, %edx
callq *0x20(%rdi)
movq 0x10(%r14), %r15
movq 0x48(%r14), %rax
movq 0x228(%r14), %rsi
andb $-0x4, 0x1f8(%r14)
movq $0x0, 0x170(%r14)
movl $0x0, 0x60(%r14)
movq %rax, 0x40(%r14)
testq %rsi, %rsi
je 0x32ce0
movq 0x28(%rsi), %r13
andb $-0x6f, 0x20(%rsi)
movq %r14, %rdi
callq 0x3bdf4
movq %r13, %rsi
testq %r13, %r13
jne 0x32cc8
movl $0x0, 0x254(%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x218(%r14)
movups %xmm0, 0x228(%r14)
movups %xmm0, 0x234(%r14)
movq 0x248(%r14), %rax
testq %rax, %rax
je 0x32d4f
movl 0x250(%r14), %ecx
shll $0x3, %ecx
testl %ecx, %ecx
je 0x32d4f
addq %rax, %rcx
movb $0x0, (%rax)
incq %rax
cmpq %rcx, %rax
jae 0x32d4f
movb $0x0, (%rax)
incq %rax
cmpq %rcx, %rax
jae 0x32d4f
movb $0x0, (%rax)
incq %rax
cmpq %rcx, %rax
jae 0x32d4f
movb $0x0, (%rax)
incq %rax
cmpq %rcx, %rax
jb 0x32d23
movq 0x198(%r14), %rdi
testq %rdi, %rdi
je 0x32d6b
callq 0x3c009
movq $0x0, 0x198(%r14)
cmpl $0x0, 0x1f4(%r14)
je 0x32d8f
movq 0x30(%r14), %rdi
movq (%rdi), %rax
movl $0x1, %esi
callq *0x40(%rax)
movl $0x1, 0x1f4(%r14)
movl $0x1, 0x1f0(%r14)
testl %r12d, %r12d
je 0x32ec0
movq (%r15), %r12
movq 0x8(%r12), %rcx
movq 0x20(%rcx), %rax
testq %rax, %rax
je 0x32dbe
movq %r15, %rdi
callq *%rax
movq 0x8(%r12), %rcx
movl 0x8(%rcx), %eax
testq %rax, %rax
je 0x32dfd
addq %r15, %rax
movq %r15, %rcx
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x32df8
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x32df8
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x32df8
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jb 0x32dcc
movq 0x8(%r12), %rcx
movq %r12, (%r15)
movq 0x18(%rcx), %rax
testq %rax, %rax
je 0x32e1e
movl 0x208(%r14), %esi
movq %r15, %rdi
callq *%rax
testl %eax, %eax
jne 0x32e3c
movq 0x8(%r12), %rcx
movq 0x30(%rcx), %rax
testq %rax, %rax
je 0x32ec0
movq 0x40(%r14), %rsi
movq %r15, %rdi
callq *%rax
testl %eax, %eax
je 0x32ec0
movl %eax, %ebx
movq 0x8(%r14), %rdi
orl $0x1, 0x10c(%rdi)
leaq 0x44f73(%rip), %rsi     # 0x77dc3
callq 0x31537
jmp 0x32ec0
movq 0x38(%r14), %rdi
testq %rdi, %rdi
je 0x32e8b
movq (%rdi), %rax
movl $0x2, %esi
callq *0x28(%rax)
movq 0x38(%r14), %r15
testq %r15, %r15
je 0x32e8b
movq (%r14), %r13
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
movq %r13, %rdi
movq %r15, %rsi
callq 0x3490d
movq $0x0, 0x38(%r14)
testb $0x3, 0x1f8(%r14)
je 0x32c85
movq %r14, %rdi
xorl %esi, %esi
callq 0x3b4bd
testl %eax, %eax
je 0x32c85
movq 0x8(%r14), %rcx
orl $0x1, 0x10c(%rcx)
movl %eax, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq