// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_html_entity_decode
static int jx9Builtin_html_entity_decode(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	const char *zCur, *zIn, *zEnd;
	int iFlags = 0x01; /* ENT_COMPAT  */
	int nLen;
	sxu32 n;
	if( nArg < 1 || !jx9_value_is_string(apArg[0]) ){
		/* Missing/Invalid arguments, return NULL */
		jx9_result_null(pCtx);
		return JX9_OK;
	}
	/* Extract the target string */
	zIn = jx9_value_to_string(apArg[0], &nLen);
	zEnd = &zIn[nLen];
	/* Extract the flags if available */
	if( nArg > 1 ){
		iFlags = jx9_value_to_int(apArg[1]);
		if( iFlags < 0 ){
			iFlags = 0x01;
		}
	}
	/* Perform the requested operation */
	for(;;){
		if( zIn >= zEnd ){
			/* No more input to process */
			break;
		}
		zCur = zIn;
		while( zIn < zEnd && zIn[0] != '&' ){
			zIn++;
		}
		if( zCur < zIn ){
			/* Append raw string verbatim */
			jx9_result_string(pCtx, zCur, (int)(zIn-zCur));
		}
		if( zIn >= zEnd ){
			break;
		}
		nLen = (int)(zEnd-zIn);
		/* Find an encoded sequence */
		for(n = 0 ; n < SX_ARRAYSIZE(azHtmlEscape) ; n += 2 ){
			int iLen = (int)SyStrlen(azHtmlEscape[n]);
			if( nLen >= iLen && SyStrnicmp(zIn, azHtmlEscape[n], (sxu32)iLen) == 0 ){
				/* Got one */
				zIn += iLen;
				break;
			}
		}
		if( n < SX_ARRAYSIZE(azHtmlEscape) ){
			int c = azHtmlEscape[n+1][0];
			/* Output the decoded character */
			if( c == '\'' && ((iFlags & 0x02) == 0 /*ENT_QUOTES*/|| (iFlags & 0x04) /*ENT_NOQUOTES*/)  ){
				/* Do not process single quotes */
				jx9_result_string(pCtx, azHtmlEscape[n], -1);
			}else if( c == '"' && (iFlags & 0x04) /*ENT_NOQUOTES*/ ){
				/* Do not process double quotes */
				jx9_result_string(pCtx, azHtmlEscape[n], -1);
			}else{
				jx9_result_string(pCtx, azHtmlEscape[n+1], -1); /* Compute length automatically */
			}
		}else{
			/* Append '&' */
			jx9_result_string(pCtx, "&", (int)sizeof(char));
			zIn++;
		}
	}
	return JX9_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, -0x30(%rbp)
testl %esi, %esi
jle 0x493ba
movq %rdx, %r15
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
jne 0x493d4
movq -0x30(%rbp), %rdi
callq 0x298e8
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %r12d
leaq -0x48(%rbp), %r13
movq %r13, %rsi
callq 0x297ed
movq %rax, %r14
movslq (%r13), %rbx
cmpl $0x1, %r12d
jne 0x493f5
pushq $0x1
popq %rcx
jmp 0x49406
movq 0x8(%r15), %rdi
callq 0x29772
testl %eax, %eax
pushq $0x1
popq %rcx
cmovnsl %eax, %ecx
movq %r14, %r12
addq %rbx, %r12
movl %ecx, -0x40(%rbp)
andl $0x6, %ecx
movl %ecx, -0x3c(%rbp)
leal (%rbx,%r14), %eax
movl %eax, -0x44(%rbp)
movq %r12, -0x38(%rbp)
cmpq %r12, %r14
jae 0x493c3
xorl %r15d, %r15d
movq %r14, %r13
cmpq %r12, %r13
jae 0x4943f
cmpb $0x26, (%r13)
je 0x4943f
incq %r13
incq %r15
jmp 0x4942b
cmpq %r13, %r14
jae 0x49453
movq -0x30(%rbp), %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x29903
cmpq %r12, %r13
jae 0x493c3
movl -0x44(%rbp), %eax
movl %eax, %ebx
subl %r14d, %ebx
subq %r15, %rbx
movl %ebx, -0x48(%rbp)
xorl %r12d, %r12d
cmpq $0x27, %r12
ja 0x494a4
leaq 0x3c746(%rip), %rax     # 0x85bc0
movq (%rax,%r12,8), %r15
movq %r15, %rdi
callq 0x28e24
cmpl %ebx, %eax
jg 0x4949e
movl %eax, %r14d
movq %r13, %rdi
movq %r15, %rsi
movl %eax, %edx
callq 0x32436
testl %eax, %eax
je 0x494c6
addq $0x2, %r12
jmp 0x4946d
movq -0x30(%rbp), %rdi
leaq 0x1c202(%rip), %rsi     # 0x656b1
pushq $0x1
popq %rdx
callq 0x29903
incq %r13
movq %r13, %r14
movq -0x38(%rbp), %r12
jmp 0x49420
movslq %r14d, %rax
movq %r13, %r14
addq %rax, %r14
leaq 0x3c6ea(%rip), %rax     # 0x85bc0
movq 0x8(%rax,%r12,8), %rsi
movzbl (%rsi), %eax
cmpl $0x22, %eax
je 0x494f8
cmpl $0x27, %eax
movq -0x38(%rbp), %r12
jne 0x494f2
cmpl $0x2, -0x3c(%rbp)
jne 0x49502
movq -0x30(%rbp), %rdi
jmp 0x49509
testb $0x4, -0x40(%rbp)
movq -0x38(%rbp), %r12
je 0x494f2
movq -0x30(%rbp), %rdi
movq %r15, %rsi
pushq $-0x1
popq %rdx
callq 0x29903
jmp 0x49420