// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_strtr
static int jx9Builtin_strtr(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	const char *zIn;
	int nLen;
	if( nArg < 1 ){
		/* Nothing to replace, return FALSE */
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	zIn = jx9_value_to_string(apArg[0], &nLen);
	if( nLen < 1 || nArg < 2 ){
		/* Invalid arguments */
		jx9_result_string(pCtx, zIn, nLen);
		return JX9_OK;
	}
	if( nArg == 2 && jx9_value_is_json_array(apArg[1]) ){
		str_replace_data sRepData;
		SyBlob sWorker;
		/* Initilaize the working buffer */
		SyBlobInit(&sWorker, &pCtx->pVm->sAllocator);
		/* Copy raw string */
		SyBlobAppend(&sWorker, (const void *)zIn, (sxu32)nLen);
		/* Init our replace data instance */
		sRepData.pWorker = &sWorker;
		sRepData.xMatch = SyBlobSearch;
		/* Iterate throw array entries and perform the replace operation.*/
		jx9_array_walk(apArg[1], StringReplaceWalker, &sRepData);
		/* All done, return the result string */
		jx9_result_string(pCtx, (const char *)SyBlobData(&sWorker), 
			(int)SyBlobLength(&sWorker)); /* Will make it's own copy */
		/* Clean-up */
		SyBlobRelease(&sWorker);
	}else{
		int i, flen, tlen, c, iOfft;
		const char *zFrom, *zTo;
		if( nArg < 3 ){
			/* Nothing to replace */
			jx9_result_string(pCtx, zIn, nLen);
			return JX9_OK;
		}
		/* Extract given arguments */
		zFrom = jx9_value_to_string(apArg[1], &flen);
		zTo = jx9_value_to_string(apArg[2], &tlen);
		if( flen < 1 || tlen < 1 ){
			/* Nothing to replace */
			jx9_result_string(pCtx, zIn, nLen);
			return JX9_OK;
		}
		/* Start the replace process */
		for( i = 0 ; i < nLen ; ++i ){
			c = zIn[i];
			if( CheckMask(c, zFrom, flen, &iOfft) ){
				if ( iOfft < tlen ){
					c = zTo[iOfft];
				}
			}
			jx9_result_string(pCtx, (const char *)&c, (int)sizeof(char));
			
		}
	}
	return JX9_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
testl %esi, %esi
jle 0x4bbcf
movq %rdx, %r12
movl %esi, %r15d
movq (%rdx), %rdi
leaq -0x30(%rbp), %r13
movq %r13, %rsi
callq 0x297ed
movq %rax, %r14
movl (%r13), %edx
testl %edx, %edx
setg %al
cmpl $0x1, %r15d
setne %cl
testb %al, %cl
jne 0x4bbea
movq %rbx, %rdi
movq %r14, %rsi
callq 0x29903
jmp 0x4bbd9
movq %rbx, %rdi
xorl %esi, %esi
callq 0x298b2
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x2, %r15d
jne 0x4bc5e
movq 0x8(%r12), %rax
testb $0x40, 0x8(%rax)
je 0x4bbc2
movq 0x60(%rbx), %rax
xorps %xmm0, %xmm0
leaq -0x60(%rbp), %r15
movups %xmm0, 0x8(%r15)
movq %rax, (%r15)
andl $0x0, 0x18(%r15)
movq %r15, %rdi
movq %r14, %rsi
callq 0x2e250
leaq -0x80(%rbp), %rdx
movq %r15, (%rdx)
leaq 0x1bae(%rip), %rax      # 0x4d7da
movq %rax, 0x8(%rdx)
movq 0x8(%r12), %rdi
leaq 0x34e2(%rip), %rsi      # 0x4f11e
callq 0x29c1e
movq 0x8(%r15), %rsi
movl 0x10(%r15), %edx
movq %rbx, %rdi
callq 0x29903
movq %r15, %rdi
callq 0x2a72f
jmp 0x4bbd9
movq 0x8(%r12), %rdi
leaq -0x80(%rbp), %r13
movq %r13, %rsi
callq 0x297ed
movq %rax, %r15
movq 0x10(%r12), %rdi
leaq -0x60(%rbp), %rsi
callq 0x297ed
movq %rax, -0x40(%rbp)
cmpl $0x0, (%r13)
jle 0x4bce8
cmpl $0x0, -0x60(%rbp)
jle 0x4bce8
xorl %r12d, %r12d
pushq $0x1
popq %r13
movslq -0x30(%rbp), %rax
cmpq %rax, %r12
jge 0x4bbd9
movsbl (%r14,%r12), %edi
movl %edi, -0x2c(%rbp)
movl -0x80(%rbp), %edx
movq %r15, %rsi
leaq -0x34(%rbp), %rcx
callq 0x4efb2
testl %eax, %eax
je 0x4bcd4
movslq -0x34(%rbp), %rax
cmpl -0x60(%rbp), %eax
jge 0x4bcd4
movq -0x40(%rbp), %rcx
movsbl (%rcx,%rax), %eax
movl %eax, -0x2c(%rbp)
movq %rbx, %rdi
leaq -0x2c(%rbp), %rsi
movl %r13d, %edx
callq 0x29903
incq %r12
jmp 0x4bc98
movl -0x30(%rbp), %edx
jmp 0x4bbc2