// File: /workspace/github_c_makefile_star2_O1/ukontainer[P]sqlite-bench/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->u.x.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->u.x.iOrderByCol = (u16)iCol;
      continue;
    }

    /* Otherwise, treat the ORDER BY term as an ordinary expression */
    pItem->u.x.iOrderByCol = 0;
    if( sqlite3ResolveExprNames(pNC, pE) ){
      return 1;
    }
    for(j=0; j<pSelect->pEList->nExpr; j++){
      if( sqlite3ExprCompare(0, pE, pSelect->pEList->a[j].pExpr, -1)==0 ){
#ifndef SQLITE_OMIT_WINDOWFUNC
        if( pE->pWin ){
          /* Since this window function is being changed into a reference
          ** to the same window function the result set, remove the instance
          ** of this window function from the Select.pWin list. */
          Window **pp;
          for(pp=&pSelect->pWin; *pp; pp=&(*pp)->pNextWin){
            if( *pp==pE->pWin ){
              *pp = (*pp)->pNextWin;
            }    
          }
        }
#endif
        pItem->u.x.iOrderByCol = j+1;
      }
    }
  }
  return sqlite3ResolveOrderGroupBy(pParse, pSelect, pOrderBy, zType);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
testq %rdx, %rdx
je 0x4574e7
movq %rcx, %r14
movq %rsi, %r15
movq %rdi, 0x28(%rsp)
movq (%rdi), %rax
movq %rax, 0x10(%rsp)
cmpl $0x0, (%rdx)
jle 0x4574c9
movq (%r15), %rax
movl (%rax), %eax
movl %eax, 0xc(%rsp)
leaq 0x8(%rdx), %r12
leaq 0x70(%r15), %rax
movq %rax, 0x18(%rsp)
xorl %ebx, %ebx
movq %r14, 0x20(%rsp)
movq %rdx, 0x30(%rsp)
movq (%r12), %rbp
movq %rbp, %r13
testq %rbp, %rbp
je 0x457389
movq %rbp, %r13
movl 0x4(%r13), %eax
btl $0xc, %eax
jae 0x457389
btl $0x12, %eax
jb 0x457378
addq $0x10, %r13
jmp 0x457380
movq 0x20(%r13), %r13
addq $0x8, %r13
movq (%r13), %r13
testq %r13, %r13
jne 0x457362
cmpb $0x47, (%r14)
je 0x4573ad
movq (%r15), %rdi
movq %r13, %rsi
callq 0x45976c
movl %eax, 0x8(%rsp)
testl %eax, %eax
jle 0x4573ad
movw %ax, 0x1c(%r12)
jmp 0x4574aa
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
callq 0x453d5d
testl %eax, %eax
je 0x4573fb
movl 0x8(%rsp), %eax
movl $0xffff0000, %edx       # imm = 0xFFFF0000
leal (%rax,%rdx), %ecx
cmpl %edx, %ecx
ja 0x4574a4
leal 0x1(%rbx), %edx
movq 0x10(%rsp), %rdi
leaq 0xfb699(%rip), %rsi     # 0x552a7a
movq %r14, %rcx
movl 0xc(%rsp), %r8d
xorl %eax, %eax
callq 0x40e237
movl $0x1, %r13d
jmp 0x4574b0
movw $0x0, 0x1c(%r12)
movq 0x28(%rsp), %rdi
movq %rbp, %rsi
callq 0x4553f9
movl $0x1, %r13d
testl %eax, %eax
jne 0x4574b0
movq (%r15), %rax
xorl %r13d, %r13d
cmpl $0x0, (%rax)
jle 0x4574b0
xorl %r14d, %r14d
movq %r14, %rcx
shlq $0x5, %rcx
movq 0x8(%rax,%rcx), %rdx
xorl %edi, %edi
movq %rbp, %rsi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x452c53
testl %eax, %eax
jne 0x45748f
cmpq $0x0, 0x48(%rbp)
je 0x457485
movq 0x18(%rsp), %rax
movq (%rax), %rax
testq %rax, %rax
je 0x457485
movq 0x18(%rsp), %rcx
cmpq 0x48(%rbp), %rax
jne 0x457475
movq 0x30(%rax), %rax
movq %rax, (%rcx)
movq (%rcx), %rcx
movq 0x30(%rcx), %rax
addq $0x30, %rcx
testq %rax, %rax
jne 0x457468
leal 0x1(%r14), %eax
movw %ax, 0x1c(%r12)
incq %r14
movq (%r15), %rax
movslq (%rax), %rcx
cmpq %rcx, %r14
jl 0x457430
movq 0x20(%rsp), %r14
jmp 0x4574b0
movw %ax, 0x1c(%r12)
movl $0x4, %r13d
testb $0x3, %r13b
jne 0x4574eb
incl %ebx
addq $0x20, %r12
movq 0x30(%rsp), %rdx
cmpl (%rdx), %ebx
jl 0x457353
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %r14, %rcx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4597fb
xorl %eax, %eax
jmp 0x4574f0
movl $0x1, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq