// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: unqliteInitVm
static int unqliteInitVm(unqlite *pDb,jx9_vm *pJx9Vm,unqlite_vm **ppOut)
{
	unqlite_vm *pVm;

	*ppOut = 0;
	/* Allocate a new VM instance */
	pVm = (unqlite_vm *)SyMemBackendPoolAlloc(&pDb->sMem,sizeof(unqlite_vm));
	if( pVm == 0 ){
		return UNQLITE_NOMEM;
	}
	/* Zero the structure */
	SyZero(pVm,sizeof(unqlite_vm));
	/* Initialize */
	SyMemBackendInitFromParent(&pVm->sAlloc,&pDb->sMem);
	/* Allocate a new collection table */
	pVm->apCol = (unqlite_col **)SyMemBackendAlloc(&pVm->sAlloc,32 * sizeof(unqlite_col *)); 
	if( pVm->apCol == 0 ){
		goto fail;
	}
	pVm->iColSize = 32; /* Must be a power of two */
	/* Zero the table */
	SyZero((void *)pVm->apCol,pVm->iColSize * sizeof(unqlite_col *));
#if defined(UNQLITE_ENABLE_THREADS)
	if( sUnqlMPGlobal.nThreadingLevel > UNQLITE_THREAD_LEVEL_SINGLE ){
		 /* Associate a recursive mutex with this instance */
		 pVm->pMutex = SyMutexNew(sUnqlMPGlobal.pMutexMethods, SXMUTEX_TYPE_RECURSIVE);
		 if( pVm->pMutex == 0 ){
			 goto fail;
		 }
	 }
#endif
	/* Link the VM to the list of active virtual machines */
	pVm->pJx9Vm = pJx9Vm;
	pVm->pDb = pDb;
	MACRO_LD_PUSH(pDb->pVms,pVm);
	pDb->iVm++;
	/* Register Jx9 functions */
	unqliteRegisterJx9Functions(pVm);
	/* Set the magic number */
	pVm->nMagic = JX9_VM_INIT; /* Same magic number as Jx9 */
	/* All done */
	*ppOut = pVm;
	return UNQLITE_OK;
fail:
	SyMemBackendRelease(&pVm->sAlloc);
	SyMemBackendPoolFree(&pDb->sMem,pVm);
	return UNQLITE_NOMEM;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movq -0x10(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x541f0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x54e34
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x54fc2
movq -0x28(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x54280
movq -0x28(%rbp), %rdi
addq $0x8, %rdi
movq -0x10(%rbp), %rsi
callq 0x60230
movq -0x28(%rbp), %rdi
addq $0x8, %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x5bf70
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0xc8(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0xc8(%rax)
jne 0x54e86
jmp 0x54fa1
movq -0x28(%rbp), %rax
movl $0x20, 0xdc(%rax)
movq -0x28(%rbp), %rax
movq 0xc8(%rax), %rdi
movq -0x28(%rbp), %rax
movl 0xdc(%rax), %eax
shlq $0x3, %rax
movl %eax, %esi
callq 0x54280
cmpl $0x1, 0x999cd(%rip)     # 0xee888
jbe 0x54eef
movq 0x999b4(%rip), %rax     # 0xee878
movl $0x2, %edi
callq *0x10(%rax)
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0xc0(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0xc0(%rax)
jne 0x54eed
jmp 0x54fa1
jmp 0x54eef
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0xe0(%rax)
movq -0x10(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x100(%rax)
jne 0x54f28
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x100(%rax)
jmp 0x54f63
movq -0x10(%rbp), %rax
movq 0x100(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0xe8(%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x100(%rax), %rax
movq %rcx, 0xf0(%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x100(%rax)
movq -0x10(%rbp), %rax
movl 0x108(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x108(%rax)
movq -0x28(%rbp), %rdi
callq 0x6bcc0
movq -0x28(%rbp), %rax
movl $0xea12cd72, 0xf8(%rax) # imm = 0xEA12CD72
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x54fc2
movq -0x28(%rbp), %rdi
addq $0x8, %rdi
callq 0x543e0
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x54490
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)