// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: sqlite3PagerSetJournalMode
SQLITE_PRIVATE int sqlite3PagerSetJournalMode(Pager *pPager, int eMode){
  u8 eOld = pPager->journalMode;    /* Prior journalmode */

  /* The eMode parameter is always valid */
  assert(      eMode==PAGER_JOURNALMODE_DELETE
            || eMode==PAGER_JOURNALMODE_TRUNCATE
            || eMode==PAGER_JOURNALMODE_PERSIST
            || eMode==PAGER_JOURNALMODE_OFF
            || eMode==PAGER_JOURNALMODE_WAL
            || eMode==PAGER_JOURNALMODE_MEMORY );

  /* This routine is only called from the OP_JournalMode opcode, and
  ** the logic there will never allow a temporary file to be changed
  ** to WAL mode.
  */
  assert( pPager->tempFile==0 || eMode!=PAGER_JOURNALMODE_WAL );

  /* Do allow the journalmode of an in-memory database to be set to
  ** anything other than MEMORY or OFF
  */
  if( MEMDB ){
    assert( eOld==PAGER_JOURNALMODE_MEMORY || eOld==PAGER_JOURNALMODE_OFF );
    if( eMode!=PAGER_JOURNALMODE_MEMORY && eMode!=PAGER_JOURNALMODE_OFF ){
      eMode = eOld;
    }
  }

  if( eMode!=eOld ){

    /* Change the journal mode. */
    assert( pPager->eState!=PAGER_ERROR );
    pPager->journalMode = (u8)eMode;

    /* When transistioning from TRUNCATE or PERSIST to any other journal
    ** mode except WAL, unless the pager is in locking_mode=exclusive mode,
    ** delete the journal file.
    */
    assert( (PAGER_JOURNALMODE_TRUNCATE & 5)==1 );
    assert( (PAGER_JOURNALMODE_PERSIST & 5)==1 );
    assert( (PAGER_JOURNALMODE_DELETE & 5)==0 );
    assert( (PAGER_JOURNALMODE_MEMORY & 5)==4 );
    assert( (PAGER_JOURNALMODE_OFF & 5)==0 );
    assert( (PAGER_JOURNALMODE_WAL & 5)==5 );

    assert( isOpen(pPager->fd) || pPager->exclusiveMode );
    if( !pPager->exclusiveMode && (eOld & 5)==1 && (eMode & 1)==0 ){

      /* In this case we would like to delete the journal file. If it is
      ** not possible, then that is not a problem. Deleting the journal file
      ** here is an optimization only.
      **
      ** Before deleting the journal file, obtain a RESERVED lock on the
      ** database file. This ensures that the journal file is not deleted
      ** while it is in use by some other client.
      */
      sqlite3OsClose(pPager->jfd);
      if( pPager->eLock>=RESERVED_LOCK ){
        sqlite3OsDelete(pPager->pVfs, pPager->zJournal, 0);
      }else{
        int rc = SQLITE_OK;
        int state = pPager->eState;
        assert( state==PAGER_OPEN || state==PAGER_READER );
        if( state==PAGER_OPEN ){
          rc = sqlite3PagerSharedLock(pPager);
        }
        if( pPager->eState==PAGER_READER ){
          assert( rc==SQLITE_OK );
          rc = pagerLockDb(pPager, RESERVED_LOCK);
        }
        if( rc==SQLITE_OK ){
          sqlite3OsDelete(pPager->pVfs, pPager->zJournal, 0);
        }
        if( rc==SQLITE_OK && state==PAGER_READER ){
          pagerUnlockDb(pPager, SHARED_LOCK);
        }else if( state==PAGER_OPEN ){
          pager_unlock(pPager);
        }
        assert( state==pPager->eState );
      }
    }else if( eMode==PAGER_JOURNALMODE_OFF ){
      sqlite3OsClose(pPager->jfd);
    }
  }

  /* Return the new journal mode */
  return (int)pPager->journalMode;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movzbl 0x9(%rdi), %eax
cmpb $0x0, 0x13(%rdi)
je 0x2a7bd9
cmpl $0x2, %esi
je 0x2a7bd9
cmpl $0x4, %esi
je 0x2a7bd9
movl %eax, %esi
cmpl %eax, %esi
jne 0x2a7be6
movzbl 0x9(%rbx), %eax
popq %rbx
popq %r14
popq %rbp
retq
movb %sil, 0x9(%rbx)
testb $0x1, %sil
jne 0x2a7c2e
andl $0x5, %eax
cmpl $0x1, %eax
jne 0x2a7c2e
cmpb $0x0, 0x8(%rbx)
jne 0x2a7c2e
movq 0x50(%rbx), %r14
movq (%r14), %rax
testq %rax, %rax
je 0x2a7c17
movq %r14, %rdi
callq *0x8(%rax)
movq $0x0, (%r14)
cmpb $0x2, 0x15(%rbx)
jb 0x2a7c4e
movq (%rbx), %rdi
movq 0xd8(%rbx), %rsi
xorl %edx, %edx
callq *0x30(%rdi)
jmp 0x2a7bdd
cmpl $0x2, %esi
jne 0x2a7bdd
movq 0x50(%rbx), %r14
movq (%r14), %rax
testq %rax, %rax
je 0x2a7bdd
movq %r14, %rdi
callq *0x8(%rax)
movq $0x0, (%r14)
jmp 0x2a7bdd
movb 0x14(%rbx), %r14b
xorl %ebp, %ebp
testb %r14b, %r14b
jne 0x2a7c63
movq %rbx, %rdi
callq 0x2966ac
movl %eax, %ebp
cmpb $0x1, 0x14(%rbx)
jne 0x2a7c78
movq %rbx, %rdi
movl $0x2, %esi
callq 0x292a65
movl %eax, %ebp
testl %ebp, %ebp
jne 0x2a7c8b
movq (%rbx), %rdi
movq 0xd8(%rbx), %rsi
xorl %edx, %edx
callq *0x30(%rdi)
testl %ebp, %ebp
setne %al
cmpb $0x1, %r14b
setne %cl
orb %al, %cl
jne 0x2a7cca
movq 0x48(%rbx), %rdi
movq (%rdi), %rax
testq %rax, %rax
je 0x2a7cbf
cmpb $0x0, 0x11(%rbx)
jne 0x2a7cb5
movl $0x1, %esi
callq *0x40(%rax)
cmpb $0x5, 0x15(%rbx)
je 0x2a7cbf
movb $0x1, 0x15(%rbx)
movb 0x10(%rbx), %al
movb %al, 0x16(%rbx)
jmp 0x2a7bdd
testb %r14b, %r14b
jne 0x2a7bdd
movq %rbx, %rdi
callq 0x293695
jmp 0x2a7bdd