// File: /workspace/github_c_makefile_star2_O0/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
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x68f71
movl $0x0, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0x694d0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x68f5d
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x6909a
cmpl $0x0, -0x1c(%rbp)
jne 0x68f6f
movl $0x0, -0x4(%rbp)
jmp 0x6909a
jmp 0x68f71
movq -0x10(%rbp), %rax
cmpl $0x0, 0x200(%rax)
je 0x68fa8
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
leaq 0x5907f(%rip), %rsi     # 0xc2014
movb $0x0, %al
callq 0x68100
movl $0xffffffb5, -0x4(%rbp) # imm = 0xFFFFFFB5
jmp 0x6909a
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
movq -0x10(%rbp), %rcx
addq $0x38, %rcx
movl $0x2, %r8d
callq 0x68de0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x68ffb
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
leaq 0x59067(%rip), %rsi     # 0xc2059
movb $0x0, %al
callq 0x68100
jmp 0x69054
movq -0x10(%rbp), %rdi
movl $0x4, %esi
callq 0x69410
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x69028
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x59062(%rip), %rsi     # 0xc2083
callq 0x58950
jmp 0x69054
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movl $0x2, %esi
callq 0x695e0
movq -0x10(%rbp), %rdi
callq 0x69610
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x693c0
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)
cmpl $0x0, -0x18(%rbp)
jne 0x69094
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
movl $0x1, %edx
callq 0x69810
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)