// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: sqlite3VdbeRecordCompareWithSkip
SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(
  int nKey1, const void *pKey1,   /* Left key */
  UnpackedRecord *pPKey2,         /* Right key */
  int bSkip                       /* If true, skip the first field */
){
  u32 d1;                         /* Offset into aKey[] of next data element */
  int i;                          /* Index of next field to compare */
  u32 szHdr1;                     /* Size of record header in bytes */
  u32 idx1;                       /* Offset of first type in header */
  int rc = 0;                     /* Return value */
  Mem *pRhs = pPKey2->aMem;       /* Next field of pPKey2 to compare */
  KeyInfo *pKeyInfo;
  const unsigned char *aKey1 = (const unsigned char *)pKey1;
  Mem mem1;

  /* If bSkip is true, then the caller has already determined that the first
  ** two elements in the keys are equal. Fix the various stack variables so
  ** that this routine begins comparing at the second field. */
  if( bSkip ){
    u32 s1;
    idx1 = 1 + getVarint32(&aKey1[1], s1);
    szHdr1 = aKey1[0];
    d1 = szHdr1 + sqlite3VdbeSerialTypeLen(s1);
    i = 1;
    pRhs++;
  }else{
    idx1 = getVarint32(aKey1, szHdr1);
    d1 = szHdr1;
    i = 0;
  }
  if( d1>(unsigned)nKey1 ){
    pPKey2->errCode = (u8)SQLITE_CORRUPT_BKPT;
    return 0;  /* Corruption */
  }

  VVA_ONLY( mem1.szMalloc = 0; ) /* Only needed by assert() statements */
  assert( pPKey2->pKeyInfo->nAllField>=pPKey2->nField
       || CORRUPT_DB );
  assert( pPKey2->pKeyInfo->aSortFlags!=0 );
  assert( pPKey2->pKeyInfo->nKeyField>0 );
  assert( idx1<=szHdr1 || CORRUPT_DB );
  do{
    u32 serial_type;

    /* RHS is an integer */
    if( pRhs->flags & (MEM_Int|MEM_IntReal) ){
      testcase( pRhs->flags & MEM_Int );
      testcase( pRhs->flags & MEM_IntReal );
      serial_type = aKey1[idx1];
      testcase( serial_type==12 );
      if( serial_type>=10 ){
        rc = +1;
      }else if( serial_type==0 ){
        rc = -1;
      }else if( serial_type==7 ){
        sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
        rc = -sqlite3IntFloatCompare(pRhs->u.i, mem1.u.r);
      }else{
        i64 lhs = vdbeRecordDecodeInt(serial_type, &aKey1[d1]);
        i64 rhs = pRhs->u.i;
        if( lhs<rhs ){
          rc = -1;
        }else if( lhs>rhs ){
          rc = +1;
        }
      }
    }

    /* RHS is real */
    else if( pRhs->flags & MEM_Real ){
      serial_type = aKey1[idx1];
      if( serial_type>=10 ){
        /* Serial types 12 or greater are strings and blobs (greater than
        ** numbers). Types 10 and 11 are currently "reserved for future
        ** use", so it doesn't really matter what the results of comparing
        ** them to numberic values are.  */
        rc = +1;
      }else if( serial_type==0 ){
        rc = -1;
      }else{
        sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
        if( serial_type==7 ){
          if( mem1.u.r<pRhs->u.r ){
            rc = -1;
          }else if( mem1.u.r>pRhs->u.r ){
            rc = +1;
          }
        }else{
          rc = sqlite3IntFloatCompare(mem1.u.i, pRhs->u.r);
        }
      }
    }

    /* RHS is a string */
    else if( pRhs->flags & MEM_Str ){
      getVarint32NR(&aKey1[idx1], serial_type);
      testcase( serial_type==12 );
      if( serial_type<12 ){
        rc = -1;
      }else if( !(serial_type & 0x01) ){
        rc = +1;
      }else{
        mem1.n = (serial_type - 12) / 2;
        testcase( (d1+mem1.n)==(unsigned)nKey1 );
        testcase( (d1+mem1.n+1)==(unsigned)nKey1 );
        if( (d1+mem1.n) > (unsigned)nKey1
         || (pKeyInfo = pPKey2->pKeyInfo)->nAllField<=i
        ){
          pPKey2->errCode = (u8)SQLITE_CORRUPT_BKPT;
          return 0;                /* Corruption */
        }else if( pKeyInfo->aColl[i] ){
          mem1.enc = pKeyInfo->enc;
          mem1.db = pKeyInfo->db;
          mem1.flags = MEM_Str;
          mem1.z = (char*)&aKey1[d1];
          rc = vdbeCompareMemString(
              &mem1, pRhs, pKeyInfo->aColl[i], &pPKey2->errCode
          );
        }else{
          int nCmp = MIN(mem1.n, pRhs->n);
          rc = memcmp(&aKey1[d1], pRhs->z, nCmp);
          if( rc==0 ) rc = mem1.n - pRhs->n;
        }
      }
    }

    /* RHS is a blob */
    else if( pRhs->flags & MEM_Blob ){
      assert( (pRhs->flags & MEM_Zero)==0 || pRhs->n==0 );
      getVarint32NR(&aKey1[idx1], serial_type);
      testcase( serial_type==12 );
      if( serial_type<12 || (serial_type & 0x01) ){
        rc = -1;
      }else{
        int nStr = (serial_type - 12) / 2;
        testcase( (d1+nStr)==(unsigned)nKey1 );
        testcase( (d1+nStr+1)==(unsigned)nKey1 );
        if( (d1+nStr) > (unsigned)nKey1 ){
          pPKey2->errCode = (u8)SQLITE_CORRUPT_BKPT;
          return 0;                /* Corruption */
        }else if( pRhs->flags & MEM_Zero ){
          if( !isAllZero((const char*)&aKey1[d1],nStr) ){
            rc = 1;
          }else{
            rc = nStr - pRhs->u.nZero;
          }
        }else{
          int nCmp = MIN(nStr, pRhs->n);
          rc = memcmp(&aKey1[d1], pRhs->z, nCmp);
          if( rc==0 ) rc = nStr - pRhs->n;
        }
      }
    }

    /* RHS is null */
    else{
      serial_type = aKey1[idx1];
      rc = (serial_type!=0);
    }

    if( rc!=0 ){
      int sortFlags = pPKey2->pKeyInfo->aSortFlags[i];
      if( sortFlags ){
        if( (sortFlags & KEYINFO_ORDER_BIGNULL)==0
         || ((sortFlags & KEYINFO_ORDER_DESC)
           !=(serial_type==0 || (pRhs->flags&MEM_Null)))
        ){
          rc = -rc;
        }
      }
      assert( vdbeRecordCompareDebug(nKey1, pKey1, pPKey2, rc) );
      assert( mem1.szMalloc==0 );  /* See comment below */
      return rc;
    }

    i++;
    if( i==pPKey2->nField ) break;
    pRhs++;
    d1 += sqlite3VdbeSerialTypeLen(serial_type);
    idx1 += sqlite3VarintLen(serial_type);
  }while( idx1<(unsigned)szHdr1 && d1<=(unsigned)nKey1 );

  /* 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.szMalloc==0 );

  /* rc==0 here means that one or both of the keys ran out of fields and
  ** all the fields up to that point were equal. Return the default_rc
  ** value.  */
  assert( CORRUPT_DB
       || vdbeRecordCompareDebug(nKey1, pKey1, pPKey2, pPKey2->default_rc)
       || pPKey2->pKeyInfo->db->mallocFailed
  );
  pPKey2->eqSeen = 1;
  return pPKey2->default_rc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %edi, %r8d
movq %rdx, 0x20(%rsp)
movq 0x8(%rdx), %r14
testl %ecx, %ecx
movq %rsi, 0x10(%rsp)
movl %edi, 0x8(%rsp)
je 0x29ffc9
movsbl 0x1(%rsi), %r15d
testl %r15d, %r15d
js 0x29ffdb
movzbl (%rsi), %r9d
movl $0x2, %ebx
jmp 0x2a0042
movsbl (%rsi), %r9d
testl %r9d, %r9d
js 0x2a0015
movl $0x1, %ebx
xorl %ebp, %ebp
jmp 0x2a0038
leaq 0x1(%rsi), %rdi
leaq 0x50(%rsp), %r12
movq %r12, %rsi
callq 0x29b609
movq 0x10(%rsp), %rsi
incb %al
movzbl %al, %ebx
movl (%r12), %r15d
movzbl (%rsi), %r9d
cmpl $0x80, %r15d
jb 0x2a003d
addl $-0xc, %r15d
shrl %r15d
movl 0x8(%rsp), %r8d
jmp 0x2a0051
leaq 0x4c(%rsp), %r12
movq %rsi, %rdi
movq %r12, %rsi
callq 0x29b609
movl 0x8(%rsp), %r8d
movq 0x10(%rsp), %rsi
movzbl %al, %ebx
xorl %ebp, %ebp
movl (%r12), %r9d
movl %r9d, %r15d
jmp 0x2a005d
movl 0x8(%rsp), %r8d
movl %r15d, %eax
leaq 0x131e24(%rip), %rcx    # 0x3d1e70
movzbl (%rax,%rcx), %r15d
addl %r9d, %r15d
addq $0x38, %r14
movl $0x1, %ebp
cmpl %r8d, %r15d
jbe 0x2a0099
leaq 0x135b62(%rip), %rsi    # 0x3d5bcb
leaq 0x135c6c(%rip), %rdx    # 0x3d5cdc
leaq 0x1359ba(%rip), %r8     # 0x3d5a31
xorl %r13d, %r13d
movl $0xb, %edi
movl $0x14147, %ecx          # imm = 0x14147
xorl %eax, %eax
callq 0x274d08
movq 0x20(%rsp), %rax
movb $0xb, 0x13(%rax)
jmp 0x2a051f
movq 0x20(%rsp), %rax
addq $0x13, %rax
movq %rax, 0x28(%rsp)
movl %r9d, 0xc(%rsp)
movzwl 0x8(%r14), %eax
testb $0x24, %al
je 0x2a0106
movl %ebx, %eax
movzbl (%rsi,%rax), %r12d
movl $0x1, %r13d
cmpl $0x9, %r12d
ja 0x2a04e3
cmpl $0x7, %r12d
je 0x2a0130
testl %r12d, %r12d
je 0x2a04dd
leal -0x1(%r12), %ecx
cmpl $0x5, %ecx
ja 0x2a040a
movl %r15d, %eax
leaq 0x1304a5(%rip), %rdx    # 0x3d0598
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movsbq (%rsi,%rax), %rax
jmp 0x2a040f
testb $0x8, %al
jne 0x2a017c
movl %ebx, %edi
testb $0x2, %al
jne 0x2a01f2
movzbl (%rsi,%rdi), %r12d
testb $0x10, %al
jne 0x2a02e3
xorl %r13d, %r13d
testl %r12d, %r12d
setne %r13b
jmp 0x2a0381
movl %r15d, %edi
addq %rsi, %rdi
movl $0x7, %r12d
movl $0x7, %esi
leaq 0x50(%rsp), %rdx
callq 0x29b6b7
movq (%r14), %rax
movq %rax, 0x40(%rsp)
fildll 0x40(%rsp)
fldl 0x50(%rsp)
xorl %eax, %eax
fxch %st(1)
fucomi %st(1), %st
seta %cl
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
ja 0x2a04e3
movb %cl, %al
negl %eax
movl %eax, %r13d
jmp 0x2a0372
movl %ebx, %eax
movzbl (%rsi,%rax), %r12d
movl $0x1, %r13d
cmpl $0x9, %r12d
ja 0x2a04e3
testl %r12d, %r12d
je 0x2a04d2
movl %r15d, %edi
addq %rsi, %rdi
movl %r12d, %esi
leaq 0x50(%rsp), %rdx
callq 0x29b6b7
movsd (%r14), %xmm0
cmpl $0x7, %r12d
jne 0x2a02ad
movsd 0x50(%rsp), %xmm1
ucomisd %xmm1, %xmm0
movl 0xc(%rsp), %r9d
ja 0x2a04d7
movl $0x7, %r12d
ucomisd %xmm0, %xmm1
movq 0x10(%rsp), %rsi
movl 0x8(%rsp), %r8d
jbe 0x2a041e
jmp 0x2a04e3
movzbl (%rsi,%rdi), %r12d
movl %r12d, 0x1c(%rsp)
testb %r12b, %r12b
jns 0x2a021d
addq %rsi, %rdi
leaq 0x1c(%rsp), %rsi
callq 0x29b609
movl 0x8(%rsp), %r8d
movq 0x10(%rsp), %rsi
movl 0x1c(%rsp), %r12d
cmpl $0xc, %r12d
jb 0x2a04dd
testb $0x1, %r12b
je 0x2a0558
leal -0xc(%r12), %eax
shrl %eax
movl %eax, 0x5c(%rsp)
leal (%rax,%r15), %ecx
cmpl %r8d, %ecx
ja 0x2a0534
movq 0x20(%rsp), %rcx
movq (%rcx), %rcx
movzwl 0x8(%rcx), %edx
cmpq %rdx, %rbp
jae 0x2a0534
movq 0x20(%rcx,%rbp,8), %rdx
testq %rdx, %rdx
je 0x2a034b
movb 0x4(%rcx), %al
movb %al, 0x5a(%rsp)
movq 0x10(%rcx), %rax
movq %rax, 0x78(%rsp)
movw $0x2, 0x58(%rsp)
movl %r15d, %eax
addq %rsi, %rax
movq %rax, 0x60(%rsp)
leaq 0x50(%rsp), %rdi
movq %r14, %rsi
movq 0x28(%rsp), %rcx
callq 0x29ed84
movq 0x10(%rsp), %rsi
movl %eax, %r13d
jmp 0x2a0377
movq 0x50(%rsp), %rax
movq %rax, 0x38(%rsp)
fildll 0x38(%rsp)
movsd %xmm0, 0x30(%rsp)
fldl 0x30(%rsp)
xorl %r13d, %r13d
fxch %st(1)
fucomi %st(1), %st
seta %al
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
ja 0x2a04d7
movb %al, %r13b
jmp 0x2a0372
movl %r12d, 0x1c(%rsp)
testb %r12b, %r12b
jns 0x2a030e
addq %rsi, %rdi
leaq 0x1c(%rsp), %rsi
callq 0x29b609
movl 0xc(%rsp), %r9d
movl 0x8(%rsp), %r8d
movq 0x10(%rsp), %rsi
movl 0x1c(%rsp), %r12d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl $0xc, %r12d
jb 0x2a04e3
movl %r12d, %eax
andl $0x1, %eax
jne 0x2a04e3
leal -0xc(%r12), %ecx
movl %ecx, %eax
shrl %eax
leal (%rax,%r15), %edx
cmpl %r8d, %edx
ja 0x2a0577
testb $0x40, 0x9(%r14)
jne 0x2a048a
movl 0xc(%r14), %ecx
movl %eax, %r13d
subl %ecx, %r13d
cmovll %eax, %ecx
movl %r15d, %edi
addq %rsi, %rdi
movq 0x10(%r14), %rsi
movslq %ecx, %rdx
callq 0x17300
testl %eax, %eax
jne 0x2a0569
movq 0x10(%rsp), %rsi
movl 0x8(%rsp), %r8d
movl 0xc(%rsp), %r9d
testl %r13d, %r13d
je 0x2a041e
jmp 0x2a04e3
movl 0x2(%rsi,%rax), %ecx
bswapl %ecx
movsbl (%rsi,%rax), %edx
shll $0x8, %edx
movzbl 0x1(%rsi,%rax), %eax
orl %edx, %eax
shlq $0x20, %rax
jmp 0x2a03fc
movsbq (%rsi,%rax), %rcx
shlq $0x10, %rcx
movzbl 0x1(%rsi,%rax), %edx
shll $0x8, %edx
orq %rcx, %rdx
movzbl 0x2(%rsi,%rax), %eax
jmp 0x2a03e9
movzbl (%rsi,%rax), %ecx
shll $0x18, %ecx
movzbl 0x1(%rsi,%rax), %edx
shll $0x10, %edx
movslq %ecx, %rcx
orq %rdx, %rcx
movzbl 0x2(%rsi,%rax), %edx
shll $0x8, %edx
orq %rcx, %rdx
movzbl 0x3(%rsi,%rax), %eax
orq %rdx, %rax
jmp 0x2a040f
movsbq (%rsi,%rax), %rcx
shlq $0x8, %rcx
movzbl 0x1(%rsi,%rax), %eax
orq %rcx, %rax
jmp 0x2a040f
movq (%rsi,%rax), %rax
bswapq %rax
jmp 0x2a040f
leal -0x8(%r12), %eax
cmpq (%r14), %rax
jl 0x2a04dd
jg 0x2a04e3
incq %rbp
movq 0x20(%rsp), %rax
movzwl 0x10(%rax), %eax
cmpq %rax, %rbp
je 0x2a04b8
movl %r12d, %eax
cmpl $0x7f, %r12d
jbe 0x2a0461
addl $-0xc, %r12d
shrl %r12d
addl %r12d, %r15d
movl $0x1, %ecx
movq %rax, %rdx
shrq $0x7, %rdx
incl %ecx
cmpq $0x4000, %rax           # imm = 0x4000
movq %rdx, %rax
jae 0x2a044e
jmp 0x2a0474
leaq 0x131a08(%rip), %rcx    # 0x3d1e70
movzbl (%rax,%rcx), %eax
addl %eax, %r15d
movl $0x1, %ecx
addl %ecx, %ebx
cmpl %r9d, %ebx
jae 0x2a04b8
addq $0x38, %r14
cmpl %r8d, %r15d
jbe 0x2a00ac
jmp 0x2a04b8
testl %ecx, %ecx
je 0x2a04a8
movl %r15d, %ecx
addq 0x10(%rsp), %rcx
movl %eax, %edx
xorl %esi, %esi
cmpb $0x0, (%rcx,%rsi)
jne 0x2a04c8
incq %rsi
cmpq %rsi, %rdx
jne 0x2a049a
subl (%r14), %eax
movl %eax, %r13d
movq 0x10(%rsp), %rsi
jmp 0x2a0381
movq 0x20(%rsp), %rax
movb $0x1, 0x16(%rax)
movsbl 0x12(%rax), %r13d
jmp 0x2a051f
movl $0x1, %r13d
xorl %eax, %eax
jmp 0x2a04e9
xorl %r12d, %r12d
jmp 0x2a04dd
movl $0x7, %r12d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
testl %r12d, %r12d
sete %al
movq 0x20(%rsp), %rcx
movq (%rcx), %rcx
movq 0x18(%rcx), %rcx
movl %ebp, %edx
movzbl (%rcx,%rdx), %ecx
testl %ecx, %ecx
je 0x2a051f
testb $0x2, %cl
je 0x2a051c
andl $0x1, %ecx
movl $0x1, %edx
testb %al, %al
jne 0x2a0518
movzwl 0x8(%r14), %edx
andl $0x1, %edx
cmpl %edx, %ecx
je 0x2a051f
negl %r13d
movl %r13d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x135690(%rip), %rsi    # 0x3d5bcb
leaq 0x13579a(%rip), %rdx    # 0x3d5cdc
leaq 0x1354e8(%rip), %r8     # 0x3d5a31
xorl %r13d, %r13d
movl $0xb, %edi
movl $0x14194, %ecx          # imm = 0x14194
jmp 0x2a0599
movl $0x1, %r13d
movl $0x7, %r12d
jmp 0x2a04e3
movl $0x7, %r12d
movl %eax, %r13d
jmp 0x2a04e3
leaq 0x13564d(%rip), %rsi    # 0x3d5bcb
leaq 0x135757(%rip), %rdx    # 0x3d5cdc
leaq 0x1354a5(%rip), %r8     # 0x3d5a31
xorl %r13d, %r13d
movl $0xb, %edi
movl $0x141b2, %ecx          # imm = 0x141B2
xorl %eax, %eax
callq 0x274d08
movq 0x28(%rsp), %rax
movb $0xb, (%rax)
jmp 0x2a051f