// File: /workspace/github_c_makefile_star2_O1/barabo[P]advanced-shell-history/src/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{
          assert( pItem->pExpr->op==TK_COLLATE );
          assert( pItem->pExpr->pLeft==pE );
          pItem->pExpr->pLeft = pNew;
        }
        sqlite3ExprDelete(db, pE);
        pItem->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 $0x88, %rsp
movq 0x48(%rsi), %rbx
testq %rbx, %rbx
je 0x4914c
movq (%rdi), %rcx
movl (%rbx), %eax
movq %rcx, -0x40(%rbp)
cmpl 0x70(%rcx), %eax
jle 0x48e02
leaq 0x324f8(%rip), %rsi     # 0x7b2ee
xorl %eax, %eax
callq 0x11724
jmp 0x49162
movq %rdi, -0x58(%rbp)
cmpl $0x0, (%rbx)
jle 0x48e29
movl $0x19, %eax
xorl %ecx, %ecx
movq 0x8(%rbx), %rdx
andb $-0x2, (%rdx,%rax)
incq %rcx
movslq (%rbx), %rdx
addq $0x20, %rax
cmpq %rdx, %rcx
jl 0x48e12
movq $0x0, 0x58(%rsi)
movq 0x50(%rsi), %rax
testq %rax, %rax
je 0x48e4f
movq %rax, %rcx
movq %rsi, 0x58(%rax)
movq 0x50(%rax), %rax
movq %rcx, %rsi
testq %rax, %rax
jne 0x48e3a
jmp 0x48e52
movq %rsi, %rcx
movl $0x1, %eax
movq %rbx, -0x60(%rbp)
testq %rcx, %rcx
je 0x49123
testl %eax, %eax
je 0x49123
cmpl $0x0, (%rbx)
movq %rcx, -0x50(%rbp)
jle 0x490fd
movq (%rcx), %rax
movq %rax, -0x68(%rbp)
movq 0x8(%rbx), %r13
xorl %r14d, %r14d
movl $0x0, -0x30(%rbp)
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
testb $0x1, 0x19(%r13)
jne 0x48ebb
movq (%r13), %r12
testq %r12, %r12
je 0x48ec9
movzbl (%r12), %eax
cmpl $0x5c, %eax
je 0x48eb4
cmpl $0x18, %eax
jne 0x48ec9
movq 0x10(%r12), %r12
jmp 0x48ea0
movl $0xb, %r15d
xorl %r12d, %r12d
jmp 0x49079
movq %r12, %rdi
leaq -0x2c(%rbp), %rsi
callq 0x4aaf6
testl %eax, %eax
je 0x48f1e
movl -0x2c(%rbp), %eax
testl %eax, %eax
jle 0x48eec
movq -0x68(%rbp), %rcx
cmpl (%rcx), %eax
jle 0x48fe9
leal 0x1(%r14), %edx
movq -0x68(%rbp), %rax
movl (%rax), %r8d
xorl %r12d, %r12d
movq -0x58(%rbp), %rdi
leaq 0x32392(%rip), %rsi     # 0x7b297
leaq 0x321bc(%rip), %rcx     # 0x7b0c8
xorl %eax, %eax
callq 0x11724
movl $0x1, %r15d
jmp 0x49079
movq -0x68(%rbp), %rdi
movq %r12, %rsi
callq 0x4b5c6
movl %eax, -0x2c(%rbp)
testl %eax, %eax
jne 0x48fe9
movq -0x40(%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x48163
movq %rax, %rsi
cmpb $0x0, 0x50(%rbx)
jne 0x48fe1
movq -0x50(%rbp), %rax
movq (%rax), %rdx
xorps %xmm0, %xmm0
movaps %xmm0, -0xb0(%rbp)
movaps %xmm0, -0x90(%rbp)
movaps %xmm0, -0xa0(%rbp)
movq $0x0, -0x80(%rbp)
movq -0x58(%rbp), %rcx
movq %rcx, -0xb0(%rbp)
movq 0x28(%rax), %rax
movq %rax, -0xa8(%rbp)
movq %rdx, -0x48(%rbp)
movq %rdx, -0xa0(%rbp)
movb $0x1, %al
movb %al, -0x80(%rbp)
movl $0x0, -0x84(%rbp)
movq (%rcx), %rbx
movb 0x53(%rbx), %r15b
movb %al, 0x53(%rbx)
leaq -0xb0(%rbp), %rdi
movq %rsi, -0x38(%rbp)
callq 0x467fe
movb %r15b, 0x53(%rbx)
xorl %r15d, %r15d
testl %eax, %eax
je 0x4909a
movq -0x38(%rbp), %rsi
movl %r15d, -0x2c(%rbp)
movq -0x40(%rbp), %rbx
movq %rbx, %rdi
callq 0x34068
movl -0x2c(%rbp), %ebx
testl %ebx, %ebx
jle 0x49059
movq $0x0, -0xb0(%rbp)
movl $0x0, -0xa8(%rbp)
xorl %r15d, %r15d
movq -0x40(%rbp), %rdi
movl $0x81, %esi
leaq -0xb0(%rbp), %rdx
xorl %ecx, %ecx
callq 0x4a949
testq %rax, %rax
je 0x4906c
orb $0x4, 0x3(%rax)
movl %ebx, 0x8(%rax)
movq (%r13), %rcx
leaq 0x10(%rcx), %rdx
cmpq %r12, %rcx
cmoveq %r13, %rdx
movq %rax, (%rdx)
movq -0x40(%rbp), %rdi
movq %r12, %rsi
callq 0x34068
movzwl -0x2c(%rbp), %eax
movw %ax, 0x1a(%r13)
orb $0x1, 0x19(%r13)
jmp 0x49063
xorl %r15d, %r15d
movl $0x1, -0x30(%rbp)
movq -0x60(%rbp), %rbx
movb $0x1, %r12b
jmp 0x49079
movl $0x1, %r15d
xorl %r12d, %r12d
movq -0x60(%rbp), %rbx
cmpl $0xb, %r15d
je 0x49088
testl %r15d, %r15d
jne 0x49111
incl %r14d
addq $0x20, %r13
cmpl (%rbx), %r14d
jl 0x48e8e
jmp 0x49104
movq -0x48(%rbp), %rcx
movslq (%rcx), %rax
testq %rax, %rax
jle 0x48fd5
movq 0x8(%rcx), %rcx
movq %rcx, -0x48(%rbp)
shlq $0x5, %rax
movl $0x1, %r15d
xorl %ebx, %ebx
movq -0x38(%rbp), %rsi
movq %rax, -0x70(%rbp)
movq -0x48(%rbp), %rax
movq (%rax,%rbx), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x4b67e
cmpl $0x2, %eax
jb 0x48fd5
incl %r15d
addq $0x20, %rbx
movq -0x70(%rbp), %rax
cmpq %rbx, %rax
movq -0x38(%rbp), %rsi
jne 0x490c6
xorl %r15d, %r15d
jmp 0x48fd9
movl $0x0, -0x30(%rbp)
movq -0x50(%rbp), %rcx
movq 0x58(%rcx), %rcx
movb $0x1, %r12b
jmp 0x49115
movq -0x50(%rbp), %rcx
testb %r12b, %r12b
movl -0x30(%rbp), %eax
jne 0x48e5b
jmp 0x49162
movslq (%rbx), %rax
testq %rax, %rax
jle 0x4914c
movq 0x8(%rbx), %rcx
shlq $0x5, %rax
movl $0x1, %edx
xorl %esi, %esi
testb $0x1, 0x19(%rcx,%rsi)
je 0x49150
incl %edx
addq $0x20, %rsi
cmpq %rsi, %rax
jne 0x4913a
xorl %eax, %eax
jmp 0x49167
leaq 0x321b9(%rip), %rsi     # 0x7b310
movq -0x58(%rbp), %rdi
xorl %eax, %eax
callq 0x11724
movl $0x1, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq