// File: /workspace/github_c_makefile_star2_O2/ArtifexSoftware[P]mujs/./jsarray.c
// Function: Ap_sort_cmp
static int Ap_sort_cmp(js_State *J, int idx_a, int idx_b)
{
	js_Object *obj = js_tovalue(J, 0)->u.object;
	if (obj->u.a.simple) {
		js_Value *val_a = &obj->u.a.array[idx_a];
		js_Value *val_b = &obj->u.a.array[idx_b];
		int und_a = val_a->t.type == JS_TUNDEFINED;
		int und_b = val_b->t.type == JS_TUNDEFINED;
		if (und_a) return und_b;
		if (und_b) return -1;
		if (js_iscallable(J, 1)) {
			double v;
			js_copy(J, 1); /* copy function */
			js_pushundefined(J); /* no 'this' binding */
			js_pushvalue(J, *val_a);
			js_pushvalue(J, *val_b);
			js_call(J, 2);
			v = js_tonumber(J, -1);
			js_pop(J, 1);
			if (isnan(v))
				return 0;
			if (v == 0)
				return 0;
			return v < 0 ? -1 : 1;
		} else {
			const char *str_a, *str_b;
			int c;
			js_pushvalue(J, *val_a);
			js_pushvalue(J, *val_b);
			str_a = js_tostring(J, -2);
			str_b = js_tostring(J, -1);
			c = strcmp(str_a, str_b);
			js_pop(J, 2);
			return c;
		}
	} else {
		int und_a, und_b;
		int has_a = js_hasindex(J, 0, idx_a);
		int has_b = js_hasindex(J, 0, idx_b);
		if (!has_a && !has_b) {
			return 0;
		}
		if (has_a && !has_b) {
			js_pop(J, 1);
			return -1;
		}
		if (!has_a && has_b) {
			js_pop(J, 1);
			return 1;
		}

		und_a = js_isundefined(J, -2);
		und_b = js_isundefined(J, -1);
		if (und_a) {
			js_pop(J, 2);
			return und_b;
		}
		if (und_b) {
			js_pop(J, 2);
			return -1;
		}

		if (js_iscallable(J, 1)) {
			double v;
			js_copy(J, 1); /* copy function */
			js_pushundefined(J); /* no 'this' binding */
			js_copy(J, -4);
			js_copy(J, -4);
			js_call(J, 2);
			v = js_tonumber(J, -1);
			js_pop(J, 3);
			if (isnan(v))
				return 0;
			if (v == 0)
				return 0;
			return v < 0 ? -1 : 1;
		} else {
			const char *str_a = js_tostring(J, -2);
			const char *str_b = js_tostring(J, -1);
			int c = strcmp(str_a, str_b);
			js_pop(J, 2);
			return c;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl %edx, %r14d
movl %esi, %edx
movq %rdi, %rbx
movslq 0x144(%rdi), %rax
leaq 0x21dce(%rip), %rcx     # 0x373f8
testq %rax, %rax
js 0x15645
cmpl 0x140(%rbx), %eax
jge 0x15645
shlq $0x4, %rax
addq 0x148(%rbx), %rax
movq %rax, %rcx
movq (%rcx), %rax
cmpl $0x0, 0x24(%rax)
je 0x1567b
movq 0x30(%rax), %rax
movslq %edx, %r15
shlq $0x4, %r15
movslq %r14d, %r14
shlq $0x4, %r14
cmpb $0x1, 0xf(%rax,%r15)
movb 0xf(%rax,%r14), %cl
jne 0x156d7
xorl %ebp, %ebp
cmpb $0x1, %cl
sete %bpl
jmp 0x1582b
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %esi, %esi
callq 0x10ecd
movl %eax, %r15d
movq %rbx, %rdi
xorl %esi, %esi
movl %r14d, %edx
callq 0x10ecd
movl %r15d, %ecx
orl %eax, %ecx
je 0x1582b
testl %eax, %eax
setne %cl
testl %r15d, %r15d
sete %dl
orb %cl, %dl
je 0x1577b
testl %r15d, %r15d
sete %cl
testl %eax, %eax
setne %al
andb %cl, %al
cmpb $0x1, %al
jne 0x157df
pushq $0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
jmp 0x157d8
cmpb $0x1, %cl
je 0x15786
addq %rax, %r15
addq %rax, %r14
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xf950
testl %eax, %eax
je 0x1578e
pushq $0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
callq 0xeee2
movq %rbx, %rdi
callq 0x7336
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq %rbx, %rdi
callq 0xf74a
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %rbx, %rdi
callq 0xf74a
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x110b0
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xfb28
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x3f3d
movsd 0x8(%rsp), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
je 0x15814
xorl %eax, %eax
ucomisd %xmm1, %xmm0
setbe %al
leal -0x1(,%rax,2), %ebp
jmp 0x1582b
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x3f3d
pushq $-0x1
popq %rbp
jmp 0x1582b
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq %rbx, %rdi
callq 0xf74a
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %rbx, %rdi
callq 0xf74a
pushq $-0x2
popq %rsi
movq %rbx, %rdi
callq 0xf64d
movq %rax, %r14
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xf64d
movq %r14, %rdi
movq %rax, %rsi
callq 0x32f0
movl %eax, %ebp
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x3f3d
jmp 0x1582b
pushq $-0x2
popq %rsi
movq %rbx, %rdi
callq 0xf8bb
movl %eax, %r12d
pushq $-0x1
popq %r14
movq %rbx, %rdi
movl %r14d, %esi
callq 0xf8bb
movl %eax, %r15d
testl %r12d, %r12d
je 0x15818
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x3f3d
movl %r15d, %ebp
jmp 0x1582b
xorl %ebp, %ebp
jmp 0x1582b
testl %r15d, %r15d
je 0x1583a
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x3f3d
movl %r14d, %ebp
movl %ebp, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xf950
testl %eax, %eax
je 0x157ac
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xeee2
movq %rbx, %rdi
callq 0x7336
pushq $-0x4
popq %r14
movq %rbx, %rdi
movl %r14d, %esi
callq 0xeee2
movq %rbx, %rdi
movl %r14d, %esi
callq 0xeee2
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x110b0
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xfb28
movsd %xmm0, 0x8(%rsp)
pushq $0x3
popq %rsi
movq %rbx, %rdi
callq 0x3f3d
movsd 0x8(%rsp), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x15766
jmp 0x1582b