// File: /workspace/github_c_makefile_star2_O2/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 0x337ae
movq 0x28(%rbx), %r14
leaq -0x48(%rbp), %rcx
movl $0x1, (%rcx)
movq 0x20(%rbx), %rsi
movq %r14, %rdi
xorl %edx, %edx
callq *0x28(%r14)
movl %eax, %r12d
testl %eax, %eax
jne 0x3393e
cmpl $0x0, -0x48(%rbp)
je 0x3393e
leaq -0x54(%rbp), %r15
andl $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 0x3393e
leaq -0x50(%rbp), %rsi
andq $0x0, (%rsi)
movq 0x30(%rbx), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
movl %eax, %r12d
testl %eax, %eax
jne 0x3393e
cmpq $0x0, -0x50(%rbp)
jle 0x3383a
cmpl $0x0, 0x200(%rbx)
je 0x337d6
movq 0x8(%rbx), %rdi
movq 0x20(%rbx), %rdx
leaq 0x3035d(%rip), %rsi     # 0x63b23
xorl %eax, %eax
callq 0x32836
pushq $-0x4b
popq %r12
jmp 0x3393e
movq 0x28(%rbx), %rdi
movq (%rbx), %rsi
movq 0x20(%rbx), %rdx
leaq 0x38(%rbx), %r14
pushq $0x2
popq %r8
movq %r14, %rcx
callq 0x33642
testl %eax, %eax
je 0x33813
movl %eax, %r12d
movq 0x8(%rbx), %rdi
movq 0x20(%rbx), %rdx
leaq 0x30361(%rip), %rsi     # 0x63b68
xorl %eax, %eax
callq 0x32836
jmp 0x33917
pushq $0x4
popq %rsi
movq %rbx, %rdi
callq 0x33bf8
testl %eax, %eax
je 0x3386a
movl %eax, %r12d
movq 0x8(%rbx), %rdi
leaq 0x30362(%rip), %rsi     # 0x63b92
callq 0x2a542
jmp 0x33917
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x33bf8
testl %eax, %eax
jne 0x3393e
movq 0x20(%rbx), %rsi
movq %r14, %rdi
xorl %edx, %edx
callq *0x20(%r14)
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x33bcd
jmp 0x3393e
movq 0x38(%rbx), %rdi
movq (%rdi), %rax
pushq $0x2
popq %rsi
callq *0x28(%rax)
movq 0x38(%rbx), %rdi
movq (%rdi), %rax
leaq -0x48(%rbp), %rsi
callq *0x30(%rax)
testl %eax, %eax
jne 0x338dd
cmpq $0x20, -0x48(%rbp)
jl 0x338dd
movq (%r14), %rdi
movq (%rdi), %rax
leaq -0x50(%rbp), %rsi
pushq $0x8
popq %rdx
xorl %ecx, %ecx
callq *0x10(%rax)
testl %eax, %eax
je 0x338c6
movl %eax, %r12d
cmpl $-0x1c, %eax
je 0x338dd
movq 0x8(%rbx), %rdi
movq 0x20(%rbx), %rdx
leaq 0x3031d(%rip), %rsi     # 0x63bda
xorl %eax, %eax
callq 0x32836
jmp 0x3390c
leaq 0x2f2e9(%rip), %rsi     # 0x62bb6
leaq -0x50(%rbp), %rdi
pushq $0x8
popq %rdx
callq 0x2d30e
testl %eax, %eax
je 0x33950
pushq $-0x1c
popq %r13
xorl %r12d, %r12d
movq (%rbx), %rdi
movq %r12, %rsi
callq 0x2d420
testl %r13d, %r13d
jne 0x33901
movq 0x30(%rbx), %rdi
movq (%rdi), %rax
pushq $0x3
popq %rsi
callq *0x28(%rax)
xorl %r12d, %r12d
cmpl $-0x1c, %r13d
cmovnel %r13d, %r12d
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x33bcd
movq (%rbx), %rdi
movq 0x38(%rbx), %rsi
callq 0x33c59
andq $0x0, 0x38(%rbx)
testl %r12d, %r12d
jne 0x3393e
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdi
pushq $0x1
popq %rdx
callq *0x20(%rdi)
xorl %r12d, %r12d
movl %r12d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r14), %rdi
leaq -0x5c(%rbp), %rsi
pushq $0x8
popq %rdx
callq 0x33c96
testl %eax, %eax
jne 0x338a6
movq 0x38(%rbx), %rdi
leaq 0x168(%rbx), %rsi
pushq $0xc
popq %rdx
callq 0x33c96
testl %eax, %eax
jne 0x338a6
leaq 0x40(%rbx), %r15
movq (%r14), %rdi
pushq $0x10
popq %rdx
movq %r15, %rsi
callq 0x33cc1
testl %eax, %eax
jne 0x338a6
movq (%r14), %rdi
leaq -0x60(%rbp), %rsi
pushq $0x18
popq %rdx
callq 0x33c96
testl %eax, %eax
jne 0x338a6
movq (%r14), %rdi
leaq -0x54(%rbp), %rsi
pushq $0x1c
popq %rdx
callq 0x33c96
testl %eax, %eax
jne 0x338a6
movl -0x54(%rbp), %eax
movl -0x60(%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 0x338dd
leal 0x1ffff(%rax), %edx
testl %eax, %edx
jne 0x338dd
leal 0x1ffff(%rcx), %edx
testl %ecx, %edx
jne 0x338dd
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 0x33a55
movl %eax, %r12d
movq 0x8(%rbx), %rdi
leaq 0x301bf(%rip), %rsi     # 0x63c0a
callq 0x2a542
jmp 0x3390c
movq (%rbx), %rdi
movl 0x208(%rbx), %esi
callq 0x2ca19
testq %rax, %rax
je 0x33b9d
movq %rax, %r12
movl 0x208(%rbx), %esi
movq %rax, %rdi
callq 0x27aea
movq 0x170(%rbx), %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x58(%rbp)
subl $0x1, -0x58(%rbp)
jb 0x33baf
movq (%r14), %rdi
leaq -0x50(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x33cc1
testl %eax, %eax
jne 0x33afa
movq -0x38(%rbp), %rax
leaq 0x8(%rax), %rcx
movq 0x38(%rbx), %rdi
movslq 0x208(%rbx), %rdx
movq (%rdi), %rax
movq %r12, %rsi
movq %rcx, -0x40(%rbp)
callq *0x10(%rax)
testl %eax, %eax
jne 0x33afa
movslq 0x208(%rbx), %rax
movq -0x40(%rbp), %rdx
addq %rax, %rdx
movq 0x38(%rbx), %rdi
leaq -0x48(%rbp), %rsi
movq %rdx, -0x40(%rbp)
callq 0x33c96
testl %eax, %eax
je 0x33b0e
movl %eax, %r13d
pushq $-0x3f
popq %rax
movl %eax, -0x2c(%rbp)
cmpl $-0x3f, %r13d
je 0x33a95
jmp 0x33bb8
addq $0x4, -0x40(%rbp)
movl -0x48(%rbp), %r13d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x33cfe
pushq $-0x3f
popq %rcx
movl %ecx, -0x2c(%rbp)
cmpl %eax, %r13d
jne 0x33b90
movq -0x50(%rbp), %rax
movl $0x0, -0x2c(%rbp)
movq %rax, -0x38(%rbp)
cmpq (%r15), %rax
jae 0x33b90
movq 0x30(%rbx), %rdi
movslq 0x208(%rbx), %rdx
movq -0x38(%rbp), %rcx
imulq %rdx, %rcx
movq (%rdi), %rax
movq %r12, %rsi
callq *0x18(%rax)
testl %eax, %eax
je 0x33b6e
movl %eax, %r13d
movq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x33afd
movq %rbx, %rdi
movq -0x38(%rbp), %rsi
callq 0x33485
testq %rax, %rax
je 0x33b90
movq (%rax), %rsi
movl 0x208(%rbx), %edx
movq %r12, %rdi
callq 0x2d3b0
movq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x33a95
movq 0x8(%rbx), %rdi
callq 0x32825
pushq $-0x1
popq %r12
jmp 0x3390c
movl -0x2c(%rbp), %r13d
jmp 0x338e4
movq 0x8(%rbx), %rdi
leaq 0x3006f(%rip), %rsi     # 0x63c32
callq 0x2a542
jmp 0x338e4