// File: /workspace/github_c_makefile_star2_O2/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 $0x18, %rsp
andq $0x0, -0x38(%rbp)
andq $0x0, -0x30(%rbp)
movq %rdi, %rbx
movq 0x158(%rdi), %rdi
movq 0x160(%rbx), %rsi
movl 0x14(%rdi), %r15d
leaq 0x20(%rdi), %rax
movq %rax, 0x158(%rbx)
cmpq %rsi, %rax
jae 0x413ef
testb $0x2, 0x31(%rdi)
jne 0x41422
leaq 0x245e0(%rip), %rcx     # 0x659d6
xorl %r14d, %r14d
pushq $0x1
popq %rsi
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0x3eed6
cmpl $-0xa, %eax
cmovel %eax, %r14d
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $0x40, %rdi
movq %rdi, 0x158(%rbx)
leaq -0x38(%rbp), %r14
movl $0x200, %edx            # imm = 0x200
movl $0x400, %ecx            # imm = 0x400
movq %r14, %r8
callq 0x424f6
movq (%r14), %r13
cmpq %r13, 0x158(%rbx)
je 0x414b7
movq 0x160(%rbx), %r12
cmpq %r12, %r13
jae 0x414b7
movq %r13, 0x160(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4012f
movl %eax, %r14d
cmpl $-0xa, %eax
je 0x41410
cmpl $-0x3, %r14d
je 0x41492
movq (%rbx), %rdi
pushq $0xb
popq %rsi
pushq $0x1
popq %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x3ee6f
movq 0x158(%rbx), %rax
testb $0x4, 0x12(%rax)
jne 0x41503
movl 0x14(%rax), %edx
leaq 0x24566(%rip), %rcx     # 0x65a0f
xorl %r14d, %r14d
pushq $0x1
popq %rsi
movq %rbx, %rdi
jmp 0x41402
leaq 0x24539(%rip), %rcx     # 0x659f7
xorl %r14d, %r14d
pushq $0x1
popq %rsi
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0x3eed6
cmpl $-0xa, %eax
jne 0x414df
pushq $-0xa
popq %r14
jmp 0x41410
movq %r13, 0x158(%rbx)
cmpq 0x160(%rbx), %r13
jae 0x41410
addq $0x20, %r13
movq %r13, 0x158(%rbx)
jmp 0x41410
addq $0x20, %rax
movq %rax, 0x158(%rbx)
movq (%rbx), %rax
movq 0xf0(%rax), %rax
movl 0x10(%rax), %edx
pushq $0x1
popq %rsi
leaq -0x30(%rbp), %r8
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x4246c
pushq $-0xa
popq %r14
testl %eax, %eax
jne 0x41410
movq -0x30(%rbp), %rax
movb $0x1, 0x48(%rax)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4012f
cmpl $-0xa, %eax
je 0x416e3
cmpl $-0x3, %eax
je 0x41582
movq (%rbx), %rdi
pushq $0x9
popq %rsi
leaq -0x3c(%rbp), %r15
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r15, %r9
callq 0x3ee6f
movq -0x30(%rbp), %rdi
movl (%r15), %edx
pushq $0x9
popq %rsi
callq 0x42528
movq 0x158(%rbx), %r15
testb $0x4, 0x12(%r15)
jne 0x415a0
movl 0x14(%r15), %edx
leaq 0x244a7(%rip), %rcx     # 0x65a42
jmp 0x414a9
leaq 0x20(%r13), %rax
movq %rax, 0x158(%rbx)
movq %r12, 0x160(%rbx)
movq %rbx, %rdi
callq 0x4254b
cmpl $-0xa, %eax
je 0x41410
movq -0x30(%rbp), %rcx
movl 0x60(%rcx), %eax
testq %rax, %rax
je 0x41609
movq 0x58(%rcx), %rcx
movq (%rbx), %rdx
movq 0xf0(%rdx), %rdx
movl 0x10(%rdx), %esi
xorl %edi, %edi
cmpq %rdi, %rax
je 0x41609
movl 0x4(%rcx,%rdi,8), %r8d
cmpl %r8d, %esi
jbe 0x41604
movq 0x8(%rdx), %r9
testq %r9, %r9
je 0x41604
imull 0x18(%rdx), %r8d
movl %esi, 0x8(%r9,%r8)
incq %rdi
jmp 0x415e2
addq $0x20, %r15
cmpq %r13, %r15
jae 0x416a0
leaq 0x20(%r15), %rax
testb $0x4, 0x12(%r15)
movq %rax, %r15
jne 0x4160d
movq 0x158(%rbx), %r15
movq 0x160(%rbx), %r12
addq $-0x20, %rax
movq %rax, 0x158(%rbx)
movq %r13, 0x160(%rbx)
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4012f
movq 0x158(%rbx), %rcx
cmpq 0x160(%rbx), %rcx
jae 0x41672
movl 0x14(%rcx), %edx
leaq 0x24406(%rip), %rcx     # 0x65a73
jmp 0x414ac
movq %r15, 0x158(%rbx)
movq %r12, 0x160(%rbx)
cmpl $-0xa, %eax
je 0x416e3
cmpl $-0x3, %eax
je 0x416a0
movq (%rbx), %rdi
pushq $0xb
popq %rsi
pushq $0x1
popq %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x3ee6f
movq (%rbx), %rdi
movq -0x30(%rbp), %rax
movl 0x10(%rax), %ecx
xorl %r14d, %r14d
pushq $0x8
popq %rsi
xorl %edx, %edx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x3ee6f
movq -0x30(%rbp), %rdi
movq (%rbx), %rax
movq 0xf0(%rax), %rax
movl 0x10(%rax), %edx
pushq $-0x1
popq %rsi
callq 0x42648
movq %rbx, %rdi
callq 0x426b3
jmp 0x41410
movl %eax, %r14d
jmp 0x41410