// File: /workspace/github_c_makefile_star2_O1/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_trim
static int jx9Builtin_trim(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	const char *zString;
	int nLen;
	if( nArg < 1 ){
		/* Missing arguments, return null */
		jx9_result_null(pCtx);
		return JX9_OK;
	}
	/* Extract the target string */
	zString = jx9_value_to_string(apArg[0], &nLen);
	if( nLen < 1 ){
		/* Empty string, return */
		jx9_result_string(pCtx, "", 0);
		return JX9_OK;
	}
	/* Start the trim process */
	if( nArg < 2 ){
		SyString sStr;
		/* Remove white spaces and NUL bytes */
		SyStringInitFromBuf(&sStr, zString, nLen);
		SyStringFullTrimSafe(&sStr);
		jx9_result_string(pCtx, sStr.zString, (int)sStr.nByte);
	}else{
		/* Char list */
		const char *zList;
		int nListlen;
		zList = jx9_value_to_string(apArg[1], &nListlen);
		if( nListlen < 1 ){
			/* Return the string unchanged */
			jx9_result_string(pCtx, zString, nLen);
		}else{
			const char *zEnd = &zString[nLen];
			const char *zCur = zString;
			const char *zPtr;
			int i;
			/* Left trim */
			for(;;){
				if( zCur >= zEnd ){
					break;
				}
				zPtr = zCur;
				for( i = 0 ; i < nListlen ; i++ ){
					if( zCur < zEnd && zCur[0] == zList[i] ){
						zCur++;
					}
				}
				if( zCur == zPtr ){
					/* No match, break immediately */
					break;
				}
			}
			/* Right trim */
			zEnd--;
			for(;;){
				if( zEnd <= zCur ){
					break;
				}
				zPtr = zEnd;
				for( i = 0 ; i < nListlen ; i++ ){
					if( zEnd > zCur && zEnd[0] == zList[i] ){
						zEnd--;
					}
				}
				if( zEnd == zPtr ){
					break;
				}
			}
			if( zCur >= zEnd ){
				/* Return the empty string */
				jx9_result_string(pCtx, "", 0);
			}else{
				zEnd++;
				jx9_result_string(pCtx, zCur, (int)(zEnd-zCur));
			}
		}
	}
	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 0x56c06
movq %rdx, %r12
movl %esi, %r13d
movq (%rdx), %rdi
leaq -0x2c(%rbp), %r15
movq %r15, %rsi
callq 0x30b04
movslq (%r15), %r15
testq %r15, %r15
jle 0x56d16
movq %rax, %r14
cmpl $0x1, %r13d
jne 0x56c14
movq %r14, %r12
addq %r15, %r12
movsbq (%r14), %r13
cmpq $-0x41, %r13
ja 0x56c6d
testb %r13b, %r13b
je 0x56bf9
callq 0xc170
movq (%rax), %rax
testb $0x20, 0x1(%rax,%r13,2)
je 0x56c6d
incq %r14
decl %r15d
jne 0x56bd6
xorl %r15d, %r15d
jmp 0x56c70
movq 0x8(%rbx), %rdi
callq 0x309f2
jmp 0x56d28
movq 0x8(%r12), %rdi
leaq -0x30(%rbp), %r15
movq %r15, %rsi
callq 0x30b04
movslq (%r15), %rdi
movslq -0x2c(%rbp), %rdx
testq %rdi, %rdi
jle 0x56cb6
movq %r14, %rcx
addq %rdx, %rcx
cmpq %rcx, %r14
jae 0x56cbf
xorl %edx, %edx
movq %r14, %rsi
cmpq %rcx, %rsi
jae 0x56c5b
movb (%rsi), %r8b
xorl %r9d, %r9d
cmpb (%rax,%rdx), %r8b
sete %r9b
addq %r9, %rsi
incq %rdx
cmpq %rdx, %rdi
jne 0x56c45
cmpq %r14, %rsi
movq %rsi, %r14
jne 0x56c3b
jmp 0x56cc2
movq %r14, %r12
testl %r15d, %r15d
je 0x56caa
movl %r15d, %r15d
leaq -0x1(%r15), %r14
movl %r14d, %eax
movsbq (%r12,%rax), %r13
cmpq $-0x41, %r13
ja 0x56caa
testb %r13b, %r13b
je 0x56c9f
callq 0xc170
movq (%rax), %rax
testb $0x20, 0x1(%rax,%r13,2)
je 0x56caa
movq %r14, %r15
testl %r14d, %r14d
jne 0x56c78
xorl %r15d, %r15d
movq 0x8(%rbx), %rdi
movq %r12, %rsi
movl %r15d, %edx
jmp 0x56d23
movq 0x8(%rbx), %rdi
movq %r14, %rsi
jmp 0x56d14
movq %r14, %rsi
decq %rcx
cmpl $0x2, %edi
movl $0x1, %r8d
cmovgel %edi, %r8d
cmpq %rsi, %rcx
jbe 0x56d04
xorl %edi, %edi
movq %rcx, %rdx
cmpq %rsi, %rdx
jbe 0x56cf2
movb (%rdx), %r9b
xorl %r10d, %r10d
cmpb (%rax,%rdi), %r9b
sete %r10b
subq %r10, %rdx
incq %rdi
cmpq %rdi, %r8
jne 0x56cdc
cmpq %rcx, %rdx
movq %rdx, %rcx
jne 0x56cd2
jmp 0x56d07
movq %rcx, %rdx
cmpq %rdx, %rsi
jae 0x56d16
subl %esi, %edx
incl %edx
movq 0x8(%rbx), %rdi
jmp 0x56d23
movq 0x8(%rbx), %rdi
leaq 0x22946(%rip), %rsi     # 0x79667
xorl %edx, %edx
callq 0x3087c
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq