// File: /workspace/github_c_makefile_star2_O1/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, %r15d
movq %rsi, %r14
movq %rdi, %rbx
movq 0x30(%rsi), %rax
testq %rax, %rax
je 0x4dd11
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)
jmp 0x4e13b
movq (%r14), %rax
testq %rax, %rax
je 0x4de09
cmpl $0x26, 0x10(%rax)
jne 0x4de30
movq 0x60(%r14), %rsi
movq %rbx, %rdi
movl %r15d, %edx
callq 0x4dcb5
testl %eax, %eax
jne 0x4e13b
xorl %eax, %eax
movl %eax, -0x54(%rbp)
leaq -0x68(%rbp), %r9
movl %eax, (%r9)
movq (%rbx), %rdi
movl $0x9, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x493c1
movq 0x8(%r14), %rsi
testq %rsi, %rsi
je 0x4dd7a
movq %rbx, %rdi
movl %r15d, %edx
callq 0x4dcb5
testl %eax, %eax
jne 0x4e13b
movq (%rbx), %rdi
xorl %r12d, %r12d
leaq -0x54(%rbp), %r9
movl $0x8, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x493c1
movq (%rbx), %rax
movl -0x68(%rbp), %ecx
movq 0xf0(%rax), %rdx
movl 0x10(%rdx), %eax
cmpl %ecx, %eax
jbe 0x4ddb4
imull 0x18(%rdx), %ecx
addq 0x8(%rdx), %rcx
movq %rcx, %r12
testq %r12, %r12
je 0x4ddbe
movl %eax, 0x8(%r12)
movq 0x10(%r14), %rsi
testq %rsi, %rsi
je 0x4ddda
movq %rbx, %rdi
movl %r15d, %edx
callq 0x4dcb5
testl %eax, %eax
jne 0x4e13b
movl -0x54(%rbp), %ecx
testl %ecx, %ecx
je 0x4dfcb
movq (%rbx), %rax
movq 0xf0(%rax), %rsi
movl 0x10(%rsi), %edx
xorl %eax, %eax
cmpl %ecx, %edx
jbe 0x4dfd2
imull 0x18(%rsi), %ecx
addq 0x8(%rsi), %rcx
jmp 0x4dfd4
movq 0x18(%r14), %rax
movl 0x14(%rax), %edx
leaq 0x2a33d(%rip), %rcx     # 0x78154
movq %rbx, %rdi
movl $0x1, %esi
xorl %eax, %eax
callq 0x49434
movl $0xfffffff6, %eax       # imm = 0xFFFFFFF6
jmp 0x4e13b
movl 0x1c(%rax), %esi
cmpq $0x0, 0x8(%r14)
je 0x4dec9
cmpl $0x10, %esi
movq %rsi, -0x50(%rbp)
jne 0x4defe
movl 0x48(%r14), %eax
testl %eax, %eax
setg %r13b
jle 0x4dfe5
movq 0x40(%r14), %rax
movl %r15d, %r12d
orl $0x2, %r12d
movq %rax, -0x60(%rbp)
movq (%rax), %rsi
movq %rbx, %rdi
movl $0x2, %edx
callq 0x4dcb5
movl $0x0, -0x40(%rbp)
testl %eax, %eax
jne 0x4dfef
movl %r12d, -0x48(%rbp)
movl $0x1, %r12d
movslq 0x48(%r14), %rax
cmpq %rax, %r12
setl %r13b
jge 0x4dfe5
movq -0x60(%rbp), %rax
movq (%rax,%r12,8), %rsi
movq %rbx, %rdi
movl $0x2, %edx
callq 0x4dcb5
incq %r12
testl %eax, %eax
je 0x4de93
movl -0x48(%rbp), %r12d
jmp 0x4dfef
xorl %ecx, %ecx
xorl %r12d, %r12d
movl $0x0, -0x2c(%rbp)
cmpq $0x0, 0x10(%r14)
je 0x4df06
movl %r12d, -0x40(%rbp)
movq %rcx, %r12
cmpl $0x28, %esi
je 0x4df11
movq %rsi, %r13
cmpl $0x27, %esi
jne 0x4df31
movq (%rbx), %rdi
leaq -0x2c(%rbp), %r9
movl $0x9, %esi
jmp 0x4df20
xorl %r12d, %r12d
jmp 0x4e002
xorl %r8d, %r8d
xorl %r15d, %r15d
jmp 0x4e0e4
movq %rsi, %r13
movq (%rbx), %rdi
leaq -0x2c(%rbp), %r9
movl $0xa, %esi
movl $0x1, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x493c1
jmp 0x4df40
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 0x4dcb5
movl %eax, %r15d
movq %r13, %rsi
cmpl $0x2a, %esi
jne 0x4df7b
movq (%rbx), %rax
movq 0xf0(%rax), %rax
movl 0x10(%rax), %edi
testl %edi, %edi
movq %r12, %rcx
je 0x4df8a
leal -0x1(%rdi), %edx
imull 0x18(%rax), %edx
addq 0x8(%rax), %rdx
jmp 0x4df8c
xorl %r8d, %r8d
movq %r12, %rcx
movl -0x40(%rbp), %r12d
jmp 0x4e0e4
xorl %edx, %edx
movl -0x40(%rbp), %r12d
movl $0x2a, %esi
testq %rdx, %rdx
je 0x4dfc3
movzbl (%rdx), %r8d
cmpl $0x3f, %r8d
je 0x4e0c8
cmpl $0x5, %r8d
jne 0x4e0d2
movl 0x4(%rdx), %r12d
movl $0x2b, %esi
xorl %r8d, %r8d
jmp 0x4e0db
xorl %r8d, %r8d
jmp 0x4e0e4
xorl %eax, %eax
jmp 0x4e13b
xorl %ecx, %ecx
testq %rcx, %rcx
je 0x4e13b
movl %edx, 0x8(%rcx)
jmp 0x4e13b
movl %eax, -0x40(%rbp)
andl $-0x3, %r15d
movl %r15d, %r12d
movl %r12d, %r15d
movl %eax, -0x60(%rbp)
testb %r13b, %r13b
movl -0x40(%rbp), %r12d
jne 0x4e13b
movq 0x8(%r14), %rsi
movq %rbx, %rdi
movl %r15d, %edx
callq 0x4dcb5
movq -0x50(%rbp), %rsi
testl %eax, %eax
jne 0x4e13b
cmpl $0x10, %esi
jne 0x4e048
movq (%rbx), %rax
movq 0xf0(%rax), %rdx
movl 0x10(%rdx), %eax
xorl %ecx, %ecx
testl %eax, %eax
je 0x4e14a
decl %eax
imull 0x18(%rdx), %eax
addq 0x8(%rdx), %rax
jmp 0x4e14c
cmpl $0x5, %esi
jne 0x4e09a
movl 0x48(%r14), %eax
testl %eax, %eax
setg %r13b
jle 0x4e1c7
movb %r13b, -0x48(%rbp)
movl %r12d, -0x40(%rbp)
movq 0x40(%r14), %r12
movl %r15d, %r13d
andl $-0x2, %r13d
movq (%r12), %rsi
movq %rbx, %rdi
movl %r13d, %edx
callq 0x4dcb5
testl %eax, %eax
je 0x4e17e
movl -0x40(%rbp), %r12d
movq -0x50(%rbp), %rsi
xorl %ecx, %ecx
movb -0x48(%rbp), %r13b
jmp 0x4e1db
movq (%r14), %rax
cmpl $0x33, 0x10(%rax)
jne 0x4e0c1
movq (%rbx), %rdi
movl $0xb, %esi
movl $0x1, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x493c1
movq -0x50(%rbp), %rsi
xorl %ecx, %ecx
jmp 0x4dece
xorl %r8d, %r8d
movl $0x1, %ecx
jmp 0x4e0e4
movq 0x10(%rdx), %r8
movl $0x2a, %esi
testl %edi, %edi
je 0x4e0e4
decl %edi
movl %edi, 0x10(%rax)
testl %esi, %esi
jle 0x4e138
leal -0x31(%rsi), %eax
cmpl $0x1, %eax
ja 0x4e0fe
testb $0x1, 0x28(%r14)
movl $0x1, %eax
cmovnel %eax, %r12d
movq (%rbx), %rdi
movl %r12d, %edx
xorl %r9d, %r9d
callq 0x493c1
movl -0x2c(%rbp), %eax
testl %eax, %eax
je 0x4e138
movq (%rbx), %rcx
movq 0xf0(%rcx), %rdx
movl 0x10(%rdx), %ecx
cmpl %eax, %ecx
jbe 0x4e12e
imull 0x18(%rdx), %eax
addq 0x8(%rdx), %rax
jmp 0x4e130
xorl %eax, %eax
testq %rax, %rax
je 0x4e138
movl %ecx, 0x8(%rax)
movl %r15d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
testq %rax, %rax
je 0x4dece
movzbl (%rax), %edx
cmpl $0x3f, %edx
je 0x4e172
cmpl $0x4, %edx
jne 0x4dece
movl $0x0, 0x4(%rax)
jmp 0x4dece
movl $0x1, 0x8(%rax)
jmp 0x4dece
movl %r13d, -0x64(%rbp)
movq %r12, -0x48(%rbp)
movl $0x1, %r12d
movslq 0x48(%r14), %rax
cmpq %rax, %r12
setl %r13b
jge 0x4e1bf
movq -0x48(%rbp), %rax
movq (%rax,%r12,8), %rsi
movq %rbx, %rdi
movl -0x64(%rbp), %edx
callq 0x4dcb5
incq %r12
testl %eax, %eax
je 0x4e18c
movl -0x40(%rbp), %r12d
movq -0x50(%rbp), %rsi
xorl %ecx, %ecx
jmp 0x4e1db
movl -0x40(%rbp), %r12d
movq -0x50(%rbp), %rsi
testl %eax, %eax
movl $0x1, %eax
cmovnel %eax, %r12d
movl %r15d, %ecx
andl $0x1, %ecx
movl -0x60(%rbp), %eax
testb %r13b, %r13b
je 0x4dece
jmp 0x4e13b