// File: /workspace/github_c_makefile_star2_O3/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, 0x10(%rsp)
testq %rdx, %rdx
je 0x456816
movq %rsi, %r12
movq %rdi, 0x28(%rsp)
movq (%rdi), %rax
movq %rax, 0x20(%rsp)
cmpl $0x0, (%rdx)
jle 0x4567f6
movq (%r12), %rax
movl (%rax), %eax
movl %eax, 0x1c(%rsp)
leaq 0x8(%rdx), %rbx
leaq 0x70(%r12), %r14
xorl %ebp, %ebp
movq %rdx, 0x30(%rsp)
movq (%rbx), %r13
testq %r13, %r13
je 0x456700
movq %r13, %r15
movl 0x4(%r15), %eax
btl $0xc, %eax
jae 0x456703
btl $0x12, %eax
jb 0x4566f0
addq $0x10, %r15
jmp 0x4566f8
movq 0x20(%r15), %r15
addq $0x8, %r15
movq (%r15), %r15
testq %r15, %r15
jne 0x4566da
xorl %r15d, %r15d
movq 0x10(%rsp), %rax
cmpb $0x47, (%rax)
je 0x456721
movq (%r12), %rdi
movq %r15, %rsi
callq 0x458951
movl %eax, 0xc(%rsp)
testl %eax, %eax
jg 0x456746
movq %r15, %rdi
leaq 0xc(%rsp), %rsi
callq 0x452fbf
testl %eax, %eax
je 0x456762
movl 0xc(%rsp), %eax
movl $0xffff0000, %edx       # imm = 0xFFFF0000
leal (%rax,%rdx), %ecx
cmpl %edx, %ecx
jbe 0x45681a
movw %ax, 0x1c(%rbx)
incl %ebp
addq $0x20, %rbx
movq 0x30(%rsp), %rdx
cmpl (%rdx), %ebp
jl 0x4566cf
jmp 0x4567f6
movw $0x0, 0x1c(%rbx)
movq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x4546de
testl %eax, %eax
jne 0x45683b
movq (%r12), %rax
cmpl $0x0, (%rax)
jle 0x45674a
xorl %r15d, %r15d
movq %r15, %rcx
shlq $0x5, %rcx
movq 0x8(%rax,%rcx), %rdx
xorl %edi, %edi
movq %r13, %rsi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x451ec3
testl %eax, %eax
jne 0x4567e2
cmpq $0x0, 0x48(%r13)
je 0x4567da
movq (%r14), %rax
testq %rax, %rax
je 0x4567da
movq %r14, %rcx
cmpq 0x48(%r13), %rax
jne 0x4567c7
movq 0x30(%rax), %rax
movq %rax, (%rcx)
movq %rax, %rcx
movq 0x30(%rax), %rdx
addq $0x30, %rcx
movq %rdx, %rax
testq %rdx, %rdx
jne 0x4567ba
leal 0x1(%r15), %eax
movw %ax, 0x1c(%rbx)
incq %r15
movq (%r12), %rax
movslq (%rax), %rcx
cmpq %rcx, %r15
jl 0x456789
jmp 0x45674a
movq 0x20(%rsp), %rdi
movq %r12, %rsi
movq 0x10(%rsp), %rcx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4589af
xorl %eax, %eax
jmp 0x456840
incl %ebp
leaq 0xfc2db(%rip), %rsi     # 0x552afe
movq 0x20(%rsp), %rdi
movl %ebp, %edx
movq 0x10(%rsp), %rcx
movl 0x1c(%rsp), %r8d
xorl %eax, %eax
callq 0x40e48a
movl $0x1, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq