// File: /workspace/github_c_makefile_star2_O0/ccxvii[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
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x2fae0
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15f20
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x18(%rbp), %rdx
leaq -0x140(%rbp), %rcx
xorl %r8d, %r8d
callq 0x2fb30
cmpl $0x0, %eax
je 0x2fbfb
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x14410
jmp 0x300de
movq -0x10(%rbp), %rax
movw $0x0, 0x12(%rax)
movq -0x138(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x130(%rbp), %rax
movq -0x138(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rdi
movl $0x2, %esi
callq 0x15290
cmpl $0x0, %eax
je 0x2fd5b
movq -0x8(%rbp), %rdi
movl $0x2, %esi
callq 0x14410
movq -0x8(%rbp), %rdi
callq 0x8640
movl $0x0, -0x38(%rbp)
leaq -0x140(%rbp), %rax
addq $0x8, %rax
movslq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
je 0x2fcdd
movq -0x8(%rbp), %rdi
leaq -0x140(%rbp), %rax
addq $0x8, %rax
movslq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rsi
leaq -0x140(%rbp), %rax
addq $0x8, %rax
movslq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
leaq -0x140(%rbp), %rcx
addq $0x8, %rcx
movslq -0x38(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
subq %rcx, %rax
movl %eax, %edx
callq 0x13a70
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x2fc59
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
cvtsi2sd %rax, %xmm0
callq 0x44d0
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x14410
movq -0x8(%rbp), %rdi
movl -0x38(%rbp), %esi
addl $0x2, %esi
callq 0x17ea0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x14b80
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq -0x30(%rbp), %rsi
callq 0xdac0
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq -0x30(%rbp), %rsi
callq 0xda70
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x4400
jmp 0x2ffb1
movq -0x8(%rbp), %rdi
movl $0x2, %esi
callq 0x14b80
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq -0x30(%rbp), %rsi
callq 0xdac0
movq -0x28(%rbp), %rax
cmpb $0x0, (%rax)
je 0x2ffaf
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x24, %eax
jne 0x2ff8b
movq -0x28(%rbp), %rax
movq %rax, %rcx
incq %rcx
movq %rcx, -0x28(%rbp)
movsbl 0x1(%rax), %eax
movl %eax, %ecx
movq %rcx, -0x148(%rbp)
subl $0x60, %eax
ja 0x2ff57
movq -0x148(%rbp), %rax
leaq 0x43ab(%rip), %rcx      # 0x3417c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x28(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x24, %edx
callq 0xd910
jmp 0x2ff7d
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq -0x30(%rbp), %rsi
callq 0xdac0
jmp 0x2ff7d
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
movslq -0x34(%rbp), %rax
addq %rax, %rdx
leaq -0x30(%rbp), %rsi
callq 0xda70
jmp 0x2ff7d
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
movq -0x20(%rbp), %rcx
movslq -0x34(%rbp), %rax
addq %rax, %rcx
leaq -0x30(%rbp), %rsi
callq 0xdac0
jmp 0x2ff7d
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
subl $0x30, %eax
movl %eax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x30, %eax
jl 0x2fe9b
movq -0x28(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x39, %eax
jg 0x2fe9b
imull $0xa, -0x38(%rbp), %eax
movq -0x28(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rbp)
movsbl 0x1(%rcx), %ecx
addl %ecx, %eax
subl $0x30, %eax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jle 0x2feee
movl -0x38(%rbp), %eax
cmpl -0x140(%rbp), %eax
jge 0x2feee
movq -0x8(%rbp), %rdi
leaq -0x140(%rbp), %rax
addq $0x8, %rax
movslq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdx
leaq -0x140(%rbp), %rax
addq $0x8, %rax
movslq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
leaq -0x30(%rbp), %rsi
callq 0xdac0
jmp 0x2ff55
movq -0x8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x24, %edx
callq 0xd910
cmpl $0xa, -0x38(%rbp)
jle 0x2ff40
movq -0x8(%rbp), %rdi
movl -0x38(%rbp), %eax
movl $0xa, %ecx
cltd
idivl %ecx
movl %eax, %edx
addl $0x30, %edx
leaq -0x30(%rbp), %rsi
callq 0xd910
movq -0x8(%rbp), %rdi
movl -0x38(%rbp), %eax
movl $0xa, %ecx
cltd
idivl %ecx
addl $0x30, %edx
leaq -0x30(%rbp), %rsi
callq 0xd910
jmp 0x2ff53
movq -0x8(%rbp), %rdi
movl -0x38(%rbp), %edx
addl $0x30, %edx
leaq -0x30(%rbp), %rsi
callq 0xd910
jmp 0x2ff55
jmp 0x2ff7d
movq -0x8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x24, %edx
callq 0xd910
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movsbl (%rax), %edx
leaq -0x30(%rbp), %rsi
callq 0xd910
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x2ffaa
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x28(%rbp)
movsbl (%rax), %edx
leaq -0x30(%rbp), %rsi
callq 0xd910
jmp 0x2fd82
jmp 0x2ffb1
movq -0x10(%rbp), %rax
movzwl 0x10(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x3002d
movq -0x130(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x30000
movq -0x18(%rbp), %rax
cmpb $0x0, (%rax)
je 0x2fffc
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movsbl (%rax), %edx
leaq -0x30(%rbp), %rsi
callq 0xd910
jmp 0x2fffe
jmp 0x3002f
jmp 0x30000
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x18(%rbp), %rdx
leaq -0x140(%rbp), %rcx
movl $0x4, %r8d
callq 0x2fb30
cmpl $0x0, %eax
jne 0x3002b
jmp 0x2fc05
jmp 0x3002d
jmp 0x3002f
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
movslq -0x34(%rbp), %rax
addq %rax, %rdx
leaq -0x30(%rbp), %rsi
callq 0xda70
movq -0x8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
xorl %edx, %edx
callq 0xd910
movq -0x8(%rbp), %rdi
callq 0x14270
movq %rax, %rdi
callq 0x30e0
cmpl $0x0, %eax
je 0x30082
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xd710
movq -0x8(%rbp), %rdi
callq 0x8cb0
movq -0x8(%rbp), %rax
movq %rax, -0x150(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x300a5
movq -0x30(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x158(%rbp)
jmp 0x300b5
leaq 0xc990(%rip), %rax      # 0x3ca3c
movq %rax, -0x158(%rbp)
jmp 0x300b5
movq -0x150(%rbp), %rdi
movq -0x158(%rbp), %rsi
callq 0x13880
movq -0x8(%rbp), %rdi
callq 0x14a10
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xd710
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
nopw (%rax,%rax)