// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_strcspn
static int jx9Builtin_strcspn(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	const char *zString, *zMask, *zEnd;
	int iMasklen, iLen;
	SyString sToken;
	int iCount = 0;
	int rc;
	if( nArg < 2 ){
		/* Missing agruments, return zero */
		jx9_result_int(pCtx, 0);
		return JX9_OK;
	}
	/* Extract the target string */
	zString = jx9_value_to_string(apArg[0], &iLen);
	/* Extract the mask */
	zMask = jx9_value_to_string(apArg[1], &iMasklen);
	if( iLen < 1 ){
		/* Nothing to process, return zero */
		jx9_result_int(pCtx, 0);
		return JX9_OK;
	}
	if( iMasklen < 1 ){
		/* No given mask, return the string length */
		jx9_result_int(pCtx, iLen);
		return JX9_OK;
	}
	if( nArg > 2 ){
		int nOfft;
		/* Extract the offset */
		nOfft = jx9_value_to_int(apArg[2]);
		if( nOfft < 0 ){
			const char *zBase = &zString[iLen + nOfft];
			if( zBase > zString ){
				iLen = (int)(&zString[iLen]-zBase);
				zString = zBase;	
			}else{
				/* Invalid offset */
				jx9_result_int(pCtx, 0);
				return JX9_OK;
			}
		}else{
			if( nOfft >= iLen ){
				/* Invalid offset */
				jx9_result_int(pCtx, 0);
				return JX9_OK;
			}else{
				/* Update offset */
				zString += nOfft;
				iLen -= nOfft;
			}
		}
		if( nArg > 3 ){
			int iUserlen;
			/* Extract the desired length */
			iUserlen = jx9_value_to_int(apArg[3]);
			if( iUserlen > 0 && iUserlen < iLen ){
				iLen = iUserlen;
			}
		}
	}
	/* Point to the end of the string */
	zEnd = &zString[iLen];
	/* Extract the first non-space token */
	rc = ExtractNonSpaceToken(&zString, zEnd, &sToken);
	if( rc == SXRET_OK && sToken.nByte > 0 ){
		/* Compare against the current mask */
		iCount = LongestStringMask2(sToken.zString, (int)sToken.nByte, zMask, iMasklen);
	}
	/* Longest match */
	jx9_result_int(pCtx, iCount);
	return JX9_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
cmpl $0x1, %esi
jle 0x4b1eb
movq %rdx, %r12
movl %esi, %r13d
movq %rdi, -0x38(%rbp)
movq (%rdx), %rdi
leaq -0x2c(%rbp), %rbx
movq %rbx, %rsi
callq 0x297ed
movq %rax, %r15
movq %rax, -0x48(%rbp)
movq 0x8(%r12), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x297ed
movl (%rbx), %esi
testl %esi, %esi
jle 0x4b1e7
cmpl $0x0, -0x3c(%rbp)
jle 0x4b136
movq %rax, %r14
cmpl $0x2, %r13d
je 0x4b180
movq 0x10(%r12), %rdi
callq 0x29772
movl -0x2c(%rbp), %esi
testl %eax, %eax
js 0x4b13f
subl %eax, %esi
jle 0x4b1e7
movl %eax, %eax
addq %rax, %r15
movq %r15, -0x48(%rbp)
movl %esi, -0x2c(%rbp)
jmp 0x4b157
movq -0x38(%rbp), %rdi
jmp 0x4b1ed
addl %eax, %esi
jle 0x4b1e7
movl %esi, %ecx
addq %rcx, %r15
negl %eax
movl %eax, -0x2c(%rbp)
movq %r15, -0x48(%rbp)
movl %eax, %esi
cmpl $0x4, %r13d
jb 0x4b180
movq 0x18(%r12), %rdi
callq 0x29772
testl %eax, %eax
setg %cl
movl -0x2c(%rbp), %esi
cmpl %esi, %eax
setl %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x4b180
movl %eax, -0x2c(%rbp)
movl %eax, %esi
movslq %esi, %rsi
addq %r15, %rsi
leaq -0x48(%rbp), %rdi
leaq -0x58(%rbp), %rbx
movq %rbx, %rdx
callq 0x4ee4e
testl %eax, %eax
sete %cl
movl 0x8(%rbx), %eax
testl %eax, %eax
setne %dl
andb %cl, %dl
xorl %esi, %esi
cmpb $0x1, %dl
jne 0x4b205
movslq %eax, %rcx
movq -0x58(%rbp), %rax
movl -0x3c(%rbp), %edx
addq %rax, %rcx
xorl %esi, %esi
testl %edx, %edx
cmovlel %esi, %edx
movq %rax, %rsi
cmpq %rcx, %rsi
jae 0x4b203
movb (%rsi), %dil
xorl %r8d, %r8d
cmpq %r8, %rdx
je 0x4b1e2
leaq 0x1(%r8), %r9
cmpb (%r14,%r8), %dil
movq %r9, %r8
jne 0x4b1ce
jmp 0x4b203
incq %rsi
jmp 0x4b1c3
movq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x2987c
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
subl %eax, %esi
movq -0x38(%rbp), %rdi
jmp 0x4b1ed