// File: /workspace/github_c_makefile_star2_O2/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:
movzwl 0xa(%rsi), %edx
pushq $0x1
popq %rax
testb $0x2, %dl
jne 0x43327
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq 0x10(%rdi), %rcx
movq 0x20(%rdi), %r12
movq (%rcx), %rdi
movq %rdi, -0x38(%rbp)
pushq $0x2
popq %r13
testb $0x10, %dl
jne 0x42d9a
movq %rcx, %rdi
movq %rcx, %rbx
movq %r12, %rdx
callq 0x449ff
cmpl $0x0, 0x50(%rbx)
movl %r13d, %eax
jne 0x43316
movq -0x38(%rbp), %rax
cmpb $0x1, 0x50(%rax)
pushq $0x2
popq %rax
sbbl $0x0, %eax
jmp 0x43316
movq 0x50(%rsi), %rdx
movq %rdx, -0x40(%rbp)
leaq -0xa0(%rbp), %rdx
xorps %xmm0, %xmm0
leaq -0xa8(%rbp), %rbx
movq %rsi, %r14
movq %rcx, -0x30(%rbp)
movq %rsi, -0x48(%rbp)
testq %r14, %r14
je 0x4304d
orb $0x2, 0xa(%r14)
movups %xmm0, 0x20(%rdx)
movups %xmm0, 0x10(%rdx)
movups %xmm0, (%rdx)
movq %rcx, -0xa8(%rbp)
movq 0x68(%r14), %rsi
movq %rbx, %rdi
callq 0x42880
testl %eax, %eax
jne 0x43045
movq 0x70(%r14), %rsi
movq %rbx, %rdi
callq 0x42880
testl %eax, %eax
jne 0x43045
xorl %r13d, %r13d
movq -0x30(%rbp), %rdi
movq %r14, -0x58(%rbp)
movq 0x28(%r14), %rax
movzbl (%rax), %ecx
cmpq %rcx, %r13
jae 0x42ec1
imulq $0x68, %r13, %rcx
movq 0x30(%rax,%rcx), %rsi
testq %rsi, %rsi
je 0x42eb9
leaq (%rax,%rcx), %r14
addq $0x8, %r14
movq 0x248(%rdi), %r15
xorl %ebx, %ebx
movq %r12, %rax
testq %rax, %rax
je 0x42e55
addl 0x28(%rax), %ebx
movq 0x20(%rax), %rax
jmp 0x42e47
movq 0x10(%r14), %rax
testq %rax, %rax
je 0x42e65
movq %rax, 0x248(%rdi)
movq %r12, %rdx
callq 0x44aee
movq -0x30(%rbp), %rdi
movq %r15, 0x248(%rdi)
cmpl $0x0, 0x50(%rdi)
jne 0x43313
movq -0x38(%rbp), %rax
cmpb $0x0, 0x50(%rax)
jne 0x43313
movq %r12, %rax
testq %rax, %rax
je 0x42ea1
subl 0x28(%rax), %ebx
movq 0x20(%rax), %rax
jmp 0x42e93
testl %ebx, %ebx
setne %al
movb 0x39(%r14), %cl
addb %al, %al
andb $-0x3, %cl
orb %al, %cl
movb %cl, 0x39(%r14)
movq -0x58(%rbp), %r14
incq %r13
jmp 0x42e11
movb $0x1, -0x78(%rbp)
movq %rax, -0xa0(%rbp)
movq %r12, -0x88(%rbp)
movq (%r14), %rbx
pushq $-0x1
popq %r14
xorl %r15d, %r15d
pushq $0x2
popq %r13
movslq (%rbx), %rax
incq %r14
cmpq %rax, %r14
jge 0x42f0d
movq 0x8(%rbx), %rax
movq (%rax,%r15), %rsi
addq $0x20, %r15
leaq -0xa8(%rbp), %rdi
callq 0x42880
testl %eax, %eax
je 0x42ee1
jmp 0x43045
movq -0x58(%rbp), %r14
movq 0x38(%r14), %r15
testq %r15, %r15
movq -0x30(%rbp), %rdi
jne 0x42f2c
movb -0x78(%rbp), %al
testb $0x2, %al
jne 0x42f2c
andb $-0x4, %al
movb %al, -0x78(%rbp)
jmp 0x42f31
orb $0x4, 0xa(%r14)
testq %r15, %r15
setne %al
movq 0x40(%r14), %rsi
testq %rsi, %rsi
sete %cl
orb %al, %cl
je 0x4307c
movq (%r14), %rax
movq %rax, -0x98(%rbp)
leaq -0xa8(%rbp), %rbx
movq %rbx, %rdi
callq 0x42880
testl %eax, %eax
jne 0x43045
movq 0x30(%r14), %rsi
movq %rbx, %rdi
callq 0x42880
testl %eax, %eax
jne 0x43045
andq $0x0, -0x88(%rbp)
orb $0x1, -0x78(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x42fb3
movq 0x48(%r14), %rdx
leaq -0xa8(%rbp), %rdi
movq %r14, %rsi
leaq 0x2a142(%rip), %rcx     # 0x6d0e8
callq 0x44b2a
testl %eax, %eax
jne 0x43045
movq -0x38(%rbp), %rax
cmpb $0x0, 0x50(%rax)
jne 0x43045
testq %r15, %r15
movq -0x48(%rbp), %rsi
xorps %xmm0, %xmm0
je 0x4301c
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
leaq 0x2a111(%rip), %rcx     # 0x6d0ee
callq 0x44b2a
testl %eax, %eax
jne 0x43045
movq -0x38(%rbp), %rax
cmpb $0x0, 0x50(%rax)
jne 0x43045
movq 0x8(%r15), %rax
movl (%r15), %ecx
testl %ecx, %ecx
movl $0x0, %edx
cmovlel %edx, %ecx
movq -0x48(%rbp), %rsi
xorps %xmm0, %xmm0
subl $0x1, %ecx
jb 0x4301c
movq (%rax), %rdx
testb $0x2, 0x2(%rdx)
jne 0x43033
addq $0x20, %rax
jmp 0x43008
movq 0x50(%r14), %r14
movq -0x30(%rbp), %rcx
pushq $0x1
popq %rax
leaq -0xa0(%rbp), %rdx
jmp 0x42dbe
leaq 0x2a0ba(%rip), %rsi     # 0x6d0f4
movq -0x30(%rbp), %rdi
xorl %eax, %eax
callq 0x104d6
movl %r13d, %eax
jmp 0x43316
cmpq $0x0, -0x40(%rbp)
je 0x43316
movq 0x48(%rsi), %rbx
testq %rbx, %rbx
je 0x43316
movq (%rcx), %r8
movl (%rbx), %eax
cmpl 0x70(%r8), %eax
jle 0x43085
leaq 0x2a297(%rip), %rsi     # 0x6d30e
movq %rcx, %rdi
jmp 0x4303e
leaq 0x2a039(%rip), %rsi     # 0x6d0bc
jmp 0x4303e
pushq $0x19
popq %rcx
xorl %edx, %edx
movslq %eax, %rdi
cmpq %rdi, %rdx
jge 0x430a5
movq 0x8(%rbx), %rax
andb $-0x2, (%rax,%rcx)
incq %rdx
movl (%rbx), %eax
addq $0x20, %rcx
jmp 0x4308a
movq %r8, -0x40(%rbp)
xorl %edx, %edx
movq %rdx, %rcx
movq %rsi, %rdx
movq %rcx, 0x58(%rsi)
movq 0x50(%rsi), %rsi
testq %rsi, %rsi
jne 0x430ab
pushq $0x1
popq %rcx
movq %rbx, -0xb0(%rbp)
testq %rdx, %rdx
je 0x43328
testl %ecx, %ecx
je 0x43328
movq %rdx, -0x60(%rbp)
movq (%rdx), %rcx
movq %rcx, -0x48(%rbp)
movq 0x8(%rbx), %r15
xorl %ecx, %ecx
xorl %r12d, %r12d
cmpl %eax, %r12d
jge 0x432f0
orl $-0x1, -0x4c(%rbp)
testb $0x1, 0x19(%r15)
jne 0x4326a
movl %ecx, -0x58(%rbp)
movq (%r15), %rdi
callq 0x45e0b
movq %rax, %r14
movq %rax, %rdi
leaq -0x4c(%rbp), %rsi
callq 0x46204
testl %eax, %eax
movl %r12d, -0x38(%rbp)
je 0x43148
movl -0x4c(%rbp), %r13d
movq -0x48(%rbp), %rax
movl (%rax), %ecx
testl %r13d, %r13d
jle 0x432fd
cmpl %ecx, %r13d
jle 0x43213
jmp 0x432fd
movq -0x48(%rbp), %rdi
movq %r14, %rsi
callq 0x46b54
movl %eax, %r13d
testl %eax, %eax
jne 0x4320b
movq %rbx, %r12
xorl %r13d, %r13d
movq -0x40(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x440d6
movq %rax, %rsi
cmpb $0x0, 0x50(%rbx)
jne 0x431fc
movq -0x60(%rbp), %rdx
movq (%rdx), %rdi
leaq -0xd8(%rbp), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq -0x30(%rbp), %rcx
movq %rcx, -0xf0(%rbp)
movq 0x28(%rdx), %rax
movq %rax, -0xe8(%rbp)
movq %rdi, -0x70(%rbp)
movq %rdi, -0xe0(%rbp)
movb $0x1, %al
movb %al, -0xc0(%rbp)
movq (%rcx), %rbx
movb 0x53(%rbx), %r13b
movb %al, 0x53(%rbx)
leaq -0xf0(%rbp), %rdi
movq %rsi, %r12
callq 0x42880
movb %r13b, 0x53(%rbx)
xorl %r13d, %r13d
testl %eax, %eax
movq %r12, %rsi
je 0x4327c
movq %rsi, %rax
movq -0xb0(%rbp), %r12
movq -0x40(%rbp), %rbx
movq %rax, %rsi
movq %rbx, %rdi
callq 0x2f476
movq %r12, %rbx
movl -0x38(%rbp), %r12d
pushq $0x1
popq %rcx
testl %r13d, %r13d
jle 0x4326a
movq %rbx, %r12
movq -0x40(%rbp), %rbx
movq %rbx, %rdi
movl $0x81, %esi
xorl %edx, %edx
callq 0x3b590
testq %rax, %rax
je 0x43313
orb $0x4, 0x3(%rax)
movl %r13d, 0x8(%rax)
movq (%r15), %rcx
leaq 0x10(%rcx), %rdx
cmpq %r14, %rcx
cmoveq %r15, %rdx
movq %rax, (%rdx)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2f476
movw %r13w, 0x1a(%r15)
orb $0x1, 0x19(%r15)
movl -0x58(%rbp), %ecx
movq %r12, %rbx
movl -0x38(%rbp), %r12d
incl %r12d
addq $0x20, %r15
movl (%rbx), %eax
pushq $0x2
popq %r13
jmp 0x430ed
movq -0x70(%rbp), %rdx
movl (%rdx), %ecx
testl %ecx, %ecx
movl $0x0, %eax
cmovlel %eax, %ecx
shlq $0x5, %rcx
movq %rcx, -0xb8(%rbp)
xorl %ecx, %ecx
pushq $0x1
popq %rbx
movq %rdx, %rax
movq %r14, -0x68(%rbp)
cmpq %rcx, -0xb8(%rbp)
je 0x431eb
movq 0x8(%rax), %rax
movq %rcx, %r12
movq (%rax,%rcx), %rdi
movq %rsi, %r14
pushq $-0x1
popq %rdx
callq 0x46bdc
cmpl $0x2, %eax
jb 0x432e1
incl %ebx
movq %r12, %rcx
addq $0x20, %rcx
movq -0x70(%rbp), %rax
movq %r14, %rsi
movq -0x68(%rbp), %r14
jmp 0x432a3
movq %r14, %rax
movl %ebx, %r13d
movq -0x68(%rbp), %r14
jmp 0x431ee
movq -0x60(%rbp), %rdx
movq 0x58(%rdx), %rdx
jmp 0x430c8
incl %r12d
leaq 0x29de1(%rip), %rsi     # 0x6d0e8
movq -0x30(%rbp), %rdi
movl %r12d, %edx
callq 0x46bc3
pushq $0x2
popq %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
shlq $0x5, %rax
pushq $0x1
popq %rdx
movl %edx, %edi
cmpq %rcx, %rax
je 0x43350
movq 0x8(%rbx), %rsi
testb $0x1, 0x19(%rsi,%rcx)
je 0x43354
incl %edx
addq $0x20, %rcx
jmp 0x43338
movl %edi, %eax
jmp 0x43316
leaq 0x29fd5(%rip), %rsi     # 0x6d330
movq -0x30(%rbp), %rdi
xorl %eax, %eax
callq 0x104d6
jmp 0x43045