// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9VmCallUserFunction
JX9_PRIVATE sxi32 jx9VmCallUserFunction(
	jx9_vm *pVm,       /* Target VM */
	jx9_value *pFunc,  /* Callback name */
	int nArg,          /* Total number of given arguments */
	jx9_value **apArg, /* Callback arguments */
	jx9_value *pResult /* Store callback return value here. NULL otherwise */
	)
{
	jx9_value *aStack;
	VmInstr aInstr[2];
	int i;
	if((pFunc->iFlags & (MEMOBJ_STRING)) == 0 ){
		/* Don't bother processing, it's invalid anyway */
		if( pResult ){
			/* Assume a null return value */
			jx9MemObjRelease(pResult);
		}
		return SXERR_INVALID;
	}
	/* Create a new operand stack */
	aStack = VmNewOperandStack(&(*pVm), 1+nArg);
	if( aStack == 0 ){
		jx9VmThrowError(&(*pVm), 0, JX9_CTX_ERR, 
			"JX9 is running out of memory while invoking user callback");
		if( pResult ){
			/* Assume a null return value */
			jx9MemObjRelease(pResult);
		}
		return SXERR_MEM;
	}
	/* Fill the operand stack with the given arguments */
	for( i = 0 ; i < nArg ; i++ ){
		jx9MemObjLoad(apArg[i], &aStack[i]);
		aStack[i].nIdx = apArg[i]->nIdx;
	}
	/* Push the function name */
	jx9MemObjLoad(pFunc, &aStack[i]);
	aStack[i].nIdx = SXU32_HIGH; /* Mark as constant */
	/* Emit the CALL istruction */
	aInstr[0].iOp = JX9_OP_CALL;
	aInstr[0].iP1 = nArg; /* Total number of given arguments */
	aInstr[0].iP2 = 0;
	aInstr[0].p3  = 0;
	/* Emit the DONE instruction */
	aInstr[1].iOp = JX9_OP_DONE;
	aInstr[1].iP1 = 1;   /* Extract function return value if available */
	aInstr[1].iP2 = 0;
	aInstr[1].p3  = 0;
	/* Execute the function body (if available) */
	VmByteCodeExec(&(*pVm), aInstr, aStack, nArg, pResult);
	/* Clean up the mess left behind */
	SyMemBackendFree(&pVm->sAllocator, aStack);
	return JX9_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, %r14
testb $0x1, 0x8(%rsi)
jne 0x381a2
pushq $-0x9
jmp 0x38283
movq %rcx, %rbx
movl %edx, %r12d
movq %rdi, %r15
movq %rsi, -0x48(%rbp)
leal 0x1(%r12), %esi
callq 0x3832f
testq %rax, %rax
je 0x3826d
movq %rax, %r13
movq %r15, -0x38(%rbp)
movq %r14, -0x40(%rbp)
xorl %r14d, %r14d
testl %r12d, %r12d
movl $0x0, %r15d
movq %r12, -0x30(%rbp)
cmovgl %r12d, %r15d
movq %rax, %r12
cmpq %r14, %r15
je 0x3820a
movq (%rbx,%r14,8), %rdi
movq %r12, %rsi
callq 0x38492
movq (%rbx,%r14,8), %rax
movl 0x38(%rax), %eax
movl %eax, 0x38(%r12)
incq %r14
addq $0x40, %r12
jmp 0x381e4
shlq $0x6, %r15
movq %r13, %rsi
addq %r15, %rsi
movq -0x48(%rbp), %rdi
callq 0x38492
orl $-0x1, 0x38(%r13,%r15)
leaq -0x80(%rbp), %rsi
movb $0x10, (%rsi)
movq -0x30(%rbp), %rcx
movl %ecx, 0x4(%rsi)
andl $0x0, 0x8(%rsi)
andq $0x0, 0x10(%rsi)
movb $0x1, 0x18(%rsi)
movq $0x1, 0x1c(%rsi)
andq $0x0, 0x28(%rsi)
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
movq %r13, %rdx
movq -0x40(%rbp), %r8
callq 0x384e3
movq %rbx, %rdi
movq %r13, %rsi
callq 0x2d420
xorl %ebx, %ebx
jmp 0x38291
leaq 0x2be87(%rip), %rcx     # 0x640fb
pushq $0x1
popq %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x38388
pushq $-0x1
popq %rbx
testq %r14, %r14
je 0x38291
movq %r14, %rdi
callq 0x296af
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq