// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x1, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x438aa9
movl $0x0, -0x4(%rbp)
jmp 0x438e2f
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
movq -0x38(%rbp), %rcx
cmpl 0x84(%rcx), %eax
jle 0x438ae4
movq -0x10(%rbp), %rdi
leaq 0x174a14(%rip), %rsi    # 0x5ad4e5
movb $0x0, %al
callq 0x3cb660
movl $0x1, -0x4(%rbp)
jmp 0x438e2f
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x438b20
movq -0x28(%rbp), %rax
addq $0x8, %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movb 0x11(%rax), %cl
andb $-0x5, %cl
orb $0x0, %cl
movb %cl, 0x11(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x438aeb
movq -0x18(%rbp), %rax
movq $0x0, 0x58(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x50(%rax)
je 0x438b55
movq -0x18(%rbp), %rcx
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rax
movq %rcx, 0x58(%rax)
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x438b2c
jmp 0x438b57
xorl %eax, %eax
cmpq $0x0, -0x18(%rbp)
movb %al, -0x71(%rbp)
je 0x438b6d
cmpl $0x0, -0x3c(%rbp)
setne %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x438b79
jmp 0x438dc5
movl $0x0, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x28(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x48(%rbp)
movl -0x1c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x438db4
movl $0xffffffff, -0x4c(%rbp) # imm = 0xFFFFFFFF
movq -0x48(%rbp), %rax
movb 0x11(%rax), %al
shrb $0x2, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x438bce
jmp 0x438d9a
movq -0x48(%rbp), %rax
movq (%rax), %rdi
callq 0x42f120
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x43bf50
cmpl $0x0, %eax
je 0x438c2e
cmpl $0x0, -0x4c(%rbp)
jle 0x438c01
movl -0x4c(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl (%rcx), %eax
jle 0x438c29
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %edx
addl $0x1, %edx
movq -0x30(%rbp), %rax
movl (%rax), %ecx
leaq 0x174525(%rip), %rsi    # 0x5ad13d
callq 0x43c020
movl $0x1, -0x4(%rbp)
jmp 0x438e2f
jmp 0x438cb4
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x58(%rbp), %rdx
callq 0x43bea0
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jne 0x438cb2
movq -0x10(%rbp), %rax
movzbl 0x11c(%rax), %eax
cmpl $0x2, %eax
jl 0x438c62
movq -0x58(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0x438c75
movq -0x38(%rbp), %rdi
movq -0x58(%rbp), %rsi
xorl %edx, %edx
callq 0x42dee0
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rax
cmpb $0x0, 0x61(%rax)
jne 0x438c93
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x60(%rbp), %rdx
callq 0x43c2c0
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x11c(%rax), %eax
cmpl $0x2, %eax
jge 0x438cb0
movq -0x38(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x40c670
jmp 0x438cb2
jmp 0x438cb4
cmpl $0x0, -0x4c(%rbp)
jle 0x438d91
movq -0x10(%rbp), %rax
movzbl 0x11c(%rax), %eax
cmpl $0x2, %eax
jge 0x438d7f
movq -0x38(%rbp), %rdi
movl $0x98, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x41d620
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0x438cfb
movl $0x1, -0x4(%rbp)
jmp 0x438e2f
movq -0x68(%rbp), %rax
movl 0x4(%rax), %ecx
orl $0x400, %ecx            # imm = 0x400
movl %ecx, 0x4(%rax)
movl -0x4c(%rbp), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x48(%rbp), %rax
movq (%rax), %rax
cmpq -0x58(%rbp), %rax
jne 0x438d2f
movq -0x68(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
jmp 0x438d64
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq 0x10(%rax), %rax
movzbl (%rax), %eax
cmpl $0x6f, %eax
jne 0x438d58
movq -0x70(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x70(%rbp)
jmp 0x438d3a
movq -0x68(%rbp), %rcx
movq -0x70(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x40c670
movl -0x4c(%rbp), %eax
movw %ax, %cx
movq -0x48(%rbp), %rax
movw %cx, 0x14(%rax)
movq -0x48(%rbp), %rax
movb 0x11(%rax), %cl
andb $-0x5, %cl
orb $0x4, %cl
movb %cl, 0x11(%rax)
jmp 0x438d98
movl $0x1, -0x3c(%rbp)
jmp 0x438d9a
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movq -0x48(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x48(%rbp)
jmp 0x438b9f
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x438b57
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x438e28
movq -0x28(%rbp), %rax
addq $0x8, %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movb 0x11(%rax), %al
shrb $0x2, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x438e1b
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %edx
addl $0x1, %edx
leaq 0x1746fc(%rip), %rsi    # 0x5ad507
movb $0x0, %al
callq 0x3cb660
movl $0x1, -0x4(%rbp)
jmp 0x438e2f
jmp 0x438e1d
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x438dcc
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)