// File: /workspace/github_c_makefile_star2_O3/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 $0x18, %rsp
movq %rdi, %rbx
movq $0x0, -0x30(%rbp)
movq 0x158(%rdi), %rax
movl 0x14(%rax), %r15d
leaq 0x20(%rax), %rcx
movq %rcx, 0x158(%rdi)
cmpq 0x160(%rdi), %rcx
jae 0x4aa30
testb $0x2, 0x31(%rax)
jne 0x4aa8c
leaq 0x2af72(%rip), %rcx     # 0x759a9
movq %rbx, %rdi
movl $0x1, %esi
movl %r15d, %edx
xorl %eax, %eax
callq 0x483d1
movl $0xfffffff6, %r14d      # imm = 0xFFFFFFF6
cmpl $-0xa, %eax
je 0x4aac1
movq 0x158(%rbx), %rcx
movq 0x160(%rbx), %rax
cmpq %rax, %rcx
jae 0x4aa87
addq $0x20, %rcx
testl $0x40040, -0x10(%rcx)   # imm = 0x40040
jne 0x4aa87
movq %rcx, 0x158(%rbx)
leaq 0x20(%rcx), %rdx
cmpq %rax, %rcx
movq %rdx, %rcx
jb 0x4aa6b
xorl %r14d, %r14d
jmp 0x4aac1
addq $0x40, %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 0x4bdf9
movl $0xfffffff6, %r14d      # imm = 0xFFFFFFF6
testl %eax, %eax
je 0x4aad3
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x158(%rbx), %r12
movq 0x160(%rbx), %r13
cmpq %r13, %r12
jae 0x4ab26
movl $0x1, %ecx
xorl %eax, %eax
movl 0x10(%r12,%rax), %edx
btl $0x9, %edx
jb 0x4ab0b
btl $0xa, %edx
jae 0x4ab0d
cmpl $0x2, %ecx
jl 0x4ac6b
decl %ecx
jmp 0x4ab0d
incl %ecx
leaq (%r12,%rax), %rdx
addq $0x20, %rdx
addq $0x20, %rax
cmpq %r13, %rdx
jb 0x4aaed
addq %rax, %r12
cmpq %r13, %r12
jb 0x4ab4f
leaq 0x2ae9f(%rip), %rcx     # 0x759cc
movq %rbx, %rdi
movl $0x1, %esi
movl %r15d, %edx
xorl %eax, %eax
callq 0x483d1
cmpl $-0xa, %eax
je 0x4aac1
movq 0x160(%rbx), %r13
movq %r12, 0x160(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x49789
cmpl $-0xa, %eax
je 0x4aac1
movq 0x158(%rbx), %r8
cmpq %r12, %r8
jae 0x4abb4
leaq 0x2b0fa(%rip), %r15     # 0x75c78
movl 0x14(%r8), %edx
movq %rbx, %rdi
movl $0x1, %esi
movq %r15, %rcx
xorl %eax, %eax
callq 0x483d1
cmpl $-0xa, %eax
je 0x4aac1
movq 0x158(%rbx), %r8
addq $0x20, %r8
movq %r8, 0x158(%rbx)
cmpq %r12, %r8
jb 0x4ab7e
addq $0x20, %r12
movq %r12, 0x158(%rbx)
movq %r13, 0x160(%rbx)
movq (%rbx), %rdi
leaq -0x34(%rbp), %r15
movl $0x9, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r15, %r9
callq 0x48365
movq -0x30(%rbp), %rdi
movl (%r15), %eax
leaq -0x3c(%rbp), %rsi
movl $0x9, (%rsi)
movl %eax, 0x4(%rsi)
addq $0x18, %rdi
callq 0x33094
movq %rbx, %rdi
callq 0x4bed4
cmpl $-0xa, %eax
je 0x4aac1
movq (%rbx), %rdi
movq -0x30(%rbp), %rax
movl 0x10(%rax), %ecx
movl $0x8, %esi
xorl %edx, %edx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x48365
movq -0x30(%rbp), %rdi
movq (%rbx), %rax
movq 0xf0(%rax), %rax
movl 0x10(%rax), %edx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x4bff5
movq 0xc8(%rbx), %rdi
testq %rdi, %rdi
je 0x4aa87
movq 0x8(%rdi), %rax
movq %rax, 0xc8(%rbx)
callq 0x484ee
jmp 0x4aa87
testq %rax, %rax
jne 0x4ab1e
jmp 0x4ab26