// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movq %rdi, %rbx
testl %esi, %esi
je 0x3bedd
movq 0x28(%rbx), %r14
leaq -0x40(%rbp), %rcx
movl $0x1, (%rcx)
movq 0x20(%rbx), %rsi
xorl %r12d, %r12d
movq %r14, %rdi
xorl %edx, %edx
callq *0x28(%r14)
movl %eax, %r15d
testl %eax, %eax
jne 0x3becb
cmpl $0x0, -0x40(%rbp)
je 0x3becb
leaq -0x4c(%rbp), %r12
movl $0x0, (%r12)
movq 0x30(%rbx), %rdi
movq (%rdi), %rax
movq %r12, %rsi
callq *0x48(%rax)
movl %eax, %r15d
movl (%r12), %eax
orl %r15d, %eax
jne 0x3bec8
leaq -0x48(%rbp), %rsi
movq $0x0, (%rsi)
movq 0x30(%rbx), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
movl %eax, %r15d
testl %eax, %eax
je 0x3bf6f
xorl %r12d, %r12d
testb %r12b, %r12b
je 0x3c115
testl %r15d, %r15d
jne 0x3c115
cmpl $0x0, 0x200(%rbx)
je 0x3bf07
movq 0x8(%rbx), %rdi
movq 0x20(%rbx), %rdx
leaq 0x39c46(%rip), %rsi     # 0x75b3b
xorl %eax, %eax
callq 0x3ac51
movl $0xffffffb5, %r15d      # imm = 0xFFFFFFB5
jmp 0x3c115
movq 0x28(%rbx), %rdi
movq (%rbx), %rsi
movq 0x20(%rbx), %rdx
leaq 0x38(%rbx), %r14
movq %r14, %rcx
movl $0x2, %r8d
callq 0x3bd28
testl %eax, %eax
je 0x3bf46
movl %eax, %r15d
movq 0x8(%rbx), %rdi
movq 0x20(%rbx), %rdx
leaq 0x39c46(%rip), %rsi     # 0x75b80
xorl %eax, %eax
callq 0x3ac51
jmp 0x3c0d9
movq %rbx, %rdi
movl $0x4, %esi
callq 0x3c3e0
testl %eax, %eax
je 0x3bfcd
movl %eax, %r15d
movq 0x8(%rbx), %rdi
leaq 0x39c45(%rip), %rsi     # 0x75baa
callq 0x31af5
jmp 0x3c0d9
movb $0x1, %r12b
cmpq $0x0, -0x48(%rbp)
jg 0x3becb
movq %rbx, %rdi
movl $0x2, %esi
callq 0x3c3e0
testl %eax, %eax
jne 0x3bec8
movq 0x20(%rbx), %rsi
xorl %r12d, %r12d
movq %r14, %rdi
xorl %edx, %edx
callq *0x20(%r14)
cmpl $0x0, 0x1f4(%rbx)
je 0x3becb
movq 0x30(%rbx), %rdi
movq (%rdi), %rax
movl $0x1, %esi
callq *0x40(%rax)
movl $0x1, 0x1f4(%rbx)
jmp 0x3bec8
movq 0x38(%rbx), %rdi
movq (%rdi), %rax
movl $0x2, %esi
callq *0x28(%rax)
leaq 0x40(%rbx), %r12
movq 0x38(%rbx), %rdi
movq (%rdi), %rax
leaq -0x40(%rbp), %rsi
callq *0x30(%rax)
movl $0xffffffe4, %r15d      # imm = 0xFFFFFFE4
testl %eax, %eax
jne 0x3c039
cmpq $0x20, -0x40(%rbp)
jl 0x3c039
movq (%r14), %rdi
movq (%rdi), %rax
leaq -0x48(%rbp), %rsi
movl $0x8, %edx
xorl %ecx, %ecx
callq *0x10(%rax)
testl %eax, %eax
je 0x3c01c
movl %eax, %r15d
jmp 0x3c039
leaq 0x38ba3(%rip), %rsi     # 0x74bc6
leaq -0x48(%rbp), %rdi
movl $0x8, %edx
callq 0x34ebe
testl %eax, %eax
je 0x3c2c2
cmpl $-0x1c, %r15d
je 0x3c077
testl %r15d, %r15d
jne 0x3c0a1
movq 0x30(%rbx), %rdi
movslq 0x208(%rbx), %rsi
imulq 0x40(%rbx), %rsi
movq (%rdi), %rax
callq *0x20(%rax)
testl %eax, %eax
je 0x3c127
movl %eax, %r15d
movq 0x8(%rbx), %rdi
leaq 0x39bb2(%rip), %rsi     # 0x75c22
callq 0x31af5
jmp 0x3c0b7
xorl %esi, %esi
movq (%rbx), %rdi
callq 0x3503f
testl %r15d, %r15d
jne 0x3c095
movq 0x30(%rbx), %rdi
movq (%rdi), %rax
movl $0x3, %esi
callq *0x28(%rax)
xorl %eax, %eax
cmpl $-0x1c, %r15d
cmovel %eax, %r15d
jmp 0x3c0b7
movq 0x8(%rbx), %rdi
movq 0x20(%rbx), %rdx
leaq 0x39b42(%rip), %rsi     # 0x75bf2
xorl %eax, %eax
callq 0x3ac51
cmpl $0x0, 0x1f4(%rbx)
je 0x3c0d9
movq 0x30(%rbx), %rdi
movq (%rdi), %rax
movl $0x1, %esi
callq *0x40(%rax)
movl $0x1, 0x1f4(%rbx)
movq (%r14), %r12
testq %r12, %r12
je 0x3c0f9
movq (%rbx), %r13
movq (%r12), %rax
movq %r12, %rdi
callq *0x8(%rax)
movq %r13, %rdi
movq %r12, %rsi
callq 0x3503f
movq $0x0, (%r14)
testl %r15d, %r15d
jne 0x3c115
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdi
movl $0x1, %edx
callq *0x20(%rdi)
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rdi
movl 0x208(%rbx), %esi
callq 0x343ed
movq %rax, -0x30(%rbp)
testq %rax, %rax
je 0x3c3a7
movl 0x208(%rbx), %ecx
testq %rcx, %rcx
je 0x3c186
movq -0x30(%rbp), %rdx
movq %rdx, %rax
addq %rcx, %rax
movq %rdx, %rcx
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x3c186
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x3c186
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x3c186
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jb 0x3c15a
movl -0x54(%rbp), %eax
movl %eax, -0x50(%rbp)
testl %eax, %eax
je 0x3c3c2
movq %r12, -0x60(%rbp)
movq 0x170(%rbx), %r12
xorl %r13d, %r13d
movq (%r14), %rdi
leaq -0x48(%rbp), %rsi
movq %r12, %rdx
callq 0x3c470
testl %eax, %eax
je 0x3c1ba
movl %eax, %r15d
jmp 0x3c203
movq %r12, -0x38(%rbp)
addq $0x8, %r12
movq 0x38(%rbx), %rdi
movslq 0x208(%rbx), %rdx
movq (%rdi), %rax
movq -0x30(%rbp), %rsi
movq %r12, %rcx
callq *0x10(%rax)
testl %eax, %eax
jne 0x3c1fc
movslq 0x208(%rbx), %rax
addq %rax, %r12
movq 0x38(%rbx), %rdi
leaq -0x40(%rbp), %rsi
movq %r12, %rdx
callq 0x3c441
testl %eax, %eax
je 0x3c220
movl %eax, %r15d
movq -0x38(%rbp), %r12
cmpl $-0x3f, %r15d
je 0x3c212
testl %r15d, %r15d
jne 0x3c3c7
incl %r13d
cmpl -0x50(%rbp), %r13d
jne 0x3c1a2
jmp 0x3c3d7
movl 0x168(%rbx), %eax
movslq 0x208(%rbx), %rdx
cmpq $0xc9, %rdx
jl 0x3c260
leaq 0xc8(%rdx), %rcx
movq -0x30(%rbp), %rdi
movq %r12, %r8
movzbl -0x190(%rdi,%rcx), %esi
addl %esi, %eax
addq $-0xc8, %rcx
cmpq $0x190, %rcx            # imm = 0x190
jg 0x3c244
jmp 0x3c263
movq %r12, %r8
addq $0x4, %r8
movl $0xffffffc1, %r15d      # imm = 0xFFFFFFC1
cmpl %eax, -0x40(%rbp)
jne 0x3c2ba
movq -0x48(%rbp), %r12
xorl %r15d, %r15d
movq -0x60(%rbp), %rax
cmpq (%rax), %r12
jae 0x3c2ba
movq %r8, -0x38(%rbp)
movq 0x30(%rbx), %rdi
movq %r12, %rcx
imulq %rdx, %rcx
movq (%rdi), %rax
movq -0x30(%rbp), %rsi
callq *0x18(%rax)
movl %eax, %r15d
testl %eax, %eax
jne 0x3c1ff
movq %rbx, %rdi
movq %r12, %rsi
movq -0x30(%rbp), %rdx
callq 0x3c4a2
jmp 0x3c1ff
movq %r8, %r12
jmp 0x3c203
movq (%r14), %rdi
leaq -0x54(%rbp), %rsi
movl $0x8, %edx
callq 0x3c441
testl %eax, %eax
jne 0x3c017
movq 0x38(%rbx), %rdi
leaq 0x168(%rbx), %rsi
movl $0xc, %edx
callq 0x3c441
testl %eax, %eax
jne 0x3c017
movq (%r14), %rdi
movl $0x10, %edx
movq %r12, %rsi
callq 0x3c470
testl %eax, %eax
jne 0x3c017
movq (%r14), %rdi
leaq -0x58(%rbp), %rsi
movl $0x18, %edx
callq 0x3c441
testl %eax, %eax
jne 0x3c017
movq (%r14), %rdi
leaq -0x4c(%rbp), %rsi
movl $0x1c, %edx
callq 0x3c441
testl %eax, %eax
jne 0x3c017
movl -0x4c(%rbp), %eax
movl -0x58(%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 0x3c039
leal 0x1ffff(%rax), %edx
testl %eax, %edx
jne 0x3c039
leal 0x1ffff(%rcx), %edx
testl %ecx, %edx
jne 0x3c039
movl %ecx, %edx
movl %ecx, 0x20c(%rbx)
movl %eax, 0x208(%rbx)
movq %rdx, 0x170(%rbx)
xorl %r15d, %r15d
jmp 0x3c039
movq 0x8(%rbx), %rdi
leaq 0x3961c(%rip), %rsi     # 0x759ce
callq 0x31af5
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x3c0b7
xorl %r15d, %r15d
jmp 0x3c3d7
movq 0x8(%rbx), %rdi
leaq 0x39878(%rip), %rsi     # 0x75c4a
callq 0x31af5
movq -0x30(%rbp), %rsi
jmp 0x3c079