// File: /workspace/github_c_makefile_star2_O3/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 0x5422f
movq %rdx, %r15
movl %esi, %r13d
movq (%rdx), %rdi
leaq -0x2c(%rbp), %r12
movq %r12, %rsi
callq 0x30577
cmpl $0x0, (%r12)
jle 0x5422f
movq %rax, %r14
movq 0x8(%r15), %rdi
leaq -0x44(%rbp), %r12
movq %r12, %rsi
callq 0x30577
movl (%r12), %ecx
testl %ecx, %ecx
jle 0x5422f
cmpl -0x2c(%rbp), %ecx
jg 0x5422f
movq %rax, -0x38(%rbp)
movq %r14, -0x40(%rbp)
movq 0x10(%r15), %r12
movq %r12, %rdi
callq 0x3f362
movl (%r12), %eax
movl -0x2c(%rbp), %r12d
testl %eax, %eax
js 0x54265
movl %eax, %r14d
cmpl %eax, %r12d
jg 0x54273
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x30465
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, %r12d
movl %r12d, %r14d
movl $0x0, %r12d
js 0x5422f
movl %r14d, %ecx
addq %rcx, -0x40(%rbp)
cmpl $0x3, %r13d
jne 0x54285
subl %eax, %r12d
jmp 0x542d6
movq 0x18(%r15), %r12
movq %r12, %rdi
callq 0x3f362
movl (%r12), %eax
testl %eax, %eax
jle 0x54305
movl -0x2c(%rbp), %ecx
movl %ecx, %r12d
subl %r14d, %r12d
addl %eax, %r14d
cmpl %ecx, %r14d
cmovlel %eax, %r12d
cmpl $0x5, %r13d
jb 0x542d6
movq 0x20(%r15), %r15
movq %r15, %rdi
callq 0x438dd
cmpl $0x0, (%r15)
movq -0x40(%rbp), %rdi
je 0x542da
movq -0x38(%rbp), %rsi
movl %r12d, %edx
callq 0x39f3f
jmp 0x542e6
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl %r12d, %edx
callq 0x59d90
movl %eax, %r14d
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x30465
movslq %r14d, %rax
movq %rax, (%rbx)
movl $0x2, %eax
jmp 0x54247
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x30465
movq $0x1, (%rbx)
jmp 0x542fb