// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movl %edx, %r12d
movq %rsi, %r15
movq %rdi, %rbx
movq 0x30(%rsi), %rax
testq %rax, %rax
je 0x4cb11
movups 0x158(%rbx), %xmm0
movaps %xmm0, -0x60(%rbp)
movq 0x18(%r15), %rcx
movq %rcx, 0x158(%rbx)
movq 0x20(%r15), %rcx
movq %rcx, 0x160(%rbx)
movq %rbx, %rdi
movl %r12d, %esi
callq *%rax
movaps -0x60(%rbp), %xmm0
movups %xmm0, 0x158(%rbx)
jmp 0x4cd2a
movq (%r15), %rax
testq %rax, %rax
je 0x4cbde
cmpl $0x26, 0x10(%rax)
jne 0x4cc06
movq 0x60(%r15), %rsi
movq %rbx, %rdi
movl %r12d, %edx
callq 0x4cab5
testl %eax, %eax
jne 0x4cd24
xorl %eax, %eax
movl %eax, -0x3c(%rbp)
leaq -0x64(%rbp), %r9
movl %eax, (%r9)
movq (%rbx), %rdi
movl $0x9, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x48365
movq 0x8(%r15), %rsi
testq %rsi, %rsi
je 0x4cb7a
movq %rbx, %rdi
movl %r12d, %edx
callq 0x4cab5
testl %eax, %eax
jne 0x4cd24
movq (%rbx), %rdi
leaq -0x3c(%rbp), %r9
movl $0x8, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x48365
movq (%rbx), %rcx
movl -0x64(%rbp), %eax
movq 0xf0(%rcx), %rdx
movl 0x10(%rdx), %ecx
cmpl %eax, %ecx
jbe 0x4cbb7
movq 0x8(%rdx), %rsi
testq %rsi, %rsi
je 0x4cbb7
imull 0x18(%rdx), %eax
movl %ecx, 0x8(%rsi,%rax)
movq 0x10(%r15), %rsi
testq %rsi, %rsi
je 0x4cbd3
movq %rbx, %rdi
movl %r12d, %edx
callq 0x4cab5
testl %eax, %eax
jne 0x4cd24
movl -0x3c(%rbp), %eax
xorl %r14d, %r14d
jmp 0x4ced1
movq 0x18(%r15), %rax
movl 0x14(%rax), %edx
leaq 0x29573(%rip), %rcx     # 0x7615f
movq %rbx, %rdi
movl $0x1, %esi
xorl %eax, %eax
callq 0x483d1
movl $0xfffffff6, %r14d      # imm = 0xFFFFFFF6
jmp 0x4cd27
movl 0x1c(%rax), %r13d
movq 0x8(%r15), %rsi
xorl %r14d, %r14d
testq %rsi, %rsi
je 0x4ccd6
cmpl $0x10, %r13d
jne 0x4cd15
movl %r12d, -0x2c(%rbp)
movl 0x48(%r15), %r12d
testl %r12d, %r12d
movq %r13, -0x48(%rbp)
jle 0x4cc68
movq 0x40(%r15), %r14
xorl %r13d, %r13d
movq (%r14,%r13,8), %rsi
movq %rbx, %rdi
movl $0x2, %edx
callq 0x4cab5
testl %eax, %eax
jne 0x4cd24
incq %r13
movslq 0x48(%r15), %r12
cmpq %r12, %r13
jl 0x4cc3c
movq 0x8(%r15), %rsi
xorl %r14d, %r14d
movl -0x2c(%rbp), %r13d
andl $-0x3, %r13d
movq %rbx, %rdi
movl %r13d, %edx
callq 0x4cab5
testl %eax, %eax
jne 0x4cd24
movl %r13d, -0x2c(%rbp)
movq (%rbx), %rax
movq 0xf0(%rax), %rdx
movl 0x10(%rdx), %eax
testl %eax, %eax
je 0x4cf11
movq 0x8(%rdx), %rcx
testq %rcx, %rcx
movq -0x48(%rbp), %r13
je 0x4cf24
decl %eax
imull 0x18(%rdx), %eax
movzbl (%rcx,%rax), %edx
cmpl $0x3f, %edx
je 0x4cf1c
cmpl $0x4, %edx
jne 0x4cf24
movl $0x0, 0x4(%rcx,%rax)
jmp 0x4cf24
movl %r12d, -0x2c(%rbp)
xorl %ecx, %ecx
xorl %r12d, %r12d
movl $0x0, -0x40(%rbp)
movq 0x10(%r15), %rsi
testq %rsi, %rsi
je 0x4ce8e
cmpl $0x27, %r13d
movq %rcx, -0x38(%rbp)
je 0x4cd9c
cmpl $0x28, %r13d
jne 0x4cdda
movl $0xa, %esi
jmp 0x4cda1
movq %rbx, %rdi
movl %r12d, %edx
callq 0x4cab5
testl %eax, %eax
je 0x4cd39
movl %eax, %r14d
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x5, %r13d
movl %r12d, -0x2c(%rbp)
jne 0x4ce5e
movl 0x48(%r15), %eax
testl %eax, %eax
jle 0x4cd88
movq %r13, -0x48(%rbp)
movq 0x40(%r15), %r14
andl $-0x2, %r12d
xorl %r13d, %r13d
movq (%r14,%r13,8), %rsi
movq %rbx, %rdi
movl %r12d, %edx
callq 0x4cab5
testl %eax, %eax
jne 0x4cd24
incq %r13
movslq 0x48(%r15), %rax
cmpq %rax, %r13
jl 0x4cd5e
xorl %r14d, %r14d
movq -0x48(%rbp), %r13
movl -0x2c(%rbp), %r12d
movl %r12d, %ecx
xorl %r12d, %r12d
testl %eax, %eax
setne %r12b
andl $0x1, %ecx
jmp 0x4ccdf
movl $0x9, %esi
movq (%rbx), %rdi
movq $0x0, -0x60(%rbp)
leaq -0x40(%rbp), %r9
movl $0x1, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x48365
movq 0x10(%r15), %rsi
movq %rbx, %rdi
movl -0x2c(%rbp), %edx
callq 0x4cab5
movl %eax, %r14d
movq -0x38(%rbp), %rcx
jmp 0x4ce9f
movq (%r15), %rax
xorl %ecx, %ecx
cmpl $0x12, 0x14(%rax)
sete %cl
movl -0x2c(%rbp), %edx
orl %ecx, %edx
movq %rbx, %rdi
callq 0x4cab5
movl %eax, %r14d
cmpl $0x2a, %r13d
jne 0x4ce8a
movq (%rbx), %rax
movq 0xf0(%rax), %rax
movl 0x10(%rax), %ecx
movl $0x2a, %r13d
testl %ecx, %ecx
je 0x4cf08
movq 0x8(%rax), %rdx
testq %rdx, %rdx
je 0x4cf08
decl %ecx
movl 0x18(%rax), %esi
imull %ecx, %esi
movzbl (%rdx,%rsi), %edi
cmpl $0x3f, %edi
je 0x4cf2b
cmpl $0x5, %edi
jne 0x4cf35
movl 0x4(%rdx,%rsi), %r12d
movl $0x2b, %r13d
movq $0x0, -0x60(%rbp)
jmp 0x4cf44
movq (%r15), %rax
cmpl $0x33, 0x10(%rax)
jne 0x4ccda
movq (%rbx), %rdi
movl $0xb, %esi
movl $0x1, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x48365
jmp 0x4ccda
movq -0x38(%rbp), %rcx
testl %r13d, %r13d
jle 0x4cd27
movq $0x0, -0x60(%rbp)
leal -0x31(%r13), %eax
cmpl $0x1, %eax
ja 0x4ceb9
testb $0x1, 0x28(%r15)
movl $0x1, %eax
cmovel %r12d, %eax
movl %eax, %r12d
movq -0x60(%rbp), %r8
movq (%rbx), %rdi
movl %r13d, %esi
movl %r12d, %edx
xorl %r9d, %r9d
callq 0x48365
movl -0x40(%rbp), %eax
testl %eax, %eax
je 0x4cd27
movq (%rbx), %rcx
movq 0xf0(%rcx), %rdx
movl 0x10(%rdx), %ecx
cmpl %eax, %ecx
jbe 0x4cd27
movq 0x8(%rdx), %rsi
testq %rsi, %rsi
je 0x4cd27
imull 0x18(%rdx), %eax
movl %ecx, 0x8(%rsi,%rax)
jmp 0x4cd27
xorl %r8d, %r8d
movq -0x38(%rbp), %rcx
jmp 0x4cebd
xorl %ecx, %ecx
movq -0x48(%rbp), %r13
jmp 0x4ccdf
movl $0x1, 0x8(%rcx,%rax)
xorl %ecx, %ecx
jmp 0x4ccdf
xorl %r8d, %r8d
movl $0x1, %ecx
jmp 0x4cebd
movq 0x10(%rdx,%rsi), %rdx
movq %rdx, -0x60(%rbp)
movl $0x2a, %r13d
movl %ecx, 0x10(%rax)
jmp 0x4cdd1