// File: /workspace/github_c_makefile_star2_O3/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 0x56d64
movq 0x8(%rdi), %rbx
jmp 0x56e5d
movq %rdx, %r12
movl %esi, %r13d
movq %rdi, -0x38(%rbp)
movq (%rdx), %rdi
leaq -0x2c(%rbp), %rbx
movq %rbx, %rsi
callq 0x30577
movq %rax, -0x48(%rbp)
movq %rax, -0x50(%rbp)
movq 0x8(%r12), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x30577
movslq (%rbx), %r15
testq %r15, %r15
jle 0x56e55
cmpl $0x0, -0x3c(%rbp)
jle 0x56db7
movq %rax, %r14
cmpl $0x2, %r13d
jne 0x56dcf
movq -0x48(%rbp), %rcx
jmp 0x56e91
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rbx
movq %rbx, %rdi
callq 0x30465
movq %r15, (%rbx)
jmp 0x56e6c
movq 0x10(%r12), %rbx
movq %rbx, %rdi
callq 0x3f362
movq (%rbx), %rax
movl -0x2c(%rbp), %r15d
testl %eax, %eax
js 0x56e02
subl %eax, %r15d
jle 0x56e55
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x48(%rbp), %rcx
addq %rax, %rcx
movq %rcx, -0x50(%rbp)
movl %r15d, -0x2c(%rbp)
jmp 0x56e20
addl %eax, %r15d
jle 0x56e55
movl %r15d, %ecx
movq -0x48(%rbp), %rdx
addq %rcx, %rdx
movq %rdx, %rcx
negl %eax
movl %eax, -0x2c(%rbp)
movq %rdx, -0x50(%rbp)
movl %eax, %r15d
cmpl $0x4, %r13d
jb 0x56e91
movq %rcx, %r13
movq 0x18(%r12), %rbx
movq %rbx, %rdi
callq 0x3f362
movq (%rbx), %r15
testl %r15d, %r15d
setg %cl
movl -0x2c(%rbp), %eax
cmpl %r15d, %eax
setg %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x56e8b
movl %r15d, -0x2c(%rbp)
jmp 0x56e8e
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rbx
movq %rbx, %rdi
callq 0x30465
movq $0x0, (%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
movl %eax, %r15d
movq %r13, %rcx
movslq %r15d, %rsi
addq %rcx, %rsi
leaq -0x50(%rbp), %rdi
leaq -0x60(%rbp), %rbx
movq %rbx, %rdx
callq 0x5b819
testl %eax, %eax
sete %al
movl 0x8(%rbx), %edx
testl %edx, %edx
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x56efd
movq -0x60(%rbp), %rax
movq %rax, %rcx
testl %edx, %edx
movq -0x38(%rbp), %r9
jle 0x56ef6
movslq %edx, %rdx
addq %rax, %rdx
movl -0x3c(%rbp), %esi
movq %rax, %rcx
testl %esi, %esi
jle 0x56eee
movb (%rcx), %dil
xorl %r8d, %r8d
cmpb (%r14,%r8), %dil
je 0x56ef6
incq %r8
cmpq %r8, %rsi
jne 0x56ee0
incq %rcx
cmpq %rdx, %rcx
jb 0x56ed6
subl %eax, %ecx
movslq %ecx, %r14
jmp 0x56f04
xorl %r14d, %r14d
movq -0x38(%rbp), %r9
movq 0x8(%r9), %rbx
movq %rbx, %rdi
callq 0x30465
movq %r14, (%rbx)
jmp 0x56e6c