// File: /workspace/github_c_makefile_star2_O1/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3MemCompare
SQLITE_PRIVATE int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){
  int rc;
  int f1, f2;
  int combined_flags;

  f1 = pMem1->flags;
  f2 = pMem2->flags;
  combined_flags = f1|f2;
  assert( (combined_flags & MEM_RowSet)==0 );
 
  /* If one value is NULL, it is less than the other. If both values
  ** are NULL, return 0.
  */
  if( combined_flags&MEM_Null ){
    return (f2&MEM_Null) - (f1&MEM_Null);
  }

  /* If one value is a number and the other is not, the number is less.
  ** If both are numbers, compare as reals if one is a real, or as integers
  ** if both values are integers.
  */
  if( combined_flags&(MEM_Int|MEM_Real) ){
    double r1, r2;
    if( (f1 & f2 & MEM_Int)!=0 ){
      if( pMem1->u.i < pMem2->u.i ) return -1;
      if( pMem1->u.i > pMem2->u.i ) return 1;
      return 0;
    }
    if( (f1&MEM_Real)!=0 ){
      r1 = pMem1->r;
    }else if( (f1&MEM_Int)!=0 ){
      r1 = (double)pMem1->u.i;
    }else{
      return 1;
    }
    if( (f2&MEM_Real)!=0 ){
      r2 = pMem2->r;
    }else if( (f2&MEM_Int)!=0 ){
      r2 = (double)pMem2->u.i;
    }else{
      return -1;
    }
    if( r1<r2 ) return -1;
    if( r1>r2 ) return 1;
    return 0;
  }

  /* If one value is a string and the other is a blob, the string is less.
  ** If both are strings, compare using the collating functions.
  */
  if( combined_flags&MEM_Str ){
    if( (f1 & MEM_Str)==0 ){
      return 1;
    }
    if( (f2 & MEM_Str)==0 ){
      return -1;
    }

    assert( pMem1->enc==pMem2->enc );
    assert( pMem1->enc==SQLITE_UTF8 || 
            pMem1->enc==SQLITE_UTF16LE || pMem1->enc==SQLITE_UTF16BE );

    /* The collation sequence must be defined at this point, even if
    ** the user deletes the collation sequence after the vdbe program is
    ** compiled (this was not always the case).
    */
    assert( !pColl || pColl->xCmp );

    if( pColl ){
      if( pMem1->enc==pColl->enc ){
        /* The strings are already in the correct encoding.  Call the
        ** comparison function directly */
        return pColl->xCmp(pColl->pUser,pMem1->n,pMem1->z,pMem2->n,pMem2->z);
      }else{
        const void *v1, *v2;
        int n1, n2;
        Mem c1;
        Mem c2;
        memset(&c1, 0, sizeof(c1));
        memset(&c2, 0, sizeof(c2));
        sqlite3VdbeMemShallowCopy(&c1, pMem1, MEM_Ephem);
        sqlite3VdbeMemShallowCopy(&c2, pMem2, MEM_Ephem);
        v1 = sqlite3ValueText((sqlite3_value*)&c1, pColl->enc);
        n1 = v1==0 ? 0 : c1.n;
        v2 = sqlite3ValueText((sqlite3_value*)&c2, pColl->enc);
        n2 = v2==0 ? 0 : c2.n;
        rc = pColl->xCmp(pColl->pUser, n1, v1, n2, v2);
        sqlite3VdbeMemRelease(&c1);
        sqlite3VdbeMemRelease(&c2);
        return rc;
      }
    }
    /* If a NULL pointer was passed as the collate function, fall through
    ** to the blob case and use memcmp().  */
  }
 
  /* Both values must be blobs.  Compare using memcmp().  */
  rc = memcmp(pMem1->z, pMem2->z, (pMem1->n>pMem2->n)?pMem2->n:pMem1->n);
  if( rc==0 ){
    rc = pMem1->n - pMem2->n;
  }
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdx, %r14
movq %rsi, %rbx
movzwl 0x24(%rdi), %edx
movzwl 0x24(%rsi), %ecx
movl %ecx, %esi
orl %edx, %esi
testb $0x1, %sil
jne 0x2c177
movq %rdi, %rax
testb $0xc, %sil
je 0x2c194
movl %edx, %esi
andl %ecx, %esi
testb $0x4, %sil
je 0x2c1c1
movq 0x18(%rbx), %rcx
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpq %rcx, 0x18(%rax)
jl 0x2c182
setg %al
movzbl %al, %r15d
jmp 0x2c182
andl $0x1, %ecx
andl $0x1, %edx
subl %edx, %ecx
movl %ecx, %r15d
movl %r15d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb $0x2, %sil
jne 0x2c1d9
movq 0x8(%rax), %rdi
movq 0x8(%rbx), %rsi
movl 0x20(%rax), %eax
movl 0x20(%rbx), %ecx
movl %eax, %r15d
subl %ecx, %r15d
cmovll %eax, %ecx
movslq %ecx, %rdx
callq 0x81a0
testl %eax, %eax
cmovnel %eax, %r15d
jmp 0x2c182
testb $0x8, %dl
jne 0x2c224
movl $0x1, %r15d
testb $0x4, %dl
je 0x2c182
cvtsi2sdq 0x18(%rax), %xmm0
jmp 0x2c229
movl $0x1, %r15d
testb $0x2, %dl
je 0x2c182
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testb $0x2, %cl
je 0x2c182
testq %r14, %r14
je 0x2c19a
movb 0x27(%rax), %cl
cmpb 0x8(%r14), %cl
jne 0x2c26a
movq 0x10(%r14), %rdi
movq 0x18(%r14), %r9
movl 0x20(%rax), %esi
movq 0x8(%rax), %rdx
movl 0x20(%rbx), %ecx
movq 0x8(%rbx), %r8
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *%r9
movsd 0x10(%rax), %xmm0
testb $0x8, %cl
jne 0x2c245
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testb $0x4, %cl
je 0x2c182
cvtsi2sdq 0x18(%rbx), %xmm1
jmp 0x2c24a
movsd 0x10(%rbx), %xmm1
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
ucomisd %xmm0, %xmm1
ja 0x2c182
xorl %r15d, %r15d
ucomisd %xmm1, %xmm0
seta %r15b
jmp 0x2c182
xorpd %xmm0, %xmm0
leaq -0x60(%rbp), %r12
movapd %xmm0, (%r12)
movapd %xmm0, 0x10(%r12)
movapd %xmm0, 0x20(%r12)
xorl %r15d, %r15d
movq %r15, 0x30(%r12)
leaq -0xa0(%rbp), %r13
movapd %xmm0, (%r13)
movapd %xmm0, 0x10(%r13)
movapd %xmm0, 0x20(%r13)
movq %r15, 0x30(%r13)
movq %r12, %rdi
movq %rax, %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x2be1f
movq %r13, %rdi
movq %rbx, %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x2be1f
movzbl 0x8(%r14), %esi
movq %r12, %rdi
callq 0xee49
movq %rax, %rbx
movl $0x0, %r12d
testq %rax, %rax
je 0x2c2ea
movl -0x40(%rbp), %r12d
movzbl 0x8(%r14), %esi
movq %r13, %rdi
callq 0xee49
testq %rax, %rax
je 0x2c300
movl -0x80(%rbp), %r15d
movq 0x10(%r14), %rdi
movl %r12d, %esi
movq %rbx, %rdx
movl %r15d, %ecx
movq %rax, %r8
callq *0x18(%r14)
movl %eax, %r15d
leaq -0x60(%rbp), %rdi
callq 0xec23
movq %r13, %rdi
callq 0xec23
jmp 0x2c182