// File: /workspace/github_c_makefile_star2_O1/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 $0x2, %esi
jge 0x583d0
xorl %r14d, %r14d
jmp 0x58548
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
movq %rax, -0x50(%rbp)
xorl %r14d, %r14d
cmpl $0x0, (%rbx)
jle 0x58544
cmpl $0x0, -0x3c(%rbp)
movq -0x38(%rbp), %rdi
jle 0x58548
cmpl $0x2, %r12d
je 0x584b8
movq 0x10(%r15), %rbx
movq %rbx, %rdi
callq 0x3fd5f
movq (%rbx), %rax
movl -0x2c(%rbp), %ebx
testl %eax, %eax
js 0x58454
subl %eax, %ebx
jle 0x58541
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addq %rax, %r13
movq %r13, -0x48(%rbp)
movl %ebx, -0x2c(%rbp)
jmp 0x58498
addl %eax, %ebx
jle 0x58468
movl %ebx, %ecx
addq %rcx, %r13
negl %eax
movl %eax, -0x2c(%rbp)
movq %r13, -0x48(%rbp)
jmp 0x58490
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 0x58565
cmpl $0x4, %r12d
jl 0x584b8
movq 0x18(%r15), %rbx
movq %rbx, %rdi
callq 0x3fd5f
movl (%rbx), %eax
testl %eax, %eax
jle 0x584b8
cmpl %eax, -0x2c(%rbp)
jle 0x584b8
movl %eax, -0x2c(%rbp)
movslq -0x2c(%rbp), %rsi
leaq -0x48(%rbp), %rdi
addq (%rdi), %rsi
leaq -0x60(%rbp), %rbx
movq %rbx, %rdx
callq 0x5d12b
testl %eax, %eax
sete %al
movl 0x8(%rbx), %esi
testl %esi, %esi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x58541
movq -0x60(%rbp), %rax
movq %rax, %rcx
testl %esi, %esi
movq -0x50(%rbp), %rbx
jle 0x5853a
movslq -0x3c(%rbp), %rdx
movq %rax, %rcx
testq %rdx, %rdx
jle 0x5853a
movslq %esi, %rsi
addq %rax, %rsi
movl %edx, %edi
movb (%rbx), %r8b
decq %rdi
movq %rax, %rcx
movb (%rcx), %r9b
cmpb %r8b, %r9b
je 0x58532
xorl %r10d, %r10d
cmpq %r10, %rdi
je 0x5853a
leaq 0x1(%r10), %r11
cmpb 0x1(%rbx,%r10), %r9b
movq %r11, %r10
jne 0x5851a
cmpq %rdx, %r11
jge 0x5853a
incq %rcx
cmpq %rsi, %rcx
jb 0x5850f
subl %eax, %ecx
movslq %ecx, %r14
jmp 0x58544
xorl %r14d, %r14d
movq -0x38(%rbp), %rdi
movq 0x8(%rdi), %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