// File: /workspace/github_c_makefile_star2_O0/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
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x0, -0x44(%rbp)
cmpl $0x2, -0x14(%rbp)
jge 0x91eb7
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x56fb0
movl $0x0, -0x4(%rbp)
jmp 0x9202a
movq -0x20(%rbp), %rax
movq (%rax), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x56e20
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x40(%rbp), %rsi
callq 0x56e20
movq %rax, -0x30(%rbp)
cmpl $0x1, -0x3c(%rbp)
jl 0x91ef4
cmpl $0x1, -0x40(%rbp)
jl 0x91ef4
movl -0x40(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jle 0x91f0b
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x56fb0
movl $0x0, -0x4(%rbp)
jmp 0x9202a
cmpl $0x2, -0x14(%rbp)
jle 0x91f60
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x56c90
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
jl 0x91f2f
movl -0x50(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jle 0x91f46
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x56fb0
movl $0x0, -0x4(%rbp)
jmp 0x9202a
movq -0x28(%rbp), %rax
movslq -0x50(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl -0x50(%rbp), %ecx
movl -0x3c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x3c(%rbp)
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
cmpl $0x3, -0x14(%rbp)
jle 0x91fbf
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x56c90
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x54(%rbp)
jl 0x91f93
movl -0x54(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jle 0x91faa
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x56fb0
movl $0x0, -0x4(%rbp)
jmp 0x9202a
movl -0x54(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
jmp 0x91fc1
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rcx, %rax
movl %eax, %esi
movq -0x30(%rbp), %rdx
movl -0x40(%rbp), %ecx
leaq -0x48(%rbp), %r8
callq 0x98fe0
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0x91fed
jmp 0x92017
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x48(%rbp), %ecx
addl -0x40(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x38(%rbp), %rax
jb 0x92015
jmp 0x92017
jmp 0x91fc1
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x56fb0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)