// File: /workspace/github_c_makefile_star2_O1/ccxvii[P]mujs/./jsstring.c
// Function: Sp_replace_string
static void Sp_replace_string(js_State *J)
{
	const char *source, *needle, *s, *r;
	js_Buffer *sb = NULL;
	int n;

	source = checkstring(J, 0);
	needle = js_tostring(J, 1);

	s = strstr(source, needle);
	if (!s) {
		js_copy(J, 0);
		return;
	}
	n = strlen(needle);

	if (js_iscallable(J, 2)) {
		js_copy(J, 2);
		js_pushundefined(J);
		js_pushlstring(J, s, n); /* arg 1: substring that matched */
		js_pushnumber(J, s - source); /* arg 2: offset within search string */
		js_copy(J, 0); /* arg 3: search string */
		js_call(J, 3);
		r = js_tostring(J, -1);
		js_putm(J, &sb, source, s);
		js_puts(J, &sb, r);
		js_puts(J, &sb, s + n);
		js_putc(J, &sb, 0);
		js_pop(J, 1);
	} else {
		r = js_tostring(J, 2);
		js_putm(J, &sb, source, s);
		while (*r) {
			if (*r == '$') {
				switch (*(++r)) {
				case 0: --r; /* end of string; back up */
				/* fallthrough */
				case '$': js_putc(J, &sb, '$'); break;
				case '&': js_putm(J, &sb, s, s + n); break;
				case '`': js_putm(J, &sb, source, s); break;
				case '\'': js_puts(J, &sb, s + n); break;
				default: js_putc(J, &sb, '$'); js_putc(J, &sb, *r); break;
				}
				++r;
			} else {
				js_putc(J, &sb, *r++);
			}
		}
		js_puts(J, &sb, s + n);
		js_putc(J, &sb, 0);
	}

	if (js_try(J)) {
		js_free(J, sb);
		js_throw(J);
	}
	js_pushstring(J, sb ? sb->s : "");
	js_endtry(J);
	js_free(J, sb);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
movq $0x0, 0x8(%rsp)
callq 0x2925f
movq %rax, %r13
movq %rax, 0x10(%rsp)
movl 0x144(%rbx), %ecx
leaq 0x16ada(%rip), %rax     # 0x403f8
cmpl $-0x1, %ecx
jl 0x2993f
incl %ecx
movq %rax, %rsi
cmpl 0x140(%rbx), %ecx
jge 0x29942
movl %ecx, %ecx
movl %ecx, %eax
shlq $0x4, %rax
addq 0x148(%rbx), %rax
movq %rax, %rsi
movq %rbx, %rdi
callq 0x1533b
movq %rax, %r15
movq %r13, %rdi
movq %rax, %rsi
callq 0x3260
testq %rax, %rax
je 0x29a06
movq %rax, %r14
movq %r15, %rdi
movq %rax, %r15
callq 0x3200
movq %rax, %r12
movq %rbx, %rdi
movl $0x2, %esi
callq 0x14e17
testl %eax, %eax
movq %r14, 0x18(%rsp)
je 0x29a15
movq %rbx, %rdi
movl $0x2, %esi
callq 0x14073
movq %rbx, %rdi
callq 0x89b6
movq %rbx, %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0x13802
movq %r14, %rax
subq 0x10(%rsp), %rax
cvtsi2sd %rax, %xmm0
movq %rbx, %rdi
callq 0x4184
movq %rbx, %rdi
xorl %esi, %esi
callq 0x14073
movq %rbx, %rdi
movl $0x3, %esi
callq 0x16c25
movslq 0x140(%rbx), %rax
movq %r12, %r15
testq %rax, %rax
jle 0x29c0f
movq 0x148(%rbx), %rcx
shlq $0x4, %rax
leaq (%rcx,%rax), %rsi
addq $-0x10, %rsi
jmp 0x29c16
movq %rbx, %rdi
xorl %esi, %esi
callq 0x14073
jmp 0x29d31
movq %r13, 0x20(%rsp)
movl 0x144(%rbx), %ecx
leaq 0x169d1(%rip), %rax     # 0x403f8
cmpl $-0x2, %ecx
movq %r12, 0x28(%rsp)
jl 0x29a4e
addl $0x2, %ecx
movq %rax, %rsi
cmpl 0x140(%rbx), %ecx
jge 0x29a51
movl %ecx, %ecx
movl %ecx, %eax
shlq $0x4, %rax
addq 0x148(%rbx), %rax
movq %rax, %rsi
movq %rbx, %rdi
callq 0x1533b
movq %rax, %rbp
cmpq %r14, 0x10(%rsp)
jae 0x29a89
leaq 0x8(%rsp), %r12
movq 0x20(%rsp), %rax
movsbl (%rax), %edx
movq %rax, %r13
incq %r13
movq %rbx, %rdi
movq %r12, %rsi
callq 0xe0bc
movq %r13, %rax
cmpq %r14, %r13
jne 0x29a6d
movq %rbp, %rax
movq 0x28(%rsp), %rcx
movslq %ecx, %r12
leaq (%r12,%r14), %rcx
incq %rcx
movq %rcx, 0x38(%rsp)
leaq 0x8(%rsp), %rbp
movq %r14, 0x40(%rsp)
movzbl (%rax), %ecx
cmpl $0x24, %ecx
je 0x29ad3
testl %ecx, %ecx
je 0x29bbd
movsbl %cl, %edx
movq %rax, %r13
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xe0bc
incq %r13
movq %r13, %rax
jmp 0x29aaa
leaq 0x1(%rax), %r13
movzbl 0x1(%rax), %ecx
cmpl $0x25, %ecx
jle 0x29b1d
cmpl $0x26, %ecx
je 0x29b2a
cmpl $0x27, %ecx
je 0x29b5e
cmpl $0x60, %ecx
jne 0x29ba3
cmpq %r14, 0x10(%rsp)
jae 0x29acb
movq 0x20(%rsp), %rax
movsbl (%rax), %edx
movq %rax, %r15
incq %r15
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xe0bc
movq %r15, %rax
cmpq %r14, %r15
jne 0x29aff
jmp 0x29acb
testl %ecx, %ecx
je 0x29b99
cmpl $0x24, %ecx
jne 0x29ba3
movl %ecx, %edx
jmp 0x29ac0
testq %r12, %r12
jle 0x29acb
xorl %eax, %eax
movq 0x18(%rsp), %r14
movq %rax, %r15
movsbl (%r14,%rax), %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xe0bc
incq %r15
movq %r15, %rax
cmpq %r15, %r12
jne 0x29b36
movq 0x40(%rsp), %r14
jmp 0x29acb
movq 0x18(%rsp), %rax
movb (%rax,%r12), %cl
testb %cl, %cl
je 0x29acb
movq 0x38(%rsp), %rax
movq %rax, %r15
movsbl %cl, %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xe0bc
movb (%r15), %dl
incq %r15
movq %r15, %rax
movl %edx, %ecx
testb %dl, %dl
jne 0x29b74
jmp 0x29acb
movl $0x24, %edx
jmp 0x29abd
movq %rbx, %rdi
movq %rbp, %rsi
movl $0x24, %edx
callq 0xe0bc
movsbl (%r13), %edx
jmp 0x29ac0
movq 0x28(%rsp), %rax
cltq
movq 0x18(%rsp), %rcx
movb (%rcx,%rax), %cl
testb %cl, %cl
je 0x29bfb
addq %r14, %rax
incq %rax
leaq 0x8(%rsp), %r14
movq %rax, %r15
movsbl %cl, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe0bc
movb (%r15), %dl
incq %r15
movq %r15, %rax
movl %edx, %ecx
testb %dl, %dl
jne 0x29bdb
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0xe0bc
jmp 0x29ce1
leaq 0x167e2(%rip), %rsi     # 0x403f8
movq %rbx, %rdi
callq 0x1533b
movq %rax, %rbp
movq %rax, 0x30(%rsp)
cmpq %r14, 0x10(%rsp)
jae 0x29c51
movq %r13, %rax
leaq 0x8(%rsp), %r13
movq %rax, %r12
movsbl (%rax), %edx
incq %r12
movq %rbx, %rdi
movq %r13, %rsi
callq 0xe0bc
movq %r12, %rax
cmpq %r14, %r12
jne 0x29c35
movq 0x30(%rsp), %rax
movb (%rax), %al
testb %al, %al
je 0x29c7e
incq %rbp
leaq 0x8(%rsp), %r12
movsbl %al, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0xe0bc
movb (%rbp), %dl
incq %rbp
movl %edx, %eax
testb %dl, %dl
jne 0x29c64
movslq %r15d, %rax
movq 0x18(%rsp), %rcx
movb (%rcx,%rax), %cl
testb %cl, %cl
je 0x29cb8
addq %r14, %rax
incq %rax
leaq 0x8(%rsp), %r14
movq %rax, %r15
movsbl %cl, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe0bc
movb (%r15), %dl
incq %r15
movq %r15, %rax
movl %edx, %ecx
testb %dl, %dl
jne 0x29c98
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0xe0bc
movl 0x140(%rbx), %ecx
movl 0x144(%rbx), %eax
movl %ecx, %edx
decl %edx
movl %edx, 0x140(%rbx)
cmpl %eax, %ecx
jle 0x29d5c
movq %rbx, %rdi
callq 0x13fbb
movq %rax, %rdi
callq 0x3100
movq 0x8(%rsp), %r14
testl %eax, %eax
jne 0x29d40
leaq 0x8(%r14), %rax
testq %r14, %r14
leaq 0xa67e(%rip), %rsi      # 0x34386
cmovneq %rax, %rsi
movq %rbx, %rdi
callq 0x13665
movl 0x8198(%rbx), %eax
testl %eax, %eax
je 0x29d53
decl %eax
movl %eax, 0x8198(%rbx)
movq (%rbx), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq *0x10(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq *0x10(%rbx)
movq %rbx, %rdi
callq 0x8ec6
leaq 0x9aaf(%rip), %rsi      # 0x33809
jmp 0x29d69
movl %eax, 0x140(%rbx)
leaq 0x9a05(%rip), %rsi      # 0x3376e
xorl %eax, %eax
movq %rbx, %rdi
callq 0xc939