// File: /workspace/github_c_makefile_star2_O3/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
movq %rdi, %rbx
leaq -0x38(%rbp), %r8
movq $0x0, (%r8)
movq (%rdi), %rax
movq 0x158(%rdi), %r13
addq $0x20, %r13
movq %r13, 0x158(%rdi)
movq 0xf0(%rax), %rax
movl 0x10(%rax), %edx
movl $0x4, %esi
xorl %ecx, %ecx
callq 0x4bdf9
movl $0xfffffff6, %r15d      # imm = 0xFFFFFFF6
testl %eax, %eax
je 0x4a02f
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x160(%rbx), %r14
cmpq %r14, %r13
jae 0x4a325
leaq 0x2bc32(%rip), %r15     # 0x75c78
testb $0x2, 0x11(%r13)
je 0x4a315
leaq 0x20(%r13), %rax
cmpq %r14, %rax
jae 0x4a23d
movl $0x20, %ecx
movl $0x1, %edx
movl 0x10(%r13,%rcx), %esi
btl $0x9, %esi
jb 0x4a086
btl $0xa, %esi
jae 0x4a088
cmpl $0x2, %edx
jl 0x4a230
decl %edx
jmp 0x4a088
incl %edx
leaq (%rcx,%r13), %rsi
addq $0x20, %rsi
addq $0x20, %rcx
cmpq %r14, %rsi
jb 0x4a068
testb $0x4, 0x11(%r13,%rcx)
je 0x4a23a
addq %rcx, %r13
movq %rax, 0x158(%rbx)
movq %r13, 0x160(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x49789
movl %eax, %r12d
movq 0x158(%rbx), %r8
cmpq %r13, %r8
jae 0x4a0fb
movl 0x14(%r8), %edx
movq %rbx, %rdi
movl $0x1, %esi
movq %r15, %rcx
xorl %eax, %eax
callq 0x483d1
movq 0x158(%rbx), %r8
addq $0x20, %r8
movq %r8, 0x158(%rbx)
jmp 0x4a0cc
addq $0x20, %r13
movq %r13, 0x158(%rbx)
movq %r14, 0x160(%rbx)
cmpl $-0xa, %r12d
je 0x4a30a
movq (%rbx), %rdi
movl $0x9, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
leaq -0x2c(%rbp), %r12
movq %r12, %r9
callq 0x48365
movq -0x38(%rbp), %rdi
movl -0x2c(%rbp), %eax
movl $0x9, -0x40(%rbp)
movl %eax, -0x3c(%rbp)
addq $0x18, %rdi
leaq -0x40(%rbp), %rsi
callq 0x33094
movq %rbx, %rdi
callq 0x4bed4
cmpl $-0xa, %eax
je 0x4a30a
movq 0x158(%rbx), %rax
cmpq 0x160(%rbx), %rax
jae 0x4a26b
testb $0x4, 0x10(%rax)
je 0x4a26b
movl 0x18(%rax), %r14d
testl $0xc000000, %r14d       # imm = 0xC000000
je 0x4a26b
movq (%rbx), %rdi
movl $0x8, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r12, %r9
callq 0x48365
movq -0x38(%rbp), %rdi
movl -0x2c(%rbp), %eax
movl $0x8, -0x40(%rbp)
movl %eax, -0x3c(%rbp)
addq $0x18, %rdi
leaq -0x40(%rbp), %rsi
callq 0x33094
btl $0x1b, %r14d
movq 0x158(%rbx), %rax
jb 0x4a1d8
movq %rax, %r13
jmp 0x4a1f5
leaq 0x20(%rax), %r13
cmpq 0x160(%rbx), %r13
jae 0x4a26b
testb $0x4, 0x30(%rax)
je 0x4a26b
cmpl $0x3, 0x38(%rax)
jne 0x4a26b
addq $0x20, %r13
movq %r13, 0x158(%rbx)
movq -0x38(%rbp), %rdi
movq (%rbx), %rax
movq 0xf0(%rax), %rax
movl 0x10(%rax), %edx
movl $0x9, %esi
callq 0x4bff5
movq 0x160(%rbx), %r14
cmpq %r14, %r13
jb 0x4a046
jmp 0x4a31f
cmpq $0x21, %rcx
jae 0x4a099
movq %rax, %r13
movl 0x14(%r13), %edx
leaq 0x2b4f5(%rip), %rcx     # 0x7573d
movq %rbx, %rdi
movl $0x1, %esi
xorl %eax, %eax
callq 0x483d1
cmpl $-0xa, %eax
movl $0xfffffff6, %r15d      # imm = 0xFFFFFFF6
je 0x4a01d
jmp 0x4a350
movq -0x38(%rbp), %rdi
movq (%rbx), %rax
movq 0xf0(%rax), %rax
movl 0x10(%rax), %edx
movl $0x9, %esi
callq 0x4bff5
movq 0x158(%rbx), %rax
cmpq 0x160(%rbx), %rax
movl $0xfffffff6, %r15d      # imm = 0xFFFFFFF6
jae 0x4a2c4
testb $0x4, 0x10(%rax)
je 0x4a2c4
testb $0x8, 0x1b(%rax)
je 0x4a2c4
addq $0x20, %rax
movq %rax, 0x158(%rbx)
movq %rbx, %rdi
callq 0x4bed4
cmpl $-0xa, %eax
je 0x4a01d
movq (%rbx), %rax
movq 0xf0(%rax), %rax
movl 0x10(%rax), %edx
movl %edx, -0x2c(%rbp)
movq -0x38(%rbp), %rdi
movl $0x8, %esi
callq 0x4bff5
movq 0xc8(%rbx), %rdi
xorl %r15d, %r15d
testq %rdi, %rdi
je 0x4a01d
movq 0x8(%rdi), %rax
movq %rax, 0xc8(%rbx)
callq 0x484ee
jmp 0x4a01d
movl $0xfffffff6, %r15d      # imm = 0xFFFFFFF6
jmp 0x4a01d
xorl %eax, %eax
movl $0xfffffff6, %r15d      # imm = 0xFFFFFFF6
jmp 0x4a32c
movl $0xfffffff6, %r15d      # imm = 0xFFFFFFF6
movq $-0x20, %rax
movl 0x14(%r13,%rax), %edx
leaq 0x2b3e9(%rip), %rcx     # 0x75721
movq %rbx, %rdi
movl $0x1, %esi
xorl %eax, %eax
callq 0x483d1
cmpl $-0xa, %eax
je 0x4a01d
movq 0x158(%rbx), %rcx
movq 0x160(%rbx), %rax
xorl %r15d, %r15d
cmpq %rax, %rcx
jae 0x4a01d
addq $0x20, %rcx
testl $0x40040, -0x10(%rcx)   # imm = 0x40040
jne 0x4a01d
movq %rcx, 0x158(%rbx)
leaq 0x20(%rcx), %rdx
cmpq %rax, %rcx
movq %rdx, %rcx
jb 0x4a36e
jmp 0x4a01d