// File: /workspace/github_c_makefile_star2_O1/ccxvii[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), %ebp
xorl %r13d, %r13d
xorl %esi, %esi
callq 0x3fcc
movl %eax, %r14d
movq %rbx, %rdi
movl $0x1, %esi
callq 0x409b
testl %eax, %eax
js 0x50ca
cmpl %r14d, %eax
cmovgel %r14d, %eax
movl %eax, %r13d
jmp 0x50d3
addl %r14d, %eax
testl %eax, %eax
cmovgl %eax, %r13d
movl 0x144(%rbx), %ecx
leaq 0x3b318(%rip), %rax     # 0x403f8
cmpl $-0x2, %ecx
jl 0x50fd
addl $0x2, %ecx
cmpl 0x140(%rbx), %ecx
jge 0x50fd
movl %ecx, %eax
shlq $0x4, %rax
addq 0x148(%rbx), %rax
cmpb $0x1, 0xf(%rax)
jne 0x510b
movl %r14d, %eax
subl %r13d, %eax
jmp 0x5118
movq %rbx, %rdi
movl $0x2, %esi
callq 0x409b
subl %ebp, %r15d
movq %r15, 0x18(%rsp)
movl %r14d, 0x4(%rsp)
movl %r14d, %ebp
subl %r13d, %ebp
cmpl %ebp, %eax
cmovll %eax, %ebp
movq %rbx, %rdi
callq 0x135de
xorl %r14d, %r14d
movl $0x0, %eax
testl %ebp, %ebp
cmovgl %ebp, %eax
movq %rax, 0x10(%rsp)
jle 0x51b1
leaq 0x3b2a5(%rip), %r12     # 0x403f8
movslq 0x144(%rbx), %rax
movq %r12, %rsi
testq %rax, %rax
js 0x517b
movq %r12, %rsi
cmpl 0x140(%rbx), %eax
jge 0x517b
shlq $0x4, %rax
addq 0x148(%rbx), %rax
movq %rax, %rsi
leal (%r14,%r13), %r15d
movq %rbx, %rdi
callq 0x15489
movq %rbx, %rdi
movq %rax, %rsi
movl %r15d, %edx
callq 0x16a4d
testl %eax, %eax
je 0x51a9
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movl %r14d, %edx
callq 0x1393c
incl %r14d
cmpl %r14d, %ebp
jne 0x5153
movq 0x10(%rsp), %r14
cvtsi2sd %r14d, %xmm0
movq %rbx, %rdi
callq 0x4184
leaq 0x2e587(%rip), %rdx     # 0x33751
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x41f3
movq 0x18(%rsp), %r12
leal -0x3(%r12), %eax
movq %rax, 0x8(%rsp)
cmpl %r14d, %eax
jge 0x52a5
movl 0x4(%rsp), %ebp
subl %r14d, %ebp
cmpl %ebp, %r13d
jge 0x5271
leaq 0x3b1f6(%rip), %r15     # 0x403f8
movl %r13d, %r12d
movslq 0x144(%rbx), %rax
movq %r15, %rsi
testq %rax, %rax
js 0x522d
movq %r15, %rsi
cmpl 0x140(%rbx), %eax
jge 0x522d
shlq $0x4, %rax
addq 0x148(%rbx), %rax
movq %rax, %rsi
addl %r12d, %r14d
movq %rbx, %rdi
callq 0x15489
movq %rbx, %rdi
movq %rax, %rsi
movl %r14d, %edx
callq 0x16a4d
movq 0x8(%rsp), %rcx
leal (%rcx,%r12), %edx
movq %rbx, %rdi
xorl %esi, %esi
testl %eax, %eax
je 0x525f
callq 0x1393c
jmp 0x5264
callq 0x16b45
incl %r12d
cmpl %ebp, %r12d
movq 0x10(%rsp), %r14
jl 0x5205
addl 0x8(%rsp), %ebp
movl 0x4(%rsp), %r15d
cmpl %ebp, %r15d
movq 0x18(%rsp), %r12
jle 0x5347
movl %r15d, %r14d
decl %r14d
movq %rbx, %rdi
xorl %esi, %esi
movl %r14d, %edx
callq 0x16b45
cmpl %ebp, %r14d
jg 0x528b
jmp 0x5347
movl 0x4(%rsp), %r15d
jle 0x5347
movl %r15d, %ebp
subl 0x10(%rsp), %ebp
cmpl %r13d, %ebp
jle 0x5347
leal -0x4(%r12), %eax
movq %rax, 0x20(%rsp)
movl %r15d, %r14d
movslq 0x144(%rbx), %rax
leaq 0x3b11d(%rip), %rsi     # 0x403f8
testq %rax, %rax
js 0x52fd
leaq 0x3b111(%rip), %rsi     # 0x403f8
cmpl 0x140(%rbx), %eax
jge 0x52fd
shlq $0x4, %rax
addq 0x148(%rbx), %rax
movq %rax, %rsi
decl %r14d
movq %rbx, %rdi
callq 0x15489
movq %rbx, %rdi
movq %rax, %rsi
movl %r14d, %edx
callq 0x16a4d
testl %eax, %eax
je 0x532e
movq 0x20(%rsp), %rax
leal (%rax,%rbp), %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1393c
jmp 0x5340
movq 0x20(%rsp), %rax
leal (%rax,%rbp), %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x16b45
decl %ebp
cmpl %r13d, %ebp
jg 0x52cd
cmpl $0x4, %r12d
jl 0x5382
movq 0x8(%rsp), %rax
cmpl $0x2, %eax
movl $0x1, %ebp
cmovgel %eax, %ebp
xorl %r14d, %r14d
leal 0x3(%r14), %esi
movq %rbx, %rdi
callq 0x14073
leal (%r14,%r13), %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1393c
incl %r14d
cmpl %r14d, %ebp
jne 0x5360
movq 0x8(%rsp), %rax
addl %r15d, %eax
subl 0x10(%rsp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq %rbx, %rdi
callq 0x4184
leaq 0x2e3ad(%rip), %rdx     # 0x33751
movq %rbx, %rdi
xorl %esi, %esi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x41f3