// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: isDistinctRedundant
static int isDistinctRedundant(
  Parse *pParse,            /* Parsing context */
  SrcList *pTabList,        /* The FROM clause */
  WhereClause *pWC,         /* The WHERE clause */
  ExprList *pDistinct       /* The result set that needs to be DISTINCT */
){
  Table *pTab;
  Index *pIdx;
  int i;
  int iBase;

  /* If there is more than one table or sub-select in the FROM clause of
  ** this query, then it will not be possible to show that the DISTINCT
  ** clause is redundant. */
  if( pTabList->nSrc!=1 ) return 0;
  iBase = pTabList->a[0].iCursor;
  pTab = pTabList->a[0].pTab;

  /* If any of the expressions is an IPK column on table iBase, then return
  ** true. Note: The (p->iTable==iBase) part of this test may be false if the
  ** current SELECT is a correlated sub-query.
  */
  for(i=0; i<pDistinct->nExpr; i++){
    Expr *p = sqlite3ExprSkipCollateAndLikely(pDistinct->a[i].pExpr);
    if( p->op==TK_COLUMN && p->iTable==iBase && p->iColumn<0 ) return 1;
  }

  /* Loop through all indices on the table, checking each to see if it makes
  ** the DISTINCT qualifier redundant. It does so if:
  **
  **   1. The index is itself UNIQUE, and
  **
  **   2. All of the columns in the index are either part of the pDistinct
  **      list, or else the WHERE clause contains a term of the form "col=X",
  **      where X is a constant value. The collation sequences of the
  **      comparison and select-list expressions must match those of the index.
  **
  **   3. All of those index columns for which the WHERE clause does not
  **      contain a "col=X" term are subject to a NOT NULL constraint.
  */
  for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
    if( !IsUniqueIndex(pIdx) ) continue;
    for(i=0; i<pIdx->nKeyCol; i++){
      if( 0==sqlite3WhereFindTerm(pWC, iBase, i, ~(Bitmask)0, WO_EQ, pIdx) ){
        if( findIndexCol(pParse, pDistinct, iBase, pIdx, i)<0 ) break;
        if( indexColumnNotNull(pIdx, i)==0 ) break;
      }
    }
    if( i==pIdx->nKeyCol ){
      /* This index implies that the DISTINCT qualifier is redundant. */
      return 1;
    }
  }

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x1, (%rax)
je 0x448c8d
movl $0x0, -0x4(%rbp)
jmp 0x448df0
movq -0x18(%rbp), %rax
movl 0x48(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x448d14
movq -0x28(%rbp), %rax
addq $0x8, %rax
movslq -0x3c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x42f120
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
cmpl $0xa4, %eax
jne 0x448d07
movq -0x48(%rbp), %rax
movl 0x2c(%rax), %eax
cmpl -0x40(%rbp), %eax
jne 0x448d07
movq -0x48(%rbp), %rax
movswl 0x30(%rax), %eax
cmpl $0x0, %eax
jge 0x448d07
movl $0x1, -0x4(%rbp)
jmp 0x448df0
jmp 0x448d09
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x448caa
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x448de9
movq -0x38(%rbp), %rax
movzbl 0x62(%rax), %eax
cmpl $0x0, %eax
jne 0x448d3d
jmp 0x448dd8
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x38(%rbp), %rcx
movzwl 0x5e(%rcx), %ecx
cmpl %ecx, %eax
jge 0x448dbe
movq -0x20(%rbp), %rdi
movl -0x40(%rbp), %esi
movl -0x3c(%rbp), %edx
movq -0x38(%rbp), %r9
movq $-0x1, %rcx
movl $0x2, %r8d
callq 0x450560
movq %rax, %rcx
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x448db1
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x40(%rbp), %edx
movq -0x38(%rbp), %rcx
movl -0x3c(%rbp), %r8d
callq 0x450630
cmpl $0x0, %eax
jge 0x448d9c
jmp 0x448dbe
movq -0x38(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x450730
cmpl $0x0, %eax
jne 0x448daf
jmp 0x448dbe
jmp 0x448db1
jmp 0x448db3
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x448d44
movl -0x3c(%rbp), %eax
movq -0x38(%rbp), %rcx
movzwl 0x5e(%rcx), %ecx
cmpl %ecx, %eax
jne 0x448dd6
movl $0x1, -0x4(%rbp)
jmp 0x448df0
jmp 0x448dd8
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x448d20
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)