// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: resolveCompoundOrderBy
static int resolveCompoundOrderBy(
  Parse *pParse,        /* Parsing context.  Leave error messages here */
  Select *pSelect       /* The SELECT statement containing the ORDER BY */
){
  int i;
  ExprList *pOrderBy;
  ExprList *pEList;
  sqlite3 *db;
  int moreToDo = 1;

  pOrderBy = pSelect->pOrderBy;
  if( pOrderBy==0 ) return 0;
  db = pParse->db;
  if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
    sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause");
    return 1;
  }
  for(i=0; i<pOrderBy->nExpr; i++){
    pOrderBy->a[i].done = 0;
  }
  pSelect->pNext = 0;
  while( pSelect->pPrior ){
    pSelect->pPrior->pNext = pSelect;
    pSelect = pSelect->pPrior;
  }
  while( pSelect && moreToDo ){
    struct ExprList_item *pItem;
    moreToDo = 0;
    pEList = pSelect->pEList;
    assert( pEList!=0 );
    for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
      int iCol = -1;
      Expr *pE, *pDup;
      if( pItem->done ) continue;
      pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr);
      if( sqlite3ExprIsInteger(pE, &iCol) ){
        if( iCol<=0 || iCol>pEList->nExpr ){
          resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr);
          return 1;
        }
      }else{
        iCol = resolveAsName(pParse, pEList, pE);
        if( iCol==0 ){
          /* Now test if expression pE matches one of the values returned
          ** by pSelect. In the usual case this is done by duplicating the
          ** expression, resolving any symbols in it, and then comparing
          ** it against each expression returned by the SELECT statement.
          ** Once the comparisons are finished, the duplicate expression
          ** is deleted.
          **
          ** Or, if this is running as part of an ALTER TABLE operation,
          ** resolve the symbols in the actual expression, not a duplicate.
          ** And, if one of the comparisons is successful, leave the expression
          ** as is instead of transforming it to an integer as in the usual
          ** case. This allows the code in alter.c to modify column
          ** refererences within the ORDER BY expression as required.  */
          if( IN_RENAME_OBJECT ){
            pDup = pE;
          }else{
            pDup = sqlite3ExprDup(db, pE, 0);
          }
          if( !db->mallocFailed ){
            assert(pDup);
            iCol = resolveOrderByTermToExprList(pParse, pSelect, pDup);
          }
          if( !IN_RENAME_OBJECT ){
            sqlite3ExprDelete(db, pDup);
          }
        }
      }
      if( iCol>0 ){
        /* Convert the ORDER BY term into an integer column number iCol,
        ** taking care to preserve the COLLATE clause if it exists */
        if( !IN_RENAME_OBJECT ){
          Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
          if( pNew==0 ) return 1;
          pNew->flags |= EP_IntValue;
          pNew->u.iValue = iCol;
          if( pItem->pExpr==pE ){
            pItem->pExpr = pNew;
          }else{
            Expr *pParent = pItem->pExpr;
            assert( pParent->op==TK_COLLATE );
            while( pParent->pLeft->op==TK_COLLATE ) pParent = pParent->pLeft;
            assert( pParent->pLeft==pE );
            pParent->pLeft = pNew;
          }
          sqlite3ExprDelete(db, pE);
          pItem->u.x.iOrderByCol = (u16)iCol;
        }
        pItem->done = 1;
      }else{
        moreToDo = 1;
      }
    }
    pSelect = pSelect->pNext;
  }
  for(i=0; i<pOrderBy->nExpr; i++){
    if( pOrderBy->a[i].done==0 ){
      sqlite3ErrorMsg(pParse, "%r ORDER BY term does not match any "
            "column in the result set", i+1);
      return 1;
    }
  }
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %r14
movq 0x48(%rsi), %rdi
testq %rdi, %rdi
je 0x2c7580
movq (%r14), %rcx
movl (%rdi), %eax
movq %rcx, 0x18(%rsp)
cmpl 0x84(%rcx), %eax
jle 0x2c7258
leaq 0x110e02(%rip), %rsi    # 0x3d804b
movq %r14, %rdi
xorl %eax, %eax
callq 0x27b48d
jmp 0x2c75a0
testl %eax, %eax
jle 0x2c7278
leaq (,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edx, %edx
andb $-0x5, 0x19(%rdi,%rdx)
addq $0x18, %rdx
cmpq %rdx, %rcx
jne 0x2c726a
movq $0x0, 0x58(%rsi)
movq 0x50(%rsi), %rcx
testq %rcx, %rcx
je 0x2c729e
movq %rcx, %rbx
movq %rsi, 0x58(%rcx)
movq 0x50(%rcx), %rcx
movq %rbx, %rsi
testq %rcx, %rcx
jne 0x2c7289
jmp 0x2c72a1
movq %rsi, %rbx
leaq 0x8(%rdi), %rcx
movq %rcx, 0x48(%rsp)
movq %rdi, 0x30(%rsp)
movq %r14, 0x40(%rsp)
testl %eax, %eax
jle 0x2c7580
movq 0x20(%rbx), %rax
movq %rax, 0x38(%rsp)
movl $0x0, 0x24(%rsp)
movq 0x48(%rsp), %r13
xorl %ebp, %ebp
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
testb $0x4, 0x11(%r13)
jne 0x2c74cb
movq (%r13), %r15
testq %r15, %r15
je 0x2c7314
movl 0x4(%r15), %eax
testl $0x41000, %eax          # imm = 0x41000
je 0x2c7317
btl $0x12, %eax
jb 0x2c7307
addq $0x10, %r15
jmp 0x2c730f
movq 0x20(%r15), %r15
addq $0x8, %r15
movq (%r15), %r15
jmp 0x2c72eb
xorl %r15d, %r15d
movq %r15, %rdi
leaq 0xc(%rsp), %rsi
callq 0x2c95b7
testl %eax, %eax
je 0x2c734c
movl 0xc(%rsp), %r12d
movq 0x38(%rsp), %rax
movl (%rax), %r8d
testl %r12d, %r12d
jle 0x2c7584
cmpl %r8d, %r12d
jle 0x2c7444
jmp 0x2c7584
movq 0x38(%rsp), %rdi
movq %r15, %rsi
callq 0x2c953c
movl %eax, %r12d
movl %eax, 0xc(%rsp)
testl %eax, %eax
jne 0x2c743b
movb 0x11c(%r14), %al
cmpb $0x1, %al
jbe 0x2c7378
movq %r15, %r8
jmp 0x2c739d
testq %r15, %r15
je 0x2c739a
movq 0x18(%rsp), %rdi
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2c2864
movq %rax, %r8
movb 0x11c(%r14), %al
jmp 0x2c739d
xorl %r8d, %r8d
movq 0x18(%rsp), %rcx
cmpb $0x0, 0x61(%rcx)
jne 0x2c7420
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rcx
leaq 0x68(%rsp), %rdx
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rdx)
movups %xmm0, (%rdx)
movq %r14, 0x50(%rsp)
movq %rcx, 0x58(%rsp)
movq %rsi, 0x28(%rsp)
movq %rsi, 0x60(%rsp)
movl $0x81, 0x78(%rsp)
movq (%r14), %r14
movb 0x65(%r14), %r12b
cmpb $0x1, %al
ja 0x2c73eb
movb $0x1, 0x65(%r14)
leaq 0x50(%rsp), %rdi
movq %r8, 0x10(%rsp)
movq %r8, %rsi
callq 0x2c496c
movb %r12b, 0x65(%r14)
xorl %ecx, %ecx
testl %eax, %eax
je 0x2c74e7
movq 0x10(%rsp), %r8
movl %ecx, 0xc(%rsp)
movq 0x40(%rsp), %r14
movb 0x11c(%r14), %al
cmpb $0x1, %al
ja 0x2c7436
testq %r8, %r8
je 0x2c7436
movq 0x18(%rsp), %rdi
movq %r8, %rsi
callq 0x2a6164
movl 0xc(%rsp), %r12d
testl %r12d, %r12d
jle 0x2c74dd
cmpb $0x1, 0x11c(%r14)
ja 0x2c74c1
movq $0x0, 0x50(%rsp)
movl $0x0, 0x58(%rsp)
movq 0x18(%rsp), %rdi
movl $0x98, %esi
leaq 0x50(%rsp), %rdx
xorl %ecx, %ecx
callq 0x2b1c27
testq %rax, %rax
je 0x2c75a0
orb $0x4, 0x5(%rax)
movl %r12d, 0x8(%rax)
movq (%r13), %rdx
movq %r13, %rcx
cmpq %r15, %rdx
je 0x2c74a2
movq %rdx, %rcx
movq 0x10(%rdx), %rdx
cmpb $0x6f, (%rdx)
je 0x2c7492
addq $0x10, %rcx
movq %rax, (%rcx)
testq %r15, %r15
je 0x2c74bc
movq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0x2a6164
movl 0xc(%rsp), %r12d
movw %r12w, 0x14(%r13)
orb $0x4, 0x11(%r13)
movq 0x30(%rsp), %rdi
incl %ebp
addq $0x18, %r13
movl (%rdi), %eax
cmpl %eax, %ebp
jl 0x2c72d4
jmp 0x2c7543
movl $0x1, 0x24(%rsp)
jmp 0x2c74c6
movq 0x28(%rsp), %rax
cmpl $0x0, (%rax)
jle 0x2c740b
leaq 0x8(%rax), %r14
xorl %r12d, %r12d
movq 0x10(%rsp), %r8
movq (%r14), %rsi
xorl %edi, %edi
movq %r8, %rdx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x2c0d98
cmpl $0x1, %eax
jbe 0x2c7538
incq %r12
movq 0x28(%rsp), %rax
movslq (%rax), %rax
addq $0x18, %r14
cmpq %rax, %r12
movq 0x10(%rsp), %r8
jl 0x2c7501
xorl %ecx, %ecx
jmp 0x2c7410
incl %r12d
movl %r12d, %ecx
jmp 0x2c740b
movq 0x58(%rbx), %rbx
testq %rbx, %rbx
je 0x2c7557
cmpl $0x0, 0x24(%rsp)
jne 0x2c72b4
testl %eax, %eax
jle 0x2c7580
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
movl $0x1, %edx
xorl %ecx, %ecx
testb $0x4, 0x19(%rdi,%rcx)
je 0x2c75b7
incl %edx
addq $0x18, %rcx
xorl %eax, %eax
cmpq %rcx, %rsi
jne 0x2c756a
jmp 0x2c75a5
xorl %eax, %eax
jmp 0x2c75a5
incl %ebp
leaq 0x1109c6(%rip), %rsi    # 0x3d7f53
leaq 0x11070f(%rip), %rcx    # 0x3d7ca3
movq %r14, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x27b48d
movl $0x1, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x110aaf(%rip), %rsi    # 0x3d806d
movq %r14, %rdi
xorl %eax, %eax
callq 0x27b48d
jmp 0x2c75a0