// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/sqlite-3.33.0/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(i=sqliteHashFirst(&db->aFunc); i; i=sqliteHashNext(i)){
    FuncDef *pNext, *p;
    p = sqliteHashData(i);
    do{
      functionDestroy(db, p);
      pNext = p->pNext;
      sqlite3DbFree(db, p);
      p = pNext;
    }while( p );
  }
  sqlite3HashClear(&db->aFunc);
  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);
    sqlite3VtabEponymousTableClear(db, pMod);
    sqlite3VtabModuleUnref(db, pMod);
  }
  sqlite3HashClear(&db->aModule);
#endif

  sqlite3Error(db, SQLITE_OK); /* Deallocates any cached error strings. */
  sqlite3ValueFree(db->pErr);
  sqlite3CloseExtensions(db);
#if SQLITE_USER_AUTHENTICATION
  sqlite3_free(db->auth.zAuthUser);
  sqlite3_free(db->auth.zAuthPW);
#endif

  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( sqlite3LookasideUsed(db,0)==0 );
  if( db->lookaside.bMalloced ){
    sqlite3_free(db->lookaside.pStart);
  }
  sqlite3_free(db);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
cmpl $0x64cffc7f, 0x70(%rdi) # imm = 0x64CFFC7F
jne 0x223e45
movq %rdi, %rbx
callq 0x28a7cc
testl %eax, %eax
je 0x223e4f
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x239313
movq %rbx, %rdi
callq 0x23940f
pushq $0x8
popq %r15
movslq 0x28(%rbx), %rax
movq 0x20(%rbx), %r12
cmpq %rax, %r14
jge 0x223e9d
movq (%r12,%r15), %rdi
testq %rdi, %rdi
je 0x223e94
callq 0x239820
andq $0x0, (%r12,%r15)
cmpq $0x1, %r14
je 0x223e94
andq $0x0, 0x10(%r12,%r15)
incq %r14
addq $0x20, %r15
jmp 0x223e68
movq 0x38(%r12), %rdi
testq %rdi, %rdi
je 0x223eac
callq 0x24401a
movq %rbx, %rdi
callq 0x24b12d
movq %rbx, %rdi
callq 0x24e082
movq %rbx, %rdi
callq 0x2394a1
movq %rbx, %rdi
callq 0x22d08a
leaq 0x228(%rbx), %r15
movq (%r15), %r15
testq %r15, %r15
je 0x223f03
movq 0x10(%r15), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x28a82f
movq 0x10(%r14), %r12
movq %rbx, %rdi
movq %r14, %rsi
callq 0x21f26b
movq %r12, %r14
testq %r12, %r12
jne 0x223edf
jmp 0x223ed3
leaq 0x220(%rbx), %rdi
callq 0x24a72c
leaq 0x240(%rbx), %r15
pushq $0x20
popq %r12
movq (%r15), %r15
testq %r15, %r15
je 0x223f55
movq 0x10(%r15), %r14
movq %r12, %r13
cmpq $0x98, %r13
je 0x223f48
movq (%r14,%r13), %rax
testq %rax, %rax
je 0x223f42
movq -0x10(%r14,%r13), %rdi
callq *%rax
addq $0x28, %r13
jmp 0x223f29
movq %rbx, %rdi
movq %r14, %rsi
callq 0x21f26b
jmp 0x223f1a
leaq 0x238(%rbx), %rdi
callq 0x24a72c
leaq 0x1f8(%rbx), %r15
movq (%r15), %r15
testq %r15, %r15
je 0x223f8c
movq 0x10(%r15), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x24dab6
movq %rbx, %rdi
movq %r14, %rsi
callq 0x23887c
jmp 0x223f68
leaq 0x1f0(%rbx), %rdi
callq 0x24a72c
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x222800
movq 0x160(%rbx), %rdi
callq 0x2245fd
movslq 0xd4(%rbx), %rax
cmpq %rax, %r14
jge 0x223fd3
movq (%rbx), %rdi
movq 0xd8(%rbx), %rax
movq (%rax,%r14,8), %rsi
callq *0x60(%rdi)
incq %r14
jmp 0x223fb1
movq 0xd8(%rbx), %rsi
movq %rbx, %rdi
callq 0x21f26b
movl $0xb5357930, 0x70(%rbx) # imm = 0xB5357930
movq 0x20(%rbx), %rax
movq 0x38(%rax), %rsi
movq %rbx, %rdi
callq 0x21f26b
movl $0x9f3c2d33, 0x70(%rbx) # imm = 0x9F3C2D33
cmpb $0x0, 0x178(%rbx)
je 0x224015
movq 0x1b8(%rbx), %rdi
callq 0x21f7f9
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x21f7f9