// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: sqlite3FkLocateIndex
SQLITE_PRIVATE int sqlite3FkLocateIndex(
  Parse *pParse,                  /* Parse context to store any error in */
  Table *pParent,                 /* Parent table of FK constraint pFKey */
  FKey *pFKey,                    /* Foreign key to find index for */
  Index **ppIdx,                  /* OUT: Unique index on parent table */
  int **paiCol                    /* OUT: Map of index columns in pFKey */
){
  Index *pIdx = 0;                    /* Value to return via *ppIdx */
  int *aiCol = 0;                     /* Value to return via *paiCol */
  int nCol = pFKey->nCol;             /* Number of columns in parent key */
  char *zKey = pFKey->aCol[0].zCol;   /* Name of left-most parent key column */

  /* The caller is responsible for zeroing output parameters. */
  assert( ppIdx && *ppIdx==0 );
  assert( !paiCol || *paiCol==0 );
  assert( pParse );

  /* If this is a non-composite (single column) foreign key, check if it
  ** maps to the INTEGER PRIMARY KEY of table pParent. If so, leave *ppIdx
  ** and *paiCol set to zero and return early.
  **
  ** Otherwise, for a composite foreign key (more than one column), allocate
  ** space for the aiCol array (returned via output parameter *paiCol).
  ** Non-composite foreign keys do not require the aiCol array.
  */
  if( nCol==1 ){
    /* The FK maps to the IPK if any of the following are true:
    **
    **   1) There is an INTEGER PRIMARY KEY column and the FK is implicitly
    **      mapped to the primary key of table pParent, or
    **   2) The FK is explicitly mapped to a column declared as INTEGER
    **      PRIMARY KEY.
    */
    if( pParent->iPKey>=0 ){
      if( !zKey ) return 0;
      if( !sqlite3StrICmp(pParent->aCol[pParent->iPKey].zName, zKey) ) return 0;
    }
  }else if( paiCol ){
    assert( nCol>1 );
    aiCol = (int *)sqlite3DbMallocRawNN(pParse->db, nCol*sizeof(int));
    if( !aiCol ) return 1;
    *paiCol = aiCol;
  }

  for(pIdx=pParent->pIndex; pIdx; pIdx=pIdx->pNext){
    if( pIdx->nKeyCol==nCol && IsUniqueIndex(pIdx) && pIdx->pPartIdxWhere==0 ){
      /* pIdx is a UNIQUE index (or a PRIMARY KEY) and has the right number
      ** of columns. If each indexed column corresponds to a foreign key
      ** column of pFKey, then this index is a winner.  */

      if( zKey==0 ){
        /* If zKey is NULL, then this foreign key is implicitly mapped to
        ** the PRIMARY KEY of table pParent. The PRIMARY KEY index may be
        ** identified by the test.  */
        if( IsPrimaryKeyIndex(pIdx) ){
          if( aiCol ){
            int i;
            for(i=0; i<nCol; i++) aiCol[i] = pFKey->aCol[i].iFrom;
          }
          break;
        }
      }else{
        /* If zKey is non-NULL, then this foreign key was declared to
        ** map to an explicit list of columns in table pParent. Check if this
        ** index matches those columns. Also, check that the index uses
        ** the default collation sequences for each column. */
        int i, j;
        for(i=0; i<nCol; i++){
          i16 iCol = pIdx->aiColumn[i];     /* Index of column in parent tbl */
          const char *zDfltColl;            /* Def. collation for column */
          char *zIdxCol;                    /* Name of indexed column */

          if( iCol<0 ) break; /* No foreign keys against expression indexes */

          /* If the index uses a collation sequence that is different from
          ** the default collation sequence for the column, this index is
          ** unusable. Bail out early in this case.  */
          zDfltColl = pParent->aCol[iCol].zColl;
          if( !zDfltColl ) zDfltColl = sqlite3StrBINARY;
          if( sqlite3StrICmp(pIdx->azColl[i], zDfltColl) ) break;

          zIdxCol = pParent->aCol[iCol].zName;
          for(j=0; j<nCol; j++){
            if( sqlite3StrICmp(pFKey->aCol[j].zCol, zIdxCol)==0 ){
              if( aiCol ) aiCol[i] = pFKey->aCol[j].iFrom;
              break;
            }
          }
          if( j==nCol ) break;
        }
        if( i==nCol ) break;      /* pIdx is usable */
      }
    }
  }

  if( !pIdx ){
    if( !pParse->disableTriggers ){
      sqlite3ErrorMsg(pParse,
           "foreign key mismatch - \"%w\" referencing \"%w\"",
           pFKey->pFrom->zName, pFKey->zTo);
    }
    sqlite3DbFree(pParse->db, aiCol);
    return 1;
  }

  *ppIdx = pIdx;
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r10
movslq 0x28(%rdx), %rbx
movq %rdx, 0x20(%rsp)
movq 0x48(%rdx), %r14
cmpq $0x1, %rbx
jne 0x2e2cd2
movswq 0x44(%r10), %rax
xorl %ebp, %ebp
testq %rax, %rax
js 0x2e2d0c
testq %r14, %r14
je 0x2e2ef9
movq %rdi, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
movq 0x8(%r10), %rcx
shlq $0x5, %rax
movq (%rcx,%rax), %rax
xorl %esi, %esi
leaq 0xee638(%rip), %rcx     # 0x3d12e0
xorl %edx, %edx
movzbl (%rax,%rdx), %r8d
movzbl (%r14,%rdx), %edi
cmpb %dil, %r8b
jne 0x2e2cc3
testq %r8, %r8
jne 0x2e2ccd
jmp 0x2e2ef7
movb (%r8,%rcx), %r8b
cmpb (%rdi,%rcx), %r8b
jne 0x2e2d18
incq %rdx
jmp 0x2e2caa
movq %r8, %rbp
movq %rcx, 0x8(%rsp)
testq %r8, %r8
movq %rdi, 0x10(%rsp)
je 0x2e2d16
movq %r10, %r15
movq (%rdi), %rdi
leaq (,%rbx,4), %rsi
callq 0x282a35
testq %rax, %rax
je 0x2e2ebf
movq %rax, %rsi
movq %rax, (%rbp)
movq %r15, %r10
jmp 0x2e2d18
movq %rdi, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
xorl %esi, %esi
movq 0x10(%r10), %rax
testq %rax, %rax
movq %rsi, (%rsp)
je 0x2e2e79
movq 0x20(%rsp), %rcx
addq $0x40, %rcx
movq %rcx, 0x18(%rsp)
leaq 0xee5a2(%rip), %r13     # 0x3d12e0
movzwl 0x5e(%rax), %ecx
cmpl %ecx, %ebx
jne 0x2e2e6c
cmpb $0x0, 0x62(%rax)
je 0x2e2e6c
cmpq $0x0, 0x48(%rax)
jne 0x2e2e6c
testq %r14, %r14
je 0x2e2e4a
testl %ebx, %ebx
jle 0x2e2e62
movq 0x8(%rax), %r15
xorl %edi, %edi
movswq (%r15,%rdi,2), %r9
testq %r9, %r9
js 0x2e2e64
movq %r10, %r12
movq 0x8(%r10), %r10
shlq $0x5, %r9
movq 0x10(%r10,%r9), %r11
testq %r11, %r11
leaq 0xeedc2(%rip), %rcx     # 0x3d1b60
cmoveq %rcx, %r11
movq 0x40(%rax), %rcx
movq (%rcx,%rdi,8), %rbp
xorl %edx, %edx
movzbl (%rbp,%rdx), %ecx
movzbl (%r11,%rdx), %r8d
cmpb %r8b, %cl
jne 0x2e2dc2
testq %rcx, %rcx
jne 0x2e2dd0
jmp 0x2e2dd5
movb (%rcx,%r13), %cl
cmpb (%r8,%r13), %cl
jne 0x2e2e59
incq %rdx
jmp 0x2e2dac
movq (%r10,%r9), %r10
xorl %r9d, %r9d
movq %r9, %rcx
shlq $0x4, %rcx
movq 0x18(%rsp), %rdx
leaq (%rdx,%rcx), %r11
movq 0x8(%rdx,%rcx), %rbp
xorl %edx, %edx
movzbl (%rbp,%rdx), %ecx
movzbl (%r10,%rdx), %r8d
cmpb %r8b, %cl
jne 0x2e2e09
testq %rcx, %rcx
jne 0x2e2e13
jmp 0x2e2e22
movb (%rcx,%r13), %cl
cmpb (%r8,%r13), %cl
jne 0x2e2e18
incq %rdx
jmp 0x2e2df3
incq %r9
cmpq %rbx, %r9
jne 0x2e2ddc
jmp 0x2e2e59
movq (%rsp), %rsi
testq %rsi, %rsi
je 0x2e2e31
movl (%r11), %ecx
movl %ecx, (%rsi,%rdi,4)
cmpl %r9d, %ebx
movq %r12, %r10
je 0x2e2e64
incq %rdi
cmpq %rbx, %rdi
jne 0x2e2d76
jmp 0x2e2eef
movzwl 0x63(%rax), %ecx
andl $0x3, %ecx
cmpw $0x2, %cx
jne 0x2e2e6c
jmp 0x2e2ec6
movq (%rsp), %rsi
movq %r12, %r10
jmp 0x2e2e64
xorl %edi, %edi
cmpl %ebx, %edi
je 0x2e2eef
movq 0x28(%rax), %rax
testq %rax, %rax
jne 0x2e2d3e
movq 0x10(%rsp), %rbx
cmpb $0x0, 0xd2(%rbx)
jne 0x2e2eab
movq 0x20(%rsp), %rcx
movq (%rcx), %rax
movq 0x10(%rcx), %rcx
movq (%rax), %rdx
leaq 0xf5ea5(%rip), %rsi     # 0x3d8d42
movq %rbx, %rdi
xorl %eax, %eax
callq 0x27b48d
movq (%rsp), %rsi
movl $0x1, %ebp
testq %rsi, %rsi
je 0x2e2ef9
movq (%rbx), %rdi
callq 0x282904
jmp 0x2e2ef9
movl $0x1, %ebp
jmp 0x2e2ef9
testl %ebx, %ebx
setle %cl
testq %rsi, %rsi
sete %dl
orb %cl, %dl
jne 0x2e2eef
shlq $0x2, %rbx
xorl %edx, %edx
movq 0x18(%rsp), %rcx
movl (%rcx,%rdx,4), %ecx
movl %ecx, (%rsi,%rdx)
addq $0x4, %rdx
cmpq %rdx, %rbx
jne 0x2e2edb
movq 0x8(%rsp), %rcx
movq %rax, (%rcx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq