// File: /workspace/github_c_makefile_star2_O3/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:
movq 0x48(%rsi), %r9
testq %r9, %r9
je 0x490c6
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq (%rdi), %r8
movl (%r9), %r10d
cmpl 0x70(%r8), %r10d
jle 0x490c9
leaq 0x32234(%rip), %rsi     # 0x7b2ee
xorl %eax, %eax
callq 0x11842
jmp 0x493be
xorl %eax, %eax
retq
movq %rdi, -0x50(%rbp)
testl %r10d, %r10d
jle 0x490f0
movl $0x19, %ecx
xorl %edx, %edx
movq 0x8(%r9), %rax
andb $-0x2, (%rax,%rcx)
incq %rdx
movslq (%r9), %r10
addq $0x20, %rcx
cmpq %r10, %rdx
jl 0x490d9
movq $0x0, 0x58(%rsi)
movq 0x50(%rsi), %rcx
testq %rcx, %rcx
je 0x49116
movq %rcx, %rax
movq %rsi, 0x58(%rcx)
movq 0x50(%rcx), %rcx
movq %rax, %rsi
testq %rcx, %rcx
jne 0x49101
jmp 0x49119
movq %rsi, %rax
movq %r9, -0x68(%rbp)
movq %r8, -0x58(%rbp)
testl %r10d, %r10d
jle 0x493d5
movq %rax, -0x60(%rbp)
movq (%rax), %rax
movq %rax, -0x70(%rbp)
movq 0x8(%r9), %r15
xorl %ebx, %ebx
movl $0x0, -0x3c(%rbp)
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
testb $0x1, 0x19(%r15)
jne 0x492d9
movq (%r15), %r13
testq %r13, %r13
je 0x49171
movzbl (%r13), %eax
cmpl $0x5c, %eax
je 0x4916b
cmpl $0x18, %eax
jne 0x49174
movq 0x10(%r13), %r13
jmp 0x49157
xorl %r13d, %r13d
movq %r13, %rdi
leaq -0x2c(%rbp), %rsi
callq 0x4ac9f
testl %eax, %eax
je 0x491a6
movl -0x2c(%rbp), %r12d
movq -0x70(%rbp), %rax
movl (%rax), %r8d
testl %r12d, %r12d
jle 0x493a1
cmpl %r8d, %r12d
jle 0x4926b
jmp 0x493a1
movq -0x70(%rbp), %rdi
movq %r13, %rsi
callq 0x4b708
movl %eax, %r12d
movl %eax, -0x2c(%rbp)
testl %eax, %eax
jne 0x49262
movq -0x58(%rbp), %r14
movq %r14, %rdi
movq %r13, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x4848c
movq %rax, %rsi
cmpb $0x0, 0x50(%r14)
je 0x491e3
movl -0x2c(%rbp), %r12d
jmp 0x49259
movq -0x60(%rbp), %rax
movq (%rax), %rdx
movq 0x28(%rax), %rax
leaq -0xa0(%rbp), %rcx
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rcx)
movups %xmm0, (%rcx)
movq -0x50(%rbp), %rcx
movq %rcx, -0xb8(%rbp)
movq %rax, -0xb0(%rbp)
movq %rdx, -0x48(%rbp)
movq %rdx, -0xa8(%rbp)
movb $0x1, %al
movb %al, -0x88(%rbp)
movq (%rcx), %r12
movb 0x53(%r12), %r14b
movb %al, 0x53(%r12)
leaq -0xb8(%rbp), %rdi
movq %rsi, -0x38(%rbp)
callq 0x46b2f
movb %r14b, 0x53(%r12)
xorl %r12d, %r12d
testl %eax, %eax
je 0x492f6
movq -0x38(%rbp), %rsi
movl %r12d, -0x2c(%rbp)
movq -0x58(%rbp), %rdi
callq 0x3479d
testl %r12d, %r12d
jle 0x492ed
movq $0x0, -0xb8(%rbp)
movl $0x0, -0xb0(%rbp)
movq -0x58(%rbp), %r14
movq %r14, %rdi
movl $0x81, %esi
leaq -0xb8(%rbp), %rdx
xorl %ecx, %ecx
callq 0x4aaef
testq %rax, %rax
je 0x493be
orb $0x4, 0x3(%rax)
movl %r12d, 0x8(%rax)
movq (%r15), %rcx
leaq 0x10(%rcx), %rdx
cmpq %r13, %rcx
cmoveq %r15, %rdx
movq %rax, (%rdx)
movq %r14, %rdi
movq %r13, %rsi
callq 0x3479d
movzwl -0x2c(%rbp), %eax
movw %ax, 0x1a(%r15)
orb $0x1, 0x19(%r15)
movq -0x68(%rbp), %r9
incl %ebx
addq $0x20, %r15
movl (%r9), %r10d
cmpl %r10d, %ebx
jl 0x49142
jmp 0x49360
movl $0x1, -0x3c(%rbp)
jmp 0x492d5
movq -0x48(%rbp), %rcx
movslq (%rcx), %rax
testq %rax, %rax
jle 0x49251
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 0x4b798
cmpl $0x2, %eax
jb 0x49357
movl -0x48(%rbp), %ecx
incl %ecx
addq $0x20, %r14
movq -0x78(%rbp), %rax
cmpq %r14, %rax
movq -0x38(%rbp), %rsi
jne 0x49322
jmp 0x49255
movl -0x48(%rbp), %r12d
jmp 0x49251
movq -0x60(%rbp), %rax
movq 0x58(%rax), %rax
testq %rax, %rax
je 0x49377
cmpl $0x0, -0x3c(%rbp)
jne 0x49121
testl %r10d, %r10d
jle 0x493d5
movq 0x8(%r9), %rcx
shlq $0x5, %r10
movl $0x1, %edx
xorl %esi, %esi
testb $0x1, 0x19(%rcx,%rsi)
je 0x493d9
incl %edx
addq $0x20, %rsi
xorl %eax, %eax
cmpq %rsi, %r10
jne 0x4938b
jmp 0x493c3
incl %ebx
leaq 0x31eed(%rip), %rsi     # 0x7b297
leaq 0x31d17(%rip), %rcx     # 0x7b0c8
movq -0x50(%rbp), %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x11842
movl $0x1, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0x493c3
leaq 0x31f30(%rip), %rsi     # 0x7b310
movq -0x50(%rbp), %rdi
xorl %eax, %eax
callq 0x11842
jmp 0x493be