// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/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 */
  ExprList *pEList;       /* Result set expression list */
  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;
    if( sqlite3ResolveExprNames(&sNC, p->pLimit) ||
        sqlite3ResolveExprNames(&sNC, p->pOffset) ){
      return WRC_Abort;
    }
  
    /* 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 ){
        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->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->isCorrelated==0 && nRef<=0 );
        pItem->isCorrelated = (nRef!=0);
      }
    }
  
    /* Set up the local name-context to pass to sqlite3ResolveExprNames() to
    ** resolve the result-set expression list.
    */
    sNC.ncFlags = NC_AllowAgg;
    sNC.pSrcList = p->pSrc;
    sNC.pNext = pOuterNC;
  
    /* Resolve names in the result set. */
    pEList = p->pEList;
    assert( pEList!=0 );
    for(i=0; i<pEList->nExpr; i++){
      Expr *pX = pEList->a[i].pExpr;
      if( sqlite3ResolveExprNames(&sNC, pX) ){
        return WRC_Abort;
      }
    }
  
    /* 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 ){
      p->selFlags |= SF_Aggregate;
    }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.
    */
    sNC.pEList = p->pEList;
    if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort;
    if( sqlite3ResolveExprNames(&sNC, p->pWhere) ) 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;

    /* 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( !isCompound && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER") ){
      return WRC_Abort;
    }
    if( db->mallocFailed ){
      return WRC_Abort;
    }
  
    /* 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;
        }
      }
    }

    /* 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
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movzwl 0xa(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x5fd3f
movl $0x1, -0x4(%rbp)
jmp 0x60285
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x90(%rbp)
movq -0x18(%rbp), %rax
movzwl 0xa(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
jne 0x5fdcd
movq -0x68(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x62770
movq -0x68(%rbp), %rcx
movb $0x1, %al
cmpl $0x0, 0x50(%rcx)
movb %al, -0xc1(%rbp)
jne 0x5fdaf
movq -0x90(%rbp), %rax
movzbl 0x50(%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0xc1(%rbp)
movb -0xc1(%rbp), %dl
movl $0x1, %eax
movl $0x2, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0x60285
movq -0x18(%rbp), %rax
cmpq $0x0, 0x50(%rax)
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x5c(%rbp)
movl $0x0, -0x60(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x88(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x6025a
movq -0x18(%rbp), %rax
movzwl 0xa(%rax), %ecx
orl $0x2, %ecx
movw %cx, 0xa(%rax)
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x8200
movq -0x68(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
movq 0x68(%rax), %rsi
leaq -0x58(%rbp), %rdi
callq 0x5f5b0
cmpl $0x0, %eax
jne 0x5fe51
movq -0x18(%rbp), %rax
movq 0x70(%rax), %rsi
leaq -0x58(%rbp), %rdi
callq 0x5f5b0
cmpl $0x0, %eax
je 0x5fe5d
movl $0x2, -0x4(%rbp)
jmp 0x60285
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
movq -0x18(%rbp), %rcx
movq 0x28(%rcx), %rcx
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x5fff2
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
addq $0x8, %rax
movslq -0x74(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0x5ffe2
movl $0x0, -0xa4(%rbp)
movq -0x68(%rbp), %rax
movq 0x248(%rax), %rax
movq %rax, -0xb0(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xa0(%rbp)
cmpq $0x0, -0xa0(%rbp)
je 0x5ff05
movq -0xa0(%rbp), %rax
movl 0x28(%rax), %eax
addl -0xa4(%rbp), %eax
movl %eax, -0xa4(%rbp)
movq -0xa0(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0xa0(%rbp)
jmp 0x5fed1
movq -0x98(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x5ff29
movq -0x98(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x248(%rax)
movq -0x68(%rbp), %rdi
movq -0x98(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0x20(%rbp), %rdx
callq 0x62820
movq -0xb0(%rbp), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x248(%rax)
movq -0x68(%rbp), %rax
cmpl $0x0, 0x50(%rax)
jne 0x5ff6d
movq -0x90(%rbp), %rax
movzbl 0x50(%rax), %eax
cmpl $0x0, %eax
je 0x5ff79
movl $0x2, -0x4(%rbp)
jmp 0x60285
movq -0x20(%rbp), %rax
movq %rax, -0xa0(%rbp)
cmpq $0x0, -0xa0(%rbp)
je 0x5ffba
movq -0xa0(%rbp), %rax
movl 0x28(%rax), %ecx
movl -0xa4(%rbp), %eax
subl %ecx, %eax
movl %eax, -0xa4(%rbp)
movq -0xa0(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0xa0(%rbp)
jmp 0x5ff84
cmpl $0x0, -0xa4(%rbp)
setne %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x98(%rbp), %rax
movb %cl, %dl
movb 0x39(%rax), %cl
andb $0x1, %dl
shlb %dl
andb $-0x3, %cl
orb %dl, %cl
movb %cl, 0x39(%rax)
jmp 0x5ffe4
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x5fe64
movb $0x1, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
movq -0x70(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x60072
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x74(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x5f5b0
cmpl $0x0, %eax
je 0x60065
movl $0x2, -0x4(%rbp)
jmp 0x60285
jmp 0x60067
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x6001c
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
jne 0x60091
movzbl -0x28(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x600a2
movq -0x18(%rbp), %rax
movzwl 0xa(%rax), %ecx
orl $0x4, %ecx
movw %cx, 0xa(%rax)
jmp 0x600ac
movzbl -0x28(%rbp), %eax
andl $-0x2, %eax
movb %al, -0x28(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0x600dc
cmpq $0x0, -0x80(%rbp)
jne 0x600dc
movq -0x68(%rbp), %rdi
leaq 0x4facf(%rip), %rsi     # 0xafb98
movb $0x0, %al
callq 0x136f0
movl $0x2, -0x4(%rbp)
jmp 0x60285
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rsi
leaq -0x58(%rbp), %rdi
callq 0x5f5b0
cmpl $0x0, %eax
je 0x60109
movl $0x2, -0x4(%rbp)
jmp 0x60285
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rsi
leaq -0x58(%rbp), %rdi
callq 0x5f5b0
cmpl $0x0, %eax
je 0x6012b
movl $0x2, -0x4(%rbp)
jmp 0x60285
movq $0x0, -0x38(%rbp)
movzbl -0x28(%rbp), %eax
orl $0x1, %eax
movb %al, -0x28(%rbp)
cmpl $0x0, -0x5c(%rbp)
jne 0x60170
movq -0x18(%rbp), %rsi
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rdx
leaq -0x58(%rbp), %rdi
leaq 0x4fa6a(%rip), %rcx     # 0xafbc4
callq 0x62880
cmpl $0x0, %eax
je 0x60170
movl $0x2, -0x4(%rbp)
jmp 0x60285
movq -0x90(%rbp), %rax
cmpb $0x0, 0x50(%rax)
je 0x60189
movl $0x2, -0x4(%rbp)
jmp 0x60285
cmpq $0x0, -0x80(%rbp)
je 0x60240
movq -0x18(%rbp), %rsi
movq -0x80(%rbp), %rdx
leaq -0x58(%rbp), %rdi
leaq 0x4fa23(%rip), %rcx     # 0xafbca
callq 0x62880
cmpl $0x0, %eax
jne 0x601c1
movq -0x90(%rbp), %rax
movzbl 0x50(%rax), %eax
cmpl $0x0, %eax
je 0x601cd
movl $0x2, -0x4(%rbp)
jmp 0x60285
movl $0x0, -0x74(%rbp)
movq -0x80(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xc0(%rbp)
movl -0x74(%rbp), %eax
movq -0x80(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x6023e
movq -0xc0(%rbp), %rax
movq (%rax), %rax
movzwl 0x2(%rax), %eax
andl $0x2, %eax
cmpl $0x2, %eax
jne 0x6021f
movq -0x68(%rbp), %rdi
leaq 0x4f9c1(%rip), %rsi     # 0xafbd0
movb $0x0, %al
callq 0x136f0
movl $0x2, -0x4(%rbp)
jmp 0x60285
jmp 0x60221
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
movq -0xc0(%rbp), %rax
addq $0x20, %rax
movq %rax, -0xc0(%rbp)
jmp 0x601e3
jmp 0x60240
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x18(%rbp)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x5fdf3
cmpl $0x0, -0x5c(%rbp)
je 0x6027e
movq -0x68(%rbp), %rdi
movq -0x88(%rbp), %rsi
callq 0x62a60
cmpl $0x0, %eax
je 0x6027e
movl $0x2, -0x4(%rbp)
jmp 0x60285
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)