// File: /workspace/github_c_makefile_star2_O3/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 0x29e3e1
cmpl $0x4, %esi
je 0x29e3e1
cmpl $0x2, %esi
jne 0x29e3e5
cmpl %esi, %eax
jne 0x29e3ee
movzbl 0x9(%rbx), %eax
popq %rbx
popq %r14
popq %rbp
retq
movb %sil, 0x9(%rbx)
testb $0x1, %sil
jne 0x29e436
andl $0x5, %eax
cmpl $0x1, %eax
jne 0x29e436
cmpb $0x0, 0x8(%rbx)
jne 0x29e436
movq 0x50(%rbx), %r14
movq (%r14), %rax
testq %rax, %rax
je 0x29e41f
movq %r14, %rdi
callq *0x8(%rax)
movq $0x0, (%r14)
cmpb $0x2, 0x15(%rbx)
jb 0x29e456
movq (%rbx), %rdi
movq 0xd8(%rbx), %rsi
xorl %edx, %edx
callq *0x30(%rdi)
jmp 0x29e3e5
cmpl $0x2, %esi
jne 0x29e3e5
movq 0x50(%rbx), %r14
movq (%r14), %rax
testq %rax, %rax
je 0x29e3e5
movq %r14, %rdi
callq *0x8(%rax)
movq $0x0, (%r14)
jmp 0x29e3e5
movb 0x14(%rbx), %bpl
xorl %eax, %eax
movl %ebp, %ecx
testb %bpl, %bpl
jne 0x29e46e
movq %rbx, %rdi
callq 0x28ca39
movb 0x14(%rbx), %cl
cmpb $0x1, %cl
jne 0x29e480
movq %rbx, %rdi
movl $0x2, %esi
callq 0x288c38
testl %eax, %eax
jne 0x29e4c8
movq (%rbx), %rdi
movq 0xd8(%rbx), %rsi
xorl %edx, %edx
callq *0x30(%rdi)
cmpb $0x1, %bpl
jne 0x29e4c8
movq 0x48(%rbx), %rdi
movq (%rdi), %rax
testq %rax, %rax
je 0x29e4bd
cmpb $0x0, 0x11(%rbx)
jne 0x29e4b3
movl $0x1, %esi
callq *0x40(%rax)
cmpb $0x5, 0x15(%rbx)
je 0x29e4bd
movb $0x1, 0x15(%rbx)
movb 0x10(%rbx), %al
movb %al, 0x16(%rbx)
jmp 0x29e3e5
testb %bpl, %bpl
jne 0x29e3e5
movq %rbx, %rdi
callq 0x289861
jmp 0x29e3e5