// File: /workspace/github_c_makefile_star2_O2/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
pushq %rax
movq %rdi, %rbx
testl %esi, %esi
jle 0x48eb5
movq %rdx, %r15
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
jne 0x48ece
movq %rbx, %rdi
callq 0x298e8
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %r12d
leaq -0x30(%rbp), %r13
movq %r13, %rsi
callq 0x297ed
movq %rax, %r14
movslq (%r13), %r13
cmpl $0x1, %r12d
jne 0x48ef2
pushq $0x41
popq %rax
movl %eax, -0x2c(%rbp)
jmp 0x48f06
movq 0x8(%r15), %rdi
callq 0x29772
testl %eax, %eax
pushq $0x41
popq %rcx
cmovnsl %eax, %ecx
movl %ecx, -0x2c(%rbp)
addq %r14, %r13
movabsq $0x500000c400000000, %r12 # imm = 0x500000C400000000
cmpq %r13, %r14
jae 0x48ebd
xorl %edx, %edx
movq %r14, %r15
cmpq %r13, %r15
jae 0x48f39
movzbl (%r15), %eax
cmpq $0x3e, %rax
ja 0x48f32
btq %rax, %r12
jb 0x48f39
incq %r15
incl %edx
jmp 0x48f1d
cmpq %r15, %r14
jae 0x48f49
movq %rbx, %rdi
movq %r14, %rsi
callq 0x29903
cmpq %r13, %r15
jae 0x48ebd
movzbl (%r15), %eax
cmpl $0x22, %eax
je 0x48fa9
cmpl $0x3e, %eax
je 0x48f7d
cmpl $0x27, %eax
je 0x48f97
cmpl $0x3c, %eax
je 0x48f89
cmpl $0x26, %eax
jne 0x48fdb
movq %rbx, %rdi
leaq 0x1df57(%rip), %rsi     # 0x66ed0
pushq $0x5
jmp 0x48fd5
movq %rbx, %rdi
leaq 0x184cb(%rip), %rsi     # 0x61452
jmp 0x48f93
movq %rbx, %rdi
leaq 0x184ba(%rip), %rsi     # 0x6144d
pushq $0x4
jmp 0x48fd5
testb $0x2, -0x2c(%rbp)
jne 0x48fbb
movq %rbx, %rdi
leaq 0x1d37f(%rip), %rsi     # 0x66326
jmp 0x48fd3
testb $0x4, -0x2c(%rbp)
jne 0x48fc9
movq %rbx, %rdi
leaq 0x1df24(%rip), %rsi     # 0x66edd
jmp 0x48fc5
movq %rbx, %rdi
leaq 0x1df11(%rip), %rsi     # 0x66ed6
pushq $0x6
jmp 0x48fd5
movq %rbx, %rdi
leaq 0x18c96(%rip), %rsi     # 0x61c69
pushq $0x1
popq %rdx
callq 0x29903
incq %r15
movq %r15, %r14
jmp 0x48f13