// File: /workspace/github_c_makefile_star2_O0/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
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rcx
addq $0x20, %rcx
movq %rcx, 0x158(%rax)
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7e8d0
movq -0x48(%rbp), %rdi
movl %eax, %edx
movl $0x4, %esi
xorl %eax, %eax
movl %eax, %ecx
leaq -0x30(%rbp), %r8
callq 0x84100
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x81422
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x818c5
jmp 0x81424
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x160(%rcx), %rax
jae 0x81446
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
jne 0x8149b
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x160(%rcx), %rax
jb 0x81463
movq -0x18(%rbp), %rax
addq $-0x20, %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x14(%rax), %edx
movl $0x1, %esi
leaq 0x42788(%rip), %rcx     # 0xc3c02
movb $0x0, %al
callq 0x7e990
movl %eax, -0x3c(%rbp)
cmpl $-0xa, -0x3c(%rbp)
jne 0x81496
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x818c5
jmp 0x81862
movq -0x18(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x160(%rax), %rsi
movl $0x200, %edx            # imm = 0x200
movl $0x400, %ecx            # imm = 0x400
leaq -0x28(%rbp), %r8
callq 0x841b0
movq -0x18(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x814e4
movq -0x28(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
jne 0x81539
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x160(%rcx), %rax
jb 0x81501
movq -0x18(%rbp), %rax
addq $-0x20, %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x14(%rax), %edx
movl $0x1, %esi
leaq 0x42706(%rip), %rcx     # 0xc3c1e
movb $0x0, %al
callq 0x7e990
movl %eax, -0x3c(%rbp)
cmpl $-0xa, -0x3c(%rbp)
jne 0x81534
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x818c5
jmp 0x81862
movq -0x10(%rbp), %rax
movq 0x160(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x158(%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x160(%rax)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x81110
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
cmpq -0x28(%rbp), %rax
jae 0x815d1
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movl 0x14(%rax), %edx
movq -0x10(%rbp), %rax
movq 0x158(%rax), %r8
movl $0x1, %esi
leaq 0x42ba7(%rip), %rcx     # 0xc4159
movb $0x0, %al
callq 0x7e990
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rcx
addq $0x20, %rcx
movq %rcx, 0x158(%rax)
jmp 0x81578
movq -0x28(%rbp), %rcx
addq $0x20, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x158(%rax)
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x160(%rax)
cmpl $-0xa, -0x3c(%rbp)
jne 0x81605
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x818c5
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl $0x9, %esi
xorl %ecx, %ecx
xorl %eax, %eax
movl %eax, %r8d
leaq -0x34(%rbp), %r9
movl %ecx, %edx
callq 0x7e8f0
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %edx
movl $0x9, %esi
callq 0x84240
movq -0x10(%rbp), %rdi
callq 0x84280
movl %eax, -0x3c(%rbp)
cmpl $-0xa, -0x3c(%rbp)
jne 0x81652
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x818c5
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x160(%rcx), %rax
jae 0x81680
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movl 0x10(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x81685
jmp 0x8178b
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movq 0x18(%rax), %rax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
andl $0xc000000, %eax        # imm = 0xC000000
cmpl $0x0, %eax
jne 0x816a9
jmp 0x8178b
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl $0x8, %esi
xorl %ecx, %ecx
xorl %eax, %eax
movl %eax, %r8d
leaq -0x34(%rbp), %r9
movl %ecx, %edx
callq 0x7e8f0
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %edx
movl $0x8, %esi
callq 0x84240
movl -0x38(%rbp), %eax
andl $0x8000000, %eax        # imm = 0x8000000
cmpl $0x0, %eax
je 0x8173d
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
addq $0x20, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x160(%rcx), %rax
jae 0x81725
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x81725
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
cmpl $0x3, %eax
je 0x81727
jmp 0x8178b
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rcx
addq $0x20, %rcx
movq %rcx, 0x158(%rax)
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rcx
addq $0x20, %rcx
movq %rcx, 0x158(%rax)
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7e8d0
movq -0x50(%rbp), %rdi
movl %eax, %edx
movl $0x9, %esi
callq 0x84440
jmp 0x81424
movq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7e8d0
movq -0x58(%rbp), %rdi
movl %eax, %edx
movl $0x9, %esi
callq 0x84440
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x160(%rcx), %rax
jae 0x8182c
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movl 0x10(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x8182c
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movq 0x18(%rax), %rax
andl $0x8000000, %eax        # imm = 0x8000000
cmpl $0x0, %eax
je 0x8182c
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rcx
addq $0x20, %rcx
movq %rcx, 0x158(%rax)
movq -0x10(%rbp), %rdi
callq 0x84280
movl %eax, -0x3c(%rbp)
cmpl $-0xa, -0x3c(%rbp)
jne 0x8182a
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x818c5
jmp 0x8182c
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7e8d0
movl %eax, -0x34(%rbp)
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %edx
movl $0x8, %esi
callq 0x84440
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x84500
movl $0x0, -0x4(%rbp)
jmp 0x818c5
jmp 0x81864
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rcx
movq -0x10(%rbp), %rdx
xorl %eax, %eax
cmpq 0x160(%rdx), %rcx
movb %al, -0x59(%rbp)
jae 0x8189d
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movl 0x10(%rax), %eax
andl $0x40040, %eax          # imm = 0x40040
cmpl $0x0, %eax
sete %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
testb $0x1, %al
jne 0x818a6
jmp 0x818be
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rcx
addq $0x20, %rcx
movq %rcx, 0x158(%rax)
jmp 0x81864
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nop