// File: /workspace/github_c_makefile_star2_O3/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
subq $0x28, %rsp
movq %rdi, %rbx
testl %esi, %esi
jle 0x5548a
movq %rdx, %r12
movl %esi, %r13d
movq (%rdx), %rdi
leaq -0x2c(%rbp), %r15
movq %r15, %rsi
callq 0x30577
movl (%r15), %r15d
testl %r15d, %r15d
jle 0x55585
movq %rax, %r14
cmpl $0x1, %r13d
jne 0x55498
movq %rbx, -0x40(%rbp)
movq %r14, %rax
addq %r15, %rax
movq %rax, -0x38(%rbp)
leal -0x1(%r15), %r13d
xorl %ebx, %ebx
movsbq (%r14), %r12
cmpq $-0x41, %r12
ja 0x554ed
testb %r12b, %r12b
je 0x55470
callq 0xc170
movq (%rax), %rax
testb $0x20, 0x1(%rax,%r12,2)
je 0x554ed
incq %r14
decl %r13d
incq %rbx
cmpl %ebx, %r15d
jne 0x5544d
xorl %r15d, %r15d
movq -0x38(%rbp), %rsi
jmp 0x55522
movq 0x8(%rbx), %rdi
callq 0x30465
jmp 0x55597
movq 0x8(%r12), %rdi
leaq -0x44(%rbp), %r15
movq %r15, %rsi
callq 0x30577
movslq (%r15), %rdi
movslq -0x2c(%rbp), %rdx
testq %rdi, %rdi
jle 0x5552f
movq %r14, %rcx
addq %rdx, %rcx
cmpq %rcx, %r14
jae 0x55538
xorl %edx, %edx
movq %r14, %rsi
cmpq %rcx, %rsi
jae 0x554db
movb (%rsi), %r8b
xorl %r9d, %r9d
cmpb (%rax,%rdx), %r8b
sete %r9b
addq %r9, %rsi
incq %rdx
cmpq %rdx, %rdi
jne 0x554c5
cmpq %r14, %rsi
movq %rsi, %r14
jne 0x554bb
jmp 0x5553b
subq %rbx, %r15
movl %r13d, %eax
movsbq (%r14,%rax), %rbx
cmpq $-0x41, %rbx
ja 0x5551f
testb %bl, %bl
je 0x55511
callq 0xc170
movq (%rax), %rax
testb $0x20, 0x1(%rax,%rbx,2)
je 0x5551f
decq %r15
decl %r13d
testl %r15d, %r15d
jne 0x554f0
xorl %r15d, %r15d
movq %r14, %rsi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
movl %r15d, %edx
jmp 0x55592
movq 0x8(%rbx), %rdi
movq %r14, %rsi
jmp 0x55583
movq %r14, %rsi
decq %rcx
movl %edi, %edi
cmpq %rsi, %rcx
jbe 0x55573
xorl %r8d, %r8d
movq %rcx, %rdx
cmpq %rsi, %rdx
jbe 0x55561
movb (%rdx), %r9b
xorl %r10d, %r10d
cmpb (%rax,%r8), %r9b
sete %r10b
subq %r10, %rdx
incq %r8
cmpq %r8, %rdi
jne 0x5554b
cmpq %rcx, %rdx
movq %rdx, %rcx
jne 0x55540
jmp 0x55576
movq %rcx, %rdx
cmpq %rdx, %rsi
jae 0x55585
subl %esi, %edx
incl %edx
movq 0x8(%rbx), %rdi
jmp 0x55592
movq 0x8(%rbx), %rdi
leaq 0x220e2(%rip), %rsi     # 0x77672
xorl %edx, %edx
callq 0x302f6
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq