// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/sqlite-3.33.0/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 */

      assert( pPager->tempFile==0 );
      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
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x1, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
cmpq $0x0, (%rax)
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
cmpl $0x0, -0x24(%rbp)
jne 0x3e7161
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0xd8(%rax), %rsi
xorl %edx, %edx
leaq -0x20(%rbp), %rcx
callq 0x3e36f0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x3e72d1
cmpl $0x0, -0x20(%rbp)
je 0x3e72d1
movl $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x3e74f0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x3e72cf
cmpl $0x0, -0x28(%rbp)
jne 0x3e72cf
movq -0x8(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x3e7430
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x3e72cd
cmpl $0x0, -0x2c(%rbp)
jne 0x3e721c
cmpl $0x0, -0x24(%rbp)
jne 0x3e721c
callq 0x3e01d0
movq -0x8(%rbp), %rdi
movl $0x2, %esi
callq 0x3e0740
cmpl $0x0, %eax
jne 0x3e7212
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0xd8(%rax), %rsi
xorl %edx, %edx
callq 0x3e3c10
movq -0x8(%rbp), %rax
cmpb $0x0, 0x8(%rax)
jne 0x3e7210
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x3e3fb0
jmp 0x3e7212
callq 0x3e0220
jmp 0x3e72cb
cmpl $0x0, -0x24(%rbp)
jne 0x3e724f
movl $0x801, -0x30(%rbp)     # imm = 0x801
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0xd8(%rax), %rsi
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rdx
movl -0x30(%rbp), %ecx
leaq -0x30(%rbp), %r8
callq 0x3dbb90
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x3e72b0
movb $0x0, -0x31(%rbp)
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rdi
leaq -0x31(%rbp), %rsi
movl $0x1, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x3dfc00
movl %eax, -0x1c(%rbp)
cmpl $0x20a, -0x1c(%rbp)     # imm = 0x20A
jne 0x3e7286
movl $0x0, -0x1c(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x3e7299
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rdi
callq 0x3dbe40
movzbl -0x31(%rbp), %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
jmp 0x3e72c9
cmpl $0xe, -0x1c(%rbp)
jne 0x3e72c7
movq -0x10(%rbp), %rax
movl $0x1, (%rax)
movl $0x0, -0x1c(%rbp)
jmp 0x3e72c9
jmp 0x3e72cb
jmp 0x3e72cd
jmp 0x3e72cf
jmp 0x3e72d1
movl -0x1c(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)