// File: /workspace/github_c_makefile_star2_O3/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, %r12
movq %rsi, %r15
movq %rdi, %rbx
xorps %xmm0, %xmm0
leaq 0xc0(%rsp), %rdi
movups %xmm0, 0x10(%rdi)
movups %xmm0, 0x20(%rdi)
movq $0x0, 0x30(%rdi)
movq %rbx, (%rdi)
movq %rsi, 0x8(%rdi)
movq (%rdx), %rsi
callq 0x2c4a43
testl %eax, %eax
jne 0x2e71b3
movq 0x8(%r12), %rsi
leaq 0xc0(%rsp), %rdi
callq 0x2c496c
testl %eax, %eax
jne 0x2e71b3
movq 0x28(%r15), %r14
movq (%r12), %rcx
movl 0x48(%r15), %ebp
testb $-0x80, 0x40(%r14)
jne 0x2e7055
cmpl $0x1, (%rcx)
jne 0x2e7055
movq 0x8(%rcx), %rax
cmpb $-0x5c, (%rax)
jne 0x2e7055
cmpw $-0x1, 0x30(%rax)
je 0x2e71b3
movq %rcx, 0x10(%rsp)
movq %r12, 0x8(%rsp)
leaq 0x30(%rsp), %r15
movl $0x90, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x173a0
movb $0x6f, (%r15)
leaq 0x78(%rsp), %rax
movq %rax, -0x38(%rax)
movb $-0x5c, (%rax)
movl %ebp, 0x2c(%rax)
movq 0x10(%r14), %r15
testq %r15, %r15
je 0x2e71a2
movq 0x10(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x20(%rsp)
cmpb $0x0, 0x62(%r15)
je 0x2e70de
movzwl 0x5e(%r15), %ecx
movzwl %cx, %eax
movq 0x10(%rsp), %rdx
cmpl %eax, (%rdx)
jne 0x2e70de
movq 0x48(%r15), %rdx
testq %rdx, %rdx
je 0x2e70f4
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rsi
testq %rsi, %rsi
je 0x2e70de
movq %rbx, %rdi
movl %ebp, %ecx
callq 0x2c0d98
testl %eax, %eax
je 0x2e70ec
movq 0x28(%r15), %r15
testq %r15, %r15
jne 0x2e70a1
jmp 0x2e71a2
movzwl 0x5e(%r15), %ecx
movzwl %cx, %eax
testw %cx, %cx
je 0x2e7197
movl %eax, %r13d
xorl %ecx, %ecx
movq %r13, 0x18(%rsp)
movq 0x40(%r15), %rax
movq (%rax,%rcx,8), %rax
movq %rax, 0x38(%rsp)
movq 0x8(%r15), %rax
movzwl (%rax,%rcx,2), %eax
cmpw $-0x2, %ax
movq %rcx, 0x28(%rsp)
jne 0x2e7142
movq 0x50(%r15), %rax
leaq (%rcx,%rcx,2), %rcx
movq 0x8(%rax,%rcx,8), %r12
cmpb $0x6f, (%r12)
je 0x2e7159
movq %r12, 0x40(%rsp)
jmp 0x2e7154
leaq 0x78(%rsp), %rcx
movq %rcx, 0x40(%rsp)
movw %ax, 0xa8(%rsp)
leaq 0x30(%rsp), %r12
movq 0x20(%rsp), %r14
movq (%r14), %rsi
movq %rbx, %rdi
movq %r12, %rdx
movl %ebp, %ecx
callq 0x2c0d98
cmpl $0x1, %eax
jbe 0x2e7181
addq $0x18, %r14
decq %r13
jne 0x2e715e
jmp 0x2e70de
movq 0x28(%rsp), %rcx
incq %rcx
movq 0x18(%rsp), %r13
cmpq %r13, %rcx
jne 0x2e7107
movq 0x8(%rsp), %rax
movq %r15, 0x20(%rax)
jmp 0x2e71b3
leaq 0xf1cf8(%rip), %rsi     # 0x3d8ea1
movq %rbx, %rdi
xorl %eax, %eax
callq 0x27b48d
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq