// File: /workspace/github_c_makefile_star2_O3/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 0x277bba
movq %rdi, %rbx
callq 0x2f0756
testl %eax, %eax
je 0x277bc4
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %rbx, %rdi
xorl %esi, %esi
callq 0x290338
movq %rbx, %rdi
callq 0x29049b
cmpl $0x0, 0x28(%rbx)
jle 0x277c1e
movl $0x8, %r14d
xorl %r15d, %r15d
movq 0x20(%rbx), %r12
movq (%r12,%r14), %rdi
testq %rdi, %rdi
je 0x277c0e
callq 0x290e57
movq $0x0, (%r12,%r14)
cmpq $0x1, %r15
je 0x277c0e
movq $0x0, 0x10(%r12,%r14)
incq %r15
movslq 0x28(%rbx), %rax
addq $0x20, %r14
cmpq %rax, %r15
jl 0x277be5
movq 0x20(%rbx), %rax
movq 0x38(%rax), %rdi
testq %rdi, %rdi
je 0x277c30
callq 0x29d6d4
movq %rbx, %rdi
callq 0x2a5baa
movq %rbx, %rdi
callq 0x2a90a7
movq %rbx, %rdi
callq 0x290a90
movq 0x247209(%rip), %rax    # 0x4bee58
testq %rax, %rax
je 0x277c87
cmpq %rbx, %rax
je 0x277c76
movq %rax, %rcx
movq 0x2f8(%rax), %rax
testq %rax, %rax
je 0x277c87
cmpq %rbx, %rax
jne 0x277c59
addq $0x2f8, %rcx            # imm = 0x2F8
jmp 0x277c7d
leaq 0x2471db(%rip), %rcx    # 0x4bee58
movq 0x2f8(%rax), %rax
movq %rax, (%rcx)
leaq 0x220(%rbx), %r14
movq 0x228(%rbx), %r12
testq %r12, %r12
je 0x277cc8
movq 0x10(%r12), %r15
movq 0x40(%r15), %rsi
movq %rbx, %rdi
callq 0x2f07cb
movq 0x10(%r15), %r13
movq %rbx, %rdi
movq %r15, %rsi
callq 0x282904
movq %r13, %r15
testq %r13, %r13
jne 0x277c9f
movq (%r12), %r12
jmp 0x277c95
movq %r14, %rdi
callq 0x2a5003
leaq 0x238(%rbx), %r14
movq 0x240(%rbx), %r12
testq %r12, %r12
je 0x277d1c
movq 0x10(%r12), %r15
movl $0x20, %r13d
movq (%r15,%r13), %rax
testq %rax, %rax
je 0x277cfe
movq -0x10(%r15,%r13), %rdi
callq *%rax
addq $0x28, %r13
cmpq $0x98, %r13
jne 0x277cee
movq %rbx, %rdi
movq %r15, %rsi
callq 0x282904
movq (%r12), %r12
jmp 0x277cde
movq %r14, %rdi
callq 0x2a5003
leaq 0x1f0(%rbx), %r14
movq 0x1f8(%rbx), %r12
testq %r12, %r12
je 0x277d6a
movq 0x10(%r12), %r15
movq 0x28(%r15), %rsi
testq %rsi, %rsi
je 0x277d59
orb $0x2, 0x40(%rsi)
movq %rbx, %rdi
callq 0x272447
movq $0x0, 0x28(%r15)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x28fc83
movq (%r12), %r12
jmp 0x277d32
movq %r14, %rdi
callq 0x2a5003
movl $0x0, 0x50(%rbx)
cmpq $0x0, 0x160(%rbx)
je 0x277d96
movq %rbx, %rdi
xorl %esi, %esi
callq 0x284b1f
movq 0x160(%rbx), %rdi
jmp 0x277d98
xorl %edi, %edi
callq 0x278453
cmpl $0x0, 0xd4(%rbx)
jle 0x277dc9
xorl %r14d, %r14d
movq (%rbx), %rdi
movq 0xd8(%rbx), %rax
movq (%rax,%r14,8), %rsi
callq *0x60(%rdi)
incq %r14
movslq 0xd4(%rbx), %rax
cmpq %rax, %r14
jl 0x277da9
movq 0xd8(%rbx), %rsi
testq %rsi, %rsi
je 0x277ddd
movq %rbx, %rdi
callq 0x282904
movl $0xb5357930, 0x70(%rbx) # imm = 0xB5357930
movq 0x20(%rbx), %rax
movq 0x38(%rax), %rsi
testq %rsi, %rsi
je 0x277df9
movq %rbx, %rdi
callq 0x282904
movl $0x9f3c2d33, 0x70(%rbx) # imm = 0x9F3C2D33
cmpb $0x0, 0x178(%rbx)
je 0x277e15
movq 0x1b8(%rbx), %rdi
callq 0x272c00
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x272c00