// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
cmpl $0xa, %esi
ja 0x98b7
movq %rcx, %r14
movq %rdx, %rbx
movq %rdi, %r15
movl %esi, %eax
leaq 0x6baa2(%rip), %rcx     # 0x75010
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x0, (%rbx)
addl $-0x4, %esi
movl 0x15c(%r15,%rsi,4), %eax
movl %eax, (%r14)
xorl %r12d, %r12d
testl %r8d, %r8d
je 0x98fe
movl $0x0, 0x15c(%r15,%rsi,4)
jmp 0x98fe
movl 0x28(%r15), %eax
xorl %r12d, %r12d
movl $0x0, %edx
testl %eax, %eax
jle 0x9602
movq 0x20(%r15), %rcx
addl $-0x7, %esi
addq $0x8, %rcx
xorl %edi, %edi
xorl %edx, %edx
movq (%rcx), %r9
testq %r9, %r9
je 0x95f3
movq 0x8(%r9), %r9
movq (%r9), %r9
addl 0xf0(%r9,%rsi,4), %edx
testl %r8d, %r8d
je 0x95f3
movl $0x0, 0xf0(%r9,%rsi,4)
movl 0x28(%r15), %eax
incq %rdi
movslq %eax, %r9
addq $0x20, %rcx
cmpq %r9, %rdi
jl 0x95c7
movl $0x0, (%r14)
movl %edx, (%rbx)
jmp 0x98fe
movl $0x0, -0x2c(%rbp)
movslq 0x28(%r15), %rax
testq %rax, %rax
movq %rbx, -0x40(%rbp)
movq %r14, -0x38(%rbp)
jle 0x98bf
movq 0x20(%r15), %rcx
movq %rax, %rdx
shlq $0x5, %rdx
xorl %esi, %esi
movq 0x8(%rcx,%rsi), %rdi
testq %rdi, %rdi
je 0x964e
movq (%rdi), %r8
movq 0x8(%rdi), %rdi
movq %r8, 0x8(%rdi)
addq $0x20, %rsi
cmpq %rsi, %rdx
jne 0x9639
leaq 0x328(%r15), %r12
leaq -0x2c(%rbp), %rcx
movq %rcx, 0x328(%r15)
testl %eax, %eax
jle 0x98cd
xorl %r13d, %r13d
movq 0x20(%r15), %rax
movq %r13, %rcx
shlq $0x5, %rcx
movq 0x18(%rax,%rcx), %rbx
testq %rbx, %rbx
je 0x9712
movl $0x28, %edi
callq *0x8ada8(%rip)          # 0x94440
movl 0x3c(%rbx), %ecx
addl 0xc(%rbx), %ecx
addl 0x24(%rbx), %ecx
addl 0x54(%rbx), %ecx
imull %eax, %ecx
addl %ecx, -0x2c(%rbp)
movq 0x18(%rbx), %rdi
callq *0x8ad84(%rip)          # 0x94438
addl %eax, -0x2c(%rbp)
movq 0x48(%rbx), %rdi
callq *0x8ad77(%rip)          # 0x94438
addl %eax, -0x2c(%rbp)
movq 0x30(%rbx), %rdi
callq *0x8ad6a(%rip)          # 0x94438
addl %eax, -0x2c(%rbp)
movq 0x60(%rbx), %rdi
callq *0x8ad5d(%rip)          # 0x94438
addl %eax, -0x2c(%rbp)
movq 0x40(%rbx), %r14
testq %r14, %r14
je 0x96f8
movq 0x10(%r14), %rsi
movq %r15, %rdi
callq 0x991b
movq (%r14), %r14
jmp 0x96e2
movq 0x10(%rbx), %rbx
testq %rbx, %rbx
je 0x9712
movq 0x10(%rbx), %rsi
movq %r15, %rdi
callq 0x9975
movq (%rbx), %rbx
jmp 0x96fc
incq %r13
movslq 0x28(%r15), %rax
cmpq %rax, %r13
jl 0x9674
movl -0x2c(%rbp), %eax
jmp 0x98cf
movl $0x0, (%r14)
movl $0x1, %eax
cmpq $0x0, 0x320(%r15)
jg 0x974d
xorl %eax, %eax
cmpq $0x0, 0x318(%r15)
setg %al
movl %eax, (%rbx)
jmp 0x98fb
leaq -0x48(%rbp), %rax
movl $0x0, (%rax)
movq %rax, 0x328(%r15)
movq 0x8(%r15), %r13
xorl %r12d, %r12d
movl $0x0, %eax
testq %r13, %r13
je 0x9798
movq %r15, %rdi
movq %r13, %rsi
callq 0x9bc9
movq %r15, %rdi
movq %r13, %rsi
callq 0x9ca4
movq 0x68(%r13), %r13
testq %r13, %r13
jne 0x9776
movl -0x48(%rbp), %eax
movq $0x0, 0x328(%r15)
movl $0x0, (%r14)
movl %eax, (%rbx)
jmp 0x98fe
movl 0x154(%r15), %eax
movl %eax, (%rbx)
movl 0x158(%r15), %eax
movl %eax, (%r14)
xorl %r12d, %r12d
testl %r8d, %r8d
je 0x98fe
movl 0x154(%r15), %eax
movl %eax, 0x158(%r15)
jmp 0x98fe
movq %r14, -0x38(%rbp)
movq %rbx, -0x40(%rbp)
movslq 0x28(%r15), %rax
movl $0x0, %edx
testq %rax, %rax
jle 0x98eb
movq 0x20(%r15), %rcx
movq %rax, %rdx
shlq $0x5, %rdx
xorl %esi, %esi
movq 0x8(%rcx,%rsi), %rdi
testq %rdi, %rdi
je 0x981f
movq (%rdi), %r8
movq 0x8(%rdi), %rdi
movq %r8, 0x8(%rdi)
addq $0x20, %rsi
cmpq %rsi, %rdx
jne 0x980a
testl %eax, %eax
jle 0x98e9
xorl %r14d, %r14d
movl $0x8, %r12d
xorl %edx, %edx
movq 0x20(%r15), %rcx
movq (%rcx,%r12), %rcx
testq %rcx, %rcx
je 0x98a6
movl %edx, -0x44(%rbp)
movq 0x8(%rcx), %rax
movq (%rax), %r13
movl 0xbc(%r13), %ebx
movzwl 0xb0(%r13), %ecx
movq 0x110(%r13), %rax
movq 0x40(%rax), %rdi
testq %rdi, %rdi
je 0x9881
movq %rcx, -0x50(%rbp)
callq *0x8ac5d(%rip)          # 0x944d8
movq -0x50(%rbp), %rcx
jmp 0x9883
xorl %eax, %eax
addl %ecx, %ebx
addl $0x70, %ebx
imull %eax, %ebx
movq %r13, %rdi
callq *0x8aba4(%rip)          # 0x94438
movl -0x44(%rbp), %edx
addl %eax, %edx
addl %ebx, %edx
addl 0xbc(%r13), %edx
movl 0x28(%r15), %eax
incq %r14
movslq %eax, %rcx
addq $0x20, %r12
cmpq %rcx, %r14
jl 0x983b
jmp 0x98eb
movl $0x1, %r12d
jmp 0x98fe
addq $0x328, %r15            # imm = 0x328
xorl %eax, %eax
movq %r15, %r12
jmp 0x98cf
xorl %eax, %eax
movq $0x0, (%r12)
movq -0x38(%rbp), %rcx
movl $0x0, (%rcx)
movq -0x40(%rbp), %rcx
movl %eax, (%rcx)
jmp 0x98fb
xorl %edx, %edx
movq -0x40(%rbp), %rax
movl %edx, (%rax)
movq -0x38(%rbp), %rax
movl $0x0, (%rax)
xorl %r12d, %r12d
movl %r12d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq