// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: sqlite3CodeSubselect
SQLITE_PRIVATE int sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
  int addrOnce = 0;           /* Address of OP_Once at top of subroutine */
  int rReg = 0;               /* Register storing resulting */
  Select *pSel;               /* SELECT statement to encode */
  SelectDest dest;            /* How to deal with SELECT result */
  int nReg;                   /* Registers to allocate */
  Expr *pLimit;               /* New limit expression */

  Vdbe *v = pParse->pVdbe;
  assert( v!=0 );
  testcase( pExpr->op==TK_EXISTS );
  testcase( pExpr->op==TK_SELECT );
  assert( pExpr->op==TK_EXISTS || pExpr->op==TK_SELECT );
  assert( ExprHasProperty(pExpr, EP_xIsSelect) );
  pSel = pExpr->x.pSelect;

  /* The evaluation of the EXISTS/SELECT must be repeated every time it
  ** is encountered if any of the following is true:
  **
  **    *  The right-hand side is a correlated subquery
  **    *  The right-hand side is an expression list containing variables
  **    *  We are inside a trigger
  **
  ** If all of the above are false, then we can run this code just once
  ** save the results, and reuse the same result on subsequent invocations.
  */
  if( !ExprHasProperty(pExpr, EP_VarSelect) ){
    /* If this routine has already been coded, then invoke it as a
    ** subroutine. */
    if( ExprHasProperty(pExpr, EP_Subrtn) ){
      ExplainQueryPlan((pParse, 0, "REUSE SUBQUERY %d", pSel->selId));
      sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
                        pExpr->y.sub.iAddr);
      return pExpr->iTable;
    }

    /* Begin coding the subroutine */
    ExprSetProperty(pExpr, EP_Subrtn);
    pExpr->y.sub.regReturn = ++pParse->nMem;
    pExpr->y.sub.iAddr =
      sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1;
    VdbeComment((v, "return address"));

    addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
  }

  /* For a SELECT, generate code to put the values for all columns of
  ** the first row into an array of registers and return the index of
  ** the first register.
  **
  ** If this is an EXISTS, write an integer 0 (not exists) or 1 (exists)
  ** into a register and return that register number.
  **
  ** In both cases, the query is augmented with "LIMIT 1".  Any
  ** preexisting limit is discarded in place of the new LIMIT 1.
  */
  ExplainQueryPlan((pParse, 1, "%sSCALAR SUBQUERY %d",
        addrOnce?"":"CORRELATED ", pSel->selId));
  nReg = pExpr->op==TK_SELECT ? pSel->pEList->nExpr : 1;
  sqlite3SelectDestInit(&dest, 0, pParse->nMem+1);
  pParse->nMem += nReg;
  if( pExpr->op==TK_SELECT ){
    dest.eDest = SRT_Mem;
    dest.iSdst = dest.iSDParm;
    dest.nSdst = nReg;
    sqlite3VdbeAddOp3(v, OP_Null, 0, dest.iSDParm, dest.iSDParm+nReg-1);
    VdbeComment((v, "Init subquery result"));
  }else{
    dest.eDest = SRT_Exists;
    sqlite3VdbeAddOp2(v, OP_Integer, 0, dest.iSDParm);
    VdbeComment((v, "Init EXISTS result"));
  }
  if( pSel->pLimit ){
    /* The subquery already has a limit.  If the pre-existing limit is X
    ** then make the new limit X<>0 so that the new limit is either 1 or 0 */
    sqlite3 *db = pParse->db;
    pLimit = sqlite3Expr(db, TK_INTEGER, "0");
    if( pLimit ){
      pLimit->affExpr = SQLITE_AFF_NUMERIC;
      pLimit = sqlite3PExpr(pParse, TK_NE,
                            sqlite3ExprDup(db, pSel->pLimit->pLeft, 0), pLimit);
    }
    sqlite3ExprDelete(db, pSel->pLimit->pLeft);
    pSel->pLimit->pLeft = pLimit;
  }else{
    /* If there is no pre-existing limit add a limit of 1 */
    pLimit = sqlite3Expr(pParse->db, TK_INTEGER, "1");
    pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
  }
  pSel->iLimit = 0;
  if( sqlite3Select(pParse, pSel, &dest) ){
    return 0;
  }
  pExpr->iTable = rReg = dest.iSDParm;
  ExprSetVVAProperty(pExpr, EP_NoReduce);
  if( addrOnce ){
    sqlite3VdbeJumpHere(v, addrOnce);

    /* Subroutine return */
    sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn);
    sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1);
    sqlite3ClearTempRegCache(pParse);
  }

  return rReg;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
jne 0x42d25b
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x2000000, %eax        # imm = 0x2000000
cmpl $0x0, %eax
je 0x42d203
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x10(%rax), %ecx
xorl %esi, %esi
leaq 0x17f932(%rip), %rdx    # 0x5acb03
movb $0x0, %al
callq 0x430b00
movq -0x68(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x44(%rax), %edx
movq -0x18(%rbp), %rax
movl 0x40(%rax), %ecx
movl $0xc, %esi
callq 0x410100
movq -0x18(%rbp), %rax
movl 0x2c(%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x42d4bd
movq -0x18(%rbp), %rax
movl 0x4(%rax), %ecx
orl $0x2000000, %ecx        # imm = 0x2000000
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rax
movl 0x38(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x38(%rax)
movq -0x18(%rbp), %rax
movl %ecx, 0x44(%rax)
movq -0x68(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x44(%rax), %ecx
movl $0x45, %esi
xorl %edx, %edx
callq 0x410100
movl %eax, %ecx
addl $0x1, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x40(%rax)
movq -0x68(%rbp), %rdi
movl $0x11, %esi
callq 0x429a40
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %edx
leaq 0x17f8c1(%rip), %rcx    # 0x5acb2a
leaq 0x1703b8(%rip), %rax    # 0x59d628
cmpl $0x0, %edx
cmovneq %rax, %rcx
movq -0x28(%rbp), %rax
movl 0x10(%rax), %r8d
movl $0x1, %esi
leaq 0x17f88a(%rip), %rdx    # 0x5acb15
movb $0x0, %al
callq 0x430b00
movq -0x18(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x88, %eax
jne 0x42d2af
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movl (%rax), %eax
movl %eax, -0x74(%rbp)
jmp 0x42d2b9
movl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x42d2b9
movl -0x74(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rax
movl 0x38(%rax), %edx
addl $0x1, %edx
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x430c20
movl -0x54(%rbp), %ecx
movq -0x10(%rbp), %rax
addl 0x38(%rax), %ecx
movl %ecx, 0x38(%rax)
movq -0x18(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x88, %eax
jne 0x42d320
movb $0xa, -0x50(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x68(%rbp), %rdi
movl -0x4c(%rbp), %ecx
movl -0x4c(%rbp), %r8d
addl -0x54(%rbp), %r8d
subl $0x1, %r8d
movl $0x48, %esi
xorl %edx, %edx
callq 0x410130
jmp 0x42d337
movb $0x3, -0x50(%rbp)
movq -0x68(%rbp), %rdi
movl -0x4c(%rbp), %ecx
movl $0x45, %esi
xorl %edx, %edx
callq 0x410100
movq -0x28(%rbp), %rax
cmpq $0x0, 0x60(%rax)
je 0x42d3d8
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
movl $0x98, %esi
leaq 0x11338c(%rip), %rdx    # 0x5406ed
callq 0x41d620
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x42d3b1
movq -0x60(%rbp), %rax
movb $0x43, 0x1(%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x70(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x60(%rax), %rax
movq 0x10(%rax), %rsi
xorl %edx, %edx
callq 0x42dee0
movq -0x80(%rbp), %rdi
movq %rax, %rdx
movq -0x60(%rbp), %rcx
movl $0x34, %esi
callq 0x418540
movq %rax, -0x60(%rbp)
movq -0x70(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x60(%rax), %rax
movq 0x10(%rax), %rsi
callq 0x40c670
movq -0x60(%rbp), %rcx
movq -0x28(%rbp), %rax
movq 0x60(%rax), %rax
movq %rcx, 0x10(%rax)
jmp 0x42d415
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl $0x98, %esi
leaq 0x11331f(%rip), %rdx    # 0x54070a
callq 0x41d620
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rdx
movl $0x92, %esi
xorl %eax, %eax
movl %eax, %ecx
callq 0x418540
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x41aee0
cmpl $0x0, %eax
je 0x42d43f
movl $0x0, -0x4(%rbp)
jmp 0x42d4bd
movl -0x4c(%rbp), %ecx
movl %ecx, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl %ecx, 0x2c(%rax)
cmpl $0x0, -0x1c(%rbp)
je 0x42d4b7
movq -0x68(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x429a70
movq -0x68(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x44(%rax), %edx
movl $0x41, %esi
callq 0x42ba70
movq -0x68(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x18(%rbp), %rax
movl 0x40(%rax), %eax
subl $0x1, %eax
movl %eax, -0x84(%rbp)
movq -0x68(%rbp), %rdi
callq 0x430ae0
movq -0x90(%rbp), %rdi
movl -0x84(%rbp), %esi
movl %eax, %edx
subl $0x1, %edx
callq 0x430c80
movq -0x10(%rbp), %rdi
callq 0x430cb0
movl -0x20(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)