// File: /workspace/github_c_makefile_star2_O1/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_htmlspecialchars
static int jx9Builtin_htmlspecialchars(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	const char *zCur, *zIn, *zEnd;
	int iFlags = 0x01|0x40; /* ENT_COMPAT | ENT_HTML401 */
	int nLen, c;
	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|0x40;
		}
	}
	/* Perform the requested operation */
	for(;;){
		if( zIn >= zEnd ){
			break;
		}
		zCur = zIn;
		while( zIn < zEnd && zIn[0] != '&' && zIn[0] != '\'' && zIn[0] != '"' && zIn[0] != '<' && zIn[0] != '>' ){
			zIn++;
		}
		if( zCur < zIn ){
			/* Append the raw string verbatim */
			jx9_result_string(pCtx, zCur, (int)(zIn-zCur));
		}
		if( zIn >= zEnd ){
			break;
		}
		c = zIn[0];
		if( c == '&' ){
			/* Expand '&amp;' */
			jx9_result_string(pCtx, "&amp;", (int)sizeof("&amp;")-1);
		}else if( c == '<' ){
			/* Expand '&lt;' */
			jx9_result_string(pCtx, "&lt;", (int)sizeof("&lt;")-1);
		}else if( c == '>' ){
			/* Expand '&gt;' */
			jx9_result_string(pCtx, "&gt;", (int)sizeof("&gt;")-1);
		}else if( c == '\'' ){
			if( iFlags & 0x02 /*ENT_QUOTES*/ ){
				/* Expand '&#039;' */
				jx9_result_string(pCtx, "&#039;", (int)sizeof("&#039;")-1);
			}else{
				/* Leave the single quote untouched */
				jx9_result_string(pCtx, "'", (int)sizeof(char));
			}
		}else if( c == '"' ){
			if( (iFlags & 0x04) == 0 /*ENT_NOQUOTES*/ ){
				/* Expand '&quot;' */
				jx9_result_string(pCtx, "&quot;", (int)sizeof("&quot;")-1);
			}else{
				/* Leave the double quote untouched */
				jx9_result_string(pCtx, "\"", (int)sizeof(char));
			}
		}
		/* Ignore the unsafe HTML character */
		zIn++;
	}
	return JX9_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, -0x30(%rbp)
testl %esi, %esi
jle 0x55d1a
movq %rdx, %r15
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
jne 0x55d38
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x309f2
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %r12d
leaq -0x38(%rbp), %r13
movq %r13, %rsi
callq 0x30b04
movq %rax, %rbx
movslq (%r13), %r13
movl $0x41, -0x34(%rbp)
cmpl $0x1, %r12d
je 0x55d77
movq 0x8(%r15), %r15
movq %r15, %rdi
callq 0x3fd5f
movl (%r15), %eax
testl %eax, %eax
movl $0x41, %ecx
cmovnsl %eax, %ecx
movl %ecx, -0x34(%rbp)
testl %r13d, %r13d
jle 0x55d27
addq %rbx, %r13
movabsq $0x500000c400000000, %r15 # imm = 0x500000C400000000
movq %rbx, %r14
movb $0x1, %r12b
movzbl (%r14), %eax
cmpq $0x3e, %rax
ja 0x55d9f
btq %rax, %r15
jb 0x55dab
incq %r14
cmpq %r13, %r14
setb %r12b
jb 0x55d8f
cmpq %r14, %rbx
jae 0x55dc5
movl %r14d, %edx
subl %ebx, %edx
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq %rbx, %rsi
callq 0x3087c
testb $0x1, %r12b
je 0x55d27
movzbl (%r14), %eax
cmpl $0x26, %eax
jle 0x55dfc
cmpl $0x27, %eax
je 0x55e20
cmpl $0x3c, %eax
je 0x55e37
cmpl $0x3e, %eax
jne 0x55e93
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x1d682(%rip), %rsi     # 0x7347c
jmp 0x55e46
cmpl $0x22, %eax
je 0x55e4d
cmpl $0x26, %eax
jne 0x55e93
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x230cc(%rip), %rsi     # 0x78ee5
movl $0x5, %edx
jmp 0x55e8e
testb $0x2, -0x34(%rbp)
jne 0x55e64
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x22506(%rip), %rsi     # 0x7833b
jmp 0x55e89
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x1d631(%rip), %rsi     # 0x73477
movl $0x4, %edx
jmp 0x55e8e
testb $0x4, -0x34(%rbp)
jne 0x55e7a
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x23090(%rip), %rsi     # 0x78ef2
jmp 0x55e73
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x23078(%rip), %rsi     # 0x78eeb
movl $0x6, %edx
jmp 0x55e8e
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x1dde9(%rip), %rsi     # 0x73c72
movl $0x1, %edx
callq 0x3087c
incq %r14
movq %r14, %rbx
cmpq %r13, %r14
jb 0x55d8c
jmp 0x55d27