// File: /workspace/github_c_makefile_star2_O1/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9_vm_release
JX9_PRIVATE int jx9_vm_release(jx9_vm *pVm)
{
	jx9 *pEngine;
	int rc;
	/* Ticket 1433-002: NULL VM is harmless operation */
	if ( JX9_VM_MISUSE(pVm) ){
		return JX9_CORRUPT;
	}
#if defined(JX9_ENABLE_THREADS)
	 /* Acquire VM mutex */
	 SyMutexEnter(sJx9MPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sJx9MPGlobal.nThreadingLevel != JX9_THREAD_LEVEL_MULTI */
	 if( sJx9MPGlobal.nThreadingLevel > JX9_THREAD_LEVEL_SINGLE && 
		 JX9_THRD_VM_RELEASE(pVm) ){
			 return JX9_ABORT; /* Another thread have released this instance */
	 }
#endif
	pEngine = pVm->pEngine;
	rc = jx9VmRelease(&(*pVm));
#if defined(JX9_ENABLE_THREADS)
	 /* Leave VM mutex */
	 SyMutexLeave(sJx9MPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sJx9MPGlobal.nThreadingLevel != JX9_THREAD_LEVEL_MULTI */
	 /* Release VM mutex */
	 SyMutexRelease(sJx9MPGlobal.pMutexMethods, pVm->pMutex) /* NO-OP if sJx9MPGlobal.nThreadingLevel != JX9_THREAD_LEVEL_MULTI */
#endif
	if( rc == JX9_OK ){
		/* Unlink from the list of active VM */
#if defined(JX9_ENABLE_THREADS)
			/* Acquire engine mutex */
			SyMutexEnter(sJx9MPGlobal.pMutexMethods, pEngine->pMutex); /* NO-OP if sJx9MPGlobal.nThreadingLevel != JX9_THREAD_LEVEL_MULTI */
			if( sJx9MPGlobal.nThreadingLevel > JX9_THREAD_LEVEL_SINGLE && 
				JX9_THRD_ENGINE_RELEASE(pEngine) ){
					return JX9_ABORT; /* Another thread have released this instance */
			}
#endif
		MACRO_LD_REMOVE(pEngine->pVms, pVm);
		pEngine->iVm--;
		/* Release the memory chunk allocated to this VM */
		SyMemBackendPoolFree(&pEngine->sAllocator, pVm);
#if defined(JX9_ENABLE_THREADS)
			/* Leave engine mutex */
			SyMutexLeave(sJx9MPGlobal.pMutexMethods, pEngine->pMutex); /* NO-OP if sJx9MPGlobal.nThreadingLevel != JX9_THREAD_LEVEL_MULTI */
#endif	
	}
	return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
testq %rdi, %rdi
je 0x2f5ea
movq %rdi, %rbx
cmpl $0xdead2bad, 0x6e8(%rdi) # imm = 0xDEAD2BAD
jne 0x2f5ef
popq %rbx
popq %r14
popq %rbp
retq
movq 0xb8(%rbx), %rdi
testq %rdi, %rdi
je 0x2f605
movq 0x67a9e(%rip), %rax     # 0x970a0
callq *0x20(%rax)
cmpl $0x2, 0x67aa4(%rip)     # 0x970b0
jb 0x2f61a
cmpl $0xdead2bad, 0x6e8(%rbx) # imm = 0xDEAD2BAD
je 0x2f5ea
movq 0xc0(%rbx), %r14
movl $0xdead2bad, 0x6e8(%rbx) # imm = 0xDEAD2BAD
movq %rbx, %rdi
callq 0x2ea67
movq 0xb8(%rbx), %rdi
testq %rdi, %rdi
je 0x2f649
movq 0x67a5a(%rip), %rax     # 0x970a0
callq *0x30(%rax)
movq 0xb8(%rbx), %rdi
testq %rdi, %rdi
je 0x2f667
movq 0x67a44(%rip), %rax     # 0x970a0
movq 0x18(%rax), %rax
testq %rax, %rax
je 0x2f667
callq *%rax
movq 0xf0(%r14), %rdi
testq %rdi, %rdi
je 0x2f67d
movq 0x67a26(%rip), %rax     # 0x970a0
callq *0x20(%rax)
cmpl $0x2, 0x67a2c(%rip)     # 0x970b0
jb 0x2f697
cmpl $0xf874bcd7, 0x118(%r14) # imm = 0xF874BCD7
jne 0x2f5ea
movq 0xf8(%r14), %rax
cmpq %rbx, %rax
jne 0x2f6b1
movq 0x6d8(%rax), %rax
movq %rax, 0xf8(%r14)
movq 0x6e0(%rbx), %rax
testq %rax, %rax
je 0x2f6cb
movq 0x6d8(%rbx), %rcx
movq %rcx, 0x6d8(%rax)
movq 0x6d8(%rbx), %rcx
testq %rcx, %rcx
je 0x2f6de
movq %rax, 0x6e0(%rcx)
decl 0x100(%r14)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2eb38
movq 0xf0(%r14), %rdi
testq %rdi, %rdi
je 0x2f5ea
movq 0x67999(%rip), %rax     # 0x970a0
popq %rbx
popq %r14
popq %rbp
jmpq *0x30(%rax)