// File: /workspace/github_c_makefile_star2_O0/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
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x628ab
movl $0x0, -0x4(%rbp)
jmp 0x62a4b
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movl -0x2c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x62a33
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
callq 0x648b0
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x47, %eax
je 0x6293a
movq -0x48(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movq -0x60(%rbp), %rdx
callq 0x66140
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jle 0x62938
movl -0x34(%rbp), %eax
movw %ax, %cx
movq -0x40(%rbp), %rax
movw %cx, 0x1a(%rax)
jmp 0x62a19
jmp 0x6293a
movq -0x60(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq 0x65040
cmpl $0x0, %eax
je 0x62990
cmpl $0x1, -0x34(%rbp)
jl 0x6295b
cmpl $0xffff, -0x34(%rbp)    # imm = 0xFFFF
jle 0x6297d
movq -0x48(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x2c(%rbp), %edx
addl $0x1, %edx
movl -0x4c(%rbp), %ecx
callq 0x661e0
movl $0x1, -0x4(%rbp)
jmp 0x62a4b
movl -0x34(%rbp), %eax
movw %ax, %cx
movq -0x40(%rbp), %rax
movw %cx, 0x1a(%rax)
jmp 0x62a19
movq -0x40(%rbp), %rax
movw $0x0, 0x1a(%rax)
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x5f5b0
cmpl $0x0, %eax
je 0x629b8
movl $0x1, -0x4(%rbp)
jmp 0x62a4b
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x18(%rbp), %rcx
movq (%rcx), %rcx
cmpl (%rcx), %eax
jge 0x62a17
movq -0x58(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movslq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x66220
cmpl $0x0, %eax
jne 0x62a0a
movl -0x30(%rbp), %eax
addl $0x1, %eax
movw %ax, %cx
movq -0x40(%rbp), %rax
movw %cx, 0x1a(%rax)
jmp 0x62a0c
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x629bf
jmp 0x62a19
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movq -0x40(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x40(%rbp)
jmp 0x628d5
movq -0x48(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x66520
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)