// File: /workspace/github_c_makefile_star2_O1/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
movq %rsi, %r14
movl %edi, %r15d
movq %rdx, 0x20(%rsp)
movq (%rdx), %rcx
movq %rcx, 0x38(%rsp)
movb 0x4(%rcx), %al
movb %al, 0x67(%rsp)
movq 0x10(%rcx), %rax
movq %rax, 0x40(%rsp)
movsbl (%rsi), %eax
testl %eax, %eax
js 0x31aab
movl %eax, 0x1c(%rsp)
movl $0x1, %r12d
jmp 0x31abc
leaq 0x1c(%rsp), %rsi
movq %r14, %rdi
callq 0x22c9d
movzbl %al, %r12d
xorl %ebx, %ebx
movl 0x1c(%rsp), %eax
xorl %ebp, %ebp
movl %eax, 0xc(%rsp)
movl %eax, %r13d
movl %r15d, 0x8(%rsp)
movq %r14, 0x30(%rsp)
movl %ebx, 0x14(%rsp)
movl %r12d, %edi
movsbl (%r14,%rdi), %eax
testl %eax, %eax
js 0x31af0
movl %eax, 0x18(%rsp)
movl $0x1, %edx
jmp 0x31b00
addq %r14, %rdi
leaq 0x18(%rsp), %rsi
callq 0x22c9d
movzbl %al, %edx
movl 0x18(%rsp), %esi
leal (%rsi,%r13), %eax
addl $0x2, %eax
cmpl %r15d, %eax
jbe 0x31b3a
cmpl $0xc, %esi
jb 0x31b1c
leal -0xc(%rsi), %ecx
shrl %ecx
jmp 0x31b27
leaq 0x3bbff(%rip), %rax     # 0x6d722
movzbl (%rsi,%rax), %ecx
addl %r13d, %ecx
movl $0x2, %eax
cmpl %r15d, %ecx
jbe 0x31b3a
movl 0x14(%rsp), %ebx
jmp 0x31bad
movl %edx, 0x10(%rsp)
movl %r13d, %edi
addq %r14, %rdi
leaq 0x40(%rsp), %r15
movq %r15, %rdx
callq 0x2d9db
addl %eax, %r13d
movl 0x14(%rsp), %ebx
movslq %ebx, %r14
imulq $0x38, %r14, %rsi
movq 0x20(%rsp), %rax
addq 0x10(%rax), %rsi
movq 0x38(%rsp), %rbp
movq 0x20(%rbp,%r14,8), %rdx
movq %r15, %rdi
callq 0x2d5cf
testl %eax, %eax
je 0x31b99
movq 0x18(%rbp), %rcx
movl %eax, %ebp
negl %ebp
cmpb $0x0, (%rcx,%r14)
cmovel %eax, %ebp
movl $0x1, %eax
movl %ebp, 0x2c(%rsp)
jmp 0x31b9f
incl %ebx
xorl %ebp, %ebp
xorl %eax, %eax
movq 0x30(%rsp), %r14
movl 0x8(%rsp), %r15d
movl 0x10(%rsp), %edx
addl %edx, %r12d
testl %eax, %eax
jne 0x31bce
cmpl 0xc(%rsp), %r12d
jae 0x31bd3
movq 0x20(%rsp), %rax
movzwl 0x8(%rax), %eax
cmpl %eax, %ebx
jl 0x31ad5
jmp 0x31bd3
cmpl $0x2, %eax
jne 0x31bfb
movq 0x20(%rsp), %rax
movzbl 0xa(%rax), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testb $0x1, %cl
jne 0x31bff
cmpl 0xc(%rsp), %r12d
movl $0x1, %eax
cmovael %ebp, %eax
testb $0x2, %cl
cmovnel %ebp, %eax
jmp 0x31bff
movl 0x2c(%rsp), %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq