// File: /workspace/github_c_makefile_star2_O3/ArtifexSoftware[P]mujs/./jsstring.c
// Function: Sp_replace_regexp
static void Sp_replace_regexp(js_State *J)
{
	js_Regexp *re;
	const char *source, *s, *r;
	js_Buffer *sb = NULL;
	int n, x;
	Resub m;

	source = checkstring(J, 0);
	re = js_toregexp(J, 1);

	if (js_doregexec(J, re->prog, source, &m, 0)) {
		js_copy(J, 0);
		return;
	}

	re->last = 0;

loop:
	s = m.sub[0].sp;
	n = m.sub[0].ep - m.sub[0].sp;

	if (js_iscallable(J, 2)) {
		js_copy(J, 2);
		js_pushundefined(J);
		for (x = 0; m.sub[x].sp; ++x) /* arg 0..x: substring and subexps that matched */
			js_pushlstring(J, m.sub[x].sp, m.sub[x].ep - m.sub[x].sp);
		js_pushnumber(J, s - source); /* arg x+2: offset within search string */
		js_copy(J, 0); /* arg x+3: search string */
		js_call(J, 2 + x);
		r = js_tostring(J, -1);
		js_putm(J, &sb, source, s);
		js_puts(J, &sb, r);
		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, source, s); break;
				case '\'': js_puts(J, &sb, s + n); break;
				case '&':
					js_putm(J, &sb, s, s + n);
					break;
				case '0': case '1': case '2': case '3': case '4':
				case '5': case '6': case '7': case '8': case '9':
					x = *r - '0';
					if (r[1] >= '0' && r[1] <= '9')
						x = x * 10 + *(++r) - '0';
					if (x > 0 && x < m.nsub) {
						js_putm(J, &sb, m.sub[x].sp, m.sub[x].ep);
					} else {
						js_putc(J, &sb, '$');
						if (x > 10) {
							js_putc(J, &sb, '0' + x / 10);
							js_putc(J, &sb, '0' + x % 10);
						} else {
							js_putc(J, &sb, '0' + x);
						}
					}
					break;
				default:
					js_putc(J, &sb, '$');
					js_putc(J, &sb, *r);
					break;
				}
				++r;
			} else {
				js_putc(J, &sb, *r++);
			}
		}
	}

	if (re->flags & JS_REGEXP_G) {
		source = m.sub[0].ep;
		if (n == 0) {
			if (*source)
				js_putc(J, &sb, *source++);
			else
				goto end;
		}
		if (!js_doregexec(J, re->prog, source, &m, REG_NOTBOL))
			goto loop;
	}

end:
	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 $0x138, %rsp            # imm = 0x138
movq %rdi, %rbx
movq $0x0, 0x10(%rsp)
callq 0x28e6e
movq %rax, %r13
movq %rbx, %rdi
movl $0x1, %esi
callq 0x1524a
movq %rax, %r15
movq (%rax), %rsi
leaq 0x30(%rsp), %rcx
movq %rbx, %rdi
movq %r13, %rdx
xorl %r8d, %r8d
callq 0x28ed6
testl %eax, %eax
je 0x28fb2
movq %rbx, %rdi
xorl %esi, %esi
callq 0x13c1a
jmp 0x294a2
movq %r15, 0x20(%rsp)
movw $0x0, 0x12(%r15)
leaq 0x10(%rsp), %r14
movq %r13, %r15
movq 0x38(%rsp), %rbp
movq 0x40(%rsp), %rax
subq %rbp, %rax
movq %rax, 0x8(%rsp)
movq %rbx, %rdi
movl $0x2, %esi
callq 0x14940
testl %eax, %eax
movq %r13, (%rsp)
je 0x29178
movl $0x2, %r13d
movq %rbx, %rdi
movl %r13d, %esi
callq 0x13c1a
movq %rbx, %rdi
callq 0x88f1
movq 0x38(%rsp), %rcx
testq %rcx, %rcx
je 0x29050
movl $0x2, %edx
leaq 0x48(%rsp), %rax
movq %rcx, %rsi
movl %edx, %r15d
movq %rax, %r12
movl -0x8(%rax), %edx
subl %esi, %edx
movq %rbx, %rdi
callq 0x133b3
movq (%r12), %rcx
incl %r15d
addq $0x10, %r12
movq %r12, %rax
movl %r15d, %r13d
movl %r15d, %edx
movq %rcx, %rsi
testq %rcx, %rcx
jne 0x29021
movq %rbp, %rax
movq (%rsp), %r15
subq %r15, %rax
cvtsi2sd %rax, %xmm0
movq %rbx, %rdi
callq 0x4124
movq %rbx, %rdi
xorl %esi, %esi
callq 0x13c1a
movq %rbx, %rdi
movl %r13d, %esi
callq 0x16762
movslq 0x140(%rbx), %rax
leaq 0x1736e(%rip), %rsi     # 0x403f8
testq %rax, %rax
jle 0x290a2
movq 0x148(%rbx), %rcx
shlq $0x4, %rax
leaq (%rcx,%rax), %rsi
addq $-0x10, %rsi
movq %rbx, %rdi
callq 0x14e64
movq %rax, %r13
cmpq %rbp, %r15
jae 0x290d1
movq %r15, %rax
movsbl (%rax), %edx
movq %rax, %r15
incq %r15
movq %rbx, %rdi
movq %r14, %rsi
callq 0xdda1
movq %r15, %rax
cmpq %rbp, %r15
jne 0x290b5
movb (%r13), %cl
testb %cl, %cl
je 0x290f7
incq %r13
movsbl %cl, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xdda1
movb (%r13), %dl
incq %r13
movl %edx, %ecx
testb %dl, %dl
jne 0x290dc
movl 0x140(%rbx), %ecx
movl 0x144(%rbx), %eax
movl %ecx, %edx
decl %edx
movl %edx, 0x140(%rbx)
cmpl %eax, %ecx
jle 0x294b4
movq 0x20(%rsp), %rax
testb $0x1, 0x10(%rax)
je 0x29408
movq 0x40(%rsp), %r13
movq 0x8(%rsp), %rcx
testl %ecx, %ecx
jne 0x2914d
movsbl (%r13), %edx
testl %edx, %edx
je 0x29408
incq %r13
movq %rbx, %rdi
movq %r14, %rsi
callq 0xdda1
movq 0x20(%rsp), %rax
movq (%rax), %rsi
movq %rbx, %rdi
movq %r13, %rdx
leaq 0x30(%rsp), %rcx
movl $0x4, %r8d
callq 0x28ed6
testl %eax, %eax
je 0x28fc3
jmp 0x29408
movl 0x144(%rbx), %eax
leaq 0x17273(%rip), %rsi     # 0x403f8
cmpl $-0x2, %eax
jl 0x291ac
addl $0x2, %eax
leaq 0x17264(%rip), %rsi     # 0x403f8
cmpl 0x140(%rbx), %eax
jge 0x291ac
movl %eax, %eax
shlq $0x4, %rax
addq 0x148(%rbx), %rax
movq %rax, %rsi
movq %rbx, %rdi
callq 0x14e64
movq %rax, %r13
cmpq %rbp, %r15
jae 0x291dc
movq (%rsp), %rax
movsbl (%rax), %edx
movq %rax, %r15
incq %r15
movq %rbx, %rdi
movq %r14, %rsi
callq 0xdda1
movq %r15, %rax
cmpq %rbp, %r15
jne 0x291c0
movq 0x8(%rsp), %rcx
movslq %ecx, %rcx
movq %rcx, 0x18(%rsp)
addq %rbp, %rcx
incq %rcx
movq %rcx, 0x28(%rsp)
movq %r13, %rax
leaq 0x2bf2(%rip), %r13      # 0x2bdf0
movzbl (%rax), %ecx
cmpl $0x24, %ecx
je 0x29227
testl %ecx, %ecx
je 0x29115
movsbl %cl, %edx
movq %rax, %r12
movq %rbx, %rdi
movq %r14, %rsi
callq 0xdda1
incq %r12
movq %r12, %rax
jmp 0x291fe
leaq 0x1(%rax), %r12
movzbl 0x1(%rax), %ecx
movl %ecx, %edx
addl $-0x24, %edx
cmpl $0x15, %edx
ja 0x2932a
movslq (%r13,%rdx,4), %rdx
addq %r13, %rdx
jmpq *%rdx
movl %ecx, %edx
addl $-0x30, %edx
movsbl 0x2(%rax), %esi
addq $0x2, %rax
movl %esi, %edi
movb %sil, %r8b
leal -0x30(%r8), %esi
cmpb $0xa, %sil
leal (%rcx,%rcx,4), %ecx
leal -0x210(%rdi,%rcx,2), %r15d
cmovbq %rax, %r12
cmovael %edx, %r15d
testl %r15d, %r15d
jle 0x292c5
cmpl 0x30(%rsp), %r15d
jge 0x292c5
movl %r15d, %r15d
movl %r15d, %eax
movq %rax, %rcx
shlq $0x4, %rcx
leaq 0x38(%rsp), %rdx
movq (%rdx,%rcx), %rax
movq 0x8(%rdx,%rcx), %r15
cmpq %r15, %rax
jae 0x2921f
movq %rax, %r13
movsbl (%rax), %edx
incq %r13
movq %rbx, %rdi
movq %r14, %rsi
callq 0xdda1
movq %r13, %rax
cmpq %r15, %r13
jne 0x292a4
jmp 0x2938c
movq %rbx, %rdi
movq %r14, %rsi
movl $0x24, %edx
callq 0xdda1
cmpl $0xb, %r15d
jl 0x2931e
movzbl %r15b, %r15d
imull $0xcd, %r15d, %r13d
shrl $0xb, %r13d
movb %r13b, %cl
leal 0x30(%rcx), %eax
movzbl %al, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xdda1
addl %r13d, %r13d
movl %r13d, %eax
leaq 0x2ae5(%rip), %r13      # 0x2bdf0
leal (%rax,%rax,4), %eax
movl %r15d, %ecx
subb %al, %cl
orb $0x30, %cl
movzbl %cl, %edx
jmp 0x29214
addl $0x30, %r15d
movl %r15d, %edx
jmp 0x29214
cmpl $0x60, %ecx
je 0x293da
testl %ecx, %ecx
jne 0x29341
movl $0x24, %edx
jmp 0x29211
movq %rbx, %rdi
movq %r14, %rsi
movl $0x24, %edx
callq 0xdda1
movsbl (%r12), %edx
jmp 0x29214
movq %rbp, %r13
movq 0x18(%rsp), %rbp
testq %rbp, %rbp
jle 0x29389
xorl %eax, %eax
movq %rax, %r15
movsbl (%r13,%rax), %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xdda1
incq %r15
movq %r15, %rax
cmpq %r15, %rbp
jne 0x2936a
movq %r13, %rbp
leaq 0x2a5d(%rip), %r13      # 0x2bdf0
jmp 0x2921f
movl %ecx, %edx
jmp 0x29214
movq 0x18(%rsp), %rax
movb (%rbp,%rax), %cl
testb %cl, %cl
je 0x2921f
movq 0x28(%rsp), %rax
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 0x293b5
jmp 0x2921f
movq (%rsp), %rax
cmpq %rbp, %rax
jae 0x2921f
movsbl (%rax), %edx
movq %rax, %r15
incq %r15
movq %rbx, %rdi
movq %r14, %rsi
callq 0xdda1
movq %r15, %rax
cmpq %rbp, %r15
jne 0x293e7
jmp 0x2921f
movq 0x8(%rsp), %rax
cltq
movb (%rbp,%rax), %cl
testb %cl, %cl
je 0x29442
addq %rbp, %rax
incq %rax
leaq 0x10(%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 0x29422
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0xdda1
movq %rbx, %rdi
callq 0x13b6c
movq %rax, %rdi
callq 0x3100
movq (%r14), %r14
testl %eax, %eax
jne 0x294cb
leaq 0x8(%r14), %rax
testq %r14, %r14
leaq 0xaf3d(%rip), %rsi      # 0x343b6
cmovneq %rax, %rsi
movq %rbx, %rdi
callq 0x13215
movl 0x8198(%rbx), %eax
testl %eax, %eax
je 0x294de
decl %eax
movl %eax, 0x8198(%rbx)
movq (%rbx), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq *0x10(%rbx)
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, 0x140(%rbx)
leaq 0xa2dd(%rip), %rsi      # 0x3379e
xorl %eax, %eax
movq %rbx, %rdi
callq 0xc666
movq (%rbx), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq *0x10(%rbx)
movq %rbx, %rdi
callq 0x8e1b
leaq 0xa354(%rip), %rsi      # 0x33839
jmp 0x294c1