// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x19360
movq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rsi
leaq -0x80(%rbp), %rdi
callq 0x4354b0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x4618eb
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x461bf7
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0x80(%rbp), %rdi
callq 0x435380
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x461910
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x461bf7
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movl 0x48(%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movl 0x40(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
jne 0x46197a
movq -0x40(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x46197a
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movzbl (%rax), %eax
cmpl $0xa4, %eax
jne 0x46197a
movq -0x48(%rbp), %rax
movswl 0x30(%rax), %eax
cmpl $-0x1, %eax
jne 0x46197a
movl $0x0, -0x4(%rbp)
jmp 0x461bf7
leaq -0x110(%rbp), %rdi
xorl %esi, %esi
movl $0x90, %edx
callq 0x19360
movb $0x6f, -0x110(%rbp)
leaq -0x110(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x100(%rbp)
movb $-0x5c, -0xc8(%rbp)
movq -0x18(%rbp), %rax
movl 0x48(%rax), %eax
movl %eax, -0x9c(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x461bde
movq -0x38(%rbp), %rax
movzbl 0x62(%rax), %eax
cmpl $0x0, %eax
jne 0x4619e3
jmp 0x461bcd
movq -0x40(%rbp), %rax
movl (%rax), %eax
movq -0x38(%rbp), %rcx
movzwl 0x5e(%rcx), %ecx
cmpl %ecx, %eax
je 0x4619fa
jmp 0x461bcd
movq -0x38(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x461a3d
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x461a15
jmp 0x461bcd
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rdx
movl -0x30(%rbp), %ecx
callq 0x42fc30
cmpl $0x0, %eax
je 0x461a3b
jmp 0x461bcd
jmp 0x461a3d
movq -0x38(%rbp), %rax
movzwl 0x5e(%rax), %eax
movl %eax, -0x11c(%rbp)
movl $0x0, -0x114(%rbp)
movl -0x114(%rbp), %eax
cmpl -0x11c(%rbp), %eax
jge 0x461ba8
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x114(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x108(%rbp)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x114(%rbp), %rcx
movswl (%rax,%rcx,2), %eax
cmpl $-0x2, %eax
jne 0x461aea
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rax
addq $0x8, %rax
movslq -0x114(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x128(%rbp)
movq -0x128(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x6f, %eax
je 0x461ae8
movq -0x128(%rbp), %rax
movq %rax, -0x100(%rbp)
leaq -0x110(%rbp), %rax
movq %rax, -0x128(%rbp)
jmp 0x461b24
leaq -0x110(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x100(%rbp)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x114(%rbp), %rcx
movw (%rax,%rcx,2), %ax
movw %ax, -0x98(%rbp)
leaq -0x110(%rbp), %rax
movq %rax, -0x128(%rbp)
movl $0x0, -0x118(%rbp)
movl -0x118(%rbp), %eax
cmpl -0x11c(%rbp), %eax
jge 0x461b82
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rax
addq $0x8, %rax
movslq -0x118(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rsi
movq -0x128(%rbp), %rdx
movl -0x30(%rbp), %ecx
callq 0x42fc30
cmpl $0x2, %eax
jge 0x461b6f
jmp 0x461b82
jmp 0x461b71
movl -0x118(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x118(%rbp)
jmp 0x461b2e
movl -0x118(%rbp), %eax
cmpl -0x11c(%rbp), %eax
jl 0x461b92
jmp 0x461ba8
jmp 0x461b94
movl -0x114(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x114(%rbp)
jmp 0x461a55
movl -0x114(%rbp), %eax
cmpl -0x11c(%rbp), %eax
jge 0x461bb8
jmp 0x461bcd
movq -0x38(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x20(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x461bf7
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x4619c6
movq -0x10(%rbp), %rdi
leaq 0x14c752(%rip), %rsi    # 0x5ae33b
movb $0x0, %al
callq 0x3cb660
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopw %cs:(%rax,%rax)