// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9CompileIf
static sxi32 jx9CompileIf(jx9_gen_state *pGen)
{
	SyToken *pToken, *pTmp, *pEnd = 0;
	GenBlock *pCondBlock = 0;
	sxu32 nJumpIdx;
	sxu32 nKeyID;
	sxi32 rc;
	/* Jump the 'if' keyword */
	pGen->pIn++;
	pToken = pGen->pIn; 
	/* Create the conditional block */
	rc = GenStateEnterBlock(&(*pGen), GEN_BLOCK_COND, jx9VmInstrLength(pGen->pVm), 0, &pCondBlock);
	if( rc != SXRET_OK ){
		return SXERR_ABORT;
	}
	/* Process as many [if/else if/elseif/else] blocks as we can */
	for(;;){
		if( pToken >= pGen->pEnd || (pToken->nType & JX9_TK_LPAREN) == 0 ){
			/* Syntax error */
			if( pToken >= pGen->pEnd ){
				pToken--;
			}
			rc = jx9GenCompileError(pGen, E_ERROR, pToken->nLine, "if/else/elseif: Missing '('");
			if( rc == SXERR_ABORT ){
				/* Error count limit reached, abort immediately */
				return SXERR_ABORT;
			}
			goto Synchronize;
		}
		/* Jump the left parenthesis '(' */
		pToken++; 
		/* Delimit the condition */
		jx9DelimitNestedTokens(pToken, pGen->pEnd, JX9_TK_LPAREN /* '(' */, JX9_TK_RPAREN /* ')' */, &pEnd);
		if( pToken >= pEnd || (pEnd->nType & JX9_TK_RPAREN) == 0 ){
			/* Syntax error */
			if( pToken >= pGen->pEnd ){
				pToken--;
			}
			rc = jx9GenCompileError(pGen, E_ERROR, pToken->nLine, "if/else/elseif: Missing ')'");
			if( rc == SXERR_ABORT ){
				/* Error count limit reached, abort immediately */
				return SXERR_ABORT;
			}
			goto Synchronize;
		}
		/* Swap token streams */
		SWAP_TOKEN_STREAM(pGen, pToken, pEnd);
		/* Compile the condition */
		rc = jx9CompileExpr(&(*pGen), 0, 0);
		/* Update token stream */
		while(pGen->pIn < pEnd ){
			jx9GenCompileError(&(*pGen), E_ERROR, pGen->pIn->nLine, "Unexpected token '%z'", &pGen->pIn->sData);
			pGen->pIn++;
		}
		pGen->pIn  = &pEnd[1];
		pGen->pEnd = pTmp;
		if( rc == SXERR_ABORT ){
			/* Expression handler request an operation abort [i.e: Out-of-memory] */
			return SXERR_ABORT;
		}
		/* Emit the false jump */
		jx9VmEmitInstr(pGen->pVm, JX9_OP_JZ, 0, 0, 0, &nJumpIdx);
		/* Save the instruction index so we can fix it later when the jump destination is resolved */
		GenStateNewJumpFixup(pCondBlock, JX9_OP_JZ, nJumpIdx);
		/* Compile the body */
		rc = jx9CompileBlock(&(*pGen));
		if( rc == SXERR_ABORT ){
			return SXERR_ABORT;
		}
		if( pGen->pIn >= pGen->pEnd || (pGen->pIn->nType & JX9_TK_KEYWORD) == 0 ){
			break;
		}
		/* Ensure that the keyword ID is 'else if' or 'else' */
		nKeyID = (sxu32)SX_PTR_TO_INT(pGen->pIn->pUserData);
		if( (nKeyID & (JX9_TKWRD_ELSE|JX9_TKWRD_ELIF)) == 0 ){
			break;
		}
		/* Emit the unconditional jump */
		jx9VmEmitInstr(pGen->pVm, JX9_OP_JMP, 0, 0, 0, &nJumpIdx);
		/* Save the instruction index so we can fix it later when the jump destination is resolved */
		GenStateNewJumpFixup(pCondBlock, JX9_OP_JMP, nJumpIdx);
		if( nKeyID & JX9_TKWRD_ELSE ){
			pToken = &pGen->pIn[1];
			if( pToken >= pGen->pEnd || (pToken->nType & JX9_TK_KEYWORD) == 0 ||
				SX_PTR_TO_INT(pToken->pUserData) != JX9_TKWRD_IF ){
					break;
			}
			pGen->pIn++; /* Jump the 'else' keyword */
		}
		pGen->pIn++; /* Jump the 'elseif/if' keyword */
		/* Synchronize cursors */
		pToken = pGen->pIn;
		/* Fix the false jump */
		GenStateFixJumps(pCondBlock, JX9_OP_JZ, jx9VmInstrLength(pGen->pVm));
	} /* For(;;) */
	/* Fix the false jump */
	GenStateFixJumps(pCondBlock, JX9_OP_JZ, jx9VmInstrLength(pGen->pVm));
	if( pGen->pIn < pGen->pEnd && (pGen->pIn->nType & JX9_TK_KEYWORD) &&
		(SX_PTR_TO_INT(pGen->pIn->pUserData) & JX9_TKWRD_ELSE) ){
			/* Compile the else block */
			pGen->pIn++;
			rc = jx9CompileBlock(&(*pGen));
			if( rc == SXERR_ABORT ){
				
				return SXERR_ABORT;
			}
	}
	nJumpIdx = jx9VmInstrLength(pGen->pVm);
	/* Fix all unconditional jumps now the destination is resolved */
	GenStateFixJumps(pCondBlock, JX9_OP_JMP, nJumpIdx);
	/* Release the conditional 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
andq $0x0, -0x40(%rbp)
leaq -0x38(%rbp), %r8
andq $0x0, (%r8)
movq %rdi, %rbx
movq (%rdi), %rax
movq 0x158(%rdi), %r14
addq $0x20, %r14
movq %r14, 0x158(%rdi)
movq 0xf0(%rax), %rax
movl 0x10(%rax), %edx
pushq $0x4
popq %rsi
xorl %ecx, %ecx
callq 0x4246c
pushq $-0xa
popq %r15
testl %eax, %eax
je 0x40983
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %r13
movq 0x160(%rbx), %rsi
cmpq %rsi, %r14
jae 0x40bdb
testb $0x2, 0x11(%r14)
je 0x40be0
leaq 0x20(%r14), %r15
movq %r15, %rdi
movl $0x200, %edx            # imm = 0x200
movl $0x400, %ecx            # imm = 0x400
leaq -0x40(%rbp), %r8
callq 0x424f6
movq -0x40(%rbp), %r12
cmpq %r12, %r15
jae 0x40bba
testb $0x4, 0x11(%r12)
je 0x40bba
movq 0x160(%rbx), %r14
movq %r15, 0x158(%rbx)
movq %r12, 0x160(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4012f
movl %eax, %r15d
movq 0x158(%rbx), %r8
cmpq %r12, %r8
jae 0x40a31
movl 0x14(%r8), %edx
movq %rbx, %rdi
movl %r13d, %esi
leaq 0x25242(%rip), %rcx     # 0x65c58
xorl %eax, %eax
callq 0x3eed6
movq 0x158(%rbx), %r8
addq $0x20, %r8
movq %r8, 0x158(%rbx)
jmp 0x40a00
addq $0x20, %r12
movq %r12, 0x158(%rbx)
movq %r14, 0x160(%rbx)
cmpl $-0xa, %r15d
je 0x40bd2
movq (%rbx), %rdi
pushq $0x9
popq %r15
movl %r15d, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
leaq -0x2c(%rbp), %r12
movq %r12, %r9
callq 0x3ee6f
movq -0x38(%rbp), %rdi
movl -0x2c(%rbp), %edx
movl %r15d, %esi
callq 0x42528
movq %rbx, %rdi
callq 0x4254b
cmpl $-0xa, %eax
je 0x40bd2
movq 0x158(%rbx), %rax
cmpq 0x160(%rbx), %rax
jae 0x40b39
testb $0x4, 0x10(%rax)
je 0x40b39
movl 0x18(%rax), %r14d
testl $0xc000000, %r14d       # imm = 0xC000000
je 0x40b39
movq (%rbx), %rdi
pushq $0x8
popq %r15
movl %r15d, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r12, %r9
callq 0x3ee6f
movq -0x38(%rbp), %rdi
movl -0x2c(%rbp), %edx
movl %r15d, %esi
callq 0x42528
btl $0x1b, %r14d
movq 0x158(%rbx), %rax
jb 0x40af7
movq %rax, %r14
pushq $0x9
popq %rsi
jmp 0x40b13
leaq 0x20(%rax), %r14
cmpq 0x160(%rbx), %r14
pushq $0x9
popq %rsi
jae 0x40b39
testb $0x4, 0x30(%rax)
je 0x40b39
cmpl $0x3, 0x38(%rax)
jne 0x40b39
addq $0x20, %r14
movq %r14, 0x158(%rbx)
movq -0x38(%rbp), %rdi
movq (%rbx), %rax
movq 0xf0(%rax), %rax
movl 0x10(%rax), %edx
callq 0x42648
jmp 0x40987
movq -0x38(%rbp), %rdi
movq (%rbx), %rax
movq 0xf0(%rax), %rax
movl 0x10(%rax), %edx
pushq $0x9
popq %rsi
callq 0x42648
movq 0x158(%rbx), %rax
cmpq 0x160(%rbx), %rax
pushq $-0xa
popq %r15
jae 0x40b8e
testb $0x4, 0x10(%rax)
je 0x40b8e
testb $0x8, 0x1b(%rax)
je 0x40b8e
addq $0x20, %rax
movq %rax, 0x158(%rbx)
movq %rbx, %rdi
callq 0x4254b
cmpl $-0xa, %eax
je 0x40971
movq (%rbx), %rax
movq 0xf0(%rax), %rax
movl 0x10(%rax), %edx
movl %edx, -0x2c(%rbp)
movq -0x38(%rbp), %rdi
pushq $0x8
popq %rsi
callq 0x42648
movq %rbx, %rdi
callq 0x426b3
xorl %r15d, %r15d
jmp 0x40971
cmpq 0x160(%rbx), %r15
cmovbq %r15, %r14
movl 0x14(%r14), %edx
leaq 0x24b4d(%rip), %rcx     # 0x6571d
jmp 0x40bee
pushq $-0xa
popq %r15
jmp 0x40971
pushq $-0x20
popq %rax
jmp 0x40be2
xorl %eax, %eax
movl 0x14(%r14,%rax), %edx
leaq 0x24b13(%rip), %rcx     # 0x65701
pushq $0x1
popq %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3eed6
cmpl $-0xa, %eax
pushq $-0xa
popq %r15
je 0x40971
movq 0x158(%rbx), %rax
movq 0x160(%rbx), %rcx
xorl %r15d, %r15d
cmpq %rcx, %rax
jae 0x40971
testl $0x40040, 0x10(%rax)    # imm = 0x40040
jne 0x40971
addq $0x20, %rax
movq %rax, 0x158(%rbx)
jmp 0x40c19