// File: /workspace/github_c_makefile_star2_O2/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
movq %rsi, %rbp
movl %edi, 0x4(%rsp)
movq %rdx, 0x8(%rsp)
movq 0x8(%rdx), %rbx
testl %ecx, %ecx
je 0x24606a
movsbl 0x1(%rbp), %r15d
testl %r15d, %r15d
js 0x24607a
movzbl (%rbp), %edx
pushq $0x2
popq %r14
jmp 0x2460aa
movsbl (%rbp), %edx
testl %edx, %edx
js 0x2460c5
pushq $0x1
popq %r14
xorl %eax, %eax
jmp 0x2460df
leaq 0x1(%rbp), %rdi
leaq 0x50(%rsp), %r15
movq %r15, %rsi
callq 0x2425d2
incb %al
movzbl %al, %r14d
movl (%r15), %r15d
movzbl (%rbp), %edx
cmpl $0x80, %r15d
jb 0x2460aa
addl $-0xc, %r15d
shrl %r15d
jmp 0x2460b9
movl %r15d, %eax
leaq 0x12c1cc(%rip), %rcx    # 0x372280
movzbl (%rax,%rcx), %r15d
addl %edx, %r15d
addq $0x38, %rbx
pushq $0x1
popq %rax
jmp 0x2460e2
leaq 0x4c(%rsp), %r12
movq %rbp, %rdi
movq %r12, %rsi
callq 0x2425d2
movzbl %al, %r14d
xorl %eax, %eax
movl (%r12), %edx
movl %edx, %r15d
cmpl 0x4(%rsp), %r15d
jbe 0x246102
movl $0x14147, %edi          # imm = 0x14147
callq 0x232547
movq 0x8(%rsp), %rcx
movb %al, 0x13(%rcx)
xorl %ebp, %ebp
jmp 0x246539
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rax
addq $0x13, %rax
movq %rax, 0x18(%rsp)
movq %rbp, 0x28(%rsp)
movl %edx, 0x24(%rsp)
movzwl 0x8(%rbx), %eax
movl %r14d, %edi
movl %r15d, %r12d
testb $0x24, %al
je 0x246173
movzbl (%rbp,%rdi), %r13d
cmpl $0x9, %r13d
ja 0x2464e9
cmpl $0x7, %r13d
je 0x24619b
testl %r13d, %r13d
je 0x246500
leal -0x1(%r13), %eax
cmpl $0x5, %eax
ja 0x24641e
leaq 0x12a849(%rip), %rcx    # 0x3709a8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movsbq (%rbp,%r12), %rax
jmp 0x246404
testb $0x8, %al
jne 0x2461e4
testb $0x2, %al
jne 0x246243
movzbl (%rbp,%rdi), %r13d
testb $0x10, %al
jne 0x246322
xorl %ebp, %ebp
testl %r13d, %r13d
setne %bpl
jmp 0x24646b
addq %rbp, %r12
movq %r12, %rdi
pushq $0x7
popq %r12
movl %r12d, %esi
leaq 0x50(%rsp), %rdx
callq 0x242680
movq (%rbx), %rax
movq %rax, 0x40(%rsp)
fildll 0x40(%rsp)
fldl 0x50(%rsp)
xorl %ebp, %ebp
fxch %st(1)
fucomi %st(1), %st
seta %al
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
ja 0x2464ed
movb %al, %bpl
negl %ebp
movl %r12d, %r13d
jmp 0x24646b
movzbl (%rbp,%rdi), %r13d
cmpl $0x9, %r13d
ja 0x2464e9
testl %r13d, %r13d
je 0x2464f5
addq %rbp, %r12
movq %r12, %rdi
movl %r13d, %esi
leaq 0x50(%rsp), %rdx
callq 0x242680
movsd (%rbx), %xmm0
cmpl $0x7, %r13d
jne 0x2462ed
movsd 0x50(%rsp), %xmm1
ucomisd %xmm1, %xmm0
ja 0x2464fa
ucomisd %xmm0, %xmm1
pushq $0x7
popq %rax
movl %eax, %r13d
jbe 0x246473
jmp 0x2464ed
movzbl (%rbp,%rdi), %r13d
movl %r13d, (%rsp)
testb %r13b, %r13b
jns 0x246261
addq %rbp, %rdi
movq %rsp, %rsi
callq 0x2425d2
movl (%rsp), %r13d
cmpl $0xc, %r13d
jb 0x246500
testb $0x1, %r13b
je 0x2464ed
leal -0xc(%r13), %eax
shrl %eax
movl %eax, 0x5c(%rsp)
leal (%rax,%r15), %ecx
cmpl 0x4(%rsp), %ecx
movq 0x10(%rsp), %rsi
ja 0x24654d
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
movzwl 0x8(%rcx), %edx
cmpq %rdx, %rsi
jae 0x24654d
movq 0x20(%rcx,%rsi,8), %rdx
testq %rdx, %rdx
je 0x246424
movb 0x4(%rcx), %al
movb %al, 0x5a(%rsp)
movq 0x10(%rcx), %rax
movq %rax, 0x78(%rsp)
movw $0x2, 0x58(%rsp)
addq %rbp, %r12
movq %r12, 0x60(%rsp)
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
movq 0x18(%rsp), %rcx
callq 0x2450c6
movl %eax, %ebp
jmp 0x24646b
movq 0x50(%rsp), %rax
movq %rax, 0x38(%rsp)
fildll 0x38(%rsp)
movsd %xmm0, 0x30(%rsp)
fldl 0x30(%rsp)
xorl %ebp, %ebp
fxch %st(1)
fucomi %st(1), %st
seta %al
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
ja 0x2464fa
movb %al, %bpl
jmp 0x24646b
movl %r13d, (%rsp)
testb %r13b, %r13b
jns 0x24633a
addq %rbp, %rdi
movq %rsp, %rsi
callq 0x2425d2
movl (%rsp), %r13d
cmpl $0xc, %r13d
jb 0x246500
movl %r13d, %eax
andl $0x1, %eax
jne 0x246500
leal -0xc(%r13), %edx
shrl %edx
leal (%rdx,%r15), %eax
cmpl 0x4(%rsp), %eax
ja 0x24655e
testb $0x40, 0x9(%rbx)
jne 0x24644c
movl 0xc(%rbx), %eax
movq %rbp, %rcx
movl %edx, %ebp
subl %eax, %ebp
cmovll %edx, %eax
addq %rcx, %r12
movq 0x10(%rbx), %rsi
movslq %eax, %rdx
jmp 0x24643b
movl 0x2(%rbp,%r12), %ecx
bswapl %ecx
movsbl (%rbp,%r12), %edx
shll $0x8, %edx
movzbl 0x1(%rbp,%r12), %eax
orl %edx, %eax
shlq $0x20, %rax
jmp 0x246401
movsbq (%rbp,%r12), %rax
shlq $0x10, %rax
movzbl 0x1(%rbp,%r12), %ecx
shll $0x8, %ecx
orq %rax, %rcx
movzbl 0x2(%rbp,%r12), %eax
jmp 0x246401
movzbl (%rbp,%r12), %eax
shll $0x18, %eax
movzbl 0x1(%rbp,%r12), %ecx
shll $0x10, %ecx
cltq
orq %rcx, %rax
movzbl 0x2(%rbp,%r12), %ecx
shll $0x8, %ecx
orq %rax, %rcx
movzbl 0x3(%rbp,%r12), %eax
jmp 0x246401
movsbq (%rbp,%r12), %rcx
shlq $0x8, %rcx
movzbl 0x1(%rbp,%r12), %eax
orq %rcx, %rax
cmpq (%rbx), %rax
jl 0x246500
jle 0x246473
jmp 0x2464e9
movq (%rbp,%r12), %rax
bswapq %rax
jmp 0x246404
leal -0x8(%r13), %eax
jmp 0x246404
movl 0xc(%rbx), %ecx
movq %rbp, %rdx
movl %eax, %ebp
subl %ecx, %ebp
cmovll %eax, %ecx
addq %rdx, %r12
movq 0x10(%rbx), %rsi
movslq %ecx, %rdx
movq %r12, %rdi
callq 0x172e0
testl %eax, %eax
je 0x24646b
jmp 0x246554
addq %rbp, %r12
movq %r12, %rdi
movq %rdx, %r12
movl %r12d, %esi
callq 0x245268
testl %eax, %eax
je 0x2464ed
subl (%rbx), %r12d
movl %r12d, %ebp
testl %ebp, %ebp
jne 0x246503
movq 0x10(%rsp), %rdx
incq %rdx
movq 0x8(%rsp), %rax
movzwl 0x10(%rax), %eax
movq %rdx, 0x10(%rsp)
cmpq %rax, %rdx
je 0x2464da
movl %r13d, %edi
cmpl $0x80, %r13d
jb 0x2464a3
addl $-0xc, %r13d
shrl %r13d
jmp 0x2464af
leaq 0x12bdd6(%rip), %rax    # 0x372280
movzbl (%rdi,%rax), %r13d
movq 0x28(%rsp), %rbp
callq 0x24289c
addl %eax, %r14d
movl 0x24(%rsp), %edx
cmpl %edx, %r14d
jae 0x2464da
addq $0x38, %rbx
addl %r15d, %r13d
movl %r13d, %r15d
cmpl 0x4(%rsp), %r13d
jbe 0x24611e
movq 0x8(%rsp), %rax
movb $0x1, 0x16(%rax)
movsbl 0x12(%rax), %ebp
jmp 0x246539
pushq $0x1
jmp 0x246502
pushq $0x1
popq %rbp
movl %ebp, %r13d
jmp 0x246503
xorl %r13d, %r13d
jmp 0x246500
pushq $0x1
popq %rax
movl %eax, %r13d
pushq $-0x1
popq %rbp
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movl 0x10(%rsp), %ecx
movzbl (%rax,%rcx), %eax
testl %eax, %eax
je 0x246539
testb $0x2, %al
je 0x246537
andl $0x1, %eax
testl %r13d, %r13d
je 0x246530
movzwl 0x8(%rbx), %ecx
andl $0x1, %ecx
jmp 0x246533
pushq $0x1
popq %rcx
cmpl %ecx, %eax
je 0x246539
negl %ebp
movl %ebp, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x14194, %edi          # imm = 0x14194
jmp 0x246563
pushq $0x1
popq %rcx
movl %ecx, %r13d
movl %eax, %ebp
jmp 0x246503
movl $0x141b2, %edi          # imm = 0x141B2
callq 0x232547
movq 0x18(%rsp), %rcx
movb %al, (%rcx)
jmp 0x2460fb