// File: /workspace/github_c_makefile_star2_O2/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 0x49b00
movq %rdx, %r15
movl %esi, %r12d
movq (%rdx), %rdi
leaq -0x2c(%rbp), %r13
movq %r13, %rsi
callq 0x297ed
movq %rax, %r14
movslq (%r13), %rax
testq %rax, %rax
jle 0x49ba8
cmpl $0x1, %r12d
jne 0x49b0d
movq %r14, %r15
addq %rax, %r15
movl %eax, %r12d
testl %r12d, %r12d
je 0x49bb9
movsbq (%r14), %r13
cmpq $-0x41, %r13
ja 0x49bb6
testb %r13b, %r13b
je 0x49af8
callq 0xc190
movq (%rax), %rax
testb $0x20, 0x1(%rax,%r13,2)
je 0x49bb6
incq %r14
decq %r12
jmp 0x49ac8
movq %rbx, %rdi
callq 0x298e8
jmp 0x49bfe
movq 0x8(%r15), %rdi
leaq -0x30(%rbp), %r15
movq %r15, %rsi
callq 0x297ed
movslq (%r15), %rdi
movslq -0x2c(%rbp), %rdx
testq %rdi, %rdi
jle 0x49bf3
movq %r14, %rcx
addq %rdx, %rcx
movq %r14, %rsi
cmpq %rcx, %r14
jae 0x49b65
xorl %edx, %edx
movq %rsi, %r14
cmpq %rdx, %rdi
je 0x49b60
cmpq %rcx, %r14
jae 0x49b5b
movb (%r14), %r8b
xorl %r9d, %r9d
cmpb (%rax,%rdx), %r8b
sete %r9b
addq %r9, %r14
incq %rdx
jmp 0x49b40
cmpq %rsi, %r14
jne 0x49b33
decq %rcx
movl %edi, %edi
cmpq %rsi, %rcx
jbe 0x49ba8
movq %rcx, %rdx
xorl %r8d, %r8d
cmpq %r8, %rdi
je 0x49b95
cmpq %rsi, %rcx
jbe 0x49b90
movb (%rcx), %r9b
xorl %r10d, %r10d
cmpb (%rax,%r8), %r9b
sete %r10b
subq %r10, %rcx
incq %r8
jmp 0x49b75
cmpq %rdx, %rcx
jne 0x49b6a
cmpq %rsi, %rdx
jbe 0x49ba8
subl %esi, %edx
incl %edx
movq %rbx, %rdi
jmp 0x49bf9
leaq 0x1daa3(%rip), %rsi     # 0x67652
movq %rbx, %rdi
xorl %edx, %edx
jmp 0x49bf9
movq %r14, %r15
movq %r12, %r14
subq $0x1, %r12
jb 0x49be5
movsbq -0x1(%r15,%r14), %r13
cmpq $-0x41, %r13
ja 0x49be8
testb %r13b, %r13b
je 0x49bb9
callq 0xc190
movq (%rax), %rax
testb $0x20, 0x1(%rax,%r13,2)
jne 0x49bb9
jmp 0x49be8
xorl %r14d, %r14d
movq %rbx, %rdi
movq %r15, %rsi
movl %r14d, %edx
jmp 0x49bf9
movq %rbx, %rdi
movq %r14, %rsi
callq 0x29903
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq