// File: /workspace/github_c_makefile_star2_O1/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9CompileFor
static sxi32 jx9CompileFor(jx9_gen_state *pGen)
{
	SyToken *pTmp, *pPostStart, *pEnd = 0;
	GenBlock *pForBlock = 0;
	sxu32 nFalseJump;
	sxu32 nLine;
	sxi32 rc;
	nLine = pGen->pIn->nLine;
	/* Jump the 'for' keyword */
	pGen->pIn++;    
	if( pGen->pIn >= pGen->pEnd || (pGen->pIn->nType & JX9_TK_LPAREN) == 0 ){
		/* Syntax error */
		rc = jx9GenCompileError(pGen, E_ERROR, nLine, "Expected '(' after 'for' keyword");
		if( rc == SXERR_ABORT ){
			/* Error count limit reached, abort immediately */
			return SXERR_ABORT;
		}
		return SXRET_OK;
	}
	/* Jump the left parenthesis '(' */
	pGen->pIn++; 
	/* Delimit the init-expr;condition;post-expr */
	jx9DelimitNestedTokens(pGen->pIn, pGen->pEnd, JX9_TK_LPAREN /* '(' */, JX9_TK_RPAREN /* ')' */, &pEnd);
	if( pGen->pIn == pEnd || pEnd >= pGen->pEnd ){
		/* Empty expression */
		rc = jx9GenCompileError(pGen, E_ERROR, nLine, "for: Invalid expression");
		if( rc == SXERR_ABORT ){
			/* Error count limit reached, abort immediately */
			return SXERR_ABORT;
		}
		/* Synchronize */
		pGen->pIn = pEnd;
		if( pGen->pIn < pGen->pEnd ){
			pGen->pIn++;
		}
		return SXRET_OK;
	}
	/* Swap token streams */
	pTmp = pGen->pEnd;
	pGen->pEnd = pEnd;
	/* Compile initialization expressions if available */
	rc = jx9CompileExpr(&(*pGen), 0, 0);
	/* Pop operand lvalues */
	if( rc == SXERR_ABORT ){
		/* Expression handler request an operation abort [i.e: Out-of-memory] */
		return SXERR_ABORT;
	}else if( rc != SXERR_EMPTY ){
		jx9VmEmitInstr(pGen->pVm, JX9_OP_POP, 1, 0, 0, 0);
	}
	if( (pGen->pIn->nType & JX9_TK_SEMI) == 0 ){
		/* Syntax error */
		rc = jx9GenCompileError(pGen, E_ERROR, pGen->pIn->nLine, 
			"for: Expected ';' after initialization expressions");
		if( rc == SXERR_ABORT ){
			/* Error count limit reached, abort immediately */
			return SXERR_ABORT;
		}
		return SXRET_OK;
	}
	/* Jump the trailing ';' */
	pGen->pIn++;
	/* Create the loop block */
	rc = GenStateEnterBlock(&(*pGen), GEN_BLOCK_LOOP, jx9VmInstrLength(pGen->pVm), 0, &pForBlock);
	if( rc != SXRET_OK ){
		return SXERR_ABORT;
	}
	/* Deffer continue jumps */
	pForBlock->bPostContinue = TRUE;
	/* Compile the condition */
	rc = jx9CompileExpr(&(*pGen), 0, 0);
	if( rc == SXERR_ABORT ){
		/* Expression handler request an operation abort [i.e: Out-of-memory] */
		return SXERR_ABORT;
	}else if( rc != SXERR_EMPTY ){
		/* Emit the false jump */
		jx9VmEmitInstr(pGen->pVm, JX9_OP_JZ, 0, 0, 0, &nFalseJump);
		/* Save the instruction index so we can fix it later when the jump destination is resolved */
		GenStateNewJumpFixup(pForBlock, JX9_OP_JZ, nFalseJump);
	}
	if( (pGen->pIn->nType & JX9_TK_SEMI) == 0 ){
		/* Syntax error */
		rc = jx9GenCompileError(pGen, E_ERROR, pGen->pIn->nLine, 
			"for: Expected ';' after conditionals expressions");
		if( rc == SXERR_ABORT ){
			/* Error count limit reached, abort immediately */
			return SXERR_ABORT;
		}
		return SXRET_OK;
	}
	/* Jump the trailing ';' */
	pGen->pIn++;
	/* Save the post condition stream */
	pPostStart = pGen->pIn;
	/* Compile the loop body */
	pGen->pIn  = &pEnd[1]; /* Jump the trailing parenthesis ')' */
	pGen->pEnd = pTmp;
	rc = jx9CompileBlock(&(*pGen));
	if( rc == SXERR_ABORT ){
		return SXERR_ABORT;
	}
	/* Fix post-continue jumps */
	if( SySetUsed(&pForBlock->aPostContFix) > 0 ){
		JumpFixup *aPost;
		VmInstr *pInstr;
		sxu32 nJumpDest;
		sxu32 n;
		aPost = (JumpFixup *)SySetBasePtr(&pForBlock->aPostContFix);
		nJumpDest = jx9VmInstrLength(pGen->pVm);
		for( n = 0 ; n < SySetUsed(&pForBlock->aPostContFix) ; ++n ){
			pInstr = jx9VmGetInstr(pGen->pVm, aPost[n].nInstrIdx);
			if( pInstr ){
				/* Fix jump */
				pInstr->iP2 = nJumpDest;
			}
		}
	}
	/* compile the post-expressions if available */
	while( pPostStart < pEnd && (pPostStart->nType & JX9_TK_SEMI) ){
		pPostStart++;
	}
	if( pPostStart < pEnd ){
		SyToken *pTmpIn, *pTmpEnd;
		SWAP_DELIMITER(pGen, pPostStart, pEnd);
		rc = jx9CompileExpr(&(*pGen), 0, 0);
		if( pGen->pIn < pGen->pEnd ){
			/* Syntax error */
			rc = jx9GenCompileError(pGen, E_ERROR, pGen->pIn->nLine, "for: Expected ')' after post-expressions");
			if( rc == SXERR_ABORT ){
				/* Error count limit reached, abort immediately */
				return SXERR_ABORT;
			}
			return SXRET_OK;
		}
		RE_SWAP_DELIMITER(pGen);
		if( rc == SXERR_ABORT ){
			/* Expression handler request an operation abort [i.e: Out-of-memory] */
			return SXERR_ABORT;
		}else if( rc != SXERR_EMPTY){
			/* Pop operand lvalue */
			jx9VmEmitInstr(pGen->pVm, JX9_OP_POP, 1, 0, 0, 0);
		}
	}
	/* Emit the unconditional jump to the start of the loop */
	jx9VmEmitInstr(pGen->pVm, JX9_OP_JMP, 0, pForBlock->nFirstInstr, 0, 0);
	/* Fix all jumps now the destination is resolved */
	GenStateFixJumps(pForBlock, -1, jx9VmInstrLength(pGen->pVm));
	/* Release the loop block */
	GenStateLeaveBlock(pGen, 0);
	/* Statement successfully compiled */
	return SXRET_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq $0x0, -0x30(%rbp)
movq 0x158(%rdi), %r12
movq 0x160(%rdi), %r13
movl 0x14(%r12), %edx
leaq 0x20(%r12), %rax
movq %rax, 0x158(%rdi)
cmpq %r13, %rax
jae 0x4bdbc
testb $0x2, 0x31(%r12)
jne 0x4bdee
leaq 0x2bc28(%rip), %rcx     # 0x779eb
xorl %r14d, %r14d
movq %rbx, %rdi
movl $0x1, %esi
xorl %eax, %eax
callq 0x49434
cmpl $-0xa, %eax
cmovel %eax, %r14d
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x40(%r12), %rcx
movq %rcx, 0x158(%rbx)
movl $0x40, %eax
cmpq %r13, %rcx
jae 0x4be36
movl $0x1, %ecx
movl 0x10(%r12,%rax), %esi
btl $0x9, %esi
jb 0x4be23
btl $0xa, %esi
jae 0x4be25
cmpl $0x2, %ecx
jl 0x4be36
decl %ecx
jmp 0x4be25
incl %ecx
leaq (%r12,%rax), %rsi
addq $0x20, %rsi
addq $0x20, %rax
cmpq %r13, %rsi
jb 0x4be09
addq %rax, %r12
cmpq $0x40, %rax
setne %al
cmpq %r13, %r12
setb %cl
testb %cl, %al
je 0x4bea5
movq %r12, 0x160(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4a7a9
movl %eax, %r14d
cmpl $-0xa, %eax
je 0x4bddc
cmpl $-0x3, %r14d
je 0x4be89
movq (%rbx), %rdi
movl $0xb, %esi
movl $0x1, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x493c1
movq 0x158(%rbx), %rax
testb $0x4, 0x12(%rax)
jne 0x4beed
movl 0x14(%rax), %edx
leaq 0x2bb84(%rip), %rcx     # 0x77a24
jmp 0x4bdc3
leaq 0x2bb60(%rip), %rcx     # 0x77a0c
movq %rbx, %rdi
movl $0x1, %esi
xorl %eax, %eax
callq 0x49434
movl $0xfffffff6, %r14d      # imm = 0xFFFFFFF6
cmpl $-0xa, %eax
je 0x4bddc
movq %r12, 0x158(%rbx)
cmpq 0x160(%rbx), %r12
jae 0x4bee5
addq $0x20, %r12
movq %r12, 0x158(%rbx)
xorl %r14d, %r14d
jmp 0x4bddc
addq $0x20, %rax
movq %rax, 0x158(%rbx)
movq (%rbx), %rax
movq 0xf0(%rax), %rax
movl 0x10(%rax), %edx
leaq -0x30(%rbp), %r8
movq %rbx, %rdi
movl $0x1, %esi
xorl %ecx, %ecx
callq 0x4cf52
movl $0xfffffff6, %r14d      # imm = 0xFFFFFFF6
testl %eax, %eax
jne 0x4bddc
movq -0x30(%rbp), %rax
movb $0x1, 0x48(%rax)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4a7a9
cmpl $-0xa, %eax
je 0x4bf9a
cmpl $-0x3, %eax
je 0x4bf7c
movq (%rbx), %rdi
leaq -0x3c(%rbp), %r15
movl $0x9, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r15, %r9
callq 0x493c1
movq -0x30(%rbp), %rdi
movl (%r15), %eax
leaq -0x44(%rbp), %rsi
movl $0x9, (%rsi)
movl %eax, 0x4(%rsi)
addq $0x18, %rdi
callq 0x336fc
movq 0x158(%rbx), %r15
testb $0x4, 0x12(%r15)
jne 0x4bfa2
movl 0x14(%r15), %edx
leaq 0x2bac2(%rip), %rcx     # 0x77a57
jmp 0x4bdc3
movl %eax, %r14d
jmp 0x4bddc
leaq 0x20(%r12), %rax
movq %rax, 0x158(%rbx)
movq %r13, 0x160(%rbx)
movq %rbx, %rdi
callq 0x4d031
cmpl $-0xa, %eax
je 0x4bddc
movq -0x30(%rbp), %rcx
movl 0x60(%rcx), %eax
testq %rax, %rax
je 0x4c00e
movq 0x58(%rcx), %rcx
movq (%rbx), %rdx
movq 0xf0(%rdx), %rdx
movl 0x10(%rdx), %esi
xorl %edi, %edi
movl 0x4(%rcx,%rdi,8), %r8d
cmpl %r8d, %esi
jbe 0x4bffa
imull 0x18(%rdx), %r8d
addq 0x8(%rdx), %r8
jmp 0x4bffd
xorl %r8d, %r8d
testq %r8, %r8
je 0x4c006
movl %esi, 0x8(%r8)
incq %rdi
cmpq %rdi, %rax
jne 0x4bfe5
addq $0x20, %r15
cmpq %r12, %r15
jae 0x4c0e8
movq %r15, %rax
addq $0x20, %r15
testb $0x4, 0x12(%rax)
jne 0x4c012
cmpq %r12, %rax
jae 0x4c0e8
addq $-0x20, %r15
movq 0x158(%rbx), %r13
movq 0x160(%rbx), %rax
movq %rax, -0x38(%rbp)
movq %r15, 0x158(%rbx)
movq %r12, 0x160(%rbx)
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4a7a9
movl %eax, %r14d
movq 0x158(%rbx), %rax
cmpq 0x160(%rbx), %rax
jae 0x4c09f
movl 0x14(%rax), %edx
leaq 0x2ba07(%rip), %rcx     # 0x77a88
movq %rbx, %rdi
movl $0x1, %esi
xorl %eax, %eax
callq 0x49434
cmpl $-0xa, %eax
movl $0x0, %r14d
cmovel %eax, %r14d
jmp 0x4c0df
movq %r13, 0x158(%rbx)
movq -0x38(%rbp), %rax
movq %rax, 0x160(%rbx)
cmpl $-0xa, %r14d
je 0x4c0dc
cmpl $-0x3, %r14d
je 0x4c0d7
movq (%rbx), %rdi
movl $0xb, %esi
movl $0x1, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x493c1
movb $0x1, %r15b
jmp 0x4c0df
xorl %r15d, %r15d
testb %r15b, %r15b
je 0x4bddc
movq (%rbx), %rdi
movq -0x30(%rbp), %rax
movl 0x10(%rax), %ecx
xorl %r14d, %r14d
movl $0x8, %esi
xorl %edx, %edx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x493c1
movq -0x30(%rbp), %rdi
movq (%rbx), %rax
movq 0xf0(%rax), %rax
movl 0x10(%rax), %edx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x4d152
movq 0xc8(%rbx), %rdi
testq %rdi, %rdi
je 0x4bddc
movq 0x8(%rdi), %rax
movq %rax, 0xc8(%rbx)
callq 0x4955d
jmp 0x4bddc