// File: /workspace/github_c_makefile_star2_O1/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 0x281556
movq %rdi, %rbx
callq 0x2f9ae4
testl %eax, %eax
je 0x281560
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %rbx, %rdi
xorl %esi, %esi
callq 0x29a0cd
movq %rbx, %rdi
callq 0x29a22c
cmpl $0x0, 0x28(%rbx)
jle 0x2815ba
movl $0x8, %r14d
xorl %r15d, %r15d
movq 0x20(%rbx), %r12
movq (%r12,%r14), %rdi
testq %rdi, %rdi
je 0x2815aa
callq 0x29ac32
movq $0x0, (%r12,%r14)
cmpq $0x1, %r15
je 0x2815aa
movq $0x0, 0x10(%r12,%r14)
incq %r15
movslq 0x28(%rbx), %rax
addq $0x20, %r14
cmpq %rax, %r15
jl 0x281581
movq 0x20(%rbx), %rax
movq 0x38(%rax), %rdi
testq %rdi, %rdi
je 0x2815cc
callq 0x2a6f82
movq %rbx, %rdi
callq 0x2af7a6
movq %rbx, %rdi
callq 0x2b2ce2
movq %rbx, %rdi
callq 0x29a897
movq 0x24886d(%rip), %rax    # 0x4c9e58
testq %rax, %rax
je 0x281623
cmpq %rbx, %rax
je 0x281612
movq %rax, %rcx
movq 0x2f8(%rax), %rax
testq %rax, %rax
je 0x281623
cmpq %rbx, %rax
jne 0x2815f5
addq $0x2f8, %rcx            # imm = 0x2F8
jmp 0x281619
leaq 0x24883f(%rip), %rcx    # 0x4c9e58
movq 0x2f8(%rax), %rax
movq %rax, (%rcx)
leaq 0x220(%rbx), %r14
movq 0x228(%rbx), %r12
testq %r12, %r12
je 0x281668
movq 0x10(%r12), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2f9b59
movq 0x10(%r15), %r13
testq %r15, %r15
je 0x28165a
movq %rbx, %rdi
movq %r15, %rsi
callq 0x28c3e7
movq %r13, %r15
testq %r13, %r13
jne 0x28163b
movq (%r12), %r12
jmp 0x281631
movq %r14, %rdi
callq 0x2aebab
leaq 0x238(%rbx), %r14
movq 0x240(%rbx), %r12
testq %r12, %r12
je 0x2816c1
movq 0x10(%r12), %r15
movl $0x20, %r13d
movq (%r15,%r13), %rax
testq %rax, %rax
je 0x28169e
movq -0x10(%r15,%r13), %rdi
callq *%rax
addq $0x28, %r13
cmpq $0x98, %r13
jne 0x28168e
testq %r15, %r15
je 0x2816bb
movq %rbx, %rdi
movq %r15, %rsi
callq 0x28c3e7
movq (%r12), %r12
jmp 0x28167e
movq %r14, %rdi
callq 0x2aebab
leaq 0x1f0(%rbx), %r14
movq 0x1f8(%rbx), %r12
testq %r12, %r12
je 0x28170f
movq 0x10(%r12), %r15
movq 0x28(%r15), %rsi
testq %rsi, %rsi
je 0x2816fe
orb $0x2, 0x40(%rsi)
movq %rbx, %rdi
callq 0x27bd74
movq $0x0, 0x28(%r15)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x299a37
movq (%r12), %r12
jmp 0x2816d7
movq %r14, %rdi
callq 0x2aebab
movl $0x0, 0x50(%rbx)
cmpq $0x0, 0x160(%rbx)
je 0x281732
movq %rbx, %rdi
xorl %esi, %esi
callq 0x28e696
movq 0x160(%rbx), %rdi
callq 0x281de6
cmpl $0x0, 0xd4(%rbx)
jle 0x28176a
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 0x28174a
movq 0xd8(%rbx), %rsi
testq %rsi, %rsi
je 0x28177e
movq %rbx, %rdi
callq 0x28c3e7
movl $0xb5357930, 0x70(%rbx) # imm = 0xB5357930
movq 0x20(%rbx), %rax
movq 0x38(%rax), %rsi
testq %rsi, %rsi
je 0x28179a
movq %rbx, %rdi
callq 0x28c3e7
movl $0x9f3c2d33, 0x70(%rbx) # imm = 0x9F3C2D33
cmpb $0x0, 0x178(%rbx)
je 0x2817b6
movq 0x1b8(%rbx), %rdi
callq 0x27c490
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x27c490