// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_strspn
static int jx9Builtin_strspn(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 || iMasklen < 1 ){
		/* Nothing to process, return zero */
		jx9_result_int(pCtx, 0);
		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 = LongestStringMask(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 $0x28, %rsp
cmpl $0x1, %esi
jle 0x4b08e
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, -0x40(%rbp)
movq 0x8(%r12), %rdi
leaq -0x30(%rbp), %rsi
callq 0x297ed
movl (%rbx), %ecx
testl %ecx, %ecx
jle 0x4b08a
cmpl $0x0, -0x30(%rbp)
jle 0x4b08a
movq %rax, %r14
cmpl $0x2, %r13d
je 0x4b025
movq 0x10(%r12), %rdi
callq 0x29772
movl -0x2c(%rbp), %ecx
testl %eax, %eax
js 0x4afe1
subl %eax, %ecx
jle 0x4b08a
movl %eax, %eax
addq %rax, %r15
movq %r15, -0x40(%rbp)
movl %ecx, -0x2c(%rbp)
jmp 0x4aff9
addl %eax, %ecx
jle 0x4b08a
movl %ecx, %ecx
addq %rcx, %r15
negl %eax
movl %eax, -0x2c(%rbp)
movq %r15, -0x40(%rbp)
movl %eax, %ecx
cmpl $0x4, %r13d
jb 0x4b025
movq 0x18(%r12), %rdi
callq 0x29772
testl %eax, %eax
setg %dl
movl -0x2c(%rbp), %ecx
cmpl %ecx, %eax
setl %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x4b025
movl %eax, -0x2c(%rbp)
movl %eax, %ecx
movslq %ecx, %rsi
addq %r15, %rsi
leaq -0x40(%rbp), %rdi
leaq -0x50(%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 0x4b0a8
movslq %eax, %rcx
movq -0x50(%rbp), %rax
movl -0x30(%rbp), %edx
addq %rax, %rcx
xorl %esi, %esi
testl %edx, %edx
cmovlel %esi, %edx
movq %rax, %rsi
cmpq %rcx, %rsi
jae 0x4b0a6
movb (%rsi), %dil
xorl %r8d, %r8d
cmpq %r8, %rdx
je 0x4b0a6
leaq 0x1(%r8), %r9
cmpb (%r14,%r8), %dil
movq %r9, %r8
jne 0x4b073
incq %rsi
jmp 0x4b068
movq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x2987c
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
subl %eax, %esi
movq -0x38(%rbp), %rdi
jmp 0x4b090