// File: /workspace/github_c_makefile_star2_O3/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: pager_journal_rollback
static int pager_journal_rollback(Pager *pPager,int check_hot)
{
	int rc;
	if( check_hot ){
		int iExists = 0; /* cc warning */
		/* Check if the journal file exists */
		rc = pager_has_hot_journal(pPager,&iExists);
		if( rc != UNQLITE_OK  ){
			/* IO error */
			return rc;
		}
		if( !iExists ){
			/* Journal file does not exists */
			return UNQLITE_OK;
		}
	}
	if( pPager->is_rdonly ){
		unqliteGenErrorFormat(pPager->pDb,
			"Cannot rollback journal file '%s' due to a read-only database handle",pPager->zJournal);
		return UNQLITE_READ_ONLY;
	}
	/* Get an EXCLUSIVE lock on the database file. At this point it is
      ** important that a RESERVED lock is not obtained on the way to the
      ** EXCLUSIVE lock. If it were, another process might open the
      ** database file, detect the RESERVED lock, and conclude that the
      ** database is safe to read while this process is still rolling the 
      ** hot-journal back.
      ** 
      ** Because the intermediate RESERVED lock is not requested, any
      ** other process attempting to access the database file will get to 
      ** this point in the code and fail to obtain its own EXCLUSIVE lock 
      ** on the database file.
      **
      ** Unless the pager is in locking_mode=exclusive mode, the lock is
      ** downgraded to SHARED_LOCK before this function returns.
      */
	/* Open the journal file */
	rc = unqliteOsOpen(pPager->pVfs,pPager->pAllocator,pPager->zJournal,&pPager->pjfd,UNQLITE_OPEN_READWRITE);
	if( rc != UNQLITE_OK ){
		unqliteGenErrorFormat(pPager->pDb,"IO error while opening journal file: '%s'",pPager->zJournal);
		goto fail;
	}
	rc = pager_lock_db(pPager,EXCLUSIVE_LOCK);
	if( rc != UNQLITE_OK ){
		unqliteGenError(pPager->pDb,"Cannot acquire an exclusive lock on the database while journal rollback");
		goto fail;
	}
	/* Sync the journal file */
	unqliteOsSync(pPager->pjfd,UNQLITE_SYNC_NORMAL);
	/* Finally rollback the database */
	rc = pager_playback(pPager);
	/* Switch back to shared lock */
	pager_unlock_db(pPager,SHARED_LOCK);
fail:
	/* Close the journal handle */
	unqliteOsCloseFree(pPager->pAllocator,pPager->pjfd);
	pPager->pjfd = 0;
	if( rc == UNQLITE_OK ){
		/* Delete the journal file */
		unqliteOsDelete(pPager->pVfs,pPager->zJournal,TRUE);
	}
	return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
testl %esi, %esi
je 0x3b577
movq 0x28(%rbx), %r14
leaq -0x48(%rbp), %rcx
movl $0x1, (%rcx)
movl $0x0, -0x2c(%rbp)
movq 0x20(%rbx), %rsi
movq %r14, %rdi
xorl %edx, %edx
callq *0x28(%r14)
movl %eax, %r12d
testl %eax, %eax
jne 0x3b72f
cmpl $0x0, -0x48(%rbp)
je 0x3b72f
leaq -0x58(%rbp), %r15
movl $0x0, (%r15)
movq 0x30(%rbx), %rdi
movq (%rdi), %rax
movq %r15, %rsi
callq *0x48(%rax)
movl %eax, %r12d
movl (%r15), %eax
orl %r12d, %eax
jne 0x3b72f
leaq -0x50(%rbp), %rsi
movq $0x0, (%rsi)
movq 0x30(%rbx), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
movl %eax, %r12d
testl %eax, %eax
jne 0x3b72f
cmpq $0x0, -0x50(%rbp)
jle 0x3b609
leaq -0x2c(%rbp), %r14
movl $0x1, (%r14)
cmpl $0x0, -0x2c(%rbp)
je 0x3b72c
cmpl $0x0, 0x200(%rbx)
je 0x3b5a1
movq 0x8(%rbx), %rdi
movq 0x20(%rbx), %rdx
leaq 0x385b4(%rip), %rsi     # 0x73b43
xorl %eax, %eax
callq 0x3a376
movl $0xffffffb5, %r12d      # imm = 0xFFFFFFB5
jmp 0x3b72f
movq 0x28(%rbx), %rdi
movq (%rbx), %rsi
movq 0x20(%rbx), %rdx
leaq 0x38(%rbx), %r14
movq %r14, %rcx
movl $0x2, %r8d
callq 0x3b3a9
testl %eax, %eax
je 0x3b5e0
movl %eax, %r12d
movq 0x8(%rbx), %rdi
movq 0x20(%rbx), %rdx
leaq 0x385b4(%rip), %rsi     # 0x73b88
xorl %eax, %eax
callq 0x3a376
jmp 0x3b6f1
movq %rbx, %rdi
movl $0x4, %esi
callq 0x3ba70
testl %eax, %eax
je 0x3b653
movl %eax, %r12d
movq 0x8(%rbx), %rdi
leaq 0x385b3(%rip), %rsi     # 0x73bb2
callq 0x31537
jmp 0x3b6f1
movq %rbx, %rdi
movl $0x2, %esi
callq 0x3ba70
testl %eax, %eax
jne 0x3b72f
movq 0x20(%rbx), %rsi
movq %r14, %rdi
xorl %edx, %edx
callq *0x20(%r14)
cmpl $0x0, 0x1f4(%rbx)
je 0x3b72f
leaq 0x1f4(%rbx), %r14
movq 0x30(%rbx), %rdi
movq (%rdi), %rax
movl $0x1, %esi
callq *0x40(%rax)
jmp 0x3b566
movq 0x38(%rbx), %rdi
movq (%rdi), %rax
movl $0x2, %esi
callq *0x28(%rax)
movq 0x38(%rbx), %rdi
movq (%rdi), %rax
leaq -0x48(%rbp), %rsi
callq *0x30(%rax)
testl %eax, %eax
jne 0x3b6cc
cmpq $0x20, -0x48(%rbp)
jl 0x3b6cc
movq (%r14), %rdi
movq (%rdi), %rax
leaq -0x50(%rbp), %rsi
movl $0x8, %edx
xorl %ecx, %ecx
callq *0x10(%rax)
testl %eax, %eax
je 0x3b6b3
movl %eax, %r12d
cmpl $-0x1c, %eax
je 0x3b6cc
movq 0x8(%rbx), %rdi
movq 0x20(%rbx), %rdx
leaq 0x38550(%rip), %rsi     # 0x73bfa
xorl %eax, %eax
callq 0x3a376
jmp 0x3b6cf
leaq 0x37518(%rip), %rsi     # 0x72bd2
leaq -0x50(%rbp), %rdi
movl $0x8, %edx
callq 0x347f1
testl %eax, %eax
je 0x3b741
xorl %r12d, %r12d
cmpl $0x0, 0x1f4(%rbx)
je 0x3b6f1
movq 0x30(%rbx), %rdi
movq (%rdi), %rax
movl $0x1, %esi
callq *0x40(%rax)
movl $0x1, 0x1f4(%rbx)
movq (%r14), %r15
testq %r15, %r15
je 0x3b710
movq (%rbx), %r13
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
movq %r13, %rdi
movq %r15, %rsi
callq 0x3490d
movq $0x0, (%r14)
testl %r12d, %r12d
jne 0x3b72f
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdi
movl $0x1, %edx
callq *0x20(%rdi)
xorl %r12d, %r12d
movl %r12d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r14), %rdi
leaq -0x68(%rbp), %rsi
movl $0x8, %edx
callq 0x3bad1
testl %eax, %eax
jne 0x3b693
movq 0x38(%rbx), %rdi
leaq 0x168(%rbx), %rsi
movl $0xc, %edx
callq 0x3bad1
testl %eax, %eax
jne 0x3b693
leaq 0x40(%rbx), %r15
movq (%r14), %rdi
movl $0x10, %edx
movq %r15, %rsi
callq 0x3bafe
testl %eax, %eax
jne 0x3b693
movq (%r14), %rdi
leaq -0x2c(%rbp), %rsi
movl $0x18, %edx
callq 0x3bad1
testl %eax, %eax
jne 0x3b693
movq (%r14), %rdi
leaq -0x58(%rbp), %rsi
movl $0x1c, %edx
callq 0x3bad1
testl %eax, %eax
jne 0x3b693
movl -0x58(%rbp), %eax
movl -0x2c(%rbp), %ecx
movl $0xfffeffff, %edx       # imm = 0xFFFEFFFF
leal (%rax,%rdx), %esi
cmpl $0xffff01ff, %esi       # imm = 0xFFFF01FF
setb %sil
addl %ecx, %edx
cmpl $0xffff001f, %edx       # imm = 0xFFFF001F
setb %dl
orb %sil, %dl
jne 0x3b6cc
leal 0x1ffff(%rax), %edx
testl %eax, %edx
jne 0x3b6cc
leal 0x1ffff(%rcx), %edx
testl %ecx, %edx
jne 0x3b6cc
movl %ecx, %edx
movl %ecx, 0x20c(%rbx)
movl %eax, 0x208(%rbx)
movq %rdx, 0x170(%rbx)
movq 0x30(%rbx), %rdi
movq 0x40(%rbx), %rsi
imulq %rax, %rsi
movq (%rdi), %rax
callq *0x20(%rax)
testl %eax, %eax
je 0x3b850
movl %eax, %r12d
movq 0x8(%rbx), %rdi
leaq 0x383e4(%rip), %rsi     # 0x73c2a
callq 0x31537
jmp 0x3b6cf
movq (%rbx), %rdi
movl 0x208(%rbx), %esi
callq 0x33d86
movq %rax, -0x38(%rbp)
testq %rax, %rax
je 0x3b9f0
movl 0x208(%rbx), %ecx
testq %rcx, %rcx
je 0x3b8af
movq -0x38(%rbp), %rdx
movq %rdx, %rax
addq %rcx, %rax
movq %rdx, %rcx
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x3b8af
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x3b8af
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x3b8af
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jb 0x3b883
movl -0x68(%rbp), %eax
movl %eax, -0x64(%rbp)
testl %eax, %eax
je 0x3ba0b
movq 0x170(%rbx), %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x54(%rbp)
movq (%r14), %rdi
leaq -0x50(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x3bafe
testl %eax, %eax
jne 0x3b929
movq -0x40(%rbp), %rax
leaq 0x8(%rax), %rcx
movq 0x38(%rbx), %rdi
movslq 0x208(%rbx), %rdx
movq (%rdi), %rax
movq -0x38(%rbp), %rsi
movq %rcx, %r12
callq *0x10(%rax)
testl %eax, %eax
jne 0x3b929
movslq 0x208(%rbx), %rax
movq %r12, %rdx
addq %rax, %rdx
movq 0x38(%rbx), %rdi
leaq -0x48(%rbp), %rsi
movq %rdx, -0x60(%rbp)
callq 0x3bad1
testl %eax, %eax
je 0x3b94e
movl %eax, %r13d
movl $0xffffffc1, %r12d      # imm = 0xFFFFFFC1
cmpl $-0x3f, %r13d
jne 0x3ba42
movl -0x54(%rbp), %eax
incl %eax
movl %eax, -0x54(%rbp)
cmpl -0x64(%rbp), %eax
jne 0x3b8cf
jmp 0x3ba19
movl 0x168(%rbx), %eax
movslq 0x208(%rbx), %rdx
cmpq $0xc9, %rdx
jl 0x3b989
leaq 0xc8(%rdx), %rcx
movq -0x38(%rbp), %rsi
movzbl -0x190(%rsi,%rcx), %esi
addl %esi, %eax
addq $-0xc8, %rcx
cmpq $0x190, %rcx            # imm = 0x190
ja 0x3b96b
addq $0x4, -0x60(%rbp)
movl $0xffffffc1, %r12d      # imm = 0xFFFFFFC1
cmpl %eax, -0x48(%rbp)
jne 0x3b9e3
movq -0x50(%rbp), %rax
xorl %r12d, %r12d
movq %rax, -0x40(%rbp)
cmpq (%r15), %rax
jae 0x3b9e3
movq 0x30(%rbx), %rdi
movq -0x40(%rbp), %rcx
imulq %rdx, %rcx
movq (%rdi), %rax
movq -0x38(%rbp), %rsi
callq *0x18(%rax)
testl %eax, %eax
je 0x3b9d3
movl %eax, %r13d
movq -0x60(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x3b92c
movq %rbx, %rdi
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x3bb2e
movq -0x60(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x3b93c
movq 0x8(%rbx), %rdi
leaq 0x37fdb(%rip), %rsi     # 0x739d6
callq 0x31537
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jmp 0x3b6cf
movq (%rbx), %rdi
movq -0x38(%rbp), %rsi
callq 0x3490d
jmp 0x3ba2e
movq (%rbx), %rdi
movq -0x38(%rbp), %rsi
callq 0x3490d
testl %r12d, %r12d
jne 0x3b6cf
movq 0x30(%rbx), %rdi
movq (%rdi), %rax
movl $0x3, %esi
callq *0x28(%rax)
jmp 0x3b6cc
movq 0x8(%rbx), %rdi
leaq 0x38205(%rip), %rsi     # 0x73c52
callq 0x31537
movq (%rbx), %rdi
movq -0x38(%rbp), %rsi
callq 0x3490d
movl %r13d, %r12d
cmpl $-0x1c, %r13d
je 0x3b6cc
jmp 0x3b6cf