// File: /workspace/github_c_makefile_star2_O3/skeeto[P]flappy/sqlite3.c
// Function: sqlite3VdbeRecordCompare
SQLITE_PRIVATE int sqlite3VdbeRecordCompare(
  int nKey1, const void *pKey1, /* Left key */
  UnpackedRecord *pPKey2        /* Right key */
){
  u32 d1;            /* Offset into aKey[] of next data element */
  u32 idx1;          /* Offset into aKey[] of next header element */
  u32 szHdr1;        /* Number of bytes in header */
  int i = 0;
  int rc = 0;
  const unsigned char *aKey1 = (const unsigned char *)pKey1;
  KeyInfo *pKeyInfo;
  Mem mem1;

  pKeyInfo = pPKey2->pKeyInfo;
  mem1.enc = pKeyInfo->enc;
  mem1.db = pKeyInfo->db;
  /* mem1.flags = 0;  // Will be initialized by sqlite3VdbeSerialGet() */
  VVA_ONLY( mem1.zMalloc = 0; ) /* Only needed by assert() statements */

  /* Compilers may complain that mem1.u.i is potentially uninitialized.
  ** We could initialize it, as shown here, to silence those complaints.
  ** But in fact, mem1.u.i will never actually be used uninitialized, and doing 
  ** the unnecessary initialization has a measurable negative performance
  ** impact, since this routine is a very high runner.  And so, we choose
  ** to ignore the compiler warnings and leave this variable uninitialized.
  */
  /*  mem1.u.i = 0;  // not needed, here to silence compiler warning */
  
  idx1 = getVarint32(aKey1, szHdr1);
  d1 = szHdr1;
  assert( pKeyInfo->nField+pKeyInfo->nXField>=pPKey2->nField || CORRUPT_DB );
  assert( pKeyInfo->aSortOrder!=0 );
  assert( pKeyInfo->nField>0 );
  assert( idx1<=szHdr1 || CORRUPT_DB );
  do{
    u32 serial_type1;

    /* Read the serial types for the next element in each key. */
    idx1 += getVarint32( aKey1+idx1, serial_type1 );

    /* Verify that there is enough key space remaining to avoid
    ** a buffer overread.  The "d1+serial_type1+2" subexpression will
    ** always be greater than or equal to the amount of required key space.
    ** Use that approximation to avoid the more expensive call to
    ** sqlite3VdbeSerialTypeLen() in the common case.
    */
    if( d1+serial_type1+2>(u32)nKey1
     && d1+sqlite3VdbeSerialTypeLen(serial_type1)>(u32)nKey1 
    ){
      break;
    }

    /* Extract the values to be compared.
    */
    d1 += sqlite3VdbeSerialGet(&aKey1[d1], serial_type1, &mem1);

    /* Do the comparison
    */
    rc = sqlite3MemCompare(&mem1, &pPKey2->aMem[i], pKeyInfo->aColl[i]);
    if( rc!=0 ){
      assert( mem1.zMalloc==0 );  /* See comment below */
      if( pKeyInfo->aSortOrder[i] ){
        rc = -rc;  /* Invert the result for DESC sort order. */
      }
      return rc;
    }
    i++;
  }while( idx1<szHdr1 && i<pPKey2->nField );

  /* No memory allocation is ever used on mem1.  Prove this using
  ** the following assert().  If the assert() fails, it indicates a
  ** memory leak and a need to call sqlite3VdbeMemRelease(&mem1).
  */
  assert( mem1.zMalloc==0 );

  /* rc==0 here means that one of the keys ran out of fields and
  ** all the fields up to that point were equal. If the UNPACKED_INCRKEY
  ** flag is set, then break the tie by treating key2 as larger.
  ** If the UPACKED_PREFIX_MATCH flag is set, then keys with common prefixes
  ** are considered to be equal.  Otherwise, the longer key is the 
  ** larger.  As it happens, the pPKey2 will always be the longer
  ** if there is a difference.
  */
  assert( rc==0 );
  if( pPKey2->flags & UNPACKED_INCRKEY ){
    rc = -1;
  }else if( pPKey2->flags & UNPACKED_PREFIX_MATCH ){
    /* Leave rc==0 */
  }else if( idx1<szHdr1 ){
    rc = 1;
  }
  return rc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %edi, 0xc(%rsp)
movq %rdx, 0x10(%rsp)
movq (%rdx), %rcx
movb 0x4(%rcx), %al
movb %al, 0x67(%rsp)
movq %rcx, 0x20(%rsp)
movq 0x10(%rcx), %rax
movq %rax, 0x40(%rsp)
movsbl (%rsi), %r14d
testl %r14d, %r14d
movq %rsi, 0x30(%rsp)
js 0x320c9
movl $0x1, %r12d
jmp 0x320e0
leaq 0x3c(%rsp), %r15
movq %rsi, %rdi
movq %r15, %rsi
callq 0x22cb5
movzbl %al, %r12d
movl (%r15), %r14d
movq $0x0, 0x28(%rsp)
xorl %ebp, %ebp
movl %r14d, %ebx
movl %r12d, %edi
movq 0x30(%rsp), %r13
movsbl (%r13,%rdi), %esi
testl %esi, %esi
js 0x32107
movl $0x1, %eax
jmp 0x3211b
addq %r13, %rdi
leaq 0x1c(%rsp), %rsi
callq 0x22cb5
movzbl %al, %eax
movl 0x1c(%rsp), %esi
addl %eax, %r12d
leal (%rbx,%rsi), %eax
addl $0x2, %eax
cmpl 0xc(%rsp), %eax
jbe 0x3214b
cmpl $0xc, %esi
jb 0x32136
leal -0xc(%rsi), %eax
shrl %eax
jmp 0x32143
movl %esi, %eax
leaq 0x3c613(%rip), %rcx     # 0x6e752
movzbl (%rax,%rcx), %eax
addl %ebx, %eax
cmpl 0xc(%rsp), %eax
ja 0x321b0
movl %r12d, %r15d
movl %ebx, %edi
addq %r13, %rdi
leaq 0x40(%rsp), %r12
movq %r12, %rdx
callq 0x2e062
movl %eax, %r13d
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rsi
addq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rax
movq 0x20(%rax,%rbp,8), %rdx
movq %r12, %rdi
callq 0x2dc80
testl %eax, %eax
jne 0x321d6
movl %r15d, %r12d
cmpl %r14d, %r15d
jae 0x321b0
addl %ebx, %r13d
incq %rbp
movq 0x10(%rsp), %rax
movzwl 0x8(%rax), %eax
addq $0x38, 0x28(%rsp)
movl %r13d, %ebx
cmpq %rax, %rbp
jb 0x320ee
movq 0x10(%rsp), %rax
movzbl 0xa(%rax), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testb $0x1, %cl
jne 0x321ec
testb $0x2, %cl
sete %al
cmpl %r14d, %r12d
setb %cl
andb %al, %cl
movzbl %cl, %eax
jmp 0x321ec
movl %eax, %ecx
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rdx
movl %ecx, %eax
negl %eax
cmpb $0x0, (%rdx,%rbp)
cmovel %ecx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq