// File: /workspace/github_c_makefile_star2_O2/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, %r12d
movq %rsi, %r14
movq %rdi, %r15
movl 0x8(%rdi), %ecx
movl 0x8(%rsi), %eax
pushq $0x1
popq %rbx
testl %edx, %edx
je 0x3b349
cmpl %eax, %ecx
movl %ecx, %eax
jne 0x3b381
movl %eax, %edx
orl %ecx, %edx
testw $0x128, %dx             # imm = 0x128
je 0x3b392
testb $0x8, %cl
jne 0x3b365
movq %r15, %rdi
callq 0x3ab00
movl 0x8(%r14), %eax
testb $0x8, %al
jne 0x3b371
movq %r14, %rdi
callq 0x3ab00
xorl %ebx, %ebx
cmpq $0x0, (%r15)
setne %bl
cmpq $0x1, (%r14)
adcl $-0x1, %ebx
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb $0x40, %dl
jne 0x3b3e9
testb $0x1, %dl
jne 0x3b3f3
testb $0x6, %dl
je 0x3b4ef
testb $0x6, %cl
jne 0x3b3b6
movq %r15, %rdi
callq 0x3acd2
movl 0x8(%r14), %eax
testb $0x6, %al
jne 0x3b3c6
movq %r14, %rdi
callq 0x3acd2
movl 0x8(%r14), %eax
movl 0x8(%r15), %ecx
movl %ecx, %edx
andl %eax, %edx
testb $0x2, %dl
je 0x3b4f6
movq (%r14), %rax
cmpq %rax, (%r15)
jg 0x3b381
setl %al
movzbl %al, %ebx
negl %ebx
jmp 0x3b381
testb $0x40, %cl
jne 0x3b453
pushq $-0x1
popq %rbx
jmp 0x3b381
testb $0x1, %cl
jne 0x3b404
movq %r15, %rdi
callq 0x36bcf
movl 0x8(%r14), %eax
testb $0x1, %al
jne 0x3b410
movq %r14, %rdi
callq 0x36bcf
movq 0x20(%r15), %rdi
movl 0x28(%r15), %r15d
movq 0x20(%r14), %rsi
movl 0x28(%r14), %r14d
cmpl %r14d, %r15d
movl %r14d, %edx
cmovbl %r15d, %edx
callq 0x2d30e
movl %eax, %ebx
testl %eax, %eax
jne 0x3b381
xorl %eax, %eax
cmpl %r14d, %r15d
movl $0x0, %ebx
sbbl %ebx, %ebx
orl $0x1, %ebx
cmpl %r14d, %r15d
cmovel %eax, %ebx
jmp 0x3b381
testb $0x40, %al
je 0x3b381
movq (%r15), %rax
movq (%r14), %r14
xorl %ebx, %ebx
cmpq %r14, %rax
je 0x3b381
movl 0x2c(%rax), %r13d
movl 0x2c(%r14), %ecx
cmpl %ecx, %r13d
jne 0x3b53e
movq 0x10(%rax), %r15
leaq -0x30(%rbp), %rax
andq $0x0, (%rax)
subl $0x1, %r13d
jb 0x3b381
cmpl $0x1, 0x8(%r15)
jne 0x3b4ac
movq 0x10(%r15), %rsi
movq %r14, %rdi
leaq -0x30(%rbp), %rdx
callq 0x36e57
jmp 0x3b4c0
movq 0x18(%r15), %rsi
movl 0x20(%r15), %edx
movq %r14, %rdi
leaq -0x30(%rbp), %rcx
callq 0x36c0a
testl %eax, %eax
jne 0x3b54e
movq -0x30(%rbp), %rsi
testl %r12d, %r12d
je 0x3b4da
movl 0x8(%r15), %eax
cmpl 0x8(%rsi), %eax
jne 0x3b54e
movq %r15, %rdi
movl %r12d, %edx
callq 0x3bc56
testl %eax, %eax
jne 0x3b555
movq 0x48(%r15), %r15
jmp 0x3b489
xorl %ebx, %ebx
jmp 0x3b381
testb $0x4, %cl
jne 0x3b507
movq %r15, %rdi
callq 0x3ac20
movl 0x8(%r14), %eax
movsd (%r15), %xmm1
testb $0x4, %al
jne 0x3b522
movq %r14, %rdi
movsd %xmm1, -0x38(%rbp)
callq 0x3ac20
movsd -0x38(%rbp), %xmm1
movsd (%r14), %xmm0
xorl %eax, %eax
ucomisd %xmm1, %xmm0
seta %al
negl %eax
ucomisd %xmm0, %xmm1
cmovbel %eax, %ebx
jmp 0x3b381
xorl %ebx, %ebx
cmpl %r13d, %ecx
adcl $-0x1, %ebx
orl $0x1, %ebx
jmp 0x3b381
pushq $0x1
jmp 0x3b3f0
movl %eax, %ebx
jmp 0x3b381