// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9CompileWhile
static sxi32 jx9CompileWhile(jx9_gen_state *pGen)
{ 
	GenBlock *pWhileBlock = 0;
	SyToken *pTmp, *pEnd = 0;
	sxu32 nFalseJump;
	sxu32 nLine;
	sxi32 rc;
	nLine = pGen->pIn->nLine;
	/* Jump the 'while' 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 'while' keyword");
		if( rc == SXERR_ABORT ){
			/* Error count limit reached, abort immediately */
			return SXERR_ABORT;
		}
		goto Synchronize;
	}
	/* Jump the left parenthesis '(' */
	pGen->pIn++; 
	/* Create the loop block */
	rc = GenStateEnterBlock(&(*pGen), GEN_BLOCK_LOOP, jx9VmInstrLength(pGen->pVm), 0, &pWhileBlock);
	if( rc != SXRET_OK ){
		return SXERR_ABORT;
	}
	/* Delimit the condition */
	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, "Expected expression after 'while' keyword");
		if( rc == SXERR_ABORT ){
			/* Error count limit reached, abort immediately */
			return SXERR_ABORT;
		}
	}
	/* Swap token streams */
	pTmp = pGen->pEnd;
	pGen->pEnd = pEnd;
	/* Compile the expression */
	rc = jx9CompileExpr(&(*pGen), 0, 0);
	if( rc == SXERR_ABORT ){
		/* Expression handler request an operation abort [i.e: Out-of-memory] */
		return SXERR_ABORT;
	}
	/* Update token stream */
	while(pGen->pIn < pEnd ){
		rc = jx9GenCompileError(&(*pGen), E_ERROR, pGen->pIn->nLine, "Unexpected token '%z'", &pGen->pIn->sData);
		if( rc == SXERR_ABORT ){
			return SXERR_ABORT;
		}
		pGen->pIn++;
	}
	/* Synchronize pointers */
	pGen->pIn  = &pEnd[1];
	pGen->pEnd = pTmp;
	/* 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(pWhileBlock, JX9_OP_JZ, nFalseJump);
	/* Compile the loop body */
	rc = jx9CompileBlock(&(*pGen));
	if( rc == SXERR_ABORT ){
		return SXERR_ABORT;
	}
	/* Emit the unconditional jump to the start of the loop */
	jx9VmEmitInstr(pGen->pVm, JX9_OP_JMP, 0, pWhileBlock->nFirstInstr, 0, 0);
	/* Fix all jumps now the destination is resolved */
	GenStateFixJumps(pWhileBlock, -1, jx9VmInstrLength(pGen->pVm));
	/* Release the loop block */
	GenStateLeaveBlock(pGen, 0);
	/* Statement successfully compiled */
	return SXRET_OK;
Synchronize:
	/* Synchronize with the first semi-colon ';' so we can avoid 
	 * compiling this erroneous block.
	 */
	while( pGen->pIn < pGen->pEnd && (pGen->pIn->nType & (JX9_TK_SEMI|JX9_TK_OCB)) == 0 ){
		pGen->pIn++;
	}
	return SXRET_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
andq $0x0, -0x30(%rbp)
andq $0x0, -0x40(%rbp)
movq %rdi, %rbx
movq 0x158(%rdi), %rax
movl 0x14(%rax), %r15d
leaq 0x20(%rax), %rcx
movq %rcx, 0x158(%rdi)
cmpq 0x160(%rdi), %rcx
jae 0x411b9
testb $0x2, 0x31(%rax)
jne 0x41207
leaq 0x247c9(%rip), %rcx     # 0x65989
pushq $0x1
popq %rsi
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0x3eed6
cmpl $-0xa, %eax
jne 0x411db
pushq $-0xa
popq %r14
jmp 0x41238
movq 0x158(%rbx), %rax
movq 0x160(%rbx), %rcx
xorl %r14d, %r14d
cmpq %rcx, %rax
jae 0x41238
testl $0x40040, 0x10(%rax)    # imm = 0x40040
jne 0x41238
addq $0x20, %rax
movq %rax, 0x158(%rbx)
jmp 0x411ec
addq $0x40, %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
je 0x4124a
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x158(%rbx), %rdi
movq 0x160(%rbx), %rsi
leaq -0x40(%rbp), %r12
movl $0x200, %edx            # imm = 0x200
movl $0x400, %ecx            # imm = 0x400
movq %r12, %r8
callq 0x424f6
movq (%r12), %r13
cmpq %r13, 0x158(%rbx)
je 0x41287
movq 0x160(%rbx), %r12
cmpq %r12, %r13
jb 0x412aa
leaq 0x2471e(%rip), %rcx     # 0x659ac
pushq $0x1
popq %rsi
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0x3eed6
cmpl $-0xa, %eax
je 0x41238
movq 0x160(%rbx), %r12
movq %r13, 0x160(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4012f
cmpl $-0xa, %eax
je 0x41238
movq %r12, -0x38(%rbp)
movq 0x158(%rbx), %r8
leaq 0x24980(%rip), %r15     # 0x65c58
pushq $0x1
popq %r12
cmpq %r13, %r8
jae 0x41312
movl 0x14(%r8), %edx
movq %rbx, %rdi
movl %r12d, %esi
movq %r15, %rcx
xorl %eax, %eax
callq 0x3eed6
cmpl $-0xa, %eax
je 0x41238
movq 0x158(%rbx), %r8
addq $0x20, %r8
movq %r8, 0x158(%rbx)
jmp 0x412dc
addq $0x20, %r13
movq %r13, 0x158(%rbx)
movq -0x38(%rbp), %rax
movq %rax, 0x160(%rbx)
movq (%rbx), %rdi
pushq $0x9
popq %r15
leaq -0x44(%rbp), %r12
movl %r15d, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r12, %r9
callq 0x3ee6f
movq -0x30(%rbp), %rdi
movl (%r12), %edx
movl %r15d, %esi
callq 0x42528
movq %rbx, %rdi
callq 0x4254b
cmpl $-0xa, %eax
je 0x41238
movq (%rbx), %rdi
movq -0x30(%rbp), %rax
movl 0x10(%rax), %ecx
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
xorl %r14d, %r14d
jmp 0x41238