// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: sqlite3_db_status
SQLITE_API int sqlite3_db_status(
  sqlite3 *db,          /* The database connection whose status is desired */
  int op,               /* Status verb */
  int *pCurrent,        /* Write current value here */
  int *pHighwater,      /* Write high-water mark here */
  int resetFlag         /* Reset high-water mark if true */
){
  int rc = SQLITE_OK;   /* Return code */
#ifdef SQLITE_ENABLE_API_ARMOR
  if( !sqlite3SafetyCheckOk(db) || pCurrent==0|| pHighwater==0 ){
    return SQLITE_MISUSE_BKPT;
  }
#endif
  sqlite3_mutex_enter(db->mutex);
  switch( op ){
    case SQLITE_DBSTATUS_LOOKASIDE_USED: {
      *pCurrent = sqlite3LookasideUsed(db, pHighwater);
      if( resetFlag ){
        LookasideSlot *p = db->lookaside.pFree;
        if( p ){
          while( p->pNext ) p = p->pNext;
          p->pNext = db->lookaside.pInit;
          db->lookaside.pInit = db->lookaside.pFree;
          db->lookaside.pFree = 0;
        }
#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
        p = db->lookaside.pSmallFree;
        if( p ){
          while( p->pNext ) p = p->pNext;
          p->pNext = db->lookaside.pSmallInit;
          db->lookaside.pSmallInit = db->lookaside.pSmallFree;
          db->lookaside.pSmallFree = 0;
        }
#endif
      }
      break;
    }

    case SQLITE_DBSTATUS_LOOKASIDE_HIT:
    case SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE:
    case SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL: {
      testcase( op==SQLITE_DBSTATUS_LOOKASIDE_HIT );
      testcase( op==SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE );
      testcase( op==SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL );
      assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)>=0 );
      assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)<3 );
      *pCurrent = 0;
      *pHighwater = db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT];
      if( resetFlag ){
        db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT] = 0;
      }
      break;
    }

    /*
    ** Return an approximation for the amount of memory currently used
    ** by all pagers associated with the given database connection.  The
    ** highwater mark is meaningless and is returned as zero.
    */
    case SQLITE_DBSTATUS_CACHE_USED_SHARED:
    case SQLITE_DBSTATUS_CACHE_USED: {
      int totalUsed = 0;
      int i;
      sqlite3BtreeEnterAll(db);
      for(i=0; i<db->nDb; i++){
        Btree *pBt = db->aDb[i].pBt;
        if( pBt ){
          Pager *pPager = sqlite3BtreePager(pBt);
          int nByte = sqlite3PagerMemUsed(pPager);
          if( op==SQLITE_DBSTATUS_CACHE_USED_SHARED ){
            nByte = nByte / sqlite3BtreeConnectionCount(pBt);
          }
          totalUsed += nByte;
        }
      }
      sqlite3BtreeLeaveAll(db);
      *pCurrent = totalUsed;
      *pHighwater = 0;
      break;
    }

    /*
    ** *pCurrent gets an accurate estimate of the amount of memory used
    ** to store the schema for all databases (main, temp, and any ATTACHed
    ** databases.  *pHighwater is set to zero.
    */
    case SQLITE_DBSTATUS_SCHEMA_USED: {
      int i;                      /* Used to iterate through schemas */
      int nByte = 0;              /* Used to accumulate return value */

      sqlite3BtreeEnterAll(db);
      db->pnBytesFreed = &nByte;
      for(i=0; i<db->nDb; i++){
        Schema *pSchema = db->aDb[i].pSchema;
        if( ALWAYS(pSchema!=0) ){
          HashElem *p;

          nByte += sqlite3GlobalConfig.m.xRoundup(sizeof(HashElem)) * (
              pSchema->tblHash.count
            + pSchema->trigHash.count
            + pSchema->idxHash.count
            + pSchema->fkeyHash.count
          );
          nByte += sqlite3_msize(pSchema->tblHash.ht);
          nByte += sqlite3_msize(pSchema->trigHash.ht);
          nByte += sqlite3_msize(pSchema->idxHash.ht);
          nByte += sqlite3_msize(pSchema->fkeyHash.ht);

          for(p=sqliteHashFirst(&pSchema->trigHash); p; p=sqliteHashNext(p)){
            sqlite3DeleteTrigger(db, (Trigger*)sqliteHashData(p));
          }
          for(p=sqliteHashFirst(&pSchema->tblHash); p; p=sqliteHashNext(p)){
            sqlite3DeleteTable(db, (Table *)sqliteHashData(p));
          }
        }
      }
      db->pnBytesFreed = 0;
      sqlite3BtreeLeaveAll(db);

      *pHighwater = 0;
      *pCurrent = nByte;
      break;
    }

    /*
    ** *pCurrent gets an accurate estimate of the amount of memory used
    ** to store all prepared statements.
    ** *pHighwater is set to zero.
    */
    case SQLITE_DBSTATUS_STMT_USED: {
      struct Vdbe *pVdbe;         /* Used to iterate through VMs */
      int nByte = 0;              /* Used to accumulate return value */

      db->pnBytesFreed = &nByte;
      for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pNext){
        sqlite3VdbeClearObject(db, pVdbe);
        sqlite3DbFree(db, pVdbe);
      }
      db->pnBytesFreed = 0;

      *pHighwater = 0;  /* IMP: R-64479-57858 */
      *pCurrent = nByte;

      break;
    }

    /*
    ** Set *pCurrent to the total cache hits or misses encountered by all
    ** pagers the database handle is connected to. *pHighwater is always set
    ** to zero.
    */
    case SQLITE_DBSTATUS_CACHE_SPILL:
      op = SQLITE_DBSTATUS_CACHE_WRITE+1;
      /* no break */ deliberate_fall_through
    case SQLITE_DBSTATUS_CACHE_HIT:
    case SQLITE_DBSTATUS_CACHE_MISS:
    case SQLITE_DBSTATUS_CACHE_WRITE:{
      int i;
      int nRet = 0;
      assert( SQLITE_DBSTATUS_CACHE_MISS==SQLITE_DBSTATUS_CACHE_HIT+1 );
      assert( SQLITE_DBSTATUS_CACHE_WRITE==SQLITE_DBSTATUS_CACHE_HIT+2 );

      for(i=0; i<db->nDb; i++){
        if( db->aDb[i].pBt ){
          Pager *pPager = sqlite3BtreePager(db->aDb[i].pBt);
          sqlite3PagerCacheStat(pPager, op, resetFlag, &nRet);
        }
      }
      *pHighwater = 0; /* IMP: R-42420-56072 */
                       /* IMP: R-54100-20147 */
                       /* IMP: R-29431-39229 */
      *pCurrent = nRet;
      break;
    }

    /* Set *pCurrent to non-zero if there are unresolved deferred foreign
    ** key constraints.  Set *pCurrent to zero if all foreign key constraints
    ** have been satisfied.  The *pHighwater is always set to zero.
    */
    case SQLITE_DBSTATUS_DEFERRED_FKS: {
      *pHighwater = 0;  /* IMP: R-11967-56545 */
      *pCurrent = db->nDeferredImmCons>0 || db->nDeferredCons>0;
      break;
    }

    default: {
      rc = SQLITE_ERROR;
    }
  }
  sqlite3_mutex_leave(db->mutex);
  return rc;
}

// Assembly:
cmpl $0xc, %esi
ja 0x21f045
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r8d, %ebp
movl %esi, %r14d
movq %rdi, %rbx
movq %rcx, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
movl %esi, %eax
leaq 0x151743(%rip), %rcx    # 0x370400
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x18(%rsp), %rax
andl $0x0, (%rax)
addl $-0x4, %r14d
movl 0x180(%rbx,%r14,4), %eax
movq 0x10(%rsp), %rcx
movl %eax, (%rcx)
xorl %eax, %eax
testl %ebp, %ebp
je 0x21f05f
andl $0x0, 0x180(%rbx,%r14,4)
jmp 0x21f05f
movq %rbx, %rdi
callq 0x21f0e2
xorl %ecx, %ecx
pushq $0x8
popq %rdx
xorl %esi, %esi
movslq 0x28(%rbx), %rax
cmpq %rax, %rcx
jge 0x21eda3
movq 0x20(%rbx), %rax
movq (%rax,%rdx), %r12
testq %r12, %r12
je 0x21ed97
movl %esi, 0x20(%rsp)
movq %rdx, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movq 0x8(%r12), %rax
movq (%rax), %r13
movl 0xbc(%r13), %eax
movzwl 0xb0(%r13), %ecx
leal (%rax,%rcx), %r15d
addl $0x70, %r15d
movq 0x118(%r13), %rax
movq 0x40(%rax), %rdi
callq *0x21b988(%rip)         # 0x43a6e8
movl %eax, %ebp
imull %r15d, %ebp
movq %r13, %rdi
callq *0x21b8d9(%rip)         # 0x43a648
addl %ebp, %eax
addl 0xbc(%r13), %eax
cmpl $0xb, %r14d
jne 0x21ed87
movq 0x8(%r12), %rcx
cltd
idivl 0x68(%rcx)
movq 0x28(%rsp), %rcx
movl 0x20(%rsp), %esi
addl %eax, %esi
movq 0x30(%rsp), %rdx
incq %rcx
addq $0x20, %rdx
jmp 0x21ed08
movq 0x18(%rsp), %rax
movl %esi, (%rax)
movq 0x10(%rsp), %rax
andl $0x0, (%rax)
jmp 0x21f05d
movq 0x10(%rsp), %rax
andl $0x0, (%rax)
cmpq $0x0, 0x2c8(%rbx)
jle 0x21f049
pushq $0x1
popq %rax
jmp 0x21f056
pushq $0xa
popq %r14
addl $-0x7, %r14d
xorl %eax, %eax
pushq $0x8
popq %rcx
xorl %edx, %edx
movslq 0x28(%rbx), %rsi
cmpq %rsi, %rax
jge 0x21ee1f
movq 0x20(%rbx), %rsi
movq (%rsi,%rcx), %rsi
testq %rsi, %rsi
je 0x21ee16
movq 0x8(%rsi), %rsi
movq (%rsi), %rsi
addl 0xf0(%rsi,%r14,4), %edx
testl %ebp, %ebp
je 0x21ee16
andl $0x0, 0xf0(%rsi,%r14,4)
incq %rax
addq $0x20, %rcx
jmp 0x21ede4
movq 0x10(%rsp), %rax
andl $0x0, (%rax)
movq 0x18(%rsp), %rax
movl %edx, (%rax)
jmp 0x21f05d
leaq 0x24(%rsp), %rax
andl $0x0, (%rax)
movq %rax, 0x2d0(%rbx)
leaq 0x8(%rbx), %r12
movq (%r12), %r12
testq %r12, %r12
je 0x21ee6b
movq %rbx, %rdi
movq %r12, %rsi
callq 0x21f1a4
movq %rbx, %rdi
movq %r12, %rsi
callq 0x22d0fc
addq $0x10, %r12
jmp 0x21ee46
andq $0x0, 0x2d0(%rbx)
movq 0x10(%rsp), %rax
andl $0x0, (%rax)
movl 0x24(%rsp), %eax
jmp 0x21f056
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0x21f06e
movq 0x18(%rsp), %rcx
movl %eax, (%rcx)
xorl %eax, %eax
testl %ebp, %ebp
je 0x21f05f
movq 0x198(%rbx), %rcx
testq %rcx, %rcx
je 0x21eed5
movq %rcx, %rsi
movq %rsi, %rdx
movq (%rsi), %rsi
testq %rsi, %rsi
jne 0x21eeb1
movq 0x190(%rbx), %rsi
movq %rsi, (%rdx)
movq %rcx, 0x190(%rbx)
andq $0x0, 0x198(%rbx)
movq 0x1a8(%rbx), %rcx
testq %rcx, %rcx
je 0x21f05f
movq %rcx, %rsi
movq %rsi, %rdx
movq (%rsi), %rsi
testq %rsi, %rsi
jne 0x21eee8
movq 0x1a0(%rbx), %rsi
movq %rsi, (%rdx)
movq %rcx, 0x1a0(%rbx)
andq $0x0, 0x1a8(%rbx)
jmp 0x21f05f
leaq 0xc(%rsp), %r14
andl $0x0, (%r14)
movq %rbx, %rdi
callq 0x21f0e2
movq %r14, 0x2d0(%rbx)
xorl %r13d, %r13d
pushq $0x20
popq %r15
movslq 0x28(%rbx), %rax
cmpq %rax, %r13
jge 0x21f02f
movq 0x20(%rbx), %rax
movq %r13, %rcx
shlq $0x5, %rcx
movq 0x18(%rax,%rcx), %rbp
testq %rbp, %rbp
je 0x21f027
movl %r15d, %edi
callq *0x21b6f1(%rip)         # 0x43a650
movl 0x3c(%rbp), %ecx
addl 0xc(%rbp), %ecx
addl 0x24(%rbp), %ecx
addl 0x54(%rbp), %ecx
imull %eax, %ecx
addl 0xc(%rsp), %ecx
movl %ecx, 0xc(%rsp)
movq 0x18(%rbp), %rdi
xorl %r12d, %r12d
movl $0x0, %eax
testq %rdi, %rdi
je 0x21ef91
callq *0x21b6bb(%rip)         # 0x43a648
movl 0xc(%rsp), %ecx
addl %eax, %ecx
movl %ecx, 0xc(%rsp)
movq 0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x21efad
callq *0x21b6a2(%rip)         # 0x43a648
movl %eax, %r12d
movl 0xc(%rsp), %ecx
addl %r12d, %ecx
movl %ecx, 0xc(%rsp)
movq 0x30(%rbp), %rdi
xorl %r12d, %r12d
movl $0x0, %eax
testq %rdi, %rdi
je 0x21efcf
callq *0x21b67d(%rip)         # 0x43a648
movl 0xc(%rsp), %ecx
addl %eax, %ecx
movl %ecx, 0xc(%rsp)
movq 0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x21efeb
callq *0x21b664(%rip)         # 0x43a648
movl %eax, %r12d
movl 0xc(%rsp), %ecx
addl %r12d, %ecx
movl %ecx, 0xc(%rsp)
leaq 0x40(%rbp), %r14
movq (%r14), %r14
testq %r14, %r14
je 0x21f00c
movq 0x10(%r14), %rsi
movq %rbx, %rdi
callq 0x21f128
jmp 0x21eff6
addq $0x10, %rbp
movq (%rbp), %rbp
testq %rbp, %rbp
je 0x21f027
movq 0x10(%rbp), %rsi
movq %rbx, %rdi
callq 0x21f182
jmp 0x21f010
incq %r13
jmp 0x21ef30
andq $0x0, 0x2d0(%rbx)
movq 0x10(%rsp), %rax
andl $0x0, (%rax)
movl 0xc(%rsp), %eax
jmp 0x21f056
pushq $0x1
popq %rax
retq
xorl %eax, %eax
cmpq $0x0, 0x2c0(%rbx)
setg %al
movq 0x18(%rsp), %rcx
movl %eax, (%rcx)
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq