// File: /workspace/github_c_makefile_star2_O3/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 0x57ab2
movq %rdx, %r12
movl %esi, %r15d
movq (%rdx), %rdi
leaq -0x30(%rbp), %r13
movq %r13, %rsi
callq 0x30577
movq %rax, %r14
movl (%r13), %edx
testl %edx, %edx
setg %al
cmpl $0x1, %r15d
setne %cl
testb %al, %cl
jne 0x57ae4
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x302f6
jmp 0x57ad3
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x30465
movq $0x0, (%rbx)
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%rbx), %eax
orl $0x8, %eax
movl %eax, 0x8(%rbx)
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x2, %r15d
jne 0x57b82
movq 0x8(%r12), %rax
testb $0x40, 0x8(%rax)
je 0x57aa4
movq 0x60(%rbx), %rax
xorps %xmm0, %xmm0
leaq -0x50(%rbp), %r15
movups %xmm0, 0x8(%r15)
movq %rax, (%r15)
movl $0x0, 0x18(%r15)
movq %r15, %rdi
movq %r14, %rsi
callq 0x359ad
movq %r15, -0x78(%rbp)
leaq 0x2366(%rip), %rax      # 0x59e90
movq %rax, -0x70(%rbp)
movq 0x8(%r12), %rax
testb $0x40, 0x8(%rax)
je 0x57b4c
movq (%rax), %rdi
leaq 0x3f7a(%rip), %rsi      # 0x5babd
leaq -0x78(%rbp), %rdx
callq 0x5134a
movq -0x48(%rbp), %rsi
movl -0x40(%rbp), %edx
movq 0x8(%rbx), %rdi
callq 0x302f6
testb $0x6, -0x38(%rbp)
jne 0x57ad3
cmpl $0x0, -0x3c(%rbp)
je 0x57ad3
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x3490d
jmp 0x57ad3
movq 0x8(%r12), %rdi
leaq -0x78(%rbp), %r13
movq %r13, %rsi
callq 0x30577
movq %rax, %r15
movq 0x10(%r12), %rdi
leaq -0x50(%rbp), %rsi
callq 0x30577
movq %rax, -0x58(%rbp)
cmpl $0x0, (%r13)
movl -0x30(%rbp), %edx
jle 0x57aa4
cmpl $0x0, -0x50(%rbp)
jle 0x57aa4
testl %edx, %edx
jle 0x57ad3
xorl %r12d, %r12d
leaq -0x2c(%rbp), %r13
movsbl (%r14,%r12), %eax
movl %eax, -0x2c(%rbp)
movslq -0x78(%rbp), %rcx
testq %rcx, %rcx
jle 0x57c02
xorl %edx, %edx
cmpb %al, (%r15,%rdx)
je 0x57bf2
incq %rdx
cmpq %rdx, %rcx
jne 0x57be2
jmp 0x57c02
cmpl %edx, -0x50(%rbp)
jle 0x57c02
movq -0x58(%rbp), %rax
movsbl (%rax,%rdx), %eax
movl %eax, -0x2c(%rbp)
movq 0x8(%rbx), %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0x302f6
incq %r12
movslq -0x30(%rbp), %rax
cmpq %rax, %r12
jl 0x57bcf
jmp 0x57ad3