// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_substr_compare
static int jx9Builtin_substr_compare(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	const char *zSource, *zOfft, *zSub;
	int nOfft, nLen, nSrcLen, nSublen;
	int iCase = 0;
	int rc;
	if( nArg < 3 ){
		/* Missing arguments, return FALSE */
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Extract the target string */
	zSource = jx9_value_to_string(apArg[0], &nSrcLen);
	if( nSrcLen < 1 ){
		/* Empty string, return FALSE */
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	nLen = nSrcLen; /* cc warning */
	/* Extract the substring */
	zSub = jx9_value_to_string(apArg[1], &nSublen);
	if( nSublen < 1 || nSublen > nSrcLen){
		/* Empty string, return FALSE */
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Extract the offset */
	nOfft = jx9_value_to_int(apArg[2]);
	if( nOfft < 0 ){
		zOfft = &zSource[nSrcLen+nOfft]; 
		if( zOfft < zSource ){
			/* Invalid offset */
			jx9_result_bool(pCtx, 0);
			return JX9_OK;
		}
		nLen = (int)(&zSource[nSrcLen]-zOfft);
		nOfft = (int)(zOfft-zSource);
	}else if( nOfft >= nSrcLen ){
		/* Invalid offset */
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}else{
		zOfft = &zSource[nOfft];
		nLen = nSrcLen - nOfft;
	}
	if( nArg > 3 ){
		/* Extract the length */
		nLen = jx9_value_to_int(apArg[3]);
		if( nLen < 1 ){
			/* Invalid  length */
			jx9_result_int(pCtx, 1);
			return JX9_OK;
		}else if( nLen + nOfft > nSrcLen ){
			/* Invalid length */
			nLen = nSrcLen - nOfft;
		}
		if( nArg > 4 ){
			/* Case-sensitive or not */
			iCase = jx9_value_to_bool(apArg[4]);
		}
	}
	/* Perform the comparison */
	if( iCase ){
		rc = SyStrnicmp(zOfft, zSub, (sxu32)nLen);
	}else{
		rc = SyStrncmp(zOfft, zSub, (sxu32)nLen);
	}
	/* Comparison result */
	jx9_result_int(pCtx, rc);
	return JX9_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
cmpl $0x2, %esi
jle 0x48bb8
movq %rdx, %r12
movl %esi, %r13d
movq (%rdx), %rdi
leaq -0x2c(%rbp), %r15
movq %r15, %rsi
callq 0x297ed
cmpl $0x0, (%r15)
jle 0x48bb8
movq %rax, %r14
movq 0x8(%r12), %rdi
leaq -0x3c(%rbp), %r15
movq %r15, %rsi
callq 0x297ed
movl (%r15), %ecx
testl %ecx, %ecx
jle 0x48bb8
cmpl -0x2c(%rbp), %ecx
jg 0x48bb8
movq %rax, -0x38(%rbp)
movq 0x10(%r12), %rdi
callq 0x29772
movl -0x2c(%rbp), %r15d
testl %eax, %eax
js 0x48bd3
movl %eax, %edx
cmpl %r15d, %eax
jl 0x48be1
movq %rbx, %rdi
xorl %esi, %esi
callq 0x298b2
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addl %eax, %r15d
movl %r15d, %edx
movl $0x0, %r15d
js 0x48bb8
movl %edx, %ecx
addq %rcx, %r14
cmpl $0x3, %r13d
jne 0x48bf1
subl %eax, %r15d
jmp 0x48c3d
movq %rdx, %r15
movq 0x18(%r12), %rdi
callq 0x29772
testl %eax, %eax
jle 0x48c5b
movq %r15, %rsi
leal (%rax,%r15), %ecx
movl -0x2c(%rbp), %edx
movl %edx, %r15d
subl %esi, %r15d
cmpl %edx, %ecx
cmovlel %eax, %r15d
cmpl $0x5, %r13d
jb 0x48c3d
movq 0x20(%r12), %rdi
callq 0x29790
testl %eax, %eax
je 0x48c3d
movq %r14, %rdi
movq -0x38(%rbp), %rsi
movl %r15d, %edx
callq 0x32436
jmp 0x48c4c
movq -0x38(%rbp), %rsi
movq %r14, %rdi
movl %r15d, %edx
callq 0x4d6c7
movq %rbx, %rdi
movl %eax, %esi
callq 0x2987c
jmp 0x48bc2
pushq $0x1
popq %rsi
movq %rbx, %rdi
jmp 0x48c51