// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: pager_has_hot_journal
static int pager_has_hot_journal(Pager *pPager, int *pExists)
{
  unqlite_vfs *pVfs = pPager->pVfs;
  int rc = UNQLITE_OK;           /* Return code */
  int exists = 1;               /* True if a journal file is present */

  *pExists = 0;
  rc = unqliteOsAccess(pVfs, pPager->zJournal, UNQLITE_ACCESS_EXISTS, &exists);
  if( rc==UNQLITE_OK && exists ){
    int locked = 0;             /* True if some process holds a RESERVED lock */

    /* Race condition here:  Another process might have been holding the
    ** the RESERVED lock and have a journal open at the unqliteOsAccess() 
    ** call above, but then delete the journal and drop the lock before
    ** we get to the following unqliteOsCheckReservedLock() call.  If that
    ** is the case, this routine might think there is a hot journal when
    ** in fact there is none.  This results in a false-positive which will
    ** be dealt with by the playback routine.
    */
    rc = unqliteOsCheckReservedLock(pPager->pfd, &locked);
    if( rc==UNQLITE_OK && !locked ){
      sxi64 n = 0;                    /* Size of db file in bytes */
 
      /* Check the size of the database file. If it consists of 0 pages,
      ** then delete the journal file. See the header comment above for 
      ** the reasoning here.  Delete the obsolete journal file under
      ** a RESERVED lock to avoid race conditions.
      */
      rc = unqliteOsFileSize(pPager->pfd,&n);
      if( rc==UNQLITE_OK ){
        if( n < 1 ){
          if( pager_lock_db(pPager, RESERVED_LOCK)==UNQLITE_OK ){
            unqliteOsDelete(pVfs, pPager->zJournal, 0);
			pager_unlock_db(pPager, SHARED_LOCK);
          }
        }else{
          /* The journal file exists and no other connection has a reserved
          ** or greater lock on the database file. */
			*pExists = 1;
        }
      }
    }
  }
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x1, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
xorl %edx, %edx
leaq -0x20(%rbp), %rcx
callq 0x69840
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x695c8
cmpl $0x0, -0x20(%rbp)
je 0x695c8
movl $0x0, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
leaq -0x24(%rbp), %rsi
callq 0x69880
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x695c6
cmpl $0x0, -0x24(%rbp)
jne 0x695c6
movq $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x698b0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x695c4
cmpq $0x1, -0x30(%rbp)
jge 0x695b8
movq -0x8(%rbp), %rdi
movl $0x2, %esi
callq 0x69410
cmpl $0x0, %eax
jne 0x695b6
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
xorl %edx, %edx
callq 0x69810
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x693c0
jmp 0x695c2
movq -0x10(%rbp), %rax
movl $0x1, (%rax)
jmp 0x695c4
jmp 0x695c6
jmp 0x695c8
movl -0x1c(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)