// File: /workspace/github_c_makefile_star2_O1/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 %rsi, -0x38(%rbp)
testq %rdx, %rdx
je 0x48da8
movq %rcx, %r14
movq %rdi, -0x60(%rbp)
movq (%rdi), %rax
movq %rax, -0x50(%rbp)
cmpl $0x0, (%rdx)
jle 0x48d8a
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
movq 0x8(%rdx), %r15
xorl %ebx, %ebx
movq %r14, -0x58(%rbp)
movq %rdx, -0x68(%rbp)
movq (%r15), %r12
movq %r12, %r13
testq %r12, %r12
je 0x48c7f
movq %r12, %r13
movzbl (%r13), %eax
cmpl $0x5c, %eax
je 0x48c76
cmpl $0x18, %eax
jne 0x48c7f
movq 0x10(%r13), %r13
testq %r13, %r13
jne 0x48c67
cmpb $0x47, (%r14)
je 0x48ca5
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movq %r13, %rsi
callq 0x4b5c6
movl %eax, -0x2c(%rbp)
testl %eax, %eax
jle 0x48ca5
movw %ax, 0x1a(%r15)
jmp 0x48d6e
movq %r13, %rdi
leaq -0x2c(%rbp), %rsi
callq 0x4aaf6
testl %eax, %eax
je 0x48cee
movl -0x2c(%rbp), %eax
movl $0xffff0000, %edx       # imm = 0xFFFF0000
leal (%rax,%rdx), %ecx
cmpl %edx, %ecx
ja 0x48d69
leal 0x1(%rbx), %edx
movq -0x50(%rbp), %rdi
leaq 0x325c1(%rip), %rsi     # 0x7b297
movq %r14, %rcx
movl -0x3c(%rbp), %r8d
xorl %eax, %eax
callq 0x11724
movl $0x1, %ecx
jmp 0x48d73
movw $0x0, 0x1a(%r15)
movq -0x60(%rbp), %rdi
movq %r12, %rsi
callq 0x467fe
movl $0x1, %ecx
testl %eax, %eax
jne 0x48d73
movq %rbx, -0x48(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movslq (%rax), %rbx
xorl %ecx, %ecx
testq %rbx, %rbx
jle 0x48d63
movq 0x8(%rax), %rax
movq %rax, -0x70(%rbp)
shlq $0x5, %rbx
movw $0x1, %r13w
xorl %r14d, %r14d
movq -0x70(%rbp), %rax
movq (%rax,%r14), %rsi
movq %r12, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x4b67e
testl %eax, %eax
jne 0x48d51
movw %r13w, 0x1a(%r15)
incl %r13d
addq $0x20, %r14
cmpq %r14, %rbx
jne 0x48d33
movq -0x58(%rbp), %r14
xorl %ecx, %ecx
movq -0x48(%rbp), %rbx
jmp 0x48d73
movw %ax, 0x1a(%r15)
movl $0x4, %ecx
testb $0x3, %cl
jne 0x48dac
incl %ebx
addq $0x20, %r15
movq -0x68(%rbp), %rdx
cmpl (%rdx), %ebx
jl 0x48c59
movq -0x50(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %r14, %rcx
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4b85f
xorl %eax, %eax
jmp 0x48db1
movl $0x1, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq