// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
movq %rdi, %rbx
movl 0x140(%rdi), %r15d
movl 0x144(%rdi), %r14d
xorl %r12d, %r12d
xorl %esi, %esi
callq 0x3f6c
movl %eax, %ebp
movq %rbx, %rdi
movl $0x1, %esi
callq 0x403b
testl %eax, %eax
js 0x503b
cmpl %ebp, %eax
cmovgel %ebp, %eax
movl %eax, %r12d
jmp 0x5043
addl %ebp, %eax
testl %eax, %eax
cmovgl %eax, %r12d
movl 0x144(%rbx), %ecx
leaq 0x3b3a8(%rip), %rax     # 0x403f8
cmpl $-0x2, %ecx
jl 0x506d
addl $0x2, %ecx
cmpl 0x140(%rbx), %ecx
jge 0x506d
movl %ecx, %eax
shlq $0x4, %rax
addq 0x148(%rbx), %rax
cmpb $0x1, 0xf(%rax)
movl %ebp, 0x4(%rsp)
jne 0x507e
subl %r12d, %ebp
movl %ebp, %eax
jmp 0x508e
movq %rbx, %rdi
movl $0x2, %esi
callq 0x403b
subl %r12d, %ebp
subl %r14d, %r15d
movq %r15, 0x18(%rsp)
cmpl %ebp, %eax
cmovll %eax, %ebp
movq %rbx, %rdi
callq 0x1318e
xorl %r14d, %r14d
movl $0x0, %eax
testl %ebp, %ebp
cmovgl %ebp, %eax
movq %rax, 0x8(%rsp)
jle 0x511c
leaq 0x3b33a(%rip), %r13     # 0x403f8
movslq 0x144(%rbx), %rax
movq %r13, %rsi
testq %rax, %rax
js 0x50e6
movq %r13, %rsi
cmpl 0x140(%rbx), %eax
jge 0x50e6
shlq $0x4, %rax
addq 0x148(%rbx), %rax
movq %rax, %rsi
leal (%r12,%r14), %r15d
movq %rbx, %rdi
callq 0x14fb2
movq %rbx, %rdi
movq %rax, %rsi
movl %r15d, %edx
callq 0x1658a
testl %eax, %eax
je 0x5114
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movl %r14d, %edx
callq 0x134ed
incl %r14d
cmpl %r14d, %ebp
jne 0x50be
movq 0x8(%rsp), %r14
cvtsi2sd %r14d, %xmm0
movq %rbx, %rdi
callq 0x4124
leaq 0x2e64c(%rip), %rdx     # 0x33781
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x4193
movq 0x18(%rsp), %r15
leal -0x3(%r15), %eax
movq %rax, 0x10(%rsp)
cmpl %r14d, %eax
jge 0x520f
movl 0x4(%rsp), %ebp
subl %r14d, %ebp
cmpl %ebp, %r12d
jge 0x51db
leaq 0x3b28c(%rip), %r15     # 0x403f8
movl %r12d, %r13d
movslq 0x144(%rbx), %rax
movq %r15, %rsi
testq %rax, %rax
js 0x5197
movq %r15, %rsi
cmpl 0x140(%rbx), %eax
jge 0x5197
shlq $0x4, %rax
addq 0x148(%rbx), %rax
movq %rax, %rsi
addl %r13d, %r14d
movq %rbx, %rdi
callq 0x14fb2
movq %rbx, %rdi
movq %rax, %rsi
movl %r14d, %edx
callq 0x1658a
movq 0x10(%rsp), %rcx
leal (%rcx,%r13), %edx
movq %rbx, %rdi
xorl %esi, %esi
testl %eax, %eax
je 0x51c9
callq 0x134ed
jmp 0x51ce
callq 0x16682
incl %r13d
cmpl %ebp, %r13d
movq 0x8(%rsp), %r14
jl 0x516f
addl 0x10(%rsp), %ebp
movl 0x4(%rsp), %r13d
cmpl %ebp, %r13d
movq 0x18(%rsp), %r15
jle 0x529f
movl %r13d, %r14d
decl %r14d
movq %rbx, %rdi
xorl %esi, %esi
movl %r14d, %edx
callq 0x16682
cmpl %ebp, %r14d
jg 0x51f5
jmp 0x529f
movl 0x4(%rsp), %r13d
jle 0x529f
movl %r13d, %ebp
subl 0x8(%rsp), %ebp
cmpl %r12d, %ebp
jle 0x529f
leal -0x4(%r15), %eax
movq %rax, 0x20(%rsp)
movl %r13d, %r14d
movslq 0x144(%rbx), %rax
leaq 0x3b1b8(%rip), %rsi     # 0x403f8
testq %rax, %rax
js 0x5262
leaq 0x3b1ac(%rip), %rsi     # 0x403f8
cmpl 0x140(%rbx), %eax
jge 0x5262
shlq $0x4, %rax
addq 0x148(%rbx), %rax
movq %rax, %rsi
decl %r14d
movq %rbx, %rdi
callq 0x14fb2
movq %rbx, %rdi
movq %rax, %rsi
movl %r14d, %edx
callq 0x1658a
movq 0x20(%rsp), %rcx
leal (%rcx,%rbp), %edx
movq %rbx, %rdi
xorl %esi, %esi
testl %eax, %eax
je 0x5293
callq 0x134ed
jmp 0x5298
callq 0x16682
decl %ebp
cmpl %r12d, %ebp
jg 0x5232
cmpl $0x4, %r15d
jl 0x52cf
movl $0x3, %r14d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x13c1a
leal (%r12,%r14), %edx
addl $-0x3, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x134ed
incl %r14d
cmpl %r14d, %r15d
jne 0x52ab
movq 0x10(%rsp), %rax
addl %r13d, %eax
subl 0x8(%rsp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq %rbx, %rdi
callq 0x4124
leaq 0x2e490(%rip), %rdx     # 0x33781
movq %rbx, %rdi
xorl %esi, %esi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4193