// File: /workspace/github_c_makefile_star2_O1/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 0x592cd
movq %rdx, %r12
movl %esi, %r15d
movq (%rdx), %rdi
leaq -0x30(%rbp), %r13
movq %r13, %rsi
callq 0x30b04
movq %rax, %r14
movl (%r13), %edx
testl %edx, %edx
setg %al
cmpl $0x1, %r15d
setne %cl
testb %al, %cl
je 0x592bf
cmpl $0x2, %r15d
jne 0x592b9
movq 0x8(%r12), %rax
testb $0x40, 0x8(%rax)
jne 0x593a1
cmpl $0x3, %r15d
jge 0x592ff
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x3087c
jmp 0x592ee
movq 0x8(%rbx), %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
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%r12), %rdi
leaq -0x78(%rbp), %r13
movq %r13, %rsi
callq 0x30b04
movq %rax, %r15
movq 0x10(%r12), %rdi
leaq -0x58(%rbp), %rsi
callq 0x30b04
movq %rax, -0x38(%rbp)
cmpl $0x0, (%r13)
movl -0x30(%rbp), %edx
jle 0x592bf
cmpl $0x0, -0x58(%rbp)
jle 0x592bf
testl %edx, %edx
jle 0x592ee
xorl %r13d, %r13d
movsbl (%r14,%r13), %eax
movl %eax, -0x2c(%rbp)
movslq -0x78(%rbp), %rcx
testq %rcx, %rcx
jle 0x5935d
xorl %edx, %edx
cmpb %al, (%r15,%rdx)
je 0x59361
incq %rdx
cmpq %rdx, %rcx
jne 0x5934f
xorl %eax, %eax
jmp 0x59366
movb $0x1, %al
movl %edx, %r12d
testb %al, %al
je 0x5937e
cmpl -0x58(%rbp), %r12d
jge 0x5937e
movslq %r12d, %rax
movq -0x38(%rbp), %rcx
movsbl (%rcx,%rax), %eax
movl %eax, -0x2c(%rbp)
movq 0x8(%rbx), %rdi
leaq -0x2c(%rbp), %rsi
movl $0x1, %edx
callq 0x3087c
incq %r13
movslq -0x30(%rbp), %rax
cmpq %rax, %r13
jl 0x5933c
jmp 0x592ee
movq 0x60(%rbx), %rax
xorps %xmm0, %xmm0
leaq -0x58(%rbp), %r15
movups %xmm0, 0x8(%r15)
movq %rax, (%r15)
movl $0x0, 0x18(%r15)
movq %r15, %rdi
movq %r14, %rsi
callq 0x360ae
movq %r15, -0x78(%rbp)
leaq 0x22a6(%rip), %rax      # 0x5b678
movq %rax, -0x70(%rbp)
movq 0x8(%r12), %rax
testb $0x40, 0x8(%rax)
je 0x593f4
movq (%rax), %rdi
leaq 0x4012(%rip), %rsi      # 0x5d3fd
leaq -0x78(%rbp), %rdx
callq 0x52ab1
leaq -0x50(%rbp), %r14
movq (%r14), %rsi
movl 0x8(%r14), %edx
movq 0x8(%rbx), %rdi
callq 0x3087c
testb $0x6, 0x10(%r14)
jne 0x59422
cmpl $0x0, -0x44(%rbp)
je 0x59422
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x3503f
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movl $0x0, 0x10(%r14)
jmp 0x592ee