// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9CompileStatic
static sxi32 jx9CompileStatic(jx9_gen_state *pGen)
{
	jx9_vm_func_static_var sStatic; /* Structure describing the static variable */
	jx9_vm_func *pFunc;             /* Enclosing function */
	GenBlock *pBlock;
	SyString *pName;
	char *zDup;
	sxu32 nLine;
	sxi32 rc;
	/* Jump the static keyword */
	nLine = pGen->pIn->nLine;
	pGen->pIn++;
	/* Extract the enclosing function if any */
	pBlock = pGen->pCurrent;
	while( pBlock ){
		if( pBlock->iFlags & GEN_BLOCK_FUNC){
			break;
		}
		/* Point to the upper block */
		pBlock = pBlock->pParent;
	}
	if( pBlock == 0 ){
		/* Static statement, called outside of a function body, treat it as a simple variable. */
		if( pGen->pIn >= pGen->pEnd || (pGen->pIn->nType & JX9_TK_DOLLAR) == 0 ){
			rc = jx9GenCompileError(&(*pGen), E_ERROR, nLine, "Expected variable after 'static' keyword");
			if( rc == SXERR_ABORT ){
				return SXERR_ABORT;
			}
			goto Synchronize;
		}
		/* Compile the expression holding the variable */
		rc = jx9CompileExpr(&(*pGen), 0, 0);
		if( rc == SXERR_ABORT ){
			return SXERR_ABORT;
		}else if( rc != SXERR_EMPTY ){
			/* Emit the POP instruction */
			jx9VmEmitInstr(pGen->pVm, JX9_OP_POP, 1, 0, 0, 0);
		}
		return SXRET_OK;
	}
	pFunc = (jx9_vm_func *)pBlock->pUserData;
	/* Make sure we are dealing with a valid statement */
	if( pGen->pIn >= pGen->pEnd || (pGen->pIn->nType & JX9_TK_DOLLAR) == 0 || &pGen->pIn[1] >= pGen->pEnd ||
		(pGen->pIn[1].nType & (JX9_TK_ID|JX9_TK_KEYWORD)) == 0 ){
			rc = jx9GenCompileError(&(*pGen), E_ERROR, nLine, "Expected variable after 'static' keyword");
			if( rc == SXERR_ABORT ){
				return SXERR_ABORT;
			}
			goto Synchronize;
	}
	pGen->pIn++;
	/* Extract variable name */
	pName = &pGen->pIn->sData;
	pGen->pIn++; /* Jump the var name */
	if( pGen->pIn < pGen->pEnd && (pGen->pIn->nType & (JX9_TK_SEMI/*';'*/|JX9_TK_EQUAL/*'='*/)) == 0 ){
		rc = jx9GenCompileError(&(*pGen), E_ERROR, pGen->pIn->nLine, "static: Unexpected token '%z'", &pGen->pIn->sData);
		goto Synchronize;
	}
	/* Initialize the structure describing the static variable */
	SySetInit(&sStatic.aByteCode, &pGen->pVm->sAllocator, sizeof(VmInstr));
	sStatic.nIdx = SXU32_HIGH; /* Not yet created */
	/* Duplicate variable name */
	zDup = SyMemBackendStrDup(&pGen->pVm->sAllocator, pName->zString, pName->nByte);
	if( zDup == 0 ){
		jx9GenCompileError(&(*pGen), E_ERROR, nLine, "Fatal, JX9 engine is running out of memory");
		return SXERR_ABORT;
	}
	SyStringInitFromBuf(&sStatic.sName, zDup, pName->nByte);
	/* Check if we have an expression to compile */
	if( pGen->pIn < pGen->pEnd && (pGen->pIn->nType & JX9_TK_EQUAL) ){
		SySet *pInstrContainer;
		pGen->pIn++; /* Jump the equal '=' sign */
		/* Swap bytecode container */
		pInstrContainer = jx9VmGetByteCodeContainer(pGen->pVm);
		jx9VmSetByteCodeContainer(pGen->pVm, &sStatic.aByteCode);
		/* Compile the expression */
		rc = jx9CompileExpr(&(*pGen), 0, 0);
		/* Emit the done instruction */
		jx9VmEmitInstr(pGen->pVm, JX9_OP_DONE, (rc != SXERR_EMPTY ? 1 : 0), 0, 0, 0);
		/* Restore default bytecode container */
		jx9VmSetByteCodeContainer(pGen->pVm, pInstrContainer);
	}
	/* Finally save the compiled static variable in the appropriate container */
	SySetPut(&pFunc->aStatic, (const void *)&sStatic);
	return SXRET_OK;
Synchronize:
	/* Synchronize with the first semi-colon ';', so we can avoid compiling this erroneous
	 * statement. 
	 */
	while(pGen->pIn < pGen->pEnd && (pGen->pIn->nType & JX9_TK_SEMI) ==  0 ){
		pGen->pIn++;
	}
	return SXRET_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x40, %rsp
movq %rdi, %rbx
movq 0x158(%rdi), %r12
movl 0x14(%r12), %r14d
leaq 0x20(%r12), %rcx
movq %rcx, 0x158(%rdi)
leaq 0xc8(%rdi), %rax
movq (%rax), %rax
testq %rax, %rax
je 0x41ef2
testb $0x8, 0x14(%rax)
jne 0x41f44
addq $0x8, %rax
jmp 0x41ede
cmpq 0x160(%rbx), %rcx
jae 0x42073
testb $0x10, 0x30(%r12)
je 0x42073
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4012f
cmpl $-0xa, %eax
je 0x42092
cmpl $-0x3, %eax
je 0x4206f
movq (%rbx), %rdi
pushq $0xb
popq %rsi
pushq $0x1
popq %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x3ee6f
jmp 0x4206f
movq 0x160(%rbx), %rdx
cmpq %rdx, %rcx
jae 0x42073
testb $0x10, 0x30(%r12)
je 0x42073
leaq 0x40(%r12), %rcx
cmpq %rdx, %rcx
jae 0x42073
testb $0xc, 0x50(%r12)
je 0x42073
movq 0x40(%rax), %r15
leaq 0x60(%r12), %r8
movq %r8, 0x158(%rbx)
cmpq %rdx, %r8
jae 0x41f9b
testb $0x44, 0x72(%r12)
je 0x420b8
movq (%rbx), %rdi
movabsq $0x1800000000, %rax     # imm = 0x1800000000
movq %rax, -0x3c(%rbp)
andl $0x0, -0x40(%rbp)
andl $0x0, -0x34(%rbp)
movq %rdi, -0x50(%rbp)
andq $0x0, -0x48(%rbp)
andq $0x0, -0x30(%rbp)
orl $-0x1, -0x28(%rbp)
movq 0x40(%r12), %rsi
movl 0x48(%r12), %edx
callq 0x35732
testq %rax, %rax
je 0x4209f
movq %rax, -0x60(%rbp)
movl 0x48(%r12), %eax
movl %eax, -0x58(%rbp)
movq 0x158(%rbx), %rax
cmpq 0x160(%rbx), %rax
jae 0x4205f
testb $0x40, 0x12(%rax)
je 0x4205f
leaq -0x50(%rbp), %rcx
addq $0x20, %rax
movq %rax, 0x158(%rbx)
movq (%rbx), %rax
movq 0xf0(%rax), %r14
movq %rcx, 0xf0(%rax)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4012f
movq (%rbx), %rdi
xorl %edx, %edx
cmpl $-0x3, %eax
setne %dl
pushq $0x1
popq %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x3ee6f
movq (%rbx), %rax
leaq 0xc8(%rax), %rcx
testq %r14, %r14
cmovneq %r14, %rcx
movq %rcx, 0xf0(%rax)
addq $0x28, %r15
leaq -0x60(%rbp), %rsi
movq %r15, %rdi
callq 0x2be00
xorl %eax, %eax
jmp 0x42092
leaq 0x23bad(%rip), %rcx     # 0x65c27
pushq $0x1
popq %rsi
movq %rbx, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0x3eed6
cmpl $-0xa, %eax
jne 0x420d1
pushq $-0xa
popq %rax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x23bc8(%rip), %rcx     # 0x65c6e
pushq $0x1
popq %rsi
movq %rbx, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0x3eed6
jmp 0x4208f
movl 0x74(%r12), %edx
leaq 0x23b8c(%rip), %rcx     # 0x65c50
pushq $0x1
popq %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3eed6
movq 0x158(%rbx), %rcx
movq 0x160(%rbx), %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
jae 0x42092
testb $0x4, 0x12(%rcx)
jne 0x42092
addq $0x20, %rcx
movq %rcx, 0x158(%rbx)
jmp 0x420e1