// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: sqlite3UpsertAnalyzeTarget
SQLITE_PRIVATE int sqlite3UpsertAnalyzeTarget(
  Parse *pParse,     /* The parsing context */
  SrcList *pTabList, /* Table into which we are inserting */
  Upsert *pUpsert    /* The ON CONFLICT clauses */
){
  Table *pTab;            /* That table into which we are inserting */
  int rc;                 /* Result code */
  int iCursor;            /* Cursor used by pTab */
  Index *pIdx;            /* One of the indexes of pTab */
  ExprList *pTarget;      /* The conflict-target clause */
  Expr *pTerm;            /* One term of the conflict-target clause */
  NameContext sNC;        /* Context for resolving symbolic names */
  Expr sCol[2];           /* Index column converted into an Expr */

  assert( pTabList->nSrc==1 );
  assert( pTabList->a[0].pTab!=0 );
  assert( pUpsert!=0 );
  assert( pUpsert->pUpsertTarget!=0 );

  /* Resolve all symbolic names in the conflict-target clause, which
  ** includes both the list of columns and the optional partial-index
  ** WHERE clause.
  */
  memset(&sNC, 0, sizeof(sNC));
  sNC.pParse = pParse;
  sNC.pSrcList = pTabList;
  rc = sqlite3ResolveExprListNames(&sNC, pUpsert->pUpsertTarget);
  if( rc ) return rc;
  rc = sqlite3ResolveExprNames(&sNC, pUpsert->pUpsertTargetWhere);
  if( rc ) return rc;

  /* Check to see if the conflict target matches the rowid. */
  pTab = pTabList->a[0].pTab;
  pTarget = pUpsert->pUpsertTarget;
  iCursor = pTabList->a[0].iCursor;
  if( HasRowid(pTab)
   && pTarget->nExpr==1
   && (pTerm = pTarget->a[0].pExpr)->op==TK_COLUMN
   && pTerm->iColumn==XN_ROWID
  ){
    /* The conflict-target is the rowid of the primary table */
    assert( pUpsert->pUpsertIdx==0 );
    return SQLITE_OK;
  }

  /* Initialize sCol[0..1] to be an expression parse tree for a
  ** single column of an index.  The sCol[0] node will be the TK_COLLATE
  ** operator and sCol[1] will be the TK_COLUMN operator.  Code below
  ** will populate the specific collation and column number values
  ** prior to comparing against the conflict-target expression.
  */
  memset(sCol, 0, sizeof(sCol));
  sCol[0].op = TK_COLLATE;
  sCol[0].pLeft = &sCol[1];
  sCol[1].op = TK_COLUMN;
  sCol[1].iTable = pTabList->a[0].iCursor;

  /* Check for matches against other indexes */
  for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
    int ii, jj, nn;
    if( !IsUniqueIndex(pIdx) ) continue;
    if( pTarget->nExpr!=pIdx->nKeyCol ) continue;
    if( pIdx->pPartIdxWhere ){
      if( pUpsert->pUpsertTargetWhere==0 ) continue;
      if( sqlite3ExprCompare(pParse, pUpsert->pUpsertTargetWhere,
                             pIdx->pPartIdxWhere, iCursor)!=0 ){
        continue;
      }
    }
    nn = pIdx->nKeyCol;
    for(ii=0; ii<nn; ii++){
      Expr *pExpr;
      sCol[0].u.zToken = (char*)pIdx->azColl[ii];
      if( pIdx->aiColumn[ii]==XN_EXPR ){
        assert( pIdx->aColExpr!=0 );
        assert( pIdx->aColExpr->nExpr>ii );
        pExpr = pIdx->aColExpr->a[ii].pExpr;
        if( pExpr->op!=TK_COLLATE ){
          sCol[0].pLeft = pExpr;
          pExpr = &sCol[0];
        }
      }else{
        sCol[0].pLeft = &sCol[1];
        sCol[1].iColumn = pIdx->aiColumn[ii];
        pExpr = &sCol[0];
      }
      for(jj=0; jj<nn; jj++){
        if( sqlite3ExprCompare(pParse, pTarget->a[jj].pExpr, pExpr,iCursor)<2 ){
          break;  /* Column ii of the index matches column jj of target */
        }
      }
      if( jj>=nn ){
        /* The target contains no match for column jj of the index */
        break;
      }
    }
    if( ii<nn ){
      /* Column ii of the index did not match any term of the conflict target.
      ** Continue the search with the next index. */
      continue;
    }
    pUpsert->pUpsertIdx = pIdx;
    return SQLITE_OK;
  }
  sqlite3ErrorMsg(pParse, "ON CONFLICT clause does not match any "
                          "PRIMARY KEY or UNIQUE constraint");
  return SQLITE_ERROR;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %rax
xorps %xmm0, %xmm0
leaq 0xc0(%rsp), %rdi
movaps %xmm0, (%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, 0x20(%rdi)
movq $0x0, 0x30(%rdi)
movq %rax, 0x10(%rsp)
movq %rax, (%rdi)
movq %rsi, 0x8(%rdi)
movq (%rdx), %rsi
callq 0x2ce1c1
testl %eax, %eax
jne 0x2f0476
movq 0x8(%rbx), %rsi
leaq 0xc0(%rsp), %rdi
callq 0x2ce0ea
testl %eax, %eax
jne 0x2f0476
movq 0x28(%r15), %r14
movq (%rbx), %rcx
movl 0x48(%r15), %eax
movl %eax, 0x4(%rsp)
testb $-0x80, 0x40(%r14)
jne 0x2f02d7
cmpl $0x1, (%rcx)
jne 0x2f02d7
movq 0x8(%rcx), %rax
cmpb $-0x5c, (%rax)
jne 0x2f02d7
cmpw $-0x1, 0x30(%rax)
je 0x2f0476
movq %rcx, 0x8(%rsp)
movq %rbx, 0x20(%rsp)
leaq 0x30(%rsp), %rbx
movl $0x90, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x173a0
movb $0x6f, (%rbx)
leaq 0x78(%rsp), %rcx
movq %rcx, -0x38(%rcx)
movb $-0x5c, (%rcx)
movl 0x4(%rsp), %eax
movl %eax, 0x2c(%rcx)
movq 0x10(%r14), %r15
testq %r15, %r15
je 0x2f0463
movq 0x8(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x28(%rsp)
cmpb $0x0, 0x62(%r15)
je 0x2f0364
movzwl 0x5e(%r15), %eax
movq 0x8(%rsp), %rcx
cmpl %eax, (%rcx)
jne 0x2f0364
movq 0x48(%r15), %rdx
testq %rdx, %rdx
je 0x2f0372
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rsi
testq %rsi, %rsi
je 0x2f0364
movq 0x10(%rsp), %rdi
movl 0x4(%rsp), %ecx
callq 0x2ca527
testl %eax, %eax
je 0x2f0372
movq 0x28(%r15), %r15
testq %r15, %r15
jne 0x2f0326
jmp 0x2f0463
movzwl 0x5e(%r15), %eax
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x2f0458
movq 0x18(%rsp), %rax
leaq -0x1(%rax), %r14
xorl %r13d, %r13d
movq 0x40(%r15), %rax
movq (%rax,%r13,8), %rax
movq %rax, 0x38(%rsp)
movq 0x8(%r15), %rax
movzwl (%rax,%r13,2), %eax
cmpw $-0x2, %ax
jne 0x2f03d9
movq 0x50(%r15), %rax
leaq (,%r13,2), %rcx
addq %r13, %rcx
movq 0x8(%rax,%rcx,8), %r12
cmpb $0x6f, (%r12)
movq 0x8(%rsp), %rax
je 0x2f03f5
movq %r12, 0x40(%rsp)
leaq 0x30(%rsp), %r12
jmp 0x2f03f5
leaq 0x78(%rsp), %rcx
movq %rcx, 0x40(%rsp)
movw %ax, 0xa8(%rsp)
leaq 0x30(%rsp), %r12
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rsp), %rdi
movq %r12, %rdx
movl 0x4(%rsp), %ecx
callq 0x2ca527
cmpl $0x2, %eax
jb 0x2f044a
movq 0x28(%rsp), %rbx
xorl %ebp, %ebp
cmpq %rbp, %r14
je 0x2f0364
movq (%rbx), %rsi
movq 0x10(%rsp), %rdi
movq %r12, %rdx
movl 0x4(%rsp), %ecx
callq 0x2ca527
addq $0x18, %rbx
incq %rbp
cmpl $0x1, %eax
ja 0x2f0416
cmpq 0x18(%rsp), %rbp
jae 0x2f0364
incq %r13
cmpq 0x18(%rsp), %r13
jne 0x2f0391
movq 0x20(%rsp), %rax
movq %r15, 0x20(%rax)
jmp 0x2f0476
leaq 0xf218c(%rip), %rsi     # 0x3e25f6
movq 0x10(%rsp), %rdi
xorl %eax, %eax
callq 0x284eb8
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq