// File: /workspace/github_c_makefile_star2_O3/ArtifexSoftware[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 $0x38, %rsp
movq %rdi, %rbx
movq $0x0, (%rsp)
callq 0x28e6e
movq %rax, %r13
movq %rax, %r12
movl 0x144(%rbx), %ecx
leaq 0x16ee0(%rip), %rax     # 0x403f8
cmpl $-0x1, %ecx
jl 0x29539
incl %ecx
movq %rax, %rsi
cmpl 0x140(%rbx), %ecx
jge 0x2953c
movl %ecx, %ecx
movl %ecx, %eax
shlq $0x4, %rax
addq 0x148(%rbx), %rax
movq %rax, %rsi
movq %rbx, %rdi
callq 0x14e64
movq %rax, %r15
movq %r12, %rdi
movq %rax, %rsi
callq 0x3260
testq %rax, %rax
je 0x295ff
movq %rax, %r14
movq %r15, %rdi
movq %rax, %r15
callq 0x3200
movq %rax, %rbp
movq %rbx, %rdi
movl $0x2, %esi
callq 0x14940
testl %eax, %eax
movq %r14, 0x8(%rsp)
je 0x2960e
movq %rbp, 0x20(%rsp)
movq %rbx, %rdi
movl $0x2, %esi
callq 0x13c1a
movq %rbx, %rdi
callq 0x88f1
movq %rbx, %rdi
movq %r15, %rsi
movl %ebp, %edx
callq 0x133b3
movq %r14, %rax
subq %r13, %rax
cvtsi2sd %rax, %xmm0
movq %rbx, %rdi
callq 0x4124
movq %rbx, %rdi
xorl %esi, %esi
callq 0x13c1a
movq %rbx, %rdi
movl $0x3, %esi
callq 0x16762
movslq 0x140(%rbx), %rax
testq %rax, %rax
jle 0x297f7
movq 0x148(%rbx), %rcx
shlq $0x4, %rax
leaq (%rcx,%rax), %rsi
addq $-0x10, %rsi
jmp 0x297fe
movq %rbx, %rdi
xorl %esi, %esi
callq 0x13c1a
jmp 0x2990c
movl 0x144(%rbx), %ecx
leaq 0x16ddd(%rip), %rax     # 0x403f8
cmpl $-0x2, %ecx
movq %r12, 0x10(%rsp)
movq %rbp, %r15
jl 0x29645
addl $0x2, %ecx
movq %rax, %rsi
cmpl 0x140(%rbx), %ecx
jge 0x29648
movl %ecx, %ecx
movl %ecx, %eax
shlq $0x4, %rax
addq 0x148(%rbx), %rax
movq %rax, %rsi
movq %rbx, %rdi
callq 0x14e64
movq %rax, %rbp
movq %r13, 0x28(%rsp)
cmpq %r14, %r13
jae 0x29681
movq %rsp, %r12
movq 0x10(%rsp), %rax
movsbl (%rax), %edx
movq %rax, %r13
incq %r13
movq %rbx, %rdi
movq %r12, %rsi
callq 0xdda1
movq %r13, %rax
cmpq %r14, %r13
jne 0x29665
movq %rbp, %rax
movslq %r15d, %r12
leaq (%r12,%r14), %rcx
incq %rcx
movq %rcx, 0x18(%rsp)
movq %rsp, %rbp
movq %r14, 0x30(%rsp)
movzbl (%rax), %ecx
cmpl $0x24, %ecx
je 0x296c4
testl %ecx, %ecx
je 0x297ae
movsbl %cl, %edx
movq %rax, %r13
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xdda1
incq %r13
movq %r13, %rax
jmp 0x2969b
leaq 0x1(%rax), %r13
movzbl 0x1(%rax), %ecx
cmpl $0x25, %ecx
jle 0x2970e
cmpl $0x26, %ecx
je 0x2971b
cmpl $0x27, %ecx
je 0x2974f
cmpl $0x60, %ecx
jne 0x29794
cmpq %r14, 0x28(%rsp)
jae 0x296bc
movq 0x10(%rsp), %rax
movsbl (%rax), %edx
movq %rax, %r15
incq %r15
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xdda1
movq %r15, %rax
cmpq %r14, %r15
jne 0x296f0
jmp 0x296bc
testl %ecx, %ecx
je 0x2978a
cmpl $0x24, %ecx
jne 0x29794
movl %ecx, %edx
jmp 0x296b1
testq %r12, %r12
jle 0x296bc
xorl %eax, %eax
movq 0x8(%rsp), %r14
movq %rax, %r15
movsbl (%r14,%rax), %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xdda1
incq %r15
movq %r15, %rax
cmpq %r15, %r12
jne 0x29727
movq 0x30(%rsp), %r14
jmp 0x296bc
movq 0x8(%rsp), %rax
movb (%rax,%r12), %cl
testb %cl, %cl
je 0x296bc
movq 0x18(%rsp), %rax
movq %rax, %r15
movsbl %cl, %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xdda1
movb (%r15), %dl
incq %r15
movq %r15, %rax
movl %edx, %ecx
testb %dl, %dl
jne 0x29765
jmp 0x296bc
movl $0x24, %edx
jmp 0x296ae
movq %rbx, %rdi
movq %rbp, %rsi
movl $0x24, %edx
callq 0xdda1
movsbl (%r13), %edx
jmp 0x296b1
movq 0x8(%rsp), %rax
movb (%rax,%r12), %cl
testb %cl, %cl
je 0x297e5
leaq (%r12,%r14), %rax
incq %rax
movq %rsp, %r14
movq %rax, %r15
movsbl %cl, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xdda1
movb (%r15), %dl
incq %r15
movq %r15, %rax
movl %edx, %ecx
testb %dl, %dl
jne 0x297c5
movq %rsp, %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0xdda1
jmp 0x298bd
leaq 0x16bfa(%rip), %rsi     # 0x403f8
movq %rbx, %rdi
callq 0x14e64
movq %rax, %rbp
movq %rax, %r15
cmpq %r14, %r13
jae 0x29833
movq %rsp, %r13
movq %r12, %rax
movq %rax, %r12
movsbl (%rax), %edx
incq %r12
movq %rbx, %rdi
movq %r13, %rsi
callq 0xdda1
movq %r12, %rax
cmpq %r14, %r12
jne 0x29817
movb (%r15), %al
testb %al, %al
je 0x2985a
incq %rbp
movq %rsp, %r12
movsbl %al, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0xdda1
movb (%rbp), %dl
incq %rbp
movl %edx, %eax
testb %dl, %dl
jne 0x29840
movq 0x20(%rsp), %rax
cltq
movq 0x8(%rsp), %rcx
movb (%rcx,%rax), %cl
testb %cl, %cl
je 0x29896
addq %r14, %rax
incq %rax
movq %rsp, %r14
movq %rax, %r15
movsbl %cl, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xdda1
movb (%r15), %dl
incq %r15
movq %r15, %rax
movl %edx, %ecx
testb %dl, %dl
jne 0x29876
movq %rsp, %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0xdda1
movl 0x140(%rbx), %ecx
movl 0x144(%rbx), %eax
movl %ecx, %edx
decl %edx
movl %edx, 0x140(%rbx)
cmpl %eax, %ecx
jle 0x29937
movq %rbx, %rdi
callq 0x13b6c
movq %rax, %rdi
callq 0x3100
movq (%rsp), %r14
testl %eax, %eax
jne 0x2991b
leaq 0x8(%r14), %rax
testq %r14, %r14
leaq 0xaad3(%rip), %rsi      # 0x343b6
cmovneq %rax, %rsi
movq %rbx, %rdi
callq 0x13215
movl 0x8198(%rbx), %eax
testl %eax, %eax
je 0x2992e
decl %eax
movl %eax, 0x8198(%rbx)
movq (%rbx), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq *0x10(%rbx)
addq $0x38, %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 0x8e1b
leaq 0x9f04(%rip), %rsi      # 0x33839
jmp 0x29944
movl %eax, 0x140(%rbx)
leaq 0x9e5a(%rip), %rsi      # 0x3379e
xorl %eax, %eax
movq %rbx, %rdi
callq 0xc666