// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: GenStateCompileFunc
static sxi32 GenStateCompileFunc(
	jx9_gen_state *pGen, /* Code generator state */
	SyString *pName,     /* Function name. NULL otherwise */
	sxi32 iFlags,        /* Control flags */
	jx9_vm_func **ppFunc /* OUT: function state */
	)
{
	jx9_vm_func *pFunc;
	SyToken *pEnd;
	sxu32 nLine;
	char *zName;
	sxi32 rc;
	/* Extract line number */
	nLine = pGen->pIn->nLine;
	/* Jump the left parenthesis '(' */
	pGen->pIn++;
	/* Delimit the function signature */
	jx9DelimitNestedTokens(pGen->pIn, pGen->pEnd, JX9_TK_LPAREN /* '(' */, JX9_TK_RPAREN /* ')' */, &pEnd);
	if( pEnd >= pGen->pEnd ){
		/* Syntax error */
		rc = jx9GenCompileError(pGen, E_ERROR, nLine, "Missing ')' after function '%z' signature", pName);
		if( rc == SXERR_ABORT ){
			/* Error count limit reached, abort immediately */
			return SXERR_ABORT;
		}
		pGen->pIn = pGen->pEnd;
		return SXRET_OK;
	}
	/* Create the function state */
	pFunc = (jx9_vm_func *)SyMemBackendPoolAlloc(&pGen->pVm->sAllocator, sizeof(jx9_vm_func));
	if( pFunc == 0 ){
		goto OutOfMem;
	}
	/* function ID */
	zName = SyMemBackendStrDup(&pGen->pVm->sAllocator, pName->zString, pName->nByte);
	if( zName == 0 ){
		/* Don't worry about freeing memory, everything will be released shortly */
		goto OutOfMem;
	}
	/* Initialize the function state */
	jx9VmInitFuncState(pGen->pVm, pFunc, zName, pName->nByte, iFlags, 0);
	if( pGen->pIn < pEnd ){
		/* Collect function arguments */
		rc = GenStateCollectFuncArgs(pFunc, &(*pGen), pEnd);
		if( rc == SXERR_ABORT ){
			/* Don't worry about freeing memory, everything will be released shortly */
			return SXERR_ABORT;
		}
	}
	/* Compile function body */
	pGen->pIn = &pEnd[1];
	/* Compile the body */
	rc = GenStateCompileFuncBody(&(*pGen), pFunc);
	if( rc == SXERR_ABORT ){
		return SXERR_ABORT;
	}
	if( ppFunc ){
		*ppFunc = pFunc;
	}
	/* Finally register the function */
	rc = jx9VmInstallUserFunction(pGen->pVm, pFunc, 0);
	return rc;
	/* Fall through if something goes wrong */
OutOfMem:
	/* If the supplied memory subsystem is so sick that we are unable to allocate
	 * a tiny chunk of memory, there is no much we can do here.
	 */
	return GenStateOutOfMem(pGen);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movl 0x14(%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rcx
addq $0x20, %rcx
movq %rcx, 0x158(%rax)
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x160(%rax), %rsi
movl $0x200, %edx            # imm = 0x200
movl $0x400, %ecx            # imm = 0x400
leaq -0x38(%rbp), %r8
callq 0x841b0
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x160(%rcx), %rax
jb 0x8469d
movq -0x10(%rbp), %rdi
movl -0x3c(%rbp), %edx
movq -0x18(%rbp), %r8
movl $0x1, %esi
leaq 0x3f644(%rip), %rcx     # 0xc3ca3
movb $0x0, %al
callq 0x7e990
movl %eax, -0x4c(%rbp)
cmpl $-0xa, -0x4c(%rbp)
jne 0x8467b
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x847b1
movq -0x10(%rbp), %rax
movq 0x160(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x158(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x847b1
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl $0xb0, %esi
callq 0x541f0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x846be
jmp 0x847a5
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movq -0x18(%rbp), %rax
movl 0x8(%rax), %edx
callq 0x6da40
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x846e8
jmp 0x847a5
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x30(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
movl -0x1c(%rbp), %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x847c0
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
cmpq -0x38(%rbp), %rax
jae 0x84742
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x84880
movl %eax, -0x4c(%rbp)
cmpl $-0xa, -0x4c(%rbp)
jne 0x84740
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x847b1
jmp 0x84742
movq -0x38(%rbp), %rcx
addq $0x20, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x158(%rax)
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x84d90
movl %eax, -0x4c(%rbp)
cmpl $-0xa, -0x4c(%rbp)
jne 0x84774
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x847b1
cmpq $0x0, -0x28(%rbp)
je 0x84786
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x30(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x84e70
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x847b1
movq -0x10(%rbp), %rdi
callq 0x84570
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)