// File: /workspace/github_c_makefile_star2_O1/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 0x562f2
movq %rdx, %r14
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
jne 0x56310
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x309f2
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %r15d
leaq -0x44(%rbp), %r13
movq %r13, %rsi
callq 0x30b04
movq %rax, %r12
movslq (%r13), %rbx
movl $0x1, -0x2c(%rbp)
cmpl $0x1, %r15d
je 0x5634f
movq 0x8(%r14), %r14
movq %r14, %rdi
callq 0x3fd5f
movl (%r14), %eax
testl %eax, %eax
movl $0x1, %ecx
cmovnsl %eax, %ecx
movl %ecx, -0x2c(%rbp)
movq %rbx, %r14
testl %r14d, %r14d
jle 0x562ff
addq %r12, %r14
movl -0x2c(%rbp), %eax
andl $0x6, %eax
movl %eax, -0x40(%rbp)
movq %r12, %r15
movq %r14, -0x50(%rbp)
movb $0x1, %bl
cmpb $0x26, (%r12)
je 0x5638d
leaq 0x1(%r12), %rax
movq %rax, %r15
cmpq %r14, %rax
setb %bl
jae 0x5638d
leaq 0x1(%r15), %rax
cmpb $0x26, (%r15)
jne 0x56378
cmpq %r15, %r12
jae 0x563a8
movl %r15d, %edx
subl %r12d, %edx
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movq %r12, %rsi
callq 0x3087c
testb %bl, %bl
je 0x562ff
movl %r14d, %ecx
subl %r15d, %ecx
movl %ecx, -0x44(%rbp)
movb $0x1, %r14b
xorl %ebx, %ebx
movl %ecx, -0x3c(%rbp)
leaq 0x3e7e8(%rip), %rax     # 0x94bb0
movq (%rax,%rbx,8), %rsi
cmpb $0x0, (%rsi)
movq %rsi, %r12
je 0x56410
leaq 0x2(%rsi), %r12
cmpb $0x0, -0x1(%r12)
je 0x56408
cmpb $0x0, (%r12)
je 0x56410
cmpb $0x0, 0x1(%r12)
je 0x5640d
leaq 0x4(%r12), %rax
cmpb $0x0, 0x2(%r12)
movq %rax, %r12
jne 0x563d8
addq $-0x2, %rax
movq %rax, %r12
jmp 0x56410
decq %r12
jmp 0x56410
incq %r12
subq %rsi, %r12
movb $0x1, %r13b
cmpl %r12d, %ecx
jl 0x56436
movq %r15, %rdi
movl %r12d, %edx
callq 0x3a837
testl %eax, %eax
jne 0x56433
movslq %r12d, %rax
addq %rax, %r15
xorl %r13d, %r13d
movl -0x3c(%rbp), %ecx
testb %r13b, %r13b
je 0x56455
leaq 0x2(%rbx), %rax
cmpq $0x26, %rbx
setb %r14b
movq %rax, %rbx
jb 0x563c1
movl $0x28, %ebx
testb $0x1, %r14b
je 0x564a6
movl %ebx, %eax
shlq $0x3, %rax
orq $0x8, %rax
leaq 0x3e744(%rip), %rcx     # 0x94bb0
movq (%rax,%rcx), %rsi
movzbl (%rsi), %eax
cmpl $0x22, %eax
movq -0x50(%rbp), %r14
je 0x564d7
cmpl $0x27, %eax
jne 0x56492
cmpl $0x2, -0x40(%rbp)
je 0x56492
leaq 0x3e722(%rip), %rax     # 0x94bb0
movq (%rax,%rbx,8), %rsi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x3087c
jmp 0x564c6
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x21211(%rip), %rsi     # 0x776c6
movl $0x1, %edx
callq 0x3087c
incq %r15
movq -0x50(%rbp), %r14
movq %r15, %r12
cmpq %r14, %r15
jb 0x5636a
jmp 0x562ff
testb $0x4, -0x2c(%rbp)
jne 0x56487
jmp 0x56492