// File: /workspace/github_c_makefile_star2_O0/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
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x85a9c
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x160(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x158(%rax)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x160(%rax)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq *%rax
movl %eax, -0x48(%rbp)
movq -0x50(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x158(%rax)
movq -0x58(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x160(%rax)
movl -0x48(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x85f9d
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x85ad4
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %edx
movl $0x1, %esi
leaq 0x3eb7f(%rip), %rcx     # 0xc4640
movb $0x0, %al
callq 0x7e990
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x85f9d
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
cmpl $0x26, 0x10(%rax)
jne 0x85c40
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rsi
movl -0x1c(%rbp), %edx
callq 0x859e0
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x48(%rbp)
je 0x85b1a
movl -0x48(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x85f9d
movl $0x0, -0x60(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl $0x9, %esi
xorl %ecx, %ecx
xorl %eax, %eax
movl %eax, %r8d
leaq -0x5c(%rbp), %r9
movl %ecx, %edx
callq 0x7e8f0
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x85b7b
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
movl -0x1c(%rbp), %edx
callq 0x859e0
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x48(%rbp)
je 0x85b79
movl -0x48(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x85f9d
jmp 0x85b7b
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl $0x8, %esi
xorl %ecx, %ecx
xorl %eax, %eax
movl %eax, %r8d
leaq -0x60(%rbp), %r9
movl %ecx, %edx
callq 0x7e8f0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl -0x5c(%rbp), %esi
callq 0x845a0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x85bc8
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7e8d0
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x85bfd
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
movl -0x1c(%rbp), %edx
callq 0x859e0
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x48(%rbp)
je 0x85bfb
movl -0x48(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x85f9d
jmp 0x85bfd
cmpl $0x0, -0x60(%rbp)
jbe 0x85c34
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl -0x60(%rbp), %esi
callq 0x845a0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x85c32
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7e8d0
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0x85c34
movl $0x0, -0x4(%rbp)
jmp 0x85f9d
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x85e07
cmpl $0x10, -0x44(%rbp)
jne 0x85ccc
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x68(%rbp)
movl -0x1c(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x1c(%rbp)
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x48(%rcx), %eax
jge 0x85cb9
movq -0x10(%rbp), %rdi
movq -0x68(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movl -0x1c(%rbp), %edx
andl $-0x2, %edx
callq 0x859e0
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x48(%rbp)
je 0x85cac
movl -0x48(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x85f9d
jmp 0x85cae
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x85c71
movq -0x18(%rbp), %rax
movl 0x48(%rax), %eax
movl %eax, -0x30(%rbp)
movl -0x1c(%rbp), %eax
andl $-0x3, %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
movl -0x1c(%rbp), %edx
callq 0x859e0
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x48(%rbp)
je 0x85cf4
movl -0x48(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x85f9d
cmpl $0x10, -0x44(%rbp)
jne 0x85d4a
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x8a310
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x85d45
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x4, %eax
jne 0x85d2a
movq -0x28(%rbp), %rax
movl $0x0, 0x4(%rax)
jmp 0x85d43
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x3f, %eax
jne 0x85d41
movq -0x28(%rbp), %rax
movl $0x1, 0x8(%rax)
jmp 0x85d43
jmp 0x85d45
jmp 0x85e05
cmpl $0x5, -0x44(%rbp)
jne 0x85dd4
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x78(%rbp)
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x48(%rcx), %eax
jge 0x85daf
movq -0x10(%rbp), %rdi
movq -0x78(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movl -0x1c(%rbp), %edx
andl $-0x2, %edx
callq 0x859e0
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x48(%rbp)
je 0x85da2
movl -0x48(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x85f9d
jmp 0x85da4
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x85d67
movq -0x18(%rbp), %rax
cmpl $0x0, 0x48(%rax)
jbe 0x85dc0
movl $0x1, -0x30(%rbp)
movl -0x1c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x85dd2
movl $0x1, -0x34(%rbp)
jmp 0x85e03
movq -0x18(%rbp), %rax
movq (%rax), %rax
cmpl $0x33, 0x10(%rax)
jne 0x85e01
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl $0xb, %esi
movl $0x1, %edx
xorl %ecx, %ecx
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %r8
callq 0x7e8f0
jmp 0x85e03
jmp 0x85e05
jmp 0x85e07
movl $0x0, -0x48(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x85f16
cmpl $0x27, -0x44(%rbp)
jne 0x85e4d
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl $0x9, %esi
movl $0x1, %edx
xorl %ecx, %ecx
xorl %eax, %eax
movl %eax, %r8d
leaq -0x2c(%rbp), %r9
callq 0x7e8f0
jmp 0x85e90
cmpl $0x28, -0x44(%rbp)
jne 0x85e76
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl $0xa, %esi
movl $0x1, %edx
xorl %ecx, %ecx
xorl %eax, %eax
movl %eax, %r8d
leaq -0x2c(%rbp), %r9
callq 0x7e8f0
jmp 0x85e8e
movq -0x18(%rbp), %rax
movq (%rax), %rax
cmpl $0x12, 0x14(%rax)
jne 0x85e8c
movl -0x1c(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x85e8e
jmp 0x85e90
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
movl -0x1c(%rbp), %edx
callq 0x859e0
movl %eax, -0x48(%rbp)
cmpl $0x2a, -0x44(%rbp)
jne 0x85f14
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x8a310
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x85f12
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x3f, %eax
jne 0x85ed9
movl $0x1, -0x34(%rbp)
jmp 0x85f10
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x5, %eax
jne 0x85ef8
movl $0x2b, -0x44(%rbp)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x30(%rbp)
jmp 0x85f04
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x85140
jmp 0x85f12
jmp 0x85f14
jmp 0x85f16
cmpl $0x0, -0x44(%rbp)
jle 0x85f97
cmpl $0x31, -0x44(%rbp)
je 0x85f28
cmpl $0x32, -0x44(%rbp)
jne 0x85f40
movq -0x18(%rbp), %rax
movl 0x28(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x85f3e
movl $0x1, -0x30(%rbp)
jmp 0x85f40
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl -0x44(%rbp), %esi
movl -0x30(%rbp), %edx
movl -0x34(%rbp), %ecx
movq -0x40(%rbp), %r8
xorl %eax, %eax
movl %eax, %r9d
callq 0x7e8f0
cmpl $0x0, -0x2c(%rbp)
jbe 0x85f95
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl -0x2c(%rbp), %esi
callq 0x845a0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x85f93
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7e8d0
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0x85f95
jmp 0x85f97
movl -0x48(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)