// File: /workspace/github_c_makefile_star2_O2/ArtifexSoftware[P]mujs/./jsarray.c
// Function: Ap_splice
static void Ap_splice(js_State *J)
{
	int top = js_gettop(J);
	int len, start, del, add, k;

	len = js_getlength(J, 0);
	start = js_tointeger(J, 1);
	if (start < 0)
		start = (len + start) > 0 ? len + start : 0;
	else if (start > len)
		start = len;

	if (js_isdefined(J, 2))
		del = js_tointeger(J, 2);
	else
		del = len - start;
	if (del > len - start)
		del = len - start;
	if (del < 0)
		del = 0;

	js_newarray(J);

	/* copy deleted items to return array */
	for (k = 0; k < del; ++k)
		if (js_hasindex(J, 0, start + k))
			js_setindex(J, -2, k);
	js_setlength(J, -1, del);

	/* shift the tail to resize the hole left by deleted items */
	add = top - 3;
	if (add < del) {
		for (k = start; k < len - del; ++k) {
			if (js_hasindex(J, 0, k + del))
				js_setindex(J, 0, k + add);
			else
				js_delindex(J, 0, k + add);
		}
		for (k = len; k > len - del + add; --k)
			js_delindex(J, 0, k - 1);
	} else if (add > del) {
		for (k = len - del; k > start; --k) {
			if (js_hasindex(J, 0, k + del - 1))
				js_setindex(J, 0, k + add - 1);
			else
				js_delindex(J, 0, k + add - 1);
		}
	}

	/* copy new items into the hole */
	for (k = 0; k < add; ++k) {
		js_copy(J, 3 + k);
		js_setindex(J, 0, start + k);
	}

	js_setlength(J, 0, len - del + add);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movl 0x140(%rdi), %eax
movq %rax, 0x8(%rsp)
movl 0x144(%rdi), %ebp
xorl %r15d, %r15d
xorl %esi, %esi
callq 0x3ecc
movl %eax, %r14d
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x3f23
testl %eax, %eax
js 0x4af6
cmpl %r14d, %eax
cmovgel %r14d, %eax
movl %eax, %r15d
jmp 0x4aff
addl %r14d, %eax
testl %eax, %eax
cmovgl %eax, %r15d
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0xf8a8
testl %eax, %eax
je 0x4b21
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x3f23
movl %r14d, %r12d
subl %r15d, %r12d
jmp 0x4b2a
movl %r14d, %r12d
subl %r15d, %r12d
movl %r12d, %eax
movq 0x8(%rsp), %rcx
subl %ebp, %ecx
movq %rcx, 0x8(%rsp)
cmpl %r12d, %eax
cmovll %eax, %r12d
movq %rbx, %rdi
callq 0xe7d1
xorl %r13d, %r13d
testl %r12d, %r12d
cmovlel %r13d, %r12d
pushq $-0x2
popq %rbp
cmpl %r13d, %r12d
je 0x4b7b
leal (%r15,%r13), %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x10ecd
testl %eax, %eax
je 0x4b76
movq %rbx, %rdi
movl %ebp, %esi
movl %r13d, %edx
callq 0xe9c5
incl %r13d
jmp 0x4b52
pushq $-0x1
popq %rsi
movq %rbx, %rdi
movl %r12d, %edx
callq 0x3f6b
movq 0x8(%rsp), %rax
leal -0x3(%rax), %r13d
cmpl %r12d, %r13d
movq %r14, 0x10(%rsp)
jge 0x4bd3
subl %r12d, %r14d
movl %r15d, %ebp
cmpl %r14d, %ebp
jge 0x4c26
leal (%r12,%rbp), %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x10ecd
leal (%r13,%rbp), %edx
movq %rbx, %rdi
xorl %esi, %esi
testl %eax, %eax
je 0x4bca
callq 0xe9c5
jmp 0x4bcf
callq 0x10fd5
incl %ebp
jmp 0x4ba2
jle 0x4c45
movq 0x10(%rsp), %rax
movl %eax, %r14d
subl %r12d, %r14d
movq 0x8(%rsp), %rcx
addl $-0x4, %ecx
movq %rcx, 0x8(%rsp)
leal -0x1(%rax), %ebp
cmpl %r15d, %r14d
jle 0x4c45
movq %rbx, %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x10ecd
movq 0x8(%rsp), %rcx
leal (%rcx,%r14), %edx
movq %rbx, %rdi
xorl %esi, %esi
testl %eax, %eax
je 0x4c1a
callq 0xe9c5
jmp 0x4c1f
callq 0x10fd5
decl %r14d
decl %ebp
jmp 0x4bf0
addl %r13d, %r14d
movq 0x10(%rsp), %rax
movl %eax, %ebp
cmpl %r14d, %ebp
jle 0x4c45
decl %ebp
movq %rbx, %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x10fd5
jmp 0x4c30
xorl %r14d, %r14d
testl %r13d, %r13d
movl $0x0, %ebp
cmovgl %r13d, %ebp
subl $0x1, %ebp
jb 0x4c7a
leal 0x3(%r14), %esi
movq %rbx, %rdi
callq 0xeee2
movq %rbx, %rdi
xorl %esi, %esi
movl %r15d, %edx
callq 0xe9c5
incl %r14d
incl %r15d
jmp 0x4c54
addl 0x10(%rsp), %r13d
subl %r12d, %r13d
movq %rbx, %rdi
xorl %esi, %esi
movl %r13d, %edx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3f6b