// File: /workspace/github_c_makefile_star2_O0/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
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, 0x13(%rax)
je 0x3ff268
cmpl $0x4, -0xc(%rbp)
je 0x3ff266
cmpl $0x2, -0xc(%rbp)
je 0x3ff266
movzbl -0xd(%rbp), %eax
movl %eax, -0xc(%rbp)
jmp 0x3ff268
movl -0xc(%rbp), %eax
movzbl -0xd(%rbp), %ecx
cmpl %ecx, %eax
je 0x3ff391
movl -0xc(%rbp), %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x9(%rax)
movq -0x8(%rbp), %rax
cmpb $0x0, 0x8(%rax)
jne 0x3ff37a
movzbl -0xd(%rbp), %eax
andl $0x5, %eax
cmpl $0x1, %eax
jne 0x3ff37a
movl -0xc(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x3ff37a
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rdi
callq 0x3dbe40
movq -0x8(%rbp), %rax
movzbl 0x15(%rax), %eax
cmpl $0x2, %eax
jl 0x3ff2e8
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0xd8(%rax), %rsi
xorl %edx, %edx
callq 0x3e3c10
jmp 0x3ff378
movl $0x0, -0x14(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x14(%rax), %eax
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x3ff30c
movq -0x8(%rbp), %rdi
callq 0x3e6c20
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x1, %eax
jne 0x3ff32a
movq -0x8(%rbp), %rdi
movl $0x2, %esi
callq 0x3e0740
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x3ff349
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0xd8(%rax), %rsi
xorl %edx, %edx
callq 0x3e3c10
cmpl $0x0, -0x14(%rbp)
jne 0x3ff365
cmpl $0x1, -0x18(%rbp)
jne 0x3ff365
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x3e3fb0
jmp 0x3ff376
cmpl $0x0, -0x18(%rbp)
jne 0x3ff374
movq -0x8(%rbp), %rdi
callq 0x3e1bf0
jmp 0x3ff376
jmp 0x3ff378
jmp 0x3ff38f
cmpl $0x2, -0xc(%rbp)
jne 0x3ff38d
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rdi
callq 0x3dbe40
jmp 0x3ff38f
jmp 0x3ff391
movq -0x8(%rbp), %rax
movzbl 0x9(%rax), %eax
addq $0x20, %rsp
popq %rbp
retq
nop