// File: /workspace/github_c_makefile_star2_O1/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 0x412fa
movl $0xfffffff7, %ebx       # imm = 0xFFFFFFF7
jmp 0x41372
movq %rcx, %r15
movl %edx, %r13d
movq %rsi, %rbx
movq %rdi, %r12
leal 0x1(%r13), %esi
callq 0x414b8
testq %rax, %rax
je 0x41357
movq %r12, -0x40(%rbp)
movq %r14, -0x48(%rbp)
testl %r13d, %r13d
movq %r13, -0x38(%rbp)
movq %rax, -0x30(%rbp)
jle 0x41381
movl %r13d, %r14d
xorl %r12d, %r12d
movq %rax, %r13
movq (%r15,%r12,8), %rdi
movq %r13, %rsi
callq 0x41707
movq (%r15,%r12,8), %rax
movl 0x38(%rax), %eax
movl %eax, 0x38(%r13)
incq %r12
addq $0x40, %r13
cmpq %r12, %r14
jne 0x41332
jmp 0x41384
leaq 0x34db5(%rip), %rcx     # 0x76113
movq %r12, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x4153c
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x413ec
movq %r14, %rdi
callq 0x309f2
jmp 0x413ec
xorl %r12d, %r12d
shlq $0x6, %r12
movq -0x30(%rbp), %r15
movq %r15, %rsi
addq %r12, %rsi
movq %rbx, %rdi
callq 0x41707
movl $0xffffffff, 0x38(%r15,%r12) # imm = 0xFFFFFFFF
leaq -0x80(%rbp), %rsi
movb $0x10, (%rsi)
movq -0x38(%rbp), %rcx
movl %ecx, 0x4(%rsi)
movl $0x0, 0x8(%rsi)
xorl %ebx, %ebx
movq %rbx, 0x10(%rsi)
movb $0x1, 0x18(%rsi)
movq $0x1, 0x1c(%rsi)
movq %rbx, 0x28(%rsi)
movq -0x40(%rbp), %r14
movq %r14, %rdi
movq %r15, %rdx
movq -0x48(%rbp), %r8
callq 0x4175d
movq %r14, %rdi
movq %r15, %rsi
callq 0x3503f
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq