// File: /workspace/github_c_makefile_star2_O2/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
movq %rcx, 0x8(%rsp)
testq %rdx, %rdx
je 0x450012
movq %rsi, %r15
movq (%rsi), %rax
movl (%rax), %eax
movl %eax, 0x14(%rsp)
movq %rdi, 0x20(%rsp)
movq (%rdi), %rax
movq %rax, 0x18(%rsp)
leaq 0x8(%rdx), %r14
leaq 0x70(%rsi), %rax
movq %rax, 0x30(%rsp)
xorl %r12d, %r12d
pushq $-0x1
popq %rbp
movq %rdx, 0x28(%rsp)
cmpl (%rdx), %r12d
jge 0x44fff2
movq (%r14), %r13
movq %r13, %rdi
callq 0x44b988
movq %rax, %rbx
movq 0x8(%rsp), %rax
cmpb $0x47, (%rax)
je 0x44ff3f
movq (%r15), %rdi
movq %rbx, %rsi
callq 0x451b02
movl %eax, 0x4(%rsp)
testl %eax, %eax
jg 0x44ff64
movq %rbx, %rdi
leaq 0x4(%rsp), %rsi
callq 0x44cd34
testl %eax, %eax
je 0x44ff77
movl 0x4(%rsp), %eax
movl $0xffff0000, %edx       # imm = 0xFFFF0000
leal (%rax,%rdx), %ecx
cmpl %edx, %ecx
jbe 0x450016
movw %ax, 0x1c(%r14)
incl %r12d
addq $0x20, %r14
movq 0x28(%rsp), %rdx
jmp 0x44ff0b
andw $0x0, 0x1c(%r14)
movq 0x20(%rsp), %rdi
movq %r13, %rsi
callq 0x44df31
testl %eax, %eax
jne 0x45002f
xorl %ebx, %ebx
movq (%r15), %rax
movslq (%rax), %rcx
cmpq %rcx, %rbx
jge 0x44ff69
movq %rbx, %rcx
shlq $0x5, %rcx
movq 0x8(%rax,%rcx), %rdx
xorl %edi, %edi
movq %r13, %rsi
movl %ebp, %ecx
callq 0x44bddb
testl %eax, %eax
jne 0x44ffed
cmpq $0x0, 0x48(%r13)
je 0x44ffe5
movq 0x30(%rsp), %rcx
movq (%rcx), %rax
testq %rax, %rax
je 0x44ffe5
cmpq 0x48(%r13), %rax
jne 0x44ffdc
movq 0x30(%rax), %rax
movq %rax, (%rcx)
addq $0x30, %rax
movq %rax, %rcx
jmp 0x44ffc7
leal 0x1(%rbx), %eax
movw %ax, 0x1c(%r14)
incq %rbx
jmp 0x44ff94
movq 0x18(%rsp), %rdi
movq %r15, %rsi
movq 0x8(%rsp), %rcx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x451b7e
xorl %eax, %eax
jmp 0x450032
incl %r12d
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl %r12d, %edx
movl 0x14(%rsp), %ecx
callq 0x451b6a
pushq $0x1
popq %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq