// File: /workspace/github_c_makefile_star2_O3/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, -0x38(%rbp)
testl %esi, %esi
jle 0x54b94
movq %rdx, %r14
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
jne 0x54bb2
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x30465
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %r15d
leaq -0x48(%rbp), %r13
movq %r13, %rsi
callq 0x30577
movq %rax, %r12
movslq (%r13), %r13
movl $0x1, -0x2c(%rbp)
cmpl $0x1, %r15d
je 0x54bf1
movq 0x8(%r14), %r14
movq %r14, %rdi
callq 0x3f362
movl (%r14), %eax
testl %eax, %eax
movl $0x1, %ecx
cmovnsl %eax, %ecx
movl %ecx, -0x2c(%rbp)
testl %r13d, %r13d
jle 0x54ba1
addq %r12, %r13
movl -0x2c(%rbp), %eax
andl $0x6, %eax
movl %eax, -0x44(%rbp)
movq %r12, %r15
movq %r13, -0x40(%rbp)
movb (%r15), %bl
cmpb $0x26, %bl
je 0x54c19
incq %r15
cmpq %r13, %r15
jb 0x54c09
cmpq %r15, %r12
jae 0x54c34
movl %r15d, %edx
subl %r12d, %edx
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movq %r12, %rsi
callq 0x302f6
cmpb $0x26, %bl
jne 0x54ba1
movl %r13d, %ebx
subl %r15d, %ebx
movl %ebx, -0x48(%rbp)
xorl %r14d, %r14d
leaq 0x3df60(%rip), %rax     # 0x92bb0
movq (%rax,%r14,8), %r12
cmpb $0x0, (%r12)
movq %r12, %r13
je 0x54c97
leaq 0x2(%r12), %r13
cmpb $0x0, -0x1(%r13)
je 0x54c8f
cmpb $0x0, (%r13)
je 0x54c97
cmpb $0x0, 0x1(%r13)
je 0x54c94
leaq 0x4(%r13), %rax
cmpb $0x0, 0x2(%r13)
movq %rax, %r13
jne 0x54c63
addq $-0x2, %rax
movq %rax, %r13
jmp 0x54c97
decq %r13
jmp 0x54c97
incq %r13
subq %r12, %r13
cmpl %r13d, %ebx
jl 0x54cb1
movq %r15, %rdi
movq %r12, %rsi
movl %r13d, %edx
callq 0x39f3f
testl %eax, %eax
je 0x54ce0
leaq 0x2(%r14), %rax
cmpq $0x26, %r14
movq %rax, %r14
jb 0x54c49
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x20a04(%rip), %rsi     # 0x756d1
movl $0x1, %edx
callq 0x302f6
incq %r15
movq -0x40(%rbp), %r13
jmp 0x54d3c
movslq %r13d, %rax
addq %rax, %r15
movl %r14d, %eax
shlq $0x3, %rax
orq $0x8, %rax
leaq 0x3deb8(%rip), %rcx     # 0x92bb0
movq (%rax,%rcx), %rsi
movzbl (%rsi), %eax
cmpl $0x22, %eax
je 0x54d1d
cmpl $0x27, %eax
movq -0x40(%rbp), %r13
jne 0x54d13
cmpl $0x2, -0x44(%rbp)
jne 0x54d27
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
jmp 0x54d32
testb $0x4, -0x2c(%rbp)
movq -0x40(%rbp), %r13
je 0x54d13
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movq %r12, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x302f6
movq %r15, %r12
cmpq %r13, %r15
jb 0x54c09
jmp 0x54ba1