// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: analyzeAggregate
static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
  int i;
  NameContext *pNC = pWalker->u.pNC;
  Parse *pParse = pNC->pParse;
  SrcList *pSrcList = pNC->pSrcList;
  AggInfo *pAggInfo = pNC->pAggInfo;

  switch( pExpr->op ){
    case TK_AGG_COLUMN:
    case TK_COLUMN: {
      testcase( pExpr->op==TK_AGG_COLUMN );
      testcase( pExpr->op==TK_COLUMN );
      /* Check to see if the column is in one of the tables in the FROM
      ** clause of the aggregate query */
      if( ALWAYS(pSrcList!=0) ){
        struct SrcList_item *pItem = pSrcList->a;
        for(i=0; i<pSrcList->nSrc; i++, pItem++){
          struct AggInfo_col *pCol;
          assert( !ExprHasAnyProperty(pExpr, EP_TokenOnly|EP_Reduced) );
          if( pExpr->iTable==pItem->iCursor ){
            /* If we reach this point, it means that pExpr refers to a table
            ** that is in the FROM clause of the aggregate query.  
            **
            ** Make an entry for the column in pAggInfo->aCol[] if there
            ** is not an entry there already.
            */
            int k;
            pCol = pAggInfo->aCol;
            for(k=0; k<pAggInfo->nColumn; k++, pCol++){
              if( pCol->iTable==pExpr->iTable &&
                  pCol->iColumn==pExpr->iColumn ){
                break;
              }
            }
            if( (k>=pAggInfo->nColumn)
             && (k = addAggInfoColumn(pParse->db, pAggInfo))>=0 
            ){
              pCol = &pAggInfo->aCol[k];
              pCol->pTab = pExpr->pTab;
              pCol->iTable = pExpr->iTable;
              pCol->iColumn = pExpr->iColumn;
              pCol->iMem = ++pParse->nMem;
              pCol->iSorterColumn = -1;
              pCol->pExpr = pExpr;
              if( pAggInfo->pGroupBy ){
                int j, n;
                ExprList *pGB = pAggInfo->pGroupBy;
                struct ExprList_item *pTerm = pGB->a;
                n = pGB->nExpr;
                for(j=0; j<n; j++, pTerm++){
                  Expr *pE = pTerm->pExpr;
                  if( pE->op==TK_COLUMN && pE->iTable==pExpr->iTable &&
                      pE->iColumn==pExpr->iColumn ){
                    pCol->iSorterColumn = j;
                    break;
                  }
                }
              }
              if( pCol->iSorterColumn<0 ){
                pCol->iSorterColumn = pAggInfo->nSortingColumn++;
              }
            }
            /* There is now an entry for pExpr in pAggInfo->aCol[] (either
            ** because it was there before or because we just created it).
            ** Convert the pExpr to be a TK_AGG_COLUMN referring to that
            ** pAggInfo->aCol[] entry.
            */
            ExprSetIrreducible(pExpr);
            pExpr->pAggInfo = pAggInfo;
            pExpr->op = TK_AGG_COLUMN;
            pExpr->iAgg = (i16)k;
            break;
          } /* endif pExpr->iTable==pItem->iCursor */
        } /* end loop over pSrcList */
      }
      return WRC_Prune;
    }
    case TK_AGG_FUNCTION: {
      if( (pNC->ncFlags & NC_InAggFunc)==0
       && pWalker->walkerDepth==pExpr->op2
      ){
        /* Check to see if pExpr is a duplicate of another aggregate 
        ** function that is already in the pAggInfo structure
        */
        struct AggInfo_func *pItem = pAggInfo->aFunc;
        for(i=0; i<pAggInfo->nFunc; i++, pItem++){
          if( sqlite3ExprCompare(pItem->pExpr, pExpr, -1)==0 ){
            break;
          }
        }
        if( i>=pAggInfo->nFunc ){
          /* pExpr is original.  Make a new entry in pAggInfo->aFunc[]
          */
          u8 enc = ENC(pParse->db);
          i = addAggInfoFunc(pParse->db, pAggInfo);
          if( i>=0 ){
            assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
            pItem = &pAggInfo->aFunc[i];
            pItem->pExpr = pExpr;
            pItem->iMem = ++pParse->nMem;
            assert( !ExprHasProperty(pExpr, EP_IntValue) );
            pItem->pFunc = sqlite3FindFunction(pParse->db,
                   pExpr->u.zToken, sqlite3Strlen30(pExpr->u.zToken),
                   pExpr->x.pList ? pExpr->x.pList->nExpr : 0, enc, 0);
            if( pExpr->flags & EP_Distinct ){
              pItem->iDistinct = pParse->nTab++;
            }else{
              pItem->iDistinct = -1;
            }
          }
        }
        /* Make pExpr point to the appropriate pAggInfo->aFunc[] entry
        */
        assert( !ExprHasAnyProperty(pExpr, EP_TokenOnly|EP_Reduced) );
        ExprSetIrreducible(pExpr);
        pExpr->iAgg = (i16)i;
        pExpr->pAggInfo = pAggInfo;
        return WRC_Prune;
      }else{
        return WRC_Continue;
      }
    }
  }
  return WRC_Continue;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x88(%rbp)
subl $0x98, %eax
je 0x7be4e
jmp 0x7be28
movl -0x88(%rbp), %eax
subl $0x99, %eax
je 0x7c09b
jmp 0x7be3b
movl -0x88(%rbp), %eax
subl $0x9a, %eax
jne 0x7c284
jmp 0x7be4e
cmpq $0x0, -0x38(%rbp)
je 0x7c08f
movq -0x38(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x38(%rbp), %rcx
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x7c08d
movq -0x18(%rbp), %rax
movl 0x2c(%rax), %eax
movq -0x48(%rbp), %rcx
cmpl 0x3c(%rcx), %eax
jne 0x7c071
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jge 0x7beef
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x2c(%rcx), %eax
jne 0x7bed6
movq -0x50(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x18(%rbp), %rcx
movswl 0x30(%rcx), %ecx
cmpl %ecx, %eax
jne 0x7bed6
jmp 0x7beef
jmp 0x7bed8
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movq -0x50(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x50(%rbp)
jmp 0x7bea5
movl -0x54(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jl 0x7c04e
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq -0x40(%rbp), %rsi
callq 0x7c2b0
movl %eax, -0x54(%rbp)
cmpl $0x0, %eax
jl 0x7c04e
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x54(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rcx
movq -0x50(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movl 0x2c(%rax), %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
movswl 0x30(%rax), %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x30(%rbp), %rax
movl 0x58(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x58(%rax)
movq -0x50(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x50(%rbp), %rax
movl $0xffffffff, 0x10(%rax) # imm = 0xFFFFFFFF
movq -0x18(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x7c02c
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x5c(%rbp)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jge 0x7c02a
movq -0x70(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x98, %eax
jne 0x7c011
movq -0x78(%rbp), %rax
movl 0x2c(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x2c(%rcx), %eax
jne 0x7c011
movq -0x78(%rbp), %rax
movswl 0x30(%rax), %eax
movq -0x18(%rbp), %rcx
movswl 0x30(%rcx), %ecx
cmpl %ecx, %eax
jne 0x7c011
movl -0x58(%rbp), %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x10(%rax)
jmp 0x7c02a
jmp 0x7c013
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
movq -0x70(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x70(%rbp)
jmp 0x7bfc0
jmp 0x7c02c
movq -0x50(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jge 0x7c04c
movq -0x40(%rbp), %rax
movl 0xc(%rax), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0xc(%rax)
movq -0x50(%rbp), %rax
movl %ecx, 0x10(%rax)
jmp 0x7c04e
movq -0x40(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x18(%rbp), %rax
movb $-0x66, (%rax)
movl -0x54(%rbp), %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x32(%rax)
jmp 0x7c08d
jmp 0x7c073
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movq -0x48(%rbp), %rax
addq $0x68, %rax
movq %rax, -0x48(%rbp)
jmp 0x7be6c
jmp 0x7c08f
movl $0x1, -0x4(%rbp)
jmp 0x7c28b
movq -0x28(%rbp), %rax
movzbl 0x30(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
jne 0x7c27b
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x18(%rbp), %rcx
movzbl 0x37(%rcx), %ecx
cmpl %ecx, %eax
jne 0x7c27b
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x80(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl 0x30(%rcx), %eax
jge 0x7c11a
movq -0x80(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x66220
cmpl $0x0, %eax
jne 0x7c101
jmp 0x7c11a
jmp 0x7c103
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movq -0x80(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x80(%rbp)
jmp 0x7c0d9
movl -0x1c(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl 0x30(%rcx), %eax
jl 0x7c258
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rax
movq 0x18(%rax), %rax
movb 0x71(%rax), %al
movb %al, -0x81(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq -0x40(%rbp), %rsi
callq 0x7c300
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jl 0x7c256
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x18(%rbp), %rcx
movq -0x80(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movl 0x58(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x58(%rax)
movq -0x80(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x92f0
movl %eax, -0x8c(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x7c1e2
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movl (%rax), %eax
movl %eax, -0xa4(%rbp)
jmp 0x7c1ec
xorl %eax, %eax
movl %eax, -0xa4(%rbp)
jmp 0x7c1ec
movl -0x8c(%rbp), %edx
movq -0x98(%rbp), %rsi
movq -0xa0(%rbp), %rdi
movl -0xa4(%rbp), %ecx
xorl %r9d, %r9d
movzbl -0x81(%rbp), %r8d
callq 0x18d90
movq %rax, %rcx
movq -0x80(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movzwl 0x2(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x7c249
movq -0x30(%rbp), %rax
movl 0x54(%rax), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0x54(%rax)
movq -0x80(%rbp), %rax
movl %ecx, 0x14(%rax)
jmp 0x7c254
movq -0x80(%rbp), %rax
movl $0xffffffff, 0x14(%rax) # imm = 0xFFFFFFFF
jmp 0x7c256
jmp 0x7c258
movl -0x1c(%rbp), %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x32(%rax)
movq -0x40(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x38(%rax)
movl $0x1, -0x4(%rbp)
jmp 0x7c28b
movl $0x0, -0x4(%rbp)
jmp 0x7c28b
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopw (%rax,%rax)