// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: GenStateEmitExprCode
static sxi32 GenStateEmitExprCode(
	jx9_gen_state *pGen,  /* Code generator state */
	jx9_expr_node *pNode, /* Root of the expression tree */
	sxi32 iFlags /* Control flags */
	)
{
	VmInstr *pInstr;
	sxu32 nJmpIdx;
	sxi32 iP1 = 0;
	sxu32 iP2 = 0;
	void *p3  = 0;
	sxi32 iVmOp;
	sxi32 rc;
	if( pNode->xCode ){
		SyToken *pTmpIn, *pTmpEnd;
		/* Compile node */
		SWAP_DELIMITER(pGen, pNode->pStart, pNode->pEnd);
		rc = pNode->xCode(&(*pGen), iFlags);
		RE_SWAP_DELIMITER(pGen);
		return rc;
	}
	if( pNode->pOp == 0 ){
		jx9GenCompileError(&(*pGen), E_ERROR, pNode->pStart->nLine, 
			"Invalid expression node, JX9 is aborting compilation");
		return SXERR_ABORT;
	}
	iVmOp = pNode->pOp->iVmOp;
	if( pNode->pOp->iOp == EXPR_OP_QUESTY ){
		sxu32 nJz, nJmp;
		/* Ternary operator require special handling */
		/* Phase#1: Compile the condition */
		rc = GenStateEmitExprCode(&(*pGen), pNode->pCond, iFlags);
		if( rc != SXRET_OK ){
			return rc;
		}
		nJz = nJmp = 0; /* cc -O6 warning */
		/* Phase#2: Emit the false jump */
		jx9VmEmitInstr(pGen->pVm, JX9_OP_JZ, 0, 0, 0, &nJz);
		if( pNode->pLeft ){
			/* Phase#3: Compile the 'then' expression  */
			rc = GenStateEmitExprCode(&(*pGen), pNode->pLeft, iFlags);
			if( rc != SXRET_OK ){
				return rc;
			}
		}
		/* Phase#4: Emit the unconditional jump */
		jx9VmEmitInstr(pGen->pVm, JX9_OP_JMP, 0, 0, 0, &nJmp);
		/* Phase#5: Fix the false jump now the jump destination is resolved. */
		pInstr = jx9VmGetInstr(pGen->pVm, nJz);
		if( pInstr ){
			pInstr->iP2 = jx9VmInstrLength(pGen->pVm);
		}
		/* Phase#6: Compile the 'else' expression */
		if( pNode->pRight ){
			rc = GenStateEmitExprCode(&(*pGen), pNode->pRight, iFlags);
			if( rc != SXRET_OK ){
				return rc;
			}
		}
		if( nJmp > 0 ){
			/* Phase#7: Fix the unconditional jump */
			pInstr = jx9VmGetInstr(pGen->pVm, nJmp);
			if( pInstr ){
				pInstr->iP2 = jx9VmInstrLength(pGen->pVm);
			}
		}
		/* All done */
		return SXRET_OK;
	}
	/* Generate code for the left tree */
	if( pNode->pLeft ){
		if( iVmOp == JX9_OP_CALL ){
			jx9_expr_node **apNode;
			sxi32 n;
			/* Recurse and generate bytecodes for function arguments */
			apNode = (jx9_expr_node **)SySetBasePtr(&pNode->aNodeArgs);
			/* Read-only load */
			iFlags |= EXPR_FLAG_RDONLY_LOAD;
			for( n = 0 ; n < (sxi32)SySetUsed(&pNode->aNodeArgs) ; ++n ){
				rc = GenStateEmitExprCode(&(*pGen), apNode[n], iFlags&~EXPR_FLAG_LOAD_IDX_STORE);
				if( rc != SXRET_OK ){
					return rc;
				}
			}
			/* Total number of given arguments */
			iP1 = (sxi32)SySetUsed(&pNode->aNodeArgs);
			/* Remove stale flags now */
			iFlags &= ~EXPR_FLAG_RDONLY_LOAD;
		}
		rc = GenStateEmitExprCode(&(*pGen), pNode->pLeft, iFlags);
		if( rc != SXRET_OK ){
			return rc;
		}
		if( iVmOp == JX9_OP_CALL ){
			pInstr = jx9VmPeekInstr(pGen->pVm);
			if( pInstr ){
				if ( pInstr->iOp == JX9_OP_LOADC ){
					/* Prevent constant expansion */
					pInstr->iP1 = 0;
				}else if( pInstr->iOp == JX9_OP_MEMBER /* $a.b(1, 2, 3) */  ){
					/* Annonymous function call, flag that */
					pInstr->iP2 = 1;
				}
			}
		}else if( iVmOp == JX9_OP_LOAD_IDX ){
			jx9_expr_node **apNode;
			sxi32 n;
			/* Recurse and generate bytecodes for array index */
			apNode = (jx9_expr_node **)SySetBasePtr(&pNode->aNodeArgs);
			for( n = 0 ; n < (sxi32)SySetUsed(&pNode->aNodeArgs) ; ++n ){
				rc = GenStateEmitExprCode(&(*pGen), apNode[n], iFlags&~EXPR_FLAG_LOAD_IDX_STORE);
				if( rc != SXRET_OK ){
					return rc;
				}
			}
			if( SySetUsed(&pNode->aNodeArgs) > 0 ){
				iP1 = 1; /* Node have an index associated with it */
			}
			if( iFlags & EXPR_FLAG_LOAD_IDX_STORE ){
				/* Create an empty entry when the desired index is not found */
				iP2 = 1;
			}
		}else if( pNode->pOp->iOp == EXPR_OP_COMMA ){
			/* POP the left node */
			jx9VmEmitInstr(pGen->pVm, JX9_OP_POP, 1, 0, 0, 0);
		}
	}
	rc = SXRET_OK;
	nJmpIdx = 0;
	/* Generate code for the right tree */
	if( pNode->pRight ){
		if( iVmOp == JX9_OP_LAND ){
			/* Emit the false jump so we can short-circuit the logical and */
			jx9VmEmitInstr(pGen->pVm, JX9_OP_JZ, 1/* Keep the value on the stack */, 0, 0, &nJmpIdx);
		}else if (iVmOp == JX9_OP_LOR ){
			/* Emit the true jump so we can short-circuit the logical or*/
			jx9VmEmitInstr(pGen->pVm, JX9_OP_JNZ, 1/* Keep the value on the stack */, 0, 0, &nJmpIdx);
		}else if( pNode->pOp->iPrec == 18 /* Combined binary operators [i.e: =, '.=', '+=', *=' ...] precedence */ ){
			iFlags |= EXPR_FLAG_LOAD_IDX_STORE;
		}
		rc = GenStateEmitExprCode(&(*pGen), pNode->pRight, iFlags);
		if( iVmOp == JX9_OP_STORE ){
			pInstr = jx9VmPeekInstr(pGen->pVm);
			if( pInstr ){
				if(pInstr->iOp == JX9_OP_MEMBER ){
					/* Perform a member store operation [i.e: $this.x = 50] */
					iP2 = 1;
				}else{
					if( pInstr->iOp == JX9_OP_LOAD_IDX ){
						/* Transform the STORE instruction to STORE_IDX instruction */
						iVmOp = JX9_OP_STORE_IDX;
						iP1 = pInstr->iP1;
					}else{
						p3 = pInstr->p3;
					}
					/* POP the last dynamic load instruction */
					(void)jx9VmPopInstr(pGen->pVm);
				}
			}
		}
	}
	if( iVmOp > 0 ){
		if( iVmOp == JX9_OP_INCR || iVmOp == JX9_OP_DECR ){
			if( pNode->iFlags & EXPR_NODE_PRE_INCR ){
				/* Pre-increment/decrement operator [i.e: ++$i, --$j ] */
				iP1 = 1;
			}
		}
		/* Finally, emit the VM instruction associated with this operator */
		jx9VmEmitInstr(pGen->pVm, iVmOp, iP1, iP2, p3, 0);
		if( nJmpIdx > 0 ){
			/* Fix short-circuited jumps now the destination is resolved */
			pInstr = jx9VmGetInstr(pGen->pVm, nJmpIdx);
			if( pInstr ){
				pInstr->iP2 = jx9VmInstrLength(pGen->pVm);
			}
		}
	}
	return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, %rbx
movq 0x30(%rsi), %rax
testq %rax, %rax
je 0x43020
movups 0x158(%rbx), %xmm0
movaps %xmm0, -0x40(%rbp)
movq 0x18(%r14), %rcx
movq %rcx, 0x158(%rbx)
movq 0x20(%r14), %rcx
movq %rcx, 0x160(%rbx)
movq %rbx, %rdi
movl %r15d, %esi
callq *%rax
movaps -0x40(%rbp), %xmm0
movups %xmm0, 0x158(%rbx)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r14), %rax
testq %rax, %rax
je 0x43112
cmpl $0x26, 0x10(%rax)
jne 0x43135
movq 0x60(%r14), %rsi
movq %rbx, %rdi
movl %r15d, %edx
callq 0x42fba
testl %eax, %eax
jne 0x43011
andl $0x0, -0x4c(%rbp)
leaq -0x5c(%rbp), %r9
andl $0x0, (%r9)
movq (%rbx), %rdi
pushq $0x9
popq %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3ee6f
movq 0x8(%r14), %rsi
testq %rsi, %rsi
je 0x4307f
movq %rbx, %rdi
movl %r15d, %edx
callq 0x42fba
testl %eax, %eax
jne 0x43011
movq (%rbx), %rdi
pushq $0x8
popq %rsi
leaq -0x4c(%rbp), %r9
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3ee6f
movq (%rbx), %rcx
movl -0x5c(%rbp), %eax
movq 0xf0(%rcx), %rdx
movl 0x10(%rdx), %ecx
cmpl %eax, %ecx
jbe 0x430ba
movq 0x8(%rdx), %rsi
testq %rsi, %rsi
je 0x430ba
imull 0x18(%rdx), %eax
movl %ecx, 0x8(%rsi,%rax)
movq 0x10(%r14), %rsi
testq %rsi, %rsi
je 0x430d6
movq %rbx, %rdi
movl %r15d, %edx
callq 0x42fba
testl %eax, %eax
jne 0x43011
movl -0x4c(%rbp), %ecx
xorl %eax, %eax
testl %ecx, %ecx
je 0x43011
movq (%rbx), %rdx
movq 0xf0(%rdx), %rsi
movl 0x10(%rsi), %edx
cmpl %ecx, %edx
jbe 0x43011
movq 0x8(%rsi), %rdi
testq %rdi, %rdi
je 0x43011
imull 0x18(%rsi), %ecx
movl %edx, 0x8(%rdi,%rcx)
jmp 0x43011
movq 0x18(%r14), %rax
movl 0x14(%rax), %edx
leaq 0x2301f(%rip), %rcx     # 0x6613f
pushq $0x1
popq %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3eed6
pushq $-0xa
popq %rax
jmp 0x43011
movl 0x1c(%rax), %r12d
movq 0x8(%r14), %rsi
xorl %eax, %eax
testq %rsi, %rsi
je 0x43180
xorl %r13d, %r13d
cmpl $0x10, %r12d
jne 0x4319a
movq %r12, -0x58(%rbp)
movl %r15d, -0x40(%rbp)
movq 0x40(%r14), %r15
xorl %r12d, %r12d
movslq 0x48(%r14), %r13
cmpq %r13, %r12
jge 0x4318a
movq (%r15,%r12,8), %rsi
movq %rbx, %rdi
pushq $0x2
popq %rdx
callq 0x42fba
incq %r12
testl %eax, %eax
je 0x4315c
jmp 0x43011
xorl %ecx, %ecx
xorl %r13d, %r13d
jmp 0x4326d
movl -0x40(%rbp), %r15d
andl $-0x3, %r15d
movq 0x8(%r14), %rsi
movq -0x58(%rbp), %r12
movq %rbx, %rdi
movl %r15d, %edx
callq 0x42fba
testl %eax, %eax
jne 0x43011
cmpl $0x10, %r12d
jne 0x431e4
movq (%rbx), %rdi
callq 0x450d2
xorl %ecx, %ecx
testq %rax, %rax
je 0x4326b
movzbl (%rax), %edx
cmpl $0x3f, %edx
je 0x43264
cmpl $0x4, %edx
jne 0x4326b
andl $0x0, 0x4(%rax)
jmp 0x4326b
cmpl $0x5, %r12d
jne 0x4322a
movq %r12, -0x58(%rbp)
movq 0x40(%r14), %rax
movq %rax, -0x40(%rbp)
movl %r15d, %eax
andl $-0x2, %eax
movl %eax, -0x48(%rbp)
xorl %r12d, %r12d
movslq 0x48(%r14), %rax
cmpq %rax, %r12
jge 0x4324f
movq -0x40(%rbp), %rax
movq (%rax,%r12,8), %rsi
movq %rbx, %rdi
movl -0x48(%rbp), %edx
callq 0x42fba
incq %r12
testl %eax, %eax
je 0x43202
jmp 0x43011
movq (%r14), %rax
xorl %ecx, %ecx
cmpl $0x33, 0x10(%rax)
jne 0x4326b
movq (%rbx), %rdi
pushq $0xb
popq %rsi
pushq $0x1
popq %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x3ee6f
xorl %ecx, %ecx
jmp 0x4326b
testl %eax, %eax
pushq $0x1
popq %rax
cmovnel %eax, %r13d
movl %r15d, %ecx
andl $0x1, %ecx
movq -0x58(%rbp), %r12
jmp 0x4326b
movl $0x1, 0x8(%rax)
xorl %eax, %eax
andl $0x0, -0x2c(%rbp)
cmpq $0x0, 0x10(%r14)
je 0x43308
cmpl $0x28, %r12d
movq %rcx, -0x48(%rbp)
je 0x43293
cmpl $0x27, %r12d
jne 0x432ac
movq (%rbx), %rdi
pushq $0x9
jmp 0x43298
movq (%rbx), %rdi
pushq $0xa
popq %rsi
pushq $0x1
popq %rdx
leaq -0x2c(%rbp), %r9
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3ee6f
jmp 0x432bb
movq (%r14), %rax
xorl %ecx, %ecx
cmpl $0x12, 0x14(%rax)
sete %cl
orl %ecx, %r15d
movq 0x10(%r14), %rsi
movq %rbx, %rdi
movl %r15d, %edx
callq 0x42fba
cmpl $0x2a, %r12d
jne 0x43304
movl %eax, -0x40(%rbp)
movq (%rbx), %r15
movq %r15, %rdi
callq 0x450d2
pushq $0x2a
popq %r12
testq %rax, %rax
je 0x43319
movzbl (%rax), %ecx
cmpl $0x3f, %ecx
je 0x43322
movq %r15, %rdi
cmpl $0x5, %ecx
jne 0x4332c
movl 0x4(%rax), %r13d
pushq $0x2b
popq %r12
xorl %r15d, %r15d
jmp 0x43334
movq -0x48(%rbp), %rcx
testl %r12d, %r12d
jle 0x43011
movl %eax, -0x40(%rbp)
xorl %r15d, %r15d
jmp 0x4333d
xorl %r15d, %r15d
movq -0x48(%rbp), %rcx
jmp 0x43356
xorl %r15d, %r15d
pushq $0x1
popq %rax
movl %eax, %ecx
jmp 0x43356
movq 0x10(%rax), %r15
pushq $0x2a
popq %r12
callq 0x42d40
movq -0x48(%rbp), %rcx
leal -0x31(%r12), %eax
cmpl $0x1, %eax
ja 0x43356
testb $0x1, 0x28(%r14)
pushq $0x1
popq %rax
cmovel %r13d, %eax
movl %eax, %r13d
movq (%rbx), %rdi
movl %r12d, %esi
movl %r13d, %edx
movq %r15, %r8
xorl %r9d, %r9d
callq 0x3ee6f
movl -0x2c(%rbp), %eax
testl %eax, %eax
je 0x43393
movq (%rbx), %rcx
movq 0xf0(%rcx), %rdx
movl 0x10(%rdx), %ecx
cmpl %eax, %ecx
jbe 0x43393
movq 0x8(%rdx), %rsi
testq %rsi, %rsi
je 0x43393
imull 0x18(%rdx), %eax
movl %ecx, 0x8(%rsi,%rax)
movl -0x40(%rbp), %eax
jmp 0x43011