// File: /workspace/github_c_makefile_star2_O3/shifengbin[P]bishe/Output/../Persistence/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 SQLITE_MAX_COLUMN
  if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
    sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause");
    return 1;
  }
#endif
  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 = sqlite3ExprSkipCollate(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 ){
          pDup = sqlite3ExprDup(db, pE, 0);
          if( !db->mallocFailed ){
            assert(pDup);
            iCol = resolveOrderByTermToExprList(pParse, pSelect, pDup);
          }
          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 */
        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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, %r14
movq 0x48(%rsi), %rdi
testq %rdi, %rdi
je 0x57983
movq (%r14), %rcx
movl (%rdi), %r8d
movq %rcx, -0x50(%rbp)
cmpl 0x70(%rcx), %r8d
jle 0x57692
leaq 0x25c55(%rip), %rsi     # 0x7d2d8
movq %r14, %rdi
xorl %eax, %eax
callq 0x14890
jmp 0x579a3
testl %r8d, %r8d
jle 0x576b5
movl $0x19, %ecx
xorl %edx, %edx
movq 0x8(%rdi), %rax
andb $-0x2, (%rax,%rcx)
incq %rdx
movslq (%rdi), %r8
addq $0x20, %rcx
cmpq %r8, %rdx
jl 0x5769e
movq $0x0, 0x58(%rsi)
movq 0x50(%rsi), %rcx
testq %rcx, %rcx
je 0x576db
movq %rcx, %rax
movq %rsi, 0x58(%rcx)
movq 0x50(%rcx), %rcx
movq %rax, %rsi
testq %rcx, %rcx
jne 0x576c6
jmp 0x576de
movq %rsi, %rax
movq %rdi, -0x60(%rbp)
movq %r14, -0x70(%rbp)
testl %r8d, %r8d
jle 0x57983
movq %rax, -0x58(%rbp)
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movq 0x8(%rdi), %r15
xorl %ebx, %ebx
movl $0x0, -0x3c(%rbp)
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
testb $0x1, 0x19(%r15)
jne 0x578bb
movq (%r15), %r13
testq %r13, %r13
je 0x57745
movl 0x4(%r13), %eax
btl $0xc, %eax
jae 0x57748
btl $0x12, %eax
jb 0x57737
addq $0x10, %r13
jmp 0x5773f
movq 0x20(%r13), %rax
movq 0x8(%rax), %r13
movq (%r13), %r13
jmp 0x5771c
xorl %r13d, %r13d
movq %r13, %rdi
leaq -0x2c(%rbp), %rsi
callq 0x54283
testl %eax, %eax
je 0x5777a
movl -0x2c(%rbp), %r12d
movq -0x68(%rbp), %rax
movl (%rax), %r8d
testl %r12d, %r12d
jle 0x57987
cmpl %r8d, %r12d
jle 0x57842
jmp 0x57987
movq -0x68(%rbp), %rdi
movq %r13, %rsi
callq 0x59892
movl %eax, %r12d
movl %eax, -0x2c(%rbp)
testl %eax, %eax
jne 0x57839
movq -0x50(%rbp), %r12
movq %r12, %rdi
movq %r13, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x5388d
movq %rax, %rsi
cmpb $0x0, 0x51(%r12)
je 0x577b8
movl -0x2c(%rbp), %r12d
jmp 0x57830
movq -0x58(%rbp), %rax
movq (%rax), %rdx
movq 0x28(%rax), %rax
leaq -0xa0(%rbp), %rcx
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rcx)
movups %xmm0, (%rcx)
movq %r14, -0xb8(%rbp)
movq %rax, -0xb0(%rbp)
movq %rdx, -0x48(%rbp)
movq %rdx, -0xa8(%rbp)
movw $0x1, -0x88(%rbp)
movq (%r14), %r12
movb 0x54(%r12), %r14b
movb $0x1, 0x54(%r12)
leaq -0xb8(%rbp), %rdi
movq %rsi, -0x38(%rbp)
callq 0x55a7d
movb %r14b, 0x54(%r12)
xorl %r12d, %r12d
testl %eax, %eax
je 0x578d8
movq -0x38(%rbp), %rsi
movl %r12d, -0x2c(%rbp)
movq -0x70(%rbp), %r14
movq -0x50(%rbp), %rdi
callq 0x3c8fe
testl %r12d, %r12d
jle 0x578cf
movq $0x0, -0xb8(%rbp)
movl $0x0, -0xb0(%rbp)
movq -0x50(%rbp), %rdi
movl $0x84, %esi
leaq -0xb8(%rbp), %rdx
xorl %ecx, %ecx
callq 0x5589f
testq %rax, %rax
je 0x579a3
orb $0x4, 0x5(%rax)
movl %r12d, 0x8(%rax)
movq (%r15), %rdx
movq %r15, %rcx
cmpq %r13, %rdx
je 0x5789a
movq %rdx, %rcx
movq 0x10(%rdx), %rdx
cmpb $0x5f, (%rdx)
je 0x5788a
addq $0x10, %rcx
movq %rax, (%rcx)
movq -0x50(%rbp), %rdi
movq %r13, %rsi
callq 0x3c8fe
movzwl -0x2c(%rbp), %eax
movw %ax, 0x1c(%r15)
orb $0x1, 0x19(%r15)
movq -0x60(%rbp), %rdi
incl %ebx
addq $0x20, %r15
movl (%rdi), %r8d
cmpl %r8d, %ebx
jl 0x57707
jmp 0x57942
movl $0x1, -0x3c(%rbp)
jmp 0x578b7
movq -0x48(%rbp), %rcx
movslq (%rcx), %rax
testq %rax, %rax
jle 0x57824
movq 0x8(%rcx), %rcx
movq %rcx, -0x80(%rbp)
shlq $0x5, %rax
movl $0x1, %ecx
xorl %r14d, %r14d
movq -0x38(%rbp), %rsi
movq %rax, -0x78(%rbp)
movl %ecx, -0x48(%rbp)
movq -0x80(%rbp), %rax
movq (%rax,%r14), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x532d3
cmpl $0x2, %eax
jb 0x57939
movl -0x48(%rbp), %ecx
incl %ecx
addq $0x20, %r14
movq -0x78(%rbp), %rax
cmpq %r14, %rax
movq -0x38(%rbp), %rsi
jne 0x57904
jmp 0x57828
movl -0x48(%rbp), %r12d
jmp 0x57824
movq -0x58(%rbp), %rax
movq 0x58(%rax), %rax
testq %rax, %rax
je 0x57959
cmpl $0x0, -0x3c(%rbp)
jne 0x576e6
testl %r8d, %r8d
jle 0x57983
movq 0x8(%rdi), %rcx
shlq $0x5, %r8
movl $0x1, %edx
xorl %esi, %esi
testb $0x1, 0x19(%rcx,%rsi)
je 0x579ba
incl %edx
addq $0x20, %rsi
xorl %eax, %eax
cmpq %rsi, %r8
jne 0x5796d
jmp 0x579a8
xorl %eax, %eax
jmp 0x579a8
incl %ebx
leaq 0x25850(%rip), %rsi     # 0x7d1e0
leaq 0x255e1(%rip), %rcx     # 0x7cf78
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x14890
movl $0x1, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x25939(%rip), %rsi     # 0x7d2fa
movq %r14, %rdi
xorl %eax, %eax
callq 0x14890
jmp 0x579a3