// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_strrpos
static int jx9Builtin_strrpos(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	const char *zStart, *zBlob, *zPattern, *zPtr, *zEnd;
	ProcStringMatch xPatternMatch = SyBlobSearch; /* Case-sensitive pattern match */
	int nLen, nPatLen;
	sxu32 nOfft;
	sxi32 rc;
	if( nArg < 2 ){
		/* Missing arguments, return FALSE */
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Extract the needle and the haystack */
	zBlob = jx9_value_to_string(apArg[0], &nLen);
	zPattern = jx9_value_to_string(apArg[1], &nPatLen);
	/* Point to the end of the pattern */
	zPtr = &zBlob[nLen - 1];
	zEnd = &zBlob[nLen];
	/* Save the starting posistion */
	zStart = zBlob;
	nOfft = 0; /* cc warning */
	/* Peek the starting offset if available */
	if( nArg > 2 ){
		int nStart;
		nStart = jx9_value_to_int(apArg[2]);
		if( nStart < 0 ){
			nStart = -nStart;
			if( nStart >= nLen ){
				/* Invalid offset */
				jx9_result_bool(pCtx, 0);
				return JX9_OK;
			}else{
				nLen -= nStart;
				zPtr = &zBlob[nLen - 1];
				zEnd = &zBlob[nLen];
			}
		}else{
			if( nStart >= nLen ){
				/* Invalid offset */
				jx9_result_bool(pCtx, 0);
				return JX9_OK;
			}else{
				zBlob += nStart;
				nLen -= nStart;
			}
		}
	}
	if( nLen > 0 && nPatLen > 0 ){
		/* Perform the lookup */
		for(;;){
			if( zBlob >= zPtr ){
				break;
			}
			rc = xPatternMatch((const void *)zPtr, (sxu32)(zEnd-zPtr), (const void *)zPattern, (sxu32)nPatLen, &nOfft);
			if( rc == SXRET_OK ){
				/* Pattern found, return it's position */
				jx9_result_int64(pCtx, (jx9_int64)(&zPtr[nOfft] - zStart));
				return JX9_OK;
			}
			zPtr--;
		}
		/* Pattern not found, return FALSE */
		jx9_result_bool(pCtx, 0);
	}else{
		jx9_result_bool(pCtx, 0);
	}
	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 $0x1, %esi
jg 0x4a47e
movq %rbx, %rdi
jmp 0x4a540
movq %rdx, %r12
movl %esi, %r13d
movq (%rdx), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x297ed
movq %rax, %r15
movq 0x8(%r12), %rdi
leaq -0x40(%rbp), %rsi
callq 0x297ed
movq %rax, %r14
leaq -0x2c(%rbp), %rax
movl (%rax), %eax
andl $0x0, -0x3c(%rbp)
cmpl $0x2, %r13d
jne 0x4a4bf
movq %rbx, -0x38(%rbp)
movl %eax, %ecx
movq %r15, %rbx
jmp 0x4a4ea
movl %eax, %r13d
movq 0x10(%r12), %rdi
callq 0x29772
testl %eax, %eax
js 0x4a558
movl -0x2c(%rbp), %ecx
subl %eax, %ecx
jle 0x4a476
movq %rbx, -0x38(%rbp)
movl %eax, %ebx
addq %r15, %rbx
movl %ecx, -0x2c(%rbp)
movl %r13d, %eax
testl %ecx, %ecx
jle 0x4a53c
cmpl $0x0, -0x40(%rbp)
jle 0x4a53c
movslq %eax, %r13
addq %r13, %r15
decq %r15
negq %r13
pushq $0x1
popq %r12
cmpq %r15, %rbx
jae 0x4a53c
movl -0x40(%rbp), %ecx
movq %r15, %rdi
movl %r12d, %esi
movq %r14, %rdx
leaq -0x3c(%rbp), %r8
callq 0x4d7da
incq %r13
decq %r15
incl %r12d
testl %eax, %eax
jne 0x4a504
movl -0x3c(%rbp), %esi
subq %r13, %rsi
movq -0x38(%rbp), %rdi
callq 0x29897
jmp 0x4a547
movq -0x38(%rbp), %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
movl %eax, %edx
negl %edx
movl -0x2c(%rbp), %ecx
cmpl %edx, %ecx
jle 0x4a476
movq %rbx, -0x38(%rbp)
addl %eax, %ecx
movl %ecx, -0x2c(%rbp)
movl %ecx, %eax
jmp 0x4a4ba