// File: /workspace/github_c_makefile_star2_O1/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 $0x78, %rsp
movq %rdi, %r14
movq 0x48(%rsi), %rdi
testq %rdi, %rdi
je 0x2d0cac
movq (%r14), %rcx
movl (%rdi), %eax
movq %rcx, 0x8(%rsp)
cmpl 0x84(%rcx), %eax
jle 0x2d0917
leaq 0x110e98(%rip), %rsi    # 0x3e17a0
movq %r14, %rdi
xorl %eax, %eax
callq 0x284eb8
jmp 0x2d0cc1
testl %eax, %eax
jle 0x2d0933
shlq $0x3, %rax
leaq (%rax,%rax,2), %rax
xorl %ecx, %ecx
andb $-0x5, 0x19(%rdi,%rcx)
addq $0x18, %rcx
cmpq %rcx, %rax
jne 0x2d0925
movq $0x0, 0x58(%rsi)
movq 0x50(%rsi), %rax
testq %rax, %rax
je 0x2d0959
movq %rax, %rcx
movq %rsi, 0x58(%rax)
movq 0x50(%rax), %rax
movq %rcx, %rsi
testq %rax, %rax
jne 0x2d0944
jmp 0x2d095c
movq %rsi, %rcx
leaq 0x8(%rdi), %rax
movq %rax, 0x38(%rsp)
movl $0x1, %eax
movq %r14, 0x10(%rsp)
movq %rdi, 0x18(%rsp)
testq %rcx, %rcx
je 0x2d0c83
testl %eax, %eax
je 0x2d0c83
cmpl $0x0, (%rdi)
movq %rcx, 0x20(%rsp)
jle 0x2d0c59
movq 0x20(%rcx), %rax
movq %rax, 0x28(%rsp)
movl $0x0, 0x4(%rsp)
movq 0x38(%rsp), %rbx
xorl %r12d, %r12d
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
testb $0x4, 0x11(%rbx)
jne 0x2d09e6
movq (%rbx), %r13
testq %r13, %r13
je 0x2d09f3
movl 0x4(%r13), %eax
testl $0x41000, %eax          # imm = 0x41000
je 0x2d09f3
btl $0x12, %eax
jb 0x2d09d8
addq $0x10, %r13
jmp 0x2d09e0
movq 0x20(%r13), %r13
addq $0x8, %r13
movq (%r13), %r13
jmp 0x2d09bc
movl $0xb, %r15d
xorl %ebp, %ebp
jmp 0x2d0bea
movq %r13, %rdi
movq %rsp, %rsi
callq 0x2d2e59
testl %eax, %eax
je 0x2d0a48
movl (%rsp), %eax
testl %eax, %eax
jle 0x2d0a16
movq 0x28(%rsp), %rcx
cmpl (%rcx), %eax
jle 0x2d0b3b
leal 0x1(%r12), %edx
movq 0x28(%rsp), %rax
movl (%rax), %r8d
xorl %ebp, %ebp
movq %r14, %rdi
leaq 0x110c79(%rip), %rsi    # 0x3e16a8
leaq 0x1109c2(%rip), %rcx    # 0x3e13f8
xorl %eax, %eax
callq 0x284eb8
movl $0x1, %r15d
jmp 0x2d0be5
movq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x2d2dd2
movl %eax, (%rsp)
testl %eax, %eax
jne 0x2d0b3b
cmpb $0x1, 0x11c(%r14)
movq %r13, %rbp
ja 0x2d0a8a
testq %r13, %r13
je 0x2d0a88
movq 0x8(%rsp), %rdi
movq %r13, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2cbf97
movq %rax, %rbp
jmp 0x2d0a8a
xorl %ebp, %ebp
movq 0x8(%rsp), %rax
cmpb $0x0, 0x61(%rax)
jne 0x2d0b1f
movq 0x20(%rsp), %rax
movq 0x20(%rax), %rcx
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x70(%rsp)
movq %r14, 0x40(%rsp)
movq 0x28(%rax), %rax
movq %rax, 0x48(%rsp)
movq %rcx, 0x30(%rsp)
movq %rcx, 0x50(%rsp)
movabsq $0x8100000000, %rax     # imm = 0x8100000000
movq %rax, 0x64(%rsp)
movq %r14, %rax
movq (%r14), %r14
movb 0x65(%r14), %r15b
cmpb $0x1, 0x11c(%rax)
ja 0x2d0afc
movb $0x1, 0x65(%r14)
leaq 0x40(%rsp), %rdi
movq %rbp, %rsi
callq 0x2ce0ea
movb %r15b, 0x65(%r14)
xorl %ecx, %ecx
testl %eax, %eax
je 0x2d0c07
movl %ecx, (%rsp)
movq 0x10(%rsp), %r14
cmpb $0x1, 0x11c(%r14)
ja 0x2d0b3b
testq %rbp, %rbp
je 0x2d0b3b
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0x2afd54
movl (%rsp), %r14d
xorl %r15d, %r15d
movb $0x1, %bpl
testl %r14d, %r14d
jle 0x2d0bce
movq 0x10(%rsp), %rax
cmpb $0x1, 0x11c(%rax)
ja 0x2d0bc8
movq $0x0, 0x40(%rsp)
movl $0x0, 0x48(%rsp)
movq 0x8(%rsp), %rdi
movl $0x98, %esi
leaq 0x40(%rsp), %rdx
xorl %ecx, %ecx
callq 0x2bb38d
testq %rax, %rax
je 0x2d0bd8
orb $0x4, 0x5(%rax)
movl %r14d, 0x8(%rax)
movq (%rbx), %rdx
movq %rbx, %rcx
cmpq %r13, %rdx
je 0x2d0bab
movq %rdx, %rcx
movq 0x10(%rdx), %rdx
cmpb $0x6f, (%rdx)
je 0x2d0b9b
addq $0x10, %rcx
movq %rax, (%rcx)
testq %r13, %r13
je 0x2d0bc0
movq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x2afd54
movzwl (%rsp), %eax
movw %ax, 0x14(%rbx)
orb $0x4, 0x11(%rbx)
jmp 0x2d0be0
movl $0x1, 0x4(%rsp)
jmp 0x2d0be0
movl $0x1, %r15d
xorl %ebp, %ebp
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rdi
cmpl $0xb, %r15d
je 0x2d0bf5
testl %r15d, %r15d
jne 0x2d0c6f
incl %r12d
addq $0x18, %rbx
cmpl (%rdi), %r12d
jl 0x2d09ac
jmp 0x2d0c61
movq 0x30(%rsp), %rax
cmpl $0x0, (%rax)
jle 0x2d0b17
leaq 0x8(%rax), %r14
xorl %r15d, %r15d
movq (%r14), %rsi
xorl %edi, %edi
movq %rbp, %rdx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x2ca527
cmpl $0x1, %eax
jbe 0x2d0c4e
incq %r15
movq 0x30(%rsp), %rax
movslq (%rax), %rax
addq $0x18, %r14
cmpq %rax, %r15
jl 0x2d0c1c
xorl %ecx, %ecx
jmp 0x2d0b17
incl %r15d
movl %r15d, %ecx
jmp 0x2d0b17
movl $0x0, 0x4(%rsp)
movq 0x20(%rsp), %rcx
movq 0x58(%rcx), %rcx
movb $0x1, %bpl
jmp 0x2d0c74
movq 0x20(%rsp), %rcx
testb %bpl, %bpl
movl 0x4(%rsp), %eax
jne 0x2d0974
jmp 0x2d0cc1
movslq (%rdi), %rax
testq %rax, %rax
jle 0x2d0cac
shlq $0x3, %rax
leaq (%rax,%rax,2), %rax
movl $0x1, %edx
xorl %ecx, %ecx
testb $0x4, 0x19(%rdi,%rcx)
je 0x2d0cb0
incl %edx
addq $0x18, %rcx
cmpq %rcx, %rax
jne 0x2d0c9a
xorl %eax, %eax
jmp 0x2d0cc6
leaq 0x110b0b(%rip), %rsi    # 0x3e17c2
movq %r14, %rdi
xorl %eax, %eax
callq 0x284eb8
movl $0x1, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq