// File: /workspace/github_c_makefile_star2_O1/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: convertCompoundSelectToSubquery
static int convertCompoundSelectToSubquery(Walker *pWalker, Select *p){
  int i;
  Select *pNew;
  Select *pX;
  sqlite3 *db;
  struct ExprList_item *a;
  SrcList *pNewSrc;
  Parse *pParse;
  Token dummy;

  if( p->pPrior==0 ) return WRC_Continue;
  if( p->pOrderBy==0 ) return WRC_Continue;
  for(pX=p; pX && (pX->op==TK_ALL || pX->op==TK_SELECT); pX=pX->pPrior){}
  if( pX==0 ) return WRC_Continue;
  a = p->pOrderBy->a;
  for(i=p->pOrderBy->nExpr-1; i>=0; i--){
    if( a[i].pExpr->flags & EP_Collate ) break;
  }
  if( i<0 ) return WRC_Continue;

  /* If we reach this point, that means the transformation is required. */

  pParse = pWalker->pParse;
  db = pParse->db;
  pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
  if( pNew==0 ) return WRC_Abort;
  memset(&dummy, 0, sizeof(dummy));
  pNewSrc = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&dummy,pNew,0,0);
  if( pNewSrc==0 ) return WRC_Abort;
  *pNew = *p;
  p->pSrc = pNewSrc;
  p->pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ALL, 0));
  p->op = TK_SELECT;
  p->pWhere = 0;
  pNew->pGroupBy = 0;
  pNew->pHaving = 0;
  pNew->pOrderBy = 0;
  p->pPrior = 0;
  pNew->pLimit = 0;
  pNew->pOffset = 0;
  return WRC_Continue;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
xorl %r14d, %r14d
cmpq $0x0, 0x50(%rsi)
je 0x491cd
movq %rsi, %rbx
movq 0x48(%rsi), %rax
testq %rax, %rax
sete %cl
testq %rsi, %rsi
sete %dl
orb %cl, %dl
jne 0x491cd
movq %rbx, %rcx
movzbl 0x8(%rcx), %edx
cmpl $0x74, %edx
je 0x491c4
cmpl $0x71, %edx
jne 0x491df
movq 0x50(%rcx), %rcx
testq %rcx, %rcx
jne 0x491b6
movl %r14d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rax), %rdx
movl (%rax), %eax
movl %eax, %ecx
sarl $0x1f, %ecx
andl %eax, %ecx
movq %rax, %rsi
shlq $0x5, %rsi
addq %rsi, %rdx
addq $-0x20, %rdx
testl %eax, %eax
jle 0x49211
movq (%rdx), %rsi
decl %eax
addq $-0x20, %rdx
testb $0x1, 0x3(%rsi)
je 0x491fa
incl %eax
movl %eax, %ecx
testl %ecx, %ecx
jle 0x491cd
movq 0x10(%rdi), %r12
movq (%r12), %r13
movq %r13, %rdi
movl $0x78, %esi
callq 0x115e9
movl $0x2, %r14d
testq %rax, %rax
je 0x491cd
movq %rax, %r15
xorps %xmm0, %xmm0
movups %xmm0, 0x60(%rax)
movups %xmm0, 0x50(%rax)
movups %xmm0, 0x40(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq $0x0, 0x70(%rax)
leaq -0x40(%rbp), %r8
movaps %xmm0, (%r8)
movups %xmm0, (%rsp)
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movq %rax, %r9
callq 0x3d62d
testq %rax, %rax
je 0x491cd
movl $0xf, %ecx
movq %r15, %rdi
movq %rbx, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rax, 0x28(%rbx)
leaq -0x50(%rbp), %rdx
xorl %r14d, %r14d
movq %r14, (%rdx)
movl $0x0, 0x8(%rdx)
movq %r13, %rdi
movl $0x71, %esi
xorl %ecx, %ecx
callq 0x4a949
movq %r12, %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0x3d42f
movq %rax, (%rbx)
movb $0x74, 0x8(%rbx)
movq %r14, 0x30(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x38(%r15)
movq %r14, 0x48(%r15)
movq %r14, 0x50(%rbx)
movups %xmm0, 0x68(%r15)
xorl %r14d, %r14d
jmp 0x491cd