// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x47829b
movl $0x0, -0x4(%rbp)
jmp 0x47849f
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
addq $0x8, %rax
movq %rax, -0x40(%rbp)
movl -0x2c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x478487
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
callq 0x470a60
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x47, %eax
je 0x47832a
movq -0x48(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movq -0x60(%rbp), %rdx
callq 0x47b640
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jle 0x478328
movl -0x34(%rbp), %eax
movw %ax, %cx
movq -0x40(%rbp), %rax
movw %cx, 0x1c(%rax)
jmp 0x47846d
jmp 0x47832a
movq -0x60(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq 0x472fb0
cmpl $0x0, %eax
je 0x478380
cmpl $0x1, -0x34(%rbp)
jl 0x47834b
cmpl $0xffff, -0x34(%rbp)    # imm = 0xFFFF
jle 0x47836d
movq -0x48(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x2c(%rbp), %edx
addl $0x1, %edx
movl -0x4c(%rbp), %ecx
callq 0x47b6e0
movl $0x1, -0x4(%rbp)
jmp 0x47849f
movl -0x34(%rbp), %eax
movw %ax, %cx
movq -0x40(%rbp), %rax
movw %cx, 0x1c(%rax)
jmp 0x47846d
movq -0x40(%rbp), %rax
movw $0x0, 0x1c(%rax)
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x4756c0
cmpl $0x0, %eax
je 0x4783a8
movl $0x1, -0x4(%rbp)
jmp 0x47849f
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x18(%rbp), %rcx
movq (%rcx), %rcx
cmpl (%rcx), %eax
jge 0x47846b
movq -0x58(%rbp), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rax
addq $0x8, %rax
movslq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rdx
xorl %eax, %eax
movl %eax, %edi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x471410
cmpl $0x0, %eax
jne 0x47845b
movq -0x58(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x47844a
movq -0x18(%rbp), %rax
addq $0x70, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq $0x0, (%rax)
je 0x478448
movq -0x68(%rbp), %rax
movq (%rax), %rax
movq -0x58(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jne 0x478435
movq -0x68(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %rcx
movq -0x68(%rbp), %rax
movq %rcx, (%rax)
jmp 0x478437
movq -0x68(%rbp), %rax
movq (%rax), %rax
addq $0x30, %rax
movq %rax, -0x68(%rbp)
jmp 0x478408
jmp 0x47844a
movl -0x30(%rbp), %eax
addl $0x1, %eax
movw %ax, %cx
movq -0x40(%rbp), %rax
movw %cx, 0x1c(%rax)
jmp 0x47845d
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x4783af
jmp 0x47846d
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movq -0x40(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x40(%rbp)
jmp 0x4782c5
movq -0x48(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x47b720
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)