// File: /workspace/github_c_makefile_star2_O1/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
jg 0x58592
movq 0x8(%rdi), %rbx
jmp 0x5860d
movq %rdx, %r15
movl %esi, %r12d
movq %rdi, -0x38(%rbp)
movq (%rdx), %rdi
leaq -0x2c(%rbp), %rbx
movq %rbx, %rsi
callq 0x30b04
movq %rax, %r13
movq %rax, -0x48(%rbp)
movq 0x8(%r15), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x30b04
movslq (%rbx), %r14
testq %r14, %r14
jle 0x58605
cmpl $0x0, -0x3c(%rbp)
jle 0x58621
movq %rax, %r14
cmpl $0x2, %r12d
je 0x58692
movq 0x10(%r15), %rbx
movq %rbx, %rdi
callq 0x3fd5f
movq (%rbx), %rax
movl -0x2c(%rbp), %ebx
testl %eax, %eax
js 0x5862e
subl %eax, %ebx
jle 0x58605
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addq %rax, %r13
movq %r13, -0x48(%rbp)
movl %ebx, -0x2c(%rbp)
jmp 0x58672
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rbx
movq %rbx, %rdi
callq 0x309f2
movq $0x0, (%rbx)
jmp 0x58715
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rbx
jmp 0x5870a
addl %eax, %ebx
jle 0x58642
movl %ebx, %ecx
addq %rcx, %r13
negl %eax
movl %eax, -0x2c(%rbp)
movq %r13, -0x48(%rbp)
jmp 0x5866a
movq -0x38(%rbp), %rax
movq 0x8(%rax), %r13
movq %r13, %rdi
callq 0x309f2
movq $0x0, (%r13)
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%r13), %eax
orl $0x2, %eax
movl %eax, 0x8(%r13)
testl %ebx, %ebx
jle 0x58723
cmpl $0x4, %r12d
jl 0x58692
movq 0x18(%r15), %rbx
movq %rbx, %rdi
callq 0x3fd5f
movl (%rbx), %eax
testl %eax, %eax
jle 0x58692
cmpl %eax, -0x2c(%rbp)
jle 0x58692
movl %eax, -0x2c(%rbp)
movslq -0x2c(%rbp), %rsi
leaq -0x48(%rbp), %rdi
addq (%rdi), %rsi
leaq -0x58(%rbp), %rbx
movq %rbx, %rdx
callq 0x5d12b
testl %eax, %eax
sete %al
movl 0x8(%rbx), %edx
testl %edx, %edx
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x586ff
movq -0x58(%rbp), %rax
movq %rax, %rcx
testl %edx, %edx
movq -0x38(%rbp), %r9
jle 0x586f8
movslq %edx, %rdx
addq %rax, %rdx
movl -0x3c(%rbp), %esi
movq %rax, %rcx
testl %esi, %esi
jle 0x586f0
movb (%rcx), %dil
xorl %r8d, %r8d
cmpb (%r14,%r8), %dil
je 0x586f8
incq %r8
cmpq %r8, %rsi
jne 0x586e2
incq %rcx
cmpq %rdx, %rcx
jb 0x586d8
subl %eax, %ecx
movslq %ecx, %r14
jmp 0x58706
xorl %r14d, %r14d
movq -0x38(%rbp), %r9
movq 0x8(%r9), %rbx
movq %rbx, %rdi
callq 0x309f2
movq %r14, (%rbx)
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%rbx), %eax
orl $0x2, %eax
movl %eax, 0x8(%rbx)
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq