// File: /workspace/github_c_makefile_star2_O2/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: resolveOrderGroupBy
static int resolveOrderGroupBy(
  NameContext *pNC,     /* The name context of the SELECT statement */
  Select *pSelect,      /* The SELECT statement holding pOrderBy */
  ExprList *pOrderBy,   /* An ORDER BY or GROUP BY clause to resolve */
  const char *zType     /* Either "ORDER" or "GROUP", as appropriate */
){
  int i, j;                      /* Loop counters */
  int iCol;                      /* Column number */
  struct ExprList_item *pItem;   /* A term of the ORDER BY clause */
  Parse *pParse;                 /* Parsing context */
  int nResult;                   /* Number of terms in the result set */

  if( pOrderBy==0 ) return 0;
  nResult = pSelect->pEList->nExpr;
  pParse = pNC->pParse;
  for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
    Expr *pE = pItem->pExpr;
    Expr *pE2 = sqlite3ExprSkipCollate(pE);
    if( zType[0]!='G' ){
      iCol = resolveAsName(pParse, pSelect->pEList, pE2);
      if( iCol>0 ){
        /* If an AS-name match is found, mark this ORDER BY column as being
        ** a copy of the iCol-th result-set column.  The subsequent call to
        ** sqlite3ResolveOrderGroupBy() will convert the expression to a
        ** copy of the iCol-th result-set expression. */
        pItem->iOrderByCol = (u16)iCol;
        continue;
      }
    }
    if( sqlite3ExprIsInteger(pE2, &iCol) ){
      /* The ORDER BY term is an integer constant.  Again, set the column
      ** number so that sqlite3ResolveOrderGroupBy() will convert the
      ** order-by term to a copy of the result-set expression */
      if( iCol<1 || iCol>0xffff ){
        resolveOutOfRangeError(pParse, zType, i+1, nResult);
        return 1;
      }
      pItem->iOrderByCol = (u16)iCol;
      continue;
    }

    /* Otherwise, treat the ORDER BY term as an ordinary expression */
    pItem->iOrderByCol = 0;
    if( sqlite3ResolveExprNames(pNC, pE) ){
      return 1;
    }
    for(j=0; j<pSelect->pEList->nExpr; j++){
      if( sqlite3ExprCompare(pE, pSelect->pEList->a[j].pExpr, -1)==0 ){
        pItem->iOrderByCol = j+1;
      }
    }
  }
  return sqlite3ResolveOrderGroupBy(pParse, pSelect, pOrderBy, zType);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, -0x48(%rbp)
testq %rdx, %rdx
je 0x44c7d
movq %rsi, -0x40(%rbp)
movq (%rsi), %rax
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
movq %rdi, -0x60(%rbp)
movq (%rdi), %rax
movq %rax, -0x58(%rbp)
movq 0x8(%rdx), %rax
movq %rax, -0x30(%rbp)
pushq $0x1
popq %r14
xorl %r15d, %r15d
movq %rdx, -0x68(%rbp)
cmpl (%rdx), %r15d
jge 0x44c5e
movq -0x30(%rbp), %rax
movq (%rax), %r12
movq %r12, %rdi
callq 0x45e0b
movq %rax, %rbx
movq -0x48(%rbp), %rax
cmpb $0x47, (%rax)
movl %r15d, -0x50(%rbp)
je 0x44bb0
movq -0x40(%rbp), %rax
movq (%rax), %rdi
movq %rbx, %rsi
callq 0x46b54
movl %eax, -0x34(%rbp)
testl %eax, %eax
jg 0x44bd3
movq %rbx, %rdi
leaq -0x34(%rbp), %rsi
callq 0x46204
testl %eax, %eax
je 0x44bf1
movl -0x34(%rbp), %eax
movl $0xffff0000, %edx       # imm = 0xFFFF0000
leal (%rax,%rdx), %ecx
cmpl %edx, %ecx
jbe 0x44c82
movq -0x30(%rbp), %rcx
movw %ax, 0x1a(%rcx)
movl -0x50(%rbp), %r15d
incl %r15d
addq $0x20, -0x30(%rbp)
pushq $0x1
popq %r14
movq -0x68(%rbp), %rdx
jmp 0x44b72
movq -0x30(%rbp), %rax
andw $0x0, 0x1a(%rax)
movq -0x60(%rbp), %rdi
movq %r12, %rsi
callq 0x42880
testl %eax, %eax
jne 0x44c98
movq -0x40(%rbp), %rax
movq (%rax), %rbx
movl (%rbx), %r14d
testl %r14d, %r14d
movl $0x0, %eax
cmovlel %eax, %r14d
shlq $0x5, %r14
movw $0x1, %r13w
xorl %r15d, %r15d
cmpq %r15, %r14
je 0x44bdb
movq 0x8(%rbx), %rax
movq (%rax,%r15), %rsi
movq %r12, %rdi
pushq $-0x1
popq %rdx
callq 0x46bdc
testl %eax, %eax
jne 0x44c55
movq -0x30(%rbp), %rax
movw %r13w, 0x1a(%rax)
incl %r13d
addq $0x20, %r15
jmp 0x44c30
movq -0x58(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rcx
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x46dc0
xorl %r14d, %r14d
jmp 0x44c98
incl %r15d
movq -0x58(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl %r15d, %edx
movl -0x4c(%rbp), %ecx
callq 0x46bc3
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq