// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
cmpl $0x1, %esi
jg 0x55eef
movq 0x8(%rdi), %rbx
jmp 0x55ffa
movq %rdx, %r12
movl %esi, %r13d
movq %rdi, -0x38(%rbp)
movq (%rdx), %rdi
leaq -0x2c(%rbp), %r15
movq %r15, %rsi
callq 0x30577
movq %rax, %r14
movq 0x8(%r12), %rdi
leaq -0x40(%rbp), %rsi
callq 0x30577
movq %rax, -0x48(%rbp)
movl (%r15), %edx
movl $0x0, -0x3c(%rbp)
cmpl $0x2, %r13d
jne 0x55f37
movl %edx, %eax
movq %r14, %rbx
movq %r14, %rcx
jmp 0x55f85
movl %edx, %r13d
movq 0x10(%r12), %r15
movq %r15, %rdi
callq 0x3f362
movq (%r15), %rbx
testl %ebx, %ebx
js 0x55f6d
movl -0x2c(%rbp), %eax
subl %ebx, %eax
jle 0x55ff2
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movq %r14, %rcx
addq %r14, %rbx
movl %eax, -0x2c(%rbp)
movl %r13d, %edx
jmp 0x55f85
movl %ebx, %ecx
negl %ecx
movl -0x2c(%rbp), %eax
cmpl %ecx, %eax
jle 0x55ff2
addl %ebx, %eax
movl %eax, -0x2c(%rbp)
movl %eax, %edx
movq %r14, %rcx
movq %r14, %rbx
testl %eax, %eax
movq -0x38(%rbp), %rax
jle 0x55ff6
cmpl $0x0, -0x40(%rbp)
jle 0x55ff6
movslq %edx, %r14
leaq (%r14,%rcx), %r15
decq %r15
negq %r14
movl $0x1, %r12d
leaq -0x3c(%rbp), %r13
cmpq %r15, %rbx
jae 0x55ff2
movl -0x40(%rbp), %ecx
movq %r15, %rdi
movl %r12d, %esi
movq -0x48(%rbp), %rdx
movq %r13, %r8
callq 0x59e90
incq %r14
decq %r15
incl %r12d
testl %eax, %eax
jne 0x55faa
movl -0x3c(%rbp), %r15d
subq %r14, %r15
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rbx
movq %rbx, %rdi
callq 0x30465
movq %r15, (%rbx)
movl $0x2, %eax
jmp 0x5600e
movq -0x38(%rbp), %rax
movq 0x8(%rax), %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