// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3PagerSetJournalMode
SQLITE_PRIVATE int sqlite3PagerSetJournalMode(Pager *pPager, int eMode){
  u8 eOld = pPager->journalMode;    /* Prior journalmode */

#ifdef SQLITE_DEBUG
  /* The print_pager_state() routine is intended to be used by the debugger
  ** only.  We invoke it once here to suppress a compiler warning. */
  print_pager_state(pPager);
#endif


  /* 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 );
      }
    }
  }

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movb 0x9(%rax), %al
movb %al, -0xd(%rbp)
movq -0x8(%rbp), %rax
cmpb $0x0, 0x12(%rax)
je 0x3f568
cmpl $0x4, -0xc(%rbp)
je 0x3f566
cmpl $0x2, -0xc(%rbp)
je 0x3f566
movzbl -0xd(%rbp), %eax
movl %eax, -0xc(%rbp)
jmp 0x3f568
movl -0xc(%rbp), %eax
movzbl -0xd(%rbp), %ecx
cmpl %ecx, %eax
je 0x3f67c
movl -0xc(%rbp), %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x9(%rax)
movq -0x8(%rbp), %rax
cmpb $0x0, 0x8(%rax)
jne 0x3f67a
movzbl -0xd(%rbp), %eax
andl $0x5, %eax
cmpl $0x1, %eax
jne 0x3f67a
movl -0xc(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x3f67a
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rdi
callq 0x20ea0
movq -0x8(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x2, %eax
jl 0x3f5e8
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0xd8(%rax), %rsi
xorl %edx, %edx
callq 0x259d0
jmp 0x3f678
movl $0x0, -0x14(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x13(%rax), %eax
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x3f60c
movq -0x8(%rbp), %rdi
callq 0x29b50
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x13(%rax), %eax
cmpl $0x1, %eax
jne 0x3f62a
movq -0x8(%rbp), %rdi
movl $0x2, %esi
callq 0x247e0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x3f649
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0xd8(%rax), %rsi
xorl %edx, %edx
callq 0x259d0
cmpl $0x0, -0x14(%rbp)
jne 0x3f665
cmpl $0x1, -0x18(%rbp)
jne 0x3f665
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x26790
jmp 0x3f676
cmpl $0x0, -0x18(%rbp)
jne 0x3f674
movq -0x8(%rbp), %rdi
callq 0x254c0
jmp 0x3f676
jmp 0x3f678
jmp 0x3f67a
jmp 0x3f67c
movq -0x8(%rbp), %rax
movzbl 0x9(%rax), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)