// File: /workspace/github_c_makefile_star2_O3/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 $0x38, %rsp
cmpl $0x1, %esi
jg 0x56bc3
movq 0x8(%rdi), %rbx
jmp 0x56c89
movq %rdx, %r12
movl %esi, %r13d
movq %rdi, -0x38(%rbp)
movq (%rdx), %rdi
leaq -0x2c(%rbp), %rbx
movq %rbx, %rsi
callq 0x30577
movq %rax, %r15
movq %rax, -0x48(%rbp)
movq 0x8(%r12), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x30577
movq %rax, %r14
movl (%rbx), %eax
testl %eax, %eax
jle 0x56c81
cmpl $0x0, -0x3c(%rbp)
jle 0x56c81
cmpl $0x2, %r13d
je 0x56cb9
movq 0x10(%r12), %rbx
movq %rbx, %rdi
callq 0x3f362
movq (%rbx), %rcx
movl -0x2c(%rbp), %eax
testl %ecx, %ecx
js 0x56c3b
subl %ecx, %eax
jle 0x56c81
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addq %rcx, %r15
movq %r15, -0x48(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x56c4f
addl %ecx, %eax
jle 0x56c81
movl %eax, %eax
addq %rax, %r15
negl %ecx
movl %ecx, -0x2c(%rbp)
movq %r15, -0x48(%rbp)
movl %ecx, %eax
cmpl $0x4, %r13d
jb 0x56cb9
movq 0x18(%r12), %rbx
movq %rbx, %rdi
callq 0x3f362
movq (%rbx), %rax
testl %eax, %eax
setg %dl
movl -0x2c(%rbp), %ecx
cmpl %eax, %ecx
setg %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x56cb7
movl %eax, -0x2c(%rbp)
jmp 0x56cb9
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 %ecx, %eax
movslq %eax, %rsi
addq %r15, %rsi
leaq -0x48(%rbp), %rdi
leaq -0x58(%rbp), %rbx
movq %rbx, %rdx
callq 0x5b819
testl %eax, %eax
sete %al
movl 0x8(%rbx), %esi
testl %esi, %esi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x56d2a
movq -0x58(%rbp), %rax
movq %rax, %rcx
testl %esi, %esi
movq -0x38(%rbp), %r9
jle 0x56d23
movl -0x3c(%rbp), %edx
movq %rax, %rcx
testl %edx, %edx
jle 0x56d23
movslq %esi, %rsi
addq %rax, %rsi
movq %rax, %rcx
movb (%rcx), %dil
xorl %r8d, %r8d
cmpb (%r14,%r8), %dil
je 0x56d1b
incq %r8
cmpq %r8, %rdx
jne 0x56d0b
jmp 0x56d23
incq %rcx
cmpq %rsi, %rcx
jb 0x56d05
subl %eax, %ecx
movslq %ecx, %r14
jmp 0x56d31
xorl %r14d, %r14d
movq -0x38(%rbp), %r9
movq 0x8(%r9), %rbx
movq %rbx, %rdi
callq 0x30465
movq %r14, (%rbx)
jmp 0x56c98