// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x2fae0
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x14b80
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3240
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x3014d
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x14410
jmp 0x30429
movq -0x18(%rbp), %rdi
callq 0x31e0
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rdi
movl $0x2, %esi
callq 0x15290
cmpl $0x0, %eax
je 0x3023b
movq -0x8(%rbp), %rdi
movl $0x2, %esi
callq 0x14410
movq -0x8(%rbp), %rdi
callq 0x8640
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x34(%rbp), %edx
callq 0x13a70
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
cvtsi2sd %rax, %xmm0
callq 0x44d0
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x14410
movq -0x8(%rbp), %rdi
movl $0x3, %esi
callq 0x17ea0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x14b80
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%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
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
movl $0x1, %esi
callq 0x4400
jmp 0x303b0
movq -0x8(%rbp), %rdi
movl $0x2, %esi
callq 0x14b80
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq -0x30(%rbp), %rsi
callq 0xdac0
movq -0x28(%rbp), %rax
cmpb $0x0, (%rax)
je 0x30389
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x24, %eax
jne 0x30365
movq -0x28(%rbp), %rax
movq %rax, %rcx
incq %rcx
movq %rcx, -0x28(%rbp)
movsbl 0x1(%rax), %eax
movl %eax, -0x38(%rbp)
testl %eax, %eax
je 0x302c2
jmp 0x3029a
movl -0x38(%rbp), %eax
subl $0x24, %eax
je 0x302ce
jmp 0x302a4
movl -0x38(%rbp), %eax
subl $0x26, %eax
je 0x302e2
jmp 0x302ae
movl -0x38(%rbp), %eax
subl $0x27, %eax
je 0x30317
jmp 0x302b8
movl -0x38(%rbp), %eax
subl $0x60, %eax
je 0x30300
jmp 0x30331
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 0x30357
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 0x30357
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq -0x30(%rbp), %rsi
callq 0xdac0
jmp 0x30357
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
movslq -0x34(%rbp), %rax
addq %rax, %rdx
leaq -0x30(%rbp), %rsi
callq 0xda70
jmp 0x30357
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 0x30384
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 0x30262
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 0x303dc
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xd710
movq -0x8(%rbp), %rdi
callq 0x8cb0
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x303f9
movq -0x30(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x48(%rbp)
jmp 0x30406
leaq 0xc63c(%rip), %rax      # 0x3ca3c
movq %rax, -0x48(%rbp)
jmp 0x30406
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x13880
movq -0x8(%rbp), %rdi
callq 0x14a10
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xd710
addq $0x50, %rsp
popq %rbp
retq
nop