// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_substr_count
static int jx9Builtin_substr_count(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	const char *zText, *zPattern, *zEnd;
	int nTextlen, nPatlen;
	int iCount = 0;
	sxu32 nOfft;
	sxi32 rc;
	if( nArg < 2 ){
		/* Missing arguments */
		jx9_result_int(pCtx, 0);
		return JX9_OK;
	}
	/* Point to the haystack */
	zText = jx9_value_to_string(apArg[0], &nTextlen);
	/* Point to the neddle */
	zPattern = jx9_value_to_string(apArg[1], &nPatlen);
	if( nTextlen < 1 || nPatlen < 1 || nPatlen > nTextlen ){
		/* NOOP, 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 || nOfft > nTextlen ){
			/* Invalid offset, return zero */
			jx9_result_int(pCtx, 0);
			return JX9_OK;
		}
		/* Point to the desired offset */
		zText = &zText[nOfft];
		/* Adjust length */
		nTextlen -= nOfft;
	}
	/* Point to the end of the string */
	zEnd = &zText[nTextlen];
	if( nArg > 3 ){
		int nLen;
		/* Extract the length */
		nLen = jx9_value_to_int(apArg[3]);
		if( nLen < 0 || nLen > nTextlen ){
			/* Invalid length, return 0 */
			jx9_result_int(pCtx, 0);
			return JX9_OK;
		}
		/* Adjust pointer */
		nTextlen = nLen;
		zEnd = &zText[nTextlen];
	}
	/* Perform the search */
	for(;;){
		rc = SyBlobSearch((const void *)zText, (sxu32)(zEnd-zText), (const void *)zPattern, nPatlen, &nOfft);
		if( rc != SXRET_OK ){
			/* Pattern not found, break immediately */
			break;
		}
		/* Increment counter and update the offset */
		iCount++;
		zText += nOfft + nPatlen;
		if( zText >= zEnd ){
			break;
		}
	}
	/* Pattern count */
	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 0x48d22
movq %rdx, %r12
movl %esi, %r13d
movq %rdi, -0x38(%rbp)
movq (%rdx), %rdi
leaq -0x2c(%rbp), %rbx
movq %rbx, %rsi
callq 0x297ed
movq %rax, %r14
movq 0x8(%r12), %rdi
leaq -0x30(%rbp), %rsi
callq 0x297ed
movq %rax, -0x48(%rbp)
movslq (%rbx), %r15
testq %r15, %r15
jle 0x48d1e
movl -0x30(%rbp), %eax
testl %eax, %eax
jle 0x48d1e
cmpl %r15d, %eax
jg 0x48d1e
cmpl $0x2, %r13d
jne 0x48d09
addq %r14, %r15
xorl %r12d, %r12d
movl -0x30(%rbp), %r13d
leaq -0x3c(%rbp), %rbx
movl %r15d, %esi
subl %r14d, %esi
movq %r14, %rdi
movq -0x48(%rbp), %rdx
movl %r13d, %ecx
movq %rbx, %r8
callq 0x4d7da
testl %eax, %eax
jne 0x48d00
incl %r12d
movl -0x3c(%rbp), %eax
addl %r13d, %eax
addq %rax, %r14
cmpq %r15, %r14
jb 0x48cd3
movq -0x38(%rbp), %rdi
movl %r12d, %esi
jmp 0x48d24
movq 0x10(%r12), %rdi
callq 0x29772
testl %eax, %eax
js 0x48d1e
movl -0x2c(%rbp), %ecx
subl %eax, %ecx
jge 0x48d3a
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
movl %eax, %eax
addq %rax, %r14
movl %ecx, -0x2c(%rbp)
cmpl $0x4, %r13d
jb 0x48d66
movq 0x18(%r12), %rdi
callq 0x29772
testl %eax, %eax
js 0x48d1e
cmpl -0x2c(%rbp), %eax
jg 0x48d1e
movl %eax, -0x2c(%rbp)
movl %eax, %r15d
jmp 0x48cc5
movslq %ecx, %r15
jmp 0x48cc5