// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x64cffc7f, 0x70(%rax) # imm = 0x64CFFC7F
jne 0x3c6e37
movq -0x8(%rbp), %rdi
callq 0x46e510
cmpl $0x0, %eax
je 0x3c6e3c
jmp 0x3c70e9
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x3ec080
movq -0x8(%rbp), %rdi
callq 0x3ec1e0
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jge 0x3c6ebf
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 0x3c6eb2
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x3ed150
movq -0x20(%rbp), %rax
movq $0x0, 0x8(%rax)
cmpl $0x1, -0x14(%rbp)
je 0x3c6eb0
movq -0x20(%rbp), %rax
movq $0x0, 0x18(%rax)
jmp 0x3c6eb2
jmp 0x3c6eb4
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x3c6e57
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
cmpq $0x0, 0x38(%rax)
je 0x3c6edf
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x38(%rax), %rdi
callq 0x3fd890
movq -0x8(%rbp), %rdi
callq 0x40bad0
movq -0x8(%rbp), %rdi
callq 0x411880
movq -0x8(%rbp), %rdi
callq 0x46e620
movq -0x8(%rbp), %rax
movq 0x228(%rax), %rax
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x3c6f60
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x46e650
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x3c00a0
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x3c6f1c
jmp 0x3c6f53
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
jmp 0x3c6f09
movq -0x8(%rbp), %rdi
addq $0x220, %rdi            # imm = 0x220
callq 0x40aa20
movq -0x8(%rbp), %rax
movq 0x240(%rax), %rax
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x3c700b
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x14(%rbp)
cmpl $0x3, -0x14(%rbp)
jge 0x3c6fee
movq -0x38(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, 0x20(%rax)
je 0x3c6fe1
movq -0x38(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x20(%rax), %rax
movq -0x38(%rbp), %rcx
movslq -0x14(%rbp), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movq 0x10(%rcx), %rdi
callq *%rax
jmp 0x3c6fe3
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x3c6f9d
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x3c00a0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
jmp 0x3c6f7f
movq -0x8(%rbp), %rdi
addq $0x238, %rdi            # imm = 0x238
callq 0x40aa20
movq -0x8(%rbp), %rax
movq 0x1f8(%rax), %rax
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x3c7064
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x410ec0
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x3eb6e0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
jmp 0x3c702a
movq -0x8(%rbp), %rdi
addq $0x1f0, %rdi            # imm = 0x1F0
callq 0x40aa20
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x3c5210
movq -0x8(%rbp), %rax
movq 0x160(%rax), %rdi
callq 0x3c7ef0
movq -0x8(%rbp), %rdi
callq 0x46e6b0
movq -0x8(%rbp), %rax
movl $0xb5357930, 0x70(%rax) # imm = 0xB5357930
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x38(%rax), %rsi
callq 0x3c00a0
movq -0x8(%rbp), %rax
movl $0x9f3c2d33, 0x70(%rax) # imm = 0x9F3C2D33
movq -0x8(%rbp), %rax
cmpb $0x0, 0x178(%rax)
je 0x3c70e0
movq -0x8(%rbp), %rax
movq 0x1b8(%rax), %rdi
callq 0x3c0800
movq -0x8(%rbp), %rdi
callq 0x3c0800
addq $0x40, %rsp
popq %rbp
retq
nop