// File: /workspace/github_c_makefile_star2_O3/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9MemObjCmp
JX9_PRIVATE sxi32 jx9MemObjCmp(jx9_value *pObj1, jx9_value *pObj2, int bStrict, int iNest)
{
	sxi32 iComb; 
	sxi32 rc;
	if( bStrict ){
		sxi32 iF1, iF2;
		/* Strict comparisons with === */
		iF1 = pObj1->iFlags;
		iF2 = pObj2->iFlags;
		if( iF1 != iF2 ){
			/* Not of the same type */
			return 1;
		}
	}
	/* Combine flag together */
	iComb = pObj1->iFlags|pObj2->iFlags;
	if( iComb & (MEMOBJ_NULL|MEMOBJ_RES|MEMOBJ_BOOL) ){
		/* Convert to boolean: Keep in mind FALSE < TRUE */
		if( (pObj1->iFlags & MEMOBJ_BOOL) == 0 ){
			jx9MemObjToBool(pObj1);
		}
		if( (pObj2->iFlags & MEMOBJ_BOOL) == 0 ){
			jx9MemObjToBool(pObj2);
		}
		return (sxi32)((pObj1->x.iVal != 0) - (pObj2->x.iVal != 0));
	}else if ( iComb & MEMOBJ_HASHMAP ){
		/* Hashmap aka 'array' comparison */
		if( (pObj1->iFlags & MEMOBJ_HASHMAP) == 0 ){
			/* Array is always greater */
			return -1;
		}
		if( (pObj2->iFlags & MEMOBJ_HASHMAP) == 0 ){
			/* Array is always greater */
			return 1;
		}
		/* Perform the comparison */
		rc = jx9HashmapCmp((jx9_hashmap *)pObj1->x.pOther, (jx9_hashmap *)pObj2->x.pOther, bStrict);
		return rc;
	}else if ( iComb & MEMOBJ_STRING ){
		SyString s1, s2;
		/* Perform a strict string comparison.*/
		if( (pObj1->iFlags&MEMOBJ_STRING) == 0 ){
			jx9MemObjToString(pObj1);
		}
		if( (pObj2->iFlags&MEMOBJ_STRING) == 0 ){
			jx9MemObjToString(pObj2);
		}
		SyStringInitFromBuf(&s1, SyBlobData(&pObj1->sBlob), SyBlobLength(&pObj1->sBlob));
		SyStringInitFromBuf(&s2, SyBlobData(&pObj2->sBlob), SyBlobLength(&pObj2->sBlob));
		/*
		 * Strings are compared using memcmp(). If one value is an exact prefix of the
		 * other, then the shorter value is less than the longer value.
		 */
		rc = SyMemcmp((const void *)s1.zString, (const void *)s2.zString, SXMIN(s1.nByte, s2.nByte));
		if( rc == 0 ){
			if( s1.nByte != s2.nByte ){
				rc = s1.nByte < s2.nByte ? -1 : 1;
			}
		}
		return rc;
	}else if( iComb & (MEMOBJ_INT|MEMOBJ_REAL) ){
		/* Perform a numeric comparison if one of the operand is numeric(integer or real) */
		if( (pObj1->iFlags & (MEMOBJ_INT|MEMOBJ_REAL)) == 0 ){
			jx9MemObjToNumeric(pObj1);
		}
		if( (pObj2->iFlags & (MEMOBJ_INT|MEMOBJ_REAL)) == 0 ){
			jx9MemObjToNumeric(pObj2);
		}
		if( (pObj1->iFlags & pObj2->iFlags & MEMOBJ_INT) == 0) {
			jx9_real r1, r2;
			/* Compare as reals */
			if( (pObj1->iFlags & MEMOBJ_REAL) == 0 ){
				jx9MemObjToReal(pObj1);
			}
			r1 = pObj1->x.rVal;	
			if( (pObj2->iFlags & MEMOBJ_REAL) == 0 ){
				jx9MemObjToReal(pObj2);
			}
			r2 = pObj2->x.rVal;
			if( r1 > r2 ){
				return 1;
			}else if( r1 < r2 ){
				return -1;
			}
			return 0;
		}else{
			/* Integer comparison */
			if( pObj1->x.iVal > pObj2->x.iVal ){
				return 1;
			}else if( pObj1->x.iVal < pObj2->x.iVal ){
				return -1;
			}
			return 0;
		}
	}
	/* NOT REACHED */
	SXUNUSED(iNest);
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %r15d
movq %rsi, %rbx
movq %rdi, %r14
movl 0x8(%rdi), %edx
movl 0x8(%rsi), %ecx
testl %r15d, %r15d
je 0x442a0
movl $0x1, %eax
cmpl %ecx, %edx
movl %edx, %ecx
jne 0x442d8
movl %ecx, %eax
orl %edx, %eax
testl $0x128, %eax            # imm = 0x128
je 0x442e7
testb $0x8, %dl
jne 0x442bb
movq %r14, %rdi
callq 0x438dd
movl 0x8(%rbx), %ecx
testb $0x8, %cl
jne 0x442c8
movq %rbx, %rdi
callq 0x438dd
xorl %eax, %eax
cmpq $0x0, (%r14)
setne %al
cmpq $0x1, (%rbx)
adcl $-0x1, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb $0x40, %al
jne 0x44343
testb $0x1, %al
jne 0x443fe
testb $0x6, %al
je 0x443f7
testb $0x6, %dl
jne 0x4430b
movq %r14, %rdi
callq 0x43b00
movl 0x8(%rbx), %ecx
testb $0x6, %cl
jne 0x4431b
movq %rbx, %rdi
callq 0x43b00
movl 0x8(%rbx), %ecx
movl 0x8(%r14), %eax
movl %eax, %edx
andl %ecx, %edx
testb $0x2, %dl
je 0x4445a
movq (%rbx), %rcx
movl $0x1, %eax
cmpq %rcx, (%r14)
jg 0x442d8
setl %al
movzbl %al, %eax
negl %eax
jmp 0x442d8
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testb $0x40, %dl
je 0x442d8
movl $0x1, %eax
testb $0x40, %cl
je 0x442d8
movq (%r14), %rax
movq (%rbx), %rbx
cmpq %rbx, %rax
je 0x443f7
movl 0x2c(%rax), %r13d
movl 0x2c(%rbx), %ecx
cmpl %ecx, %r13d
jne 0x444a5
movq 0x10(%rax), %r14
movq $0x0, -0x30(%rbp)
testl %r13d, %r13d
je 0x443f7
leaq -0x30(%rbp), %r12
cmpl $0x1, 0x8(%r14)
jne 0x443a3
movq 0x10(%r14), %rsi
movq %rbx, %rdi
movq %r12, %rdx
callq 0x3f43c
jmp 0x443b6
movq 0x18(%r14), %rsi
movl 0x20(%r14), %edx
movq %rbx, %rdi
movq %r12, %rcx
callq 0x3f1b7
movl %eax, %ecx
movl $0x1, %eax
testl %ecx, %ecx
jne 0x442d8
movq -0x30(%rbp), %rsi
testl %r15d, %r15d
je 0x443db
movl 0x8(%r14), %ecx
cmpl 0x8(%rsi), %ecx
jne 0x442d8
movq %r14, %rdi
movl %r15d, %edx
callq 0x44c71
testl %eax, %eax
jne 0x442d8
movq 0x48(%r14), %r14
decl %r13d
jne 0x4438b
xorl %eax, %eax
jmp 0x442d8
testb $0x1, %dl
jne 0x4440e
movq %r14, %rdi
callq 0x3f163
movl 0x8(%rbx), %ecx
testb $0x1, %cl
jne 0x4441b
movq %rbx, %rdi
callq 0x3f163
movq 0x20(%r14), %rdi
movl 0x28(%r14), %r14d
movq 0x20(%rbx), %rsi
movl 0x28(%rbx), %ebx
cmpl %ebx, %r14d
movl %ebx, %edx
cmovbl %r14d, %edx
callq 0x347f1
testl %eax, %eax
jne 0x442d8
xorl %ecx, %ecx
cmpl %ebx, %r14d
movl $0x0, %eax
sbbl %eax, %eax
orl $0x1, %eax
cmpl %ebx, %r14d
cmovel %ecx, %eax
jmp 0x442d8
testb $0x4, %al
jne 0x44469
movq %r14, %rdi
callq 0x43a31
movl 0x8(%rbx), %ecx
movsd (%r14), %xmm1
testb $0x4, %cl
jne 0x44485
movq %rbx, %rdi
movsd %xmm1, -0x38(%rbp)
callq 0x43a31
movsd -0x38(%rbp), %xmm1
movsd (%rbx), %xmm0
xorl %ecx, %ecx
ucomisd %xmm1, %xmm0
seta %cl
negl %ecx
ucomisd %xmm0, %xmm1
movl $0x1, %eax
cmovbel %ecx, %eax
jmp 0x442d8
xorl %eax, %eax
cmpl %r13d, %ecx
adcl $-0x1, %eax
orl $0x1, %eax
jmp 0x442d8