// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: sqlite3Close
static int sqlite3Close(sqlite3 *db, int forceZombie){
  if( !db ){
    /* EVIDENCE-OF: R-63257-11740 Calling sqlite3_close() or
    ** sqlite3_close_v2() with a NULL pointer argument is a harmless no-op. */
    return SQLITE_OK;
  }
  if( !sqlite3SafetyCheckSickOrOk(db) ){
    return SQLITE_MISUSE_BKPT;
  }
  sqlite3_mutex_enter(db->mutex);
  if( db->mTrace & SQLITE_TRACE_CLOSE ){
    db->trace.xV2(SQLITE_TRACE_CLOSE, db->pTraceArg, db, 0);
  }

  /* Force xDisconnect calls on all virtual tables */
  disconnectAllVtab(db);

  /* If a transaction is open, the disconnectAllVtab() call above
  ** will not have called the xDisconnect() method on any virtual
  ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
  ** call will do so. We need to do this before the check for active
  ** SQL statements below, as the v-table implementation may be storing
  ** some prepared statements internally.
  */
  sqlite3VtabRollback(db);

  /* Legacy behavior (sqlite3_close() behavior) is to return
  ** SQLITE_BUSY if the connection can not be closed immediately.
  */
  if( !forceZombie && connectionIsBusy(db) ){
    sqlite3ErrorWithMsg(db, SQLITE_BUSY, "unable to close due to unfinalized "
       "statements or unfinished backups");
    sqlite3_mutex_leave(db->mutex);
    return SQLITE_BUSY;
  }

#ifdef SQLITE_ENABLE_SQLLOG
  if( sqlite3GlobalConfig.xSqllog ){
    /* Closing the handle. Fourth parameter is passed the value 2. */
    sqlite3GlobalConfig.xSqllog(sqlite3GlobalConfig.pSqllogArg, db, 0, 2);
  }
#endif

  /* Convert the connection into a zombie and then close it.
  */
  db->magic = SQLITE_MAGIC_ZOMBIE;
  sqlite3LeaveMutexAndCloseZombie(db);
  return SQLITE_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x22a6a5
movl %esi, %ebp
movq %rdi, %rbx
callq 0x22b247
testl %eax, %eax
je 0x22a6b4
testb $0x8, 0x68(%rbx)
je 0x22a60e
movq 0xe8(%rbx), %rsi
pushq $0x8
popq %rdi
movq %rbx, %rdx
xorl %ecx, %ecx
callq *0xe0(%rbx)
movq %rbx, %rdi
callq 0x21f0e2
xorl %r14d, %r14d
movslq 0x28(%rbx), %rax
cmpq %rax, %r14
jge 0x22a65c
movq 0x20(%rbx), %rax
movq %r14, %rcx
shlq $0x5, %rcx
movq 0x18(%rax,%rcx), %r15
testq %r15, %r15
je 0x22a657
addq $0x10, %r15
movq (%r15), %r15
testq %r15, %r15
je 0x22a657
movq 0x10(%r15), %rsi
cmpl $0x0, 0x54(%rsi)
je 0x22a63b
movq %rbx, %rdi
callq 0x28a807
jmp 0x22a63b
incq %r14
jmp 0x22a619
leaq 0x1f8(%rbx), %r14
movq (%r14), %r14
testq %r14, %r14
je 0x22a682
movq 0x10(%r14), %rax
movq 0x28(%rax), %rsi
testq %rsi, %rsi
je 0x22a663
movq %rbx, %rdi
callq 0x28a807
jmp 0x22a663
movq %rbx, %rdi
callq 0x24b12d
movq %rbx, %rdi
callq 0x239b40
testl %ebp, %ebp
je 0x22a6c8
movl $0x64cffc7f, 0x70(%rbx) # imm = 0x64CFFC7F
movq %rbx, %rdi
callq 0x223e27
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl $0x27998, %edi          # imm = 0x27998
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x21ec3c
movq %rbx, %rdi
callq 0x28a7cc
testl %eax, %eax
je 0x22a696
leaq 0x14fff1(%rip), %rdx    # 0x37a6cc
pushq $0x5
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
xorl %eax, %eax
callq 0x2226f3
jmp 0x22a6a7