// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: resolveSelectStep
static int resolveSelectStep(Walker *pWalker, Select *p){
  NameContext *pOuterNC;  /* Context that contains this SELECT */
  NameContext sNC;        /* Name context of this SELECT */
  int isCompound;         /* True if p is a compound select */
  int nCompound;          /* Number of compound terms processed so far */
  Parse *pParse;          /* Parsing context */
  int i;                  /* Loop counter */
  ExprList *pGroupBy;     /* The GROUP BY clause */
  Select *pLeftmost;      /* Left-most of SELECT of a compound */
  sqlite3 *db;            /* Database connection */


  assert( p!=0 );
  if( p->selFlags & SF_Resolved ){
    return WRC_Prune;
  }
  pOuterNC = pWalker->u.pNC;
  pParse = pWalker->pParse;
  db = pParse->db;

  /* Normally sqlite3SelectExpand() will be called first and will have
  ** already expanded this SELECT.  However, if this is a subquery within
  ** an expression, sqlite3ResolveExprNames() will be called without a
  ** prior call to sqlite3SelectExpand().  When that happens, let
  ** sqlite3SelectPrep() do all of the processing for this SELECT.
  ** sqlite3SelectPrep() will invoke both sqlite3SelectExpand() and
  ** this routine in the correct order.
  */
  if( (p->selFlags & SF_Expanded)==0 ){
    sqlite3SelectPrep(pParse, p, pOuterNC);
    return (pParse->nErr || db->mallocFailed) ? WRC_Abort : WRC_Prune;
  }

  isCompound = p->pPrior!=0;
  nCompound = 0;
  pLeftmost = p;
  while( p ){
    assert( (p->selFlags & SF_Expanded)!=0 );
    assert( (p->selFlags & SF_Resolved)==0 );
    p->selFlags |= SF_Resolved;

    /* Resolve the expressions in the LIMIT and OFFSET clauses. These
    ** are not allowed to refer to any names, so pass an empty NameContext.
    */
    memset(&sNC, 0, sizeof(sNC));
    sNC.pParse = pParse;
    sNC.pWinSelect = p;
    if( sqlite3ResolveExprNames(&sNC, p->pLimit) ){
      return WRC_Abort;
    }

    /* If the SF_Converted flags is set, then this Select object was
    ** was created by the convertCompoundSelectToSubquery() function.
    ** In this case the ORDER BY clause (p->pOrderBy) should be resolved
    ** as if it were part of the sub-query, not the parent. This block
    ** moves the pOrderBy down to the sub-query. It will be moved back
    ** after the names have been resolved.  */
    if( p->selFlags & SF_Converted ){
      Select *pSub = p->pSrc->a[0].pSelect;
      assert( p->pSrc->nSrc==1 && p->pOrderBy );
      assert( pSub->pPrior && pSub->pOrderBy==0 );
      pSub->pOrderBy = p->pOrderBy;
      p->pOrderBy = 0;
    }

    /* Recursively resolve names in all subqueries
    */
    for(i=0; i<p->pSrc->nSrc; i++){
      struct SrcList_item *pItem = &p->pSrc->a[i];
      if( pItem->pSelect && (pItem->pSelect->selFlags & SF_Resolved)==0 ){
        NameContext *pNC;         /* Used to iterate name contexts */
        int nRef = 0;             /* Refcount for pOuterNC and outer contexts */
        const char *zSavedContext = pParse->zAuthContext;

        /* Count the total number of references to pOuterNC and all of its
        ** parent contexts. After resolving references to expressions in
        ** pItem->pSelect, check if this value has changed. If so, then
        ** SELECT statement pItem->pSelect must be correlated. Set the
        ** pItem->fg.isCorrelated flag if this is the case. */
        for(pNC=pOuterNC; pNC; pNC=pNC->pNext) nRef += pNC->nRef;

        if( pItem->zName ) pParse->zAuthContext = pItem->zName;
        sqlite3ResolveSelectNames(pParse, pItem->pSelect, pOuterNC);
        pParse->zAuthContext = zSavedContext;
        if( pParse->nErr || db->mallocFailed ) return WRC_Abort;

        for(pNC=pOuterNC; pNC; pNC=pNC->pNext) nRef -= pNC->nRef;
        assert( pItem->fg.isCorrelated==0 && nRef<=0 );
        pItem->fg.isCorrelated = (nRef!=0);
      }
    }

    /* Set up the local name-context to pass to sqlite3ResolveExprNames() to
    ** resolve the result-set expression list.
    */
    sNC.ncFlags = NC_AllowAgg|NC_AllowWin;
    sNC.pSrcList = p->pSrc;
    sNC.pNext = pOuterNC;

    /* Resolve names in the result set. */
    if( sqlite3ResolveExprListNames(&sNC, p->pEList) ) return WRC_Abort;
    sNC.ncFlags &= ~NC_AllowWin;

    /* If there are no aggregate functions in the result-set, and no GROUP BY
    ** expression, do not allow aggregates in any of the other expressions.
    */
    assert( (p->selFlags & SF_Aggregate)==0 );
    pGroupBy = p->pGroupBy;
    if( pGroupBy || (sNC.ncFlags & NC_HasAgg)!=0 ){
      assert( NC_MinMaxAgg==SF_MinMaxAgg );
      p->selFlags |= SF_Aggregate | (sNC.ncFlags&NC_MinMaxAgg);
    }else{
      sNC.ncFlags &= ~NC_AllowAgg;
    }

    /* If a HAVING clause is present, then there must be a GROUP BY clause.
    */
    if( p->pHaving && !pGroupBy ){
      sqlite3ErrorMsg(pParse, "a GROUP BY clause is required before HAVING");
      return WRC_Abort;
    }

    /* Add the output column list to the name-context before parsing the
    ** other expressions in the SELECT statement. This is so that
    ** expressions in the WHERE clause (etc.) can refer to expressions by
    ** aliases in the result set.
    **
    ** Minor point: If this is the case, then the expression will be
    ** re-evaluated for each reference to it.
    */
    assert( (sNC.ncFlags & (NC_UAggInfo|NC_UUpsert))==0 );
    sNC.uNC.pEList = p->pEList;
    sNC.ncFlags |= NC_UEList;
    if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort;
    if( sqlite3ResolveExprNames(&sNC, p->pWhere) ) return WRC_Abort;

    /* Resolve names in table-valued-function arguments */
    for(i=0; i<p->pSrc->nSrc; i++){
      struct SrcList_item *pItem = &p->pSrc->a[i];
      if( pItem->fg.isTabFunc
       && sqlite3ResolveExprListNames(&sNC, pItem->u1.pFuncArg)
      ){
        return WRC_Abort;
      }
    }

    /* The ORDER BY and GROUP BY clauses may not refer to terms in
    ** outer queries
    */
    sNC.pNext = 0;
    sNC.ncFlags |= NC_AllowAgg|NC_AllowWin;

    /* If this is a converted compound query, move the ORDER BY clause from
    ** the sub-query back to the parent query. At this point each term
    ** within the ORDER BY clause has been transformed to an integer value.
    ** These integers will be replaced by copies of the corresponding result
    ** set expressions by the call to resolveOrderGroupBy() below.  */
    if( p->selFlags & SF_Converted ){
      Select *pSub = p->pSrc->a[0].pSelect;
      p->pOrderBy = pSub->pOrderBy;
      pSub->pOrderBy = 0;
    }

    /* Process the ORDER BY clause for singleton SELECT statements.
    ** The ORDER BY clause for compounds SELECT statements is handled
    ** below, after all of the result-sets for all of the elements of
    ** the compound have been resolved.
    **
    ** If there is an ORDER BY clause on a term of a compound-select other
    ** than the right-most term, then that is a syntax error.  But the error
    ** is not detected until much later, and so we need to go ahead and
    ** resolve those symbols on the incorrect ORDER BY for consistency.
    */
    if( isCompound<=nCompound  /* Defer right-most ORDER BY of a compound */
     && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER")
    ){
      return WRC_Abort;
    }
    if( db->mallocFailed ){
      return WRC_Abort;
    }
    sNC.ncFlags &= ~NC_AllowWin;

    /* Resolve the GROUP BY clause.  At the same time, make sure
    ** the GROUP BY clause does not contain aggregate functions.
    */
    if( pGroupBy ){
      struct ExprList_item *pItem;

      if( resolveOrderGroupBy(&sNC, p, pGroupBy, "GROUP") || db->mallocFailed ){
        return WRC_Abort;
      }
      for(i=0, pItem=pGroupBy->a; i<pGroupBy->nExpr; i++, pItem++){
        if( ExprHasProperty(pItem->pExpr, EP_Agg) ){
          sqlite3ErrorMsg(pParse, "aggregate functions are not allowed in "
              "the GROUP BY clause");
          return WRC_Abort;
        }
      }
    }

#ifndef SQLITE_OMIT_WINDOWFUNC
    if( IN_RENAME_OBJECT ){
      Window *pWin;
      for(pWin=p->pWinDefn; pWin; pWin=pWin->pNextWin){
        if( sqlite3ResolveExprListNames(&sNC, pWin->pOrderBy)
         || sqlite3ResolveExprListNames(&sNC, pWin->pPartition)
        ){
          return WRC_Abort;
        }
      }
    }
#endif

    /* If this is part of a compound SELECT, check that it has the right
    ** number of expressions in the select list. */
    if( p->pNext && p->pEList->nExpr!=p->pNext->pEList->nExpr ){
      sqlite3SelectWrongNumTermsError(pParse, p->pNext);
      return WRC_Abort;
    }

    /* Advance to the next term of the compound
    */
    p = p->pPrior;
    nCompound++;
  }

  /* Resolve the ORDER BY on a compound SELECT after all terms of
  ** the compound have been resolved.
  */
  if( isCompound && resolveCompoundOrderBy(pParse, pLeftmost) ){
    return WRC_Abort;
  }

  return WRC_Prune;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl 0x4(%rsi), %eax
movl $0x1, %ebx
testb $0x4, %al
jne 0x2c674c
movq (%rdi), %r14
movq 0x28(%rdi), %r12
movq (%r14), %rcx
movq %rcx, 0x8(%rsp)
testb $0x40, %al
jne 0x2c634c
movq %r14, %rdi
movq %r12, %rdx
callq 0x2c6ee7
movl $0x2, %ebx
cmpl $0x0, 0x30(%r14)
jne 0x2c674c
movq 0x8(%rsp), %rax
cmpb $0x1, 0x61(%rax)
sbbl $0x0, %ebx
jmp 0x2c674c
movq 0x50(%rsi), %rax
movq %rax, 0x50(%rsp)
movq $0x0, 0x10(%rsp)
leaq 0x20(%rsp), %rax
xorps %xmm0, %xmm0
leaq 0x18(%rsp), %r13
movq %rsi, 0x60(%rsp)
movq %rsi, %r15
movq %r12, 0x58(%rsp)
orb $0x4, 0x4(%r15)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq $0x0, 0x20(%rax)
movq %r14, 0x18(%rsp)
movq %r15, 0x48(%rsp)
movq 0x60(%r15), %rsi
movq %r13, %rdi
callq 0x2c496c
testl %eax, %eax
jne 0x2c6747
testb $0x1, 0x6(%r15)
movq 0x28(%r15), %rax
je 0x2c63c9
movq 0x30(%rax), %rcx
movq 0x48(%r15), %rdx
movq %rdx, 0x48(%rcx)
movq $0x0, 0x48(%r15)
movl (%rax), %ecx
testl %ecx, %ecx
jle 0x2c64c6
xorl %r13d, %r13d
imulq $0x70, %r13, %rdx
movq 0x30(%rax,%rdx), %rsi
testq %rsi, %rsi
je 0x2c64b7
testb $0x4, 0x4(%rsi)
jne 0x2c64b7
xorl %ebp, %ebp
testq %r12, %r12
je 0x2c6405
addl 0x20(%r12), %ebp
movq 0x18(%r12), %r12
jmp 0x2c63f4
leaq (%rax,%rdx), %rbx
addq $0x8, %rbx
movq 0x160(%r14), %r12
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0x2c6424
movq %rax, 0x160(%r14)
leaq -0x18bc(%rip), %rax     # 0x2c4b6f
movq %rax, 0x70(%rsp)
leaq -0x14b(%rip), %rax      # 0x2c62ec
movq %rax, 0x78(%rsp)
movq $0x0, 0x80(%rsp)
movq %r14, 0x68(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x90(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x2c0b5b
movq %r12, 0x160(%r14)
cmpl $0x0, 0x30(%r14)
jne 0x2c6747
movq 0x8(%rsp), %rax
cmpb $0x0, 0x61(%rax)
jne 0x2c6747
movq 0x58(%rsp), %r12
testq %r12, %r12
je 0x2c649e
movq %r12, %rax
subl 0x20(%rax), %ebp
movq 0x18(%rax), %rax
testq %rax, %rax
jne 0x2c6492
testl %ebp, %ebp
setne %al
movb 0x3d(%rbx), %cl
shlb $0x3, %al
andb $-0x9, %cl
orb %al, %cl
movb %cl, 0x3d(%rbx)
movq 0x28(%r15), %rax
movl (%rax), %ecx
incq %r13
movslq %ecx, %rdx
cmpq %rdx, %r13
jl 0x2c63d6
movl $0x4001, 0x40(%rsp)     # imm = 0x4001
movq %rax, 0x20(%rsp)
movq %r12, 0x30(%rsp)
movq 0x20(%r15), %rsi
leaq 0x18(%rsp), %rdi
callq 0x2c4a43
testl %eax, %eax
jne 0x2c6747
movl 0x40(%rsp), %ecx
movl %ecx, %eax
andl $0xffffbfff, %eax       # imm = 0xFFFFBFFF
movl %eax, 0x40(%rsp)
movq 0x38(%r15), %r13
testq %r13, %r13
setne %dl
movl %ecx, %esi
andl $0x10, %esi
shrl $0x4, %esi
orb %dl, %sil
cmpb $0x1, %sil
jne 0x2c652b
andl $0x1000, %ecx           # imm = 0x1000
orl 0x4(%r15), %ecx
orl $0x8, %ecx
movl %ecx, 0x4(%r15)
jmp 0x2c6537
andl $0xffffbfee, %ecx       # imm = 0xFFFFBFEE
movl %ecx, 0x40(%rsp)
movl %ecx, %eax
testq %r13, %r13
setne %cl
movq 0x40(%r15), %rsi
testq %rsi, %rsi
sete %dl
orb %cl, %dl
je 0x2c6760
movq 0x20(%r15), %rcx
movq %rcx, 0x28(%rsp)
orl $0x80, %eax
movl %eax, 0x40(%rsp)
leaq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x2c496c
testl %eax, %eax
jne 0x2c6747
movq 0x30(%r15), %rsi
movq %rbx, %rdi
callq 0x2c496c
testl %eax, %eax
jne 0x2c6747
movq 0x28(%r15), %rax
movl (%rax), %ecx
testl %ecx, %ecx
jle 0x2c65cd
movl $0x68, %ebx
xorl %ebp, %ebp
testb $0x4, -0x23(%rax,%rbx)
je 0x2c65be
movq (%rax,%rbx), %rsi
leaq 0x18(%rsp), %rdi
callq 0x2c4a43
testl %eax, %eax
jne 0x2c6747
movq 0x28(%r15), %rax
movl (%rax), %ecx
incq %rbp
movslq %ecx, %rdx
addq $0x70, %rbx
cmpq %rdx, %rbp
jl 0x2c659b
movq $0x0, 0x30(%rsp)
orl $0x4001, 0x40(%rsp)     # imm = 0x4001
testb $0x1, 0x6(%r15)
je 0x2c65f9
movq 0x30(%rax), %rax
movq 0x48(%rax), %rcx
movq %rcx, 0x48(%r15)
movq $0x0, 0x48(%rax)
cmpq $0x0, 0x50(%rsp)
setne %al
cmpl $0x0, 0x10(%rsp)
sete %cl
testb %cl, %al
jne 0x2c662e
movq 0x48(%r15), %rdx
leaq 0x18(%rsp), %rdi
movq %r15, %rsi
leaq 0x111682(%rip), %rcx    # 0x3d7ca3
callq 0x2c6ffa
testl %eax, %eax
jne 0x2c6747
movq 0x8(%rsp), %rax
cmpb $0x0, 0x61(%rax)
jne 0x2c6747
andb $-0x41, 0x41(%rsp)
testq %r13, %r13
je 0x2c6697
leaq 0x18(%rsp), %rdi
movq %r15, %rsi
movq %r13, %rdx
leaq 0x111650(%rip), %rcx    # 0x3d7ca9
callq 0x2c6ffa
testl %eax, %eax
jne 0x2c6747
movq 0x8(%rsp), %rax
cmpb $0x0, 0x61(%rax)
jne 0x2c6747
movl (%r13), %eax
testl %eax, %eax
jle 0x2c6697
addq $0x8, %r13
movq (%r13), %rcx
testb $0x10, 0x4(%rcx)
jne 0x2c6736
addq $0x18, %r13
decl %eax
jne 0x2c6681
cmpb $0x2, 0x11c(%r14)
leaq 0x18(%rsp), %r13
jb 0x2c66d9
movq 0x78(%r15), %rbx
testq %rbx, %rbx
je 0x2c66d9
movq 0x18(%rbx), %rsi
movq %r13, %rdi
callq 0x2c4a43
testl %eax, %eax
jne 0x2c6747
movq 0x10(%rbx), %rsi
movq %r13, %rdi
callq 0x2c4a43
testl %eax, %eax
jne 0x2c6747
movq 0x40(%rbx), %rbx
jmp 0x2c66aa
movq 0x58(%r15), %rsi
testq %rsi, %rsi
je 0x2c66f0
movq 0x20(%r15), %rax
movl (%rax), %eax
movq 0x20(%rsi), %rcx
cmpl (%rcx), %eax
jne 0x2c6769
movq 0x50(%r15), %r15
movq 0x10(%rsp), %rax
incl %eax
movq %rax, 0x10(%rsp)
testq %r15, %r15
leaq 0x20(%rsp), %rax
xorps %xmm0, %xmm0
jne 0x2c6378
cmpq $0x0, 0x50(%rsp)
movl $0x2, %ebx
je 0x2c672f
movq %r14, %rdi
movq 0x60(%rsp), %rsi
callq 0x2c720f
testl %eax, %eax
jne 0x2c674c
movl $0x1, %ebx
jmp 0x2c674c
leaq 0x111572(%rip), %rsi    # 0x3d7caf
movq %r14, %rdi
xorl %eax, %eax
callq 0x27b48d
movl $0x2, %ebx
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x111510(%rip), %rsi    # 0x3d7c77
jmp 0x2c673d
movq %r14, %rdi
callq 0x2c71ce
jmp 0x2c6747