// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3LeaveMutexAndCloseZombie
SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3 *db){
  HashElem *i;                    /* Hash table iterator */
  int j;

  /* If there are outstanding sqlite3_stmt or sqlite3_backup objects
  ** or if the connection has not yet been closed by sqlite3_close_v2(),
  ** then just leave the mutex and return.
  */
  if( db->magic!=SQLITE_MAGIC_ZOMBIE || connectionIsBusy(db) ){
    sqlite3_mutex_leave(db->mutex);
    return;
  }

  /* If we reach this point, it means that the database connection has
  ** closed all sqlite3_stmt and sqlite3_backup objects and has been
  ** passed to sqlite3_close (meaning that it is a zombie).  Therefore,
  ** go ahead and free all resources.
  */

  /* If a transaction is open, roll it back. This also ensures that if
  ** any database schemas have been modified by an uncommitted transaction
  ** they are reset. And that the required b-tree mutex is held to make
  ** the pager rollback and schema reset an atomic operation. */
  sqlite3RollbackAll(db, SQLITE_OK);

  /* Free any outstanding Savepoint structures. */
  sqlite3CloseSavepoints(db);

  /* Close all database connections */
  for(j=0; j<db->nDb; j++){
    struct Db *pDb = &db->aDb[j];
    if( pDb->pBt ){
      sqlite3BtreeClose(pDb->pBt);
      pDb->pBt = 0;
      if( j!=1 ){
        pDb->pSchema = 0;
      }
    }
  }
  /* Clear the TEMP schema separately and last */
  if( db->aDb[1].pSchema ){
    sqlite3SchemaClear(db->aDb[1].pSchema);
  }
  sqlite3VtabUnlockList(db);

  /* Free up the array of auxiliary databases */
  sqlite3CollapseDatabaseArray(db);
  assert( db->nDb<=2 );
  assert( db->aDb==db->aDbStatic );

  /* Tell the code in notify.c that the connection no longer holds any
  ** locks and does not require any further unlock-notify callbacks.
  */
  sqlite3ConnectionClosed(db);

  for(j=0; j<ArraySize(db->aFunc.a); j++){
    FuncDef *pNext, *pHash, *p;
    for(p=db->aFunc.a[j]; p; p=pHash){
      pHash = p->pHash;
      while( p ){
        functionDestroy(db, p);
        pNext = p->pNext;
        sqlite3DbFree(db, p);
        p = pNext;
      }
    }
  }
  for(i=sqliteHashFirst(&db->aCollSeq); i; i=sqliteHashNext(i)){
    CollSeq *pColl = (CollSeq *)sqliteHashData(i);
    /* Invoke any destructors registered for collation sequence user data. */
    for(j=0; j<3; j++){
      if( pColl[j].xDel ){
        pColl[j].xDel(pColl[j].pUser);
      }
    }
    sqlite3DbFree(db, pColl);
  }
  sqlite3HashClear(&db->aCollSeq);
#ifndef SQLITE_OMIT_VIRTUALTABLE
  for(i=sqliteHashFirst(&db->aModule); i; i=sqliteHashNext(i)){
    Module *pMod = (Module *)sqliteHashData(i);
    if( pMod->xDestroy ){
      pMod->xDestroy(pMod->pAux);
    }
    sqlite3DbFree(db, pMod);
  }
  sqlite3HashClear(&db->aModule);
#endif

  sqlite3Error(db, SQLITE_OK, 0); /* Deallocates any cached error strings. */
  if( db->pErr ){
    sqlite3ValueFree(db->pErr);
  }
  sqlite3CloseExtensions(db);

  db->magic = SQLITE_MAGIC_ERROR;

  /* The temp-database schema is allocated differently from the other schema
  ** objects (using sqliteMalloc() directly, instead of sqlite3BtreeSchema()).
  ** So it needs to be freed here. Todo: Why not roll the temp schema into
  ** the same sqliteMalloc() as the one that allocates the database 
  ** structure?
  */
  sqlite3DbFree(db, db->aDb[1].pSchema);
  sqlite3_mutex_leave(db->mutex);
  db->magic = SQLITE_MAGIC_CLOSED;
  sqlite3_mutex_free(db->mutex);
  assert( db->lookaside.nOut==0 );  /* Fails on a lookaside memory leak */
  if( db->lookaside.bMalloced ){
    sqlite3_free(db->lookaside.pStart);
  }
  sqlite3_free(db);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x64cffc7f, 0x5c(%rax) # imm = 0x64CFFC7F
jne 0xf927
movq -0x8(%rbp), %rdi
callq 0x8ad80
cmpl $0x0, %eax
je 0xf92c
jmp 0xfbf9
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x2efa0
movq -0x8(%rbp), %rdi
callq 0x2f0d0
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jge 0xf9af
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x14(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xf9a2
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x2fe80
movq -0x20(%rbp), %rax
movq $0x0, 0x8(%rax)
cmpl $0x1, -0x14(%rbp)
je 0xf9a0
movq -0x20(%rbp), %rax
movq $0x0, 0x18(%rax)
jmp 0xf9a2
jmp 0xf9a4
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xf947
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
cmpq $0x0, 0x38(%rax)
je 0xf9cf
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x38(%rax), %rdi
callq 0x40d30
movq -0x8(%rbp), %rdi
callq 0x4b240
movq -0x8(%rbp), %rdi
callq 0x4b2b0
movl $0x0, -0x14(%rbp)
cmpl $0x17, -0x14(%rbp)
jge 0xfa65
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq 0x1d8(%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0xfa58
movq -0x38(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0xfa4c
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x8ae90
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x9cd0
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0xfa15
jmp 0xfa4e
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0xfa02
jmp 0xfa5a
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xf9e8
movq -0x8(%rbp), %rax
movq 0x298(%rax), %rax
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0xfb00
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x14(%rbp)
cmpl $0x3, -0x14(%rbp)
jge 0xfae3
movq -0x40(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, 0x20(%rax)
je 0xfad6
movq -0x40(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rcx
movslq -0x14(%rbp), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movq 0x10(%rcx), %rdi
callq *%rax
jmp 0xfad8
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xfa92
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x9cd0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
jmp 0xfa74
movq -0x8(%rbp), %rdi
addq $0x290, %rdi            # imm = 0x290
callq 0x40eb0
movq -0x8(%rbp), %rax
movq 0x1b0(%rax), %rax
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0xfb69
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0xfb4f
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x48(%rbp), %rcx
movq 0x10(%rcx), %rdi
callq *%rax
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x9cd0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
jmp 0xfb1f
movq -0x8(%rbp), %rdi
addq $0x1a8, %rdi            # imm = 0x1A8
callq 0x40eb0
movq -0x8(%rbp), %rdi
xorl %esi, %esi
xorl %eax, %eax
movl %eax, %edx
movb $0x0, %al
callq 0xd720
movq -0x8(%rbp), %rax
cmpq $0x0, 0x130(%rax)
je 0xfba8
movq -0x8(%rbp), %rax
movq 0x130(%rax), %rdi
callq 0x17020
movq -0x8(%rbp), %rax
movl $0xb5357930, 0x5c(%rax) # imm = 0xB5357930
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x38(%rax), %rsi
callq 0x9cd0
movq -0x8(%rbp), %rax
movl $0x9f3c2d33, 0x5c(%rax) # imm = 0x9F3C2D33
movq -0x8(%rbp), %rax
cmpb $0x0, 0x153(%rax)
je 0xfbf0
movq -0x8(%rbp), %rax
movq 0x170(%rax), %rdi
callq 0xa420
movq -0x8(%rbp), %rdi
callq 0xa420
addq $0x50, %rsp
popq %rbp
retq
nop