// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/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 */
  sqlite3_mutex_enter(db->mutex);
  switch( op ){
    case SQLITE_DBSTATUS_LOOKASIDE_USED: {
      *pCurrent = db->lookaside.nOut;
      *pHighwater = db->lookaside.mxOut;
      if( resetFlag ){
        db->lookaside.mxOut = db->lookaside.nOut;
      }
      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: {
      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);
          totalUsed += sqlite3PagerMemUsed(pPager);
        }
      }
      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 += sqlite3MallocSize(pSchema->tblHash.ht);
          nByte += sqlite3MallocSize(pSchema->trigHash.ht);
          nByte += sqlite3MallocSize(pSchema->idxHash.ht);
          nByte += sqlite3MallocSize(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;
      *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_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;
      *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;
      *pCurrent = db->nDeferredImmCons>0 || db->nDeferredCons>0;
      break;
    }

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl -0xc(%rbp), %eax
movq %rax, -0x80(%rbp)
subq $0xa, %rax
ja 0x9872
movq -0x80(%rbp), %rax
leaq 0x9fb6f(%rip), %rcx     # 0xa9010
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rax
movl 0x154(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rax
movl 0x158(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x0, -0x24(%rbp)
je 0x94e4
movq -0x8(%rbp), %rax
movl 0x154(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x158(%rax)
jmp 0x9879
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x4, %ecx
movslq %ecx, %rcx
movl 0x15c(%rax,%rcx,4), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x0, -0x24(%rbp)
je 0x952b
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x4, %ecx
movslq %ecx, %rcx
movl $0x0, 0x15c(%rax,%rcx,4)
jmp 0x9879
movl $0x0, -0x2c(%rbp)
movq -0x8(%rbp), %rdi
callq 0x9890
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jge 0x959e
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x9591
movq -0x38(%rbp), %rdi
callq 0x98f0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x9910
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x9593
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x9547
movl -0x2c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
jmp 0x9879
movl $0x0, -0x48(%rbp)
movq -0x8(%rbp), %rdi
callq 0x9890
movq -0x8(%rbp), %rax
leaq -0x48(%rbp), %rcx
movq %rcx, 0x328(%rax)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jge 0x9702
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x44(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x96f2
movl $0x28, %edi
callq *0xc6eb3(%rip)          # 0xd04d0
movq -0x50(%rbp), %rcx
movl 0xc(%rcx), %ecx
movq -0x50(%rbp), %rdx
addl 0x3c(%rdx), %ecx
movq -0x50(%rbp), %rdx
addl 0x24(%rdx), %ecx
movq -0x50(%rbp), %rdx
addl 0x54(%rdx), %ecx
imull %ecx, %eax
addl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x9990
addl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x50(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x9990
addl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x50(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x9990
addl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x50(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x9990
addl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x50(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x96bf
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x99b0
movq -0x58(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0x969a
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x96f0
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x9a30
movq -0x58(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0x96cb
jmp 0x96f2
jmp 0x96f4
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x95dc
movq -0x8(%rbp), %rax
movq $0x0, 0x328(%rax)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movl -0x48(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
jmp 0x9879
movl $0x0, -0x64(%rbp)
movq -0x8(%rbp), %rax
leaq -0x64(%rbp), %rcx
movq %rcx, 0x328(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x977a
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x9b90
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x9cd0
movq -0x60(%rbp), %rax
movq 0x68(%rax), %rax
movq %rax, -0x60(%rbp)
jmp 0x974b
movq -0x8(%rbp), %rax
movq $0x0, 0x328(%rax)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movl -0x64(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
jmp 0x9879
movl $0x0, -0x6c(%rbp)
movl $0x0, -0x68(%rbp)
movl -0x68(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jge 0x9815
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x68(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpq $0x0, 0x8(%rax)
je 0x9808
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x68(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
callq 0x98f0
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x24(%rbp), %edx
leaq -0x6c(%rbp), %rcx
callq 0x9d80
jmp 0x980a
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x97af
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movl -0x6c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
jmp 0x9879
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movq -0x8(%rbp), %rcx
movb $0x1, %al
cmpq $0x0, 0x320(%rcx)
movb %al, -0x81(%rbp)
jg 0x985f
movq -0x8(%rbp), %rax
cmpq $0x0, 0x318(%rax)
setg %al
movb %al, -0x81(%rbp)
movb -0x81(%rbp), %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
jmp 0x9879
movl $0x1, -0x28(%rbp)
movl -0x28(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)