// File: /workspace/github_c_makefile_star2_O0/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
subq $0x70, %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 0x62a96
movl $0x0, -0x4(%rbp)
jmp 0x62dab
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
movq -0x38(%rbp), %rcx
cmpl 0x70(%rcx), %eax
jle 0x62ace
movq -0x10(%rbp), %rdi
leaq 0x4d32f(%rip), %rsi     # 0xafdea
movb $0x0, %al
callq 0x136f0
movl $0x1, -0x4(%rbp)
jmp 0x62dab
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x62b0a
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movb 0x19(%rax), %cl
andb $-0x2, %cl
orb $0x0, %cl
movb %cl, 0x19(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x62ad5
movq -0x18(%rbp), %rax
movq $0x0, 0x58(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x50(%rax)
je 0x62b3f
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 0x62b16
jmp 0x62b41
xorl %eax, %eax
cmpq $0x0, -0x18(%rbp)
movb %al, -0x69(%rbp)
je 0x62b57
cmpl $0x0, -0x3c(%rbp)
setne %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0x62b63
jmp 0x62d44
movl $0x0, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movl -0x1c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x62d33
movl $0xffffffff, -0x4c(%rbp) # imm = 0xFFFFFFFF
movq -0x48(%rbp), %rax
movb 0x19(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x62bb4
jmp 0x62d19
movq -0x48(%rbp), %rax
movq (%rax), %rdi
callq 0x648b0
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x65040
cmpl $0x0, %eax
je 0x62c11
cmpl $0x0, -0x4c(%rbp)
jle 0x62be7
movl -0x4c(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl (%rcx), %eax
jle 0x62c0f
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %edx
addl $0x1, %edx
movq -0x30(%rbp), %rax
movl (%rax), %ecx
leaq 0x4cfc6(%rip), %rsi     # 0xafbc4
callq 0x661e0
movl $0x1, -0x4(%rbp)
jmp 0x62dab
jmp 0x62c6b
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x58(%rbp), %rdx
callq 0x66140
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jne 0x62c69
movq -0x38(%rbp), %rdi
movq -0x58(%rbp), %rsi
xorl %edx, %edx
callq 0x61690
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rax
cmpb $0x0, 0x50(%rax)
jne 0x62c5c
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x60(%rbp), %rdx
callq 0x66780
movl %eax, -0x4c(%rbp)
movq -0x38(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x47330
jmp 0x62c6b
cmpl $0x0, -0x4c(%rbp)
jle 0x62d10
movq -0x38(%rbp), %rdi
movl $0x81, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x548b0
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0x62c9e
movl $0x1, -0x4(%rbp)
jmp 0x62dab
movq -0x68(%rbp), %rax
movzwl 0x2(%rax), %ecx
orl $0x400, %ecx            # imm = 0x400
movw %cx, 0x2(%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 0x62cd4
movq -0x68(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
jmp 0x62ce3
movq -0x68(%rbp), %rcx
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x47330
movl -0x4c(%rbp), %eax
movw %ax, %cx
movq -0x48(%rbp), %rax
movw %cx, 0x1a(%rax)
movq -0x48(%rbp), %rax
movb 0x19(%rax), %cl
andb $-0x2, %cl
orb $0x1, %cl
movb %cl, 0x19(%rax)
jmp 0x62d17
movl $0x1, -0x3c(%rbp)
jmp 0x62d19
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movq -0x48(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x48(%rbp)
jmp 0x62b88
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x62b41
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x62da4
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movb 0x19(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x62d97
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %edx
addl $0x1, %edx
leaq 0x4d085(%rip), %rsi     # 0xafe0c
movb $0x0, %al
callq 0x136f0
movl $0x1, -0x4(%rbp)
jmp 0x62dab
jmp 0x62d99
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x62d4b
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)