// File: /workspace/github_c_makefile_star2_O1/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
movl $0x8, %r14d
cmpl $0x2, %esi
jl 0x57779
movq %rdx, %rbx
movl %esi, %r15d
movq %rdi, -0x38(%rbp)
movq (%rdx), %rdi
leaq -0x2c(%rbp), %r12
movq %r12, %rsi
callq 0x30b04
movq %rax, %r14
movq 0x8(%rbx), %rdi
leaq -0x40(%rbp), %rsi
callq 0x30b04
movq %rax, -0x48(%rbp)
movslq (%r12), %rax
leaq (%r14,%rax), %r12
leaq (%r14,%rax), %r13
decq %r13
movl $0x0, -0x3c(%rbp)
cmpl $0x2, %r15d
jne 0x576af
movq %r14, %r15
jmp 0x5772d
movq 0x10(%rbx), %rbx
movq %rbx, %rdi
callq 0x3fd5f
movq (%rbx), %r15
testl %r15d, %r15d
js 0x576dc
movl -0x2c(%rbp), %eax
subl %r15d, %eax
jle 0x576ff
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
addq %r14, %r15
movl %eax, -0x2c(%rbp)
movb $0x1, %al
jmp 0x57729
movl %r15d, %ecx
negl %ecx
movl -0x2c(%rbp), %eax
cmpl %ecx, %eax
jle 0x576ff
addl %r15d, %eax
movl %eax, -0x2c(%rbp)
cltq
leaq (%r14,%rax), %r12
leaq (%r14,%rax), %r13
decq %r13
movb $0x1, %al
jmp 0x57726
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rbx
movq %rbx, %rdi
callq 0x309f2
movq $0x0, (%rbx)
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%rbx), %eax
orl $0x8, %eax
movl %eax, 0x8(%rbx)
xorl %eax, %eax
movq %r14, %r15
testb %al, %al
je 0x57799
cmpl $0x0, -0x2c(%rbp)
jle 0x5776f
cmpl $0x0, -0x40(%rbp)
jle 0x5776f
cmpq %r13, %r15
jae 0x5776f
subq %r13, %r14
subl %r13d, %r12d
leaq -0x3c(%rbp), %rbx
movl -0x40(%rbp), %ecx
movq %r13, %rdi
movl %r12d, %esi
movq -0x48(%rbp), %rdx
movq %rbx, %r8
callq 0x5b678
testl %eax, %eax
je 0x577aa
decq %r13
incq %r14
incl %r12d
cmpq %r13, %r15
jb 0x57748
movl $0x8, %r14d
movq -0x38(%rbp), %rdi
xorl %r15d, %r15d
movq 0x8(%rdi), %rbx
movq %rbx, %rdi
callq 0x309f2
movq %r15, (%rbx)
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%rbx), %eax
orl %r14d, %eax
movl %eax, 0x8(%rbx)
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl -0x3c(%rbp), %r15d
subq %r14, %r15
movl $0x2, %r14d
movq -0x38(%rbp), %rdi
jmp 0x5777c