// File: /workspace/github_c_makefile_star2_O1/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 $0x28, %rsp
movq %rdi, %rbx
cmpl $0x2, %esi
jle 0x55919
movq %rdx, %r12
movl %esi, %r13d
movq (%rdx), %rdi
leaq -0x2c(%rbp), %r15
movq %r15, %rsi
callq 0x30b04
cmpl $0x0, (%r15)
jle 0x55919
movq %rax, %r14
movq 0x8(%r12), %rdi
leaq -0x44(%rbp), %r15
movq %r15, %rsi
callq 0x30b04
movl (%r15), %ecx
testl %ecx, %ecx
jle 0x55919
cmpl -0x2c(%rbp), %ecx
jg 0x55919
movq %rax, -0x38(%rbp)
movq 0x10(%r12), %r15
movq %r15, %rdi
callq 0x3fd5f
movl (%r15), %eax
movl -0x2c(%rbp), %r15d
testl %eax, %eax
js 0x5594f
movl %eax, %edi
cmpl %eax, %r15d
jg 0x5595d
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x309f2
movq $0x0, (%rbx)
movl $0x8, %eax
movl $0xfffffe90, %ecx       # imm = 0xFFFFFE90
andl 0x8(%rbx), %ecx
orl %eax, %ecx
movl %ecx, 0x8(%rbx)
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addl %eax, %r15d
movl %r15d, %edi
movl $0x0, %r15d
js 0x55919
movb $0x1, %cl
cmpl $0x3, %r13d
jne 0x5596a
subl %eax, %r15d
jmp 0x559b7
movq %rdi, -0x40(%rbp)
movq 0x18(%r12), %r15
movq %r15, %rdi
callq 0x3fd5f
movl (%r15), %eax
testl %eax, %eax
jle 0x559f5
movq -0x40(%rbp), %rdi
leal (%rdi,%rax), %ecx
movl -0x2c(%rbp), %edx
movl %edx, %r15d
subl %edi, %r15d
cmpl %edx, %ecx
cmovlel %eax, %r15d
cmpl $0x5, %r13d
jl 0x55a0a
movq 0x20(%r12), %r12
movq %r12, %rdi
callq 0x446ef
movq -0x40(%rbp), %rdi
cmpl $0x0, (%r12)
sete %cl
movq -0x38(%rbp), %rsi
movl %edi, %eax
addq %rax, %r14
movq %r14, %rdi
movl %r15d, %edx
testb %cl, %cl
je 0x559d1
callq 0x5b530
jmp 0x559d6
callq 0x3a837
movl %eax, %r14d
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x309f2
movslq %r14d, %rax
movq %rax, (%rbx)
movl $0x2, %eax
jmp 0x55931
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x309f2
movq $0x1, (%rbx)
jmp 0x559eb
movq -0x38(%rbp), %rsi
movb $0x1, %cl
jmp 0x559bb