// File: /workspace/github_c_makefile_star2_O1/shifengbin[P]bishe/Output/../Persistence/sqlite3.c
// Function: hasHotJournal
static int hasHotJournal(Pager *pPager, int *pExists){
  sqlite3_vfs * const pVfs = pPager->pVfs;
  int rc = SQLITE_OK;           /* Return code */
  int exists = 1;               /* True if a journal file is present */
  int jrnlOpen = !!isOpen(pPager->jfd);

  assert( pPager->useJournal );
  assert( isOpen(pPager->fd) );
  assert( pPager->eState==PAGER_OPEN );

  assert( jrnlOpen==0 || ( sqlite3OsDeviceCharacteristics(pPager->jfd) &
    SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
  ));

  *pExists = 0;
  if( !jrnlOpen ){
    rc = sqlite3OsAccess(pVfs, pPager->zJournal, SQLITE_ACCESS_EXISTS, &exists);
  }
  if( rc==SQLITE_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 sqlite3OsAccess() 
    ** call above, but then delete the journal and drop the lock before
    ** we get to the following sqlite3OsCheckReservedLock() 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.  Ticket #3883.
    */
    rc = sqlite3OsCheckReservedLock(pPager->fd, &locked);
    if( rc==SQLITE_OK && !locked ){
      Pgno nPage;                 /* Number of pages in database file */

      rc = pagerPagecount(pPager, &nPage);
      if( rc==SQLITE_OK ){
        /* If the database is zero pages in size, that means that either (1) the
        ** journal is a remnant from a prior database with the same name where
        ** the database file but not the journal was deleted, or (2) the initial
        ** transaction that populates a new database is being rolled back.
        ** In either case, the journal file can be deleted.  However, take care
        ** not to delete the journal file if it is already open due to
        ** journal_mode=PERSIST.
        */
        if( nPage==0 && !jrnlOpen ){
          sqlite3BeginBenignMalloc();
          if( pagerLockDb(pPager, RESERVED_LOCK)==SQLITE_OK ){
            sqlite3OsDelete(pVfs, pPager->zJournal, 0);
            if( !pPager->exclusiveMode ) pagerUnlockDb(pPager, SHARED_LOCK);
          }
          sqlite3EndBenignMalloc();
        }else{
          /* The journal file exists and no other connection has a reserved
          ** or greater lock on the database file. Now check that there is
          ** at least one non-zero bytes at the start of the journal file.
          ** If there is, then we consider this journal to be hot. If not, 
          ** it can be ignored.
          */
          if( !jrnlOpen ){
            int f = SQLITE_OPEN_READONLY|SQLITE_OPEN_MAIN_JOURNAL;
            rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, f, &f);
          }
          if( rc==SQLITE_OK ){
            u8 first = 0;
            rc = sqlite3OsRead(pPager->jfd, (void *)&first, 1, 0);
            if( rc==SQLITE_IOERR_SHORT_READ ){
              rc = SQLITE_OK;
            }
            if( !jrnlOpen ){
              sqlite3OsClose(pPager->jfd);
            }
            *pExists = (first!=0);
          }else if( rc==SQLITE_CANTOPEN ){
            /* If we cannot open the rollback journal file in order to see if
            ** it has a zero header, that might be due to an I/O error, or
            ** it might be due to the race condition described above and in
            ** ticket #3883.  Either way, assume that the journal is hot.
            ** This might be a false positive.  But if it is, then the
            ** automatic journal playback and recovery mechanism will deal
            ** with it under an EXCLUSIVE lock where we do not need to
            ** worry so much with race conditions.
            */
            *pExists = 1;
            rc = SQLITE_OK;
          }
        }
      }
    }
  }

  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r13
movq %rdi, %rbx
movq (%rdi), %r15
movl $0x1, -0x30(%rbp)
movq 0x50(%rdi), %rax
movq (%rax), %r14
xorl %r12d, %r12d
movl $0x0, (%rsi)
testq %r14, %r14
jne 0x25aca
movq 0xd8(%rbx), %rsi
leaq -0x30(%rbp), %rcx
movq %r15, %rdi
xorl %edx, %edx
callq *0x38(%r15)
movl %eax, %r12d
testl %r12d, %r12d
jne 0x25b0e
cmpl $0x0, -0x30(%rbp)
je 0x25b0e
movq %r13, -0x40(%rbp)
leaq -0x44(%rbp), %r13
movl $0x0, (%r13)
movq 0x48(%rbx), %rdi
movq (%rdi), %rax
movq %r13, %rsi
callq *0x48(%rax)
movl %eax, %r12d
orl (%r13), %eax
jne 0x25b0e
leaq -0x34(%rbp), %rsi
movq %rbx, %rdi
callq 0x25c4f
movl %eax, %r12d
testl %eax, %eax
je 0x25b20
movl %r12d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r14, %r14
jne 0x25b77
cmpl $0x0, -0x34(%rbp)
jne 0x25b77
movq 0x6f9a6(%rip), %rax     # 0x954d8
testq %rax, %rax
je 0x25b39
callq *%rax
movq %rbx, %rdi
movl $0x2, %esi
callq 0x21c14
testl %eax, %eax
jne 0x25b64
movq 0xd8(%rbx), %rsi
movq %r15, %rdi
xorl %edx, %edx
callq *0x30(%r15)
cmpb $0x0, 0x8(%rbx)
je 0x25c1e
movq 0x6f975(%rip), %rax     # 0x954e0
xorl %r12d, %r12d
testq %rax, %rax
je 0x25b0e
callq *%rax
jmp 0x25b0e
xorl %r12d, %r12d
testq %r14, %r14
jne 0x25ba4
leaq -0x2c(%rbp), %r8
movl $0x801, (%r8)           # imm = 0x801
movq 0x50(%rbx), %rdx
movq 0xd8(%rbx), %rsi
movq %r15, %rdi
movl $0x801, %ecx            # imm = 0x801
callq *0x28(%r15)
movl %eax, %r12d
cmpl $0xe, %r12d
je 0x25c0c
testl %r12d, %r12d
jne 0x25b0e
leaq -0x2c(%rbp), %rsi
movb $0x0, (%rsi)
movq 0x50(%rbx), %rdi
movq (%rdi), %rax
xorl %r15d, %r15d
movl $0x1, %edx
xorl %ecx, %ecx
callq *0x10(%rax)
movl %eax, %r12d
cmpl $0x20a, %eax            # imm = 0x20A
cmovel %r15d, %r12d
testq %r14, %r14
jne 0x25bf8
movq 0x50(%rbx), %rbx
movq (%rbx), %rax
testq %rax, %rax
je 0x25bf8
movq %rbx, %rdi
callq *0x8(%rax)
movq $0x0, (%rbx)
xorl %eax, %eax
cmpb $0x0, -0x2c(%rbp)
setne %al
movq -0x40(%rbp), %rcx
movl %eax, (%rcx)
jmp 0x25b0e
movq -0x40(%rbp), %rax
movl $0x1, (%rax)
xorl %r12d, %r12d
jmp 0x25b0e
movq 0x48(%rbx), %rdi
movq (%rdi), %rax
testq %rax, %rax
je 0x25b64
cmpb $0x0, 0x11(%rbx)
jne 0x25c3c
movl $0x1, %esi
callq *0x40(%rax)
cmpb $0x5, 0x15(%rbx)
je 0x25b64
movb $0x1, 0x15(%rbx)
jmp 0x25b64