// File: /workspace/github_c_makefile_star2_O2/ukontainer[P]sqlite-bench/sqlite3.c
// Function: sqlite3CodeSubselect
SQLITE_PRIVATE int sqlite3CodeSubselect(
  Parse *pParse,          /* Parsing context */
  Expr *pExpr,            /* The IN, SELECT, or EXISTS operator */
  int rHasNullFlag,       /* Register that records whether NULLs exist in RHS */
  int isRowid             /* If true, LHS of IN operator is a rowid */
){
  int jmpIfDynamic = -1;                      /* One-time test address */
  int rReg = 0;                           /* Register storing resulting */
  Vdbe *v = sqlite3GetVdbe(pParse);
  if( NEVER(v==0) ) return 0;

  /* The evaluation of the IN/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) ){
    jmpIfDynamic = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
  }

  switch( pExpr->op ){
    case TK_IN: {
      int addr;                   /* Address of OP_OpenEphemeral instruction */
      Expr *pLeft = pExpr->pLeft; /* the LHS of the IN operator */
      KeyInfo *pKeyInfo = 0;      /* Key information */
      int nVal;                   /* Size of vector pLeft */
      
      nVal = sqlite3ExprVectorSize(pLeft);
      assert( !isRowid || nVal==1 );

      /* Whether this is an 'x IN(SELECT...)' or an 'x IN(<exprlist>)'
      ** expression it is handled the same way.  An ephemeral table is 
      ** filled with index keys representing the results from the 
      ** SELECT or the <exprlist>.
      **
      ** If the 'x' expression is a column value, or the SELECT...
      ** statement returns a column value, then the affinity of that
      ** column is used to build the index keys. If both 'x' and the
      ** SELECT... statement are columns, then numeric affinity is used
      ** if either column has NUMERIC or INTEGER affinity. If neither
      ** 'x' nor the SELECT... statement are columns, then numeric affinity
      ** is used.
      */
      pExpr->iTable = pParse->nTab++;
      addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, 
          pExpr->iTable, (isRowid?0:nVal));
      pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, nVal, 1);

      if( ExprHasProperty(pExpr, EP_xIsSelect) ){
        /* Case 1:     expr IN (SELECT ...)
        **
        ** Generate code to write the results of the select into the temporary
        ** table allocated and opened above.
        */
        Select *pSelect = pExpr->x.pSelect;
        ExprList *pEList = pSelect->pEList;

        ExplainQueryPlan((pParse, 1, "%sLIST SUBQUERY",
            jmpIfDynamic>=0?"":"CORRELATED "
        ));
        assert( !isRowid );
        /* If the LHS and RHS of the IN operator do not match, that
        ** error will have been caught long before we reach this point. */
        if( ALWAYS(pEList->nExpr==nVal) ){
          SelectDest dest;
          int i;
          sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable);
          dest.zAffSdst = exprINAffinity(pParse, pExpr);
          pSelect->iLimit = 0;
          testcase( pSelect->selFlags & SF_Distinct );
          testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
          if( sqlite3Select(pParse, pSelect, &dest) ){
            sqlite3DbFree(pParse->db, dest.zAffSdst);
            sqlite3KeyInfoUnref(pKeyInfo);
            return 0;
          }
          sqlite3DbFree(pParse->db, dest.zAffSdst);
          assert( pKeyInfo!=0 ); /* OOM will cause exit after sqlite3Select() */
          assert( pEList!=0 );
          assert( pEList->nExpr>0 );
          assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
          for(i=0; i<nVal; i++){
            Expr *p = sqlite3VectorFieldSubexpr(pLeft, i);
            pKeyInfo->aColl[i] = sqlite3BinaryCompareCollSeq(
                pParse, p, pEList->a[i].pExpr
            );
          }
        }
      }else if( ALWAYS(pExpr->x.pList!=0) ){
        /* Case 2:     expr IN (exprlist)
        **
        ** For each expression, build an index key from the evaluation and
        ** store it in the temporary table. If <expr> is a column, then use
        ** that columns affinity when building index keys. If <expr> is not
        ** a column, use numeric affinity.
        */
        char affinity;            /* Affinity of the LHS of the IN */
        int i;
        ExprList *pList = pExpr->x.pList;
        struct ExprList_item *pItem;
        int r1, r2, r3;
        affinity = sqlite3ExprAffinity(pLeft);
        if( !affinity ){
          affinity = SQLITE_AFF_BLOB;
        }
        if( pKeyInfo ){
          assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
          pKeyInfo->aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
        }

        /* Loop through each expression in <exprlist>. */
        r1 = sqlite3GetTempReg(pParse);
        r2 = sqlite3GetTempReg(pParse);
        if( isRowid ) sqlite3VdbeAddOp4(v, OP_Blob, 0, r2, 0, "", P4_STATIC);
        for(i=pList->nExpr, pItem=pList->a; i>0; i--, pItem++){
          Expr *pE2 = pItem->pExpr;
          int iValToIns;

          /* If the expression is not constant then we will need to
          ** disable the test that was generated above that makes sure
          ** this code only executes once.  Because for a non-constant
          ** expression we need to rerun this code each time.
          */
          if( jmpIfDynamic>=0 && !sqlite3ExprIsConstant(pE2) ){
            sqlite3VdbeChangeToNoop(v, jmpIfDynamic);
            jmpIfDynamic = -1;
          }

          /* Evaluate the expression and insert it into the temp table */
          if( isRowid && sqlite3ExprIsInteger(pE2, &iValToIns) ){
            sqlite3VdbeAddOp3(v, OP_InsertInt, pExpr->iTable, r2, iValToIns);
          }else{
            r3 = sqlite3ExprCodeTarget(pParse, pE2, r1);
            if( isRowid ){
              sqlite3VdbeAddOp2(v, OP_MustBeInt, r3,
                                sqlite3VdbeCurrentAddr(v)+2);
              VdbeCoverage(v);
              sqlite3VdbeAddOp3(v, OP_Insert, pExpr->iTable, r2, r3);
            }else{
              sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
              sqlite3VdbeAddOp4Int(v, OP_IdxInsert, pExpr->iTable, r2, r3, 1);
            }
          }
        }
        sqlite3ReleaseTempReg(pParse, r1);
        sqlite3ReleaseTempReg(pParse, r2);
      }
      if( pKeyInfo ){
        sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO);
      }
      break;
    }

    case TK_EXISTS:
    case TK_SELECT:
    default: {
      /* Case 3:    (SELECT ... FROM ...)
      **     or:    EXISTS(SELECT ... FROM ...)
      **
      ** 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.
      */
      Select *pSel;                         /* SELECT statement to encode */
      SelectDest dest;                      /* How to deal with SELECT result */
      int nReg;                             /* Registers to allocate */
      Expr *pLimit;                         /* New limit expression */

      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;
      ExplainQueryPlan((pParse, 1, "%sSCALAR SUBQUERY",
            jmpIfDynamic>=0?"":"CORRELATED "));
      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"));
      }
      pLimit = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[1], 0);
      if( pSel->pLimit ){
        sqlite3ExprDelete(pParse->db, pSel->pLimit->pLeft);
        pSel->pLimit->pLeft = pLimit;
      }else{
        pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
      }
      pSel->iLimit = 0;
      if( sqlite3Select(pParse, pSel, &dest) ){
        return 0;
      }
      rReg = dest.iSDParm;
      ExprSetVVAProperty(pExpr, EP_NoReduce);
      break;
    }
  }

  if( rHasNullFlag ){
    sqlite3SetHasNullFlag(v, pExpr->iTable, rHasNullFlag);
  }

  if( jmpIfDynamic>=0 ){
    sqlite3VdbeJumpHere(v, jmpIfDynamic);
  }

  return rReg;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %ecx, %ebp
movl %edx, %r12d
movq %rsi, %r13
movq %rdi, 0x30(%rsp)
callq 0x44856b
testq %rax, %rax
je 0x44a6c7
movq %rax, %rbx
testb $0x20, 0x4(%r13)
jne 0x44a308
pushq $0x11
popq %rsi
movq %rbx, %rdi
callq 0x448599
jmp 0x44a30b
pushq $-0x1
popq %rax
movl %eax, 0x10(%rsp)
cmpb $0x31, (%r13)
jne 0x44a51d
movq 0x10(%r13), %rdi
movq %rdi, 0x38(%rsp)
callq 0x44a7dc
movl %eax, %r15d
movq 0x30(%rsp), %r14
movl 0x34(%r14), %edx
leal 0x1(%rdx), %eax
movl %eax, 0x34(%r14)
movl %edx, 0x2c(%r13)
movq $0x0, 0x28(%rsp)
testl %ebp, %ebp
movl $0x0, %ecx
cmovel %r15d, %ecx
pushq $0x71
popq %rsi
movq %rbx, %rdi
callq 0x432a3f
movl %eax, 0x40(%rsp)
testl %ebp, %ebp
jne 0x44a379
movq (%r14), %rdi
pushq $0x1
popq %rdx
movl %r15d, %esi
callq 0x44894b
movq %rax, 0x28(%rsp)
testb $0x8, 0x5(%r13)
movq %r13, 0x18(%rsp)
movq 0x20(%r13), %r13
jne 0x44a5a1
testq %r13, %r13
je 0x44a72e
movq 0x38(%rsp), %rdi
callq 0x44b9d3
testb %al, %al
movzbl %al, %eax
pushq $0x41
popq %rcx
cmovnel %eax, %ecx
movb %cl, 0x17(%rsp)
movq 0x28(%rsp), %r15
testq %r15, %r15
movq 0x30(%rsp), %r14
je 0x44a3d3
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rsi
movq %r14, %rdi
callq 0x433a1a
movq %rax, 0x20(%r15)
movl %r12d, 0x24(%rsp)
movq %r14, %rdi
callq 0x44b9b3
movl %eax, 0x38(%rsp)
movq %r14, %rdi
callq 0x44b9b3
movl %eax, %r15d
testl %ebp, %ebp
je 0x44a411
orl $-0x1, (%rsp)
leaq 0x115e8f(%rip), %r9     # 0x56028d
pushq $0x4b
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
movl %r15d, %ecx
xorl %r8d, %r8d
callq 0x4485b6
movl (%r13), %r12d
addq $0x8, %r13
movl %ebp, 0x44(%rsp)
testl %r12d, %r12d
jle 0x44a6d9
movq (%r13), %r14
cmpl $0x0, 0x10(%rsp)
js 0x44a450
movq %r14, %rdi
callq 0x44a105
testl %eax, %eax
jne 0x44a450
movq %rbx, %rdi
movl 0x10(%rsp), %esi
callq 0x44ccf3
pushq $-0x1
popq %rax
movl %eax, 0x10(%rsp)
testl %ebp, %ebp
je 0x44a47d
movq %r14, %rdi
leaq 0x48(%rsp), %rsi
callq 0x44cd34
testl %eax, %eax
je 0x44a47d
movq 0x18(%rsp), %rax
movl 0x2c(%rax), %edx
movl 0x48(%rsp), %r8d
movq %rbx, %rdi
pushq $0x7b
popq %rsi
movl %r15d, %ecx
jmp 0x44a4c0
movq 0x30(%rsp), %rdi
movq %r14, %rsi
movl 0x38(%rsp), %edx
callq 0x448a28
movl %eax, %r14d
testl %ebp, %ebp
je 0x44a4c7
movl 0xb8(%rbx), %ecx
addl $0x2, %ecx
movq %rbx, %rdi
pushq $0xf
popq %rsi
movl %r14d, %edx
callq 0x432a3f
movq 0x18(%rsp), %rax
movl 0x2c(%rax), %edx
movq %rbx, %rdi
pushq $0x7a
popq %rsi
movl %r15d, %ecx
movl %r14d, %r8d
callq 0x432a44
jmp 0x44a511
movl $0x1, (%rsp)
movq %rbx, %rdi
pushq $0x66
popq %rsi
movl %r14d, %edx
movq %rbx, %rbp
pushq $0x1
popq %rbx
movl %ebx, %ecx
movl %r15d, %r8d
leaq 0x17(%rsp), %r9
callq 0x4485b6
movq 0x18(%rsp), %rax
movl 0x2c(%rax), %edx
movq %rbp, %rdi
movl $0x85, %esi
movl %r15d, %ecx
movl %r14d, %r8d
movl %ebx, %r9d
movq %rbp, %rbx
movl 0x44(%rsp), %ebp
callq 0x40c85b
decl %r12d
addq $0x20, %r13
jmp 0x44a41d
movq 0x20(%r13), %r15
cmpl $0x0, 0x10(%rsp)
leaq 0x115d60(%rip), %rax    # 0x56028d
leaq 0xf5dd6(%rip), %rcx     # 0x54030a
cmovnsq %rax, %rcx
leaq 0xf5dd7(%rip), %rdx     # 0x540316
pushq $0x1
popq %rbp
movq 0x30(%rsp), %rdi
movl %ebp, %esi
xorl %eax, %eax
callq 0x44cb60
movb (%r13), %al
cmpb $0x7f, %al
jne 0x44a55d
movq (%r15), %rcx
movl (%rcx), %ebp
movq 0x30(%rsp), %rdx
movl 0x38(%rdx), %r8d
leal 0x1(%r8), %ecx
addl %ebp, %r8d
movl %ecx, 0x4c(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x50(%rsp)
movl %r8d, 0x38(%rdx)
cmpb $0x7f, %al
jne 0x44a646
movl %ecx, 0x50(%rsp)
movl %ebp, 0x54(%rsp)
pushq $0x49
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x432a44
movb $0xa, %al
jmp 0x44a655
movl %r12d, 0x24(%rsp)
movq (%r13), %r12
cmpl $0x0, 0x10(%rsp)
leaq 0x115cd7(%rip), %rax    # 0x56028d
leaq 0xf5d4d(%rip), %rcx     # 0x54030a
cmovnsq %rax, %rcx
leaq 0xf5d32(%rip), %rdx     # 0x5402fa
pushq $0x1
popq %rsi
movq 0x30(%rsp), %rbp
movq %rbp, %rdi
xorl %eax, %eax
callq 0x44cb60
cmpl %r15d, (%r12)
jne 0x44a729
movq 0x18(%rsp), %rsi
movl 0x2c(%rsi), %eax
leaq 0x48(%rsp), %r14
movb $0xb, (%r14)
movl %eax, 0x4(%r14)
andq $0x0, 0x8(%r14)
movq %rbp, %rdi
callq 0x44cc3e
movq %rax, 0x10(%r14)
andl $0x0, 0x10(%r13)
movq %rbp, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x43b73c
movq %rbp, %r13
movl %eax, %ebp
movq (%r13), %rdi
movq 0x10(%r14), %rsi
callq 0x4043ed
testl %ebp, %ebp
je 0x44a788
movq 0x28(%rsp), %rdi
callq 0x41e83c
jmp 0x44a6c7
pushq $0x46
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x432a3f
movb $0x3, %al
movb %al, 0x48(%rsp)
movq 0x30(%rsp), %rbp
movq (%rbp), %rdi
leaq 0x146d57(%rip), %rdx    # 0x5913c0
movl $0x8f, %esi
xorl %ecx, %ecx
callq 0x440b7f
movq %rax, %r14
movq 0x60(%r15), %rax
testq %rax, %rax
je 0x44a698
movq (%rbp), %rdi
movq 0x10(%rax), %rsi
callq 0x430b70
movq 0x60(%r15), %rax
movq %r14, 0x10(%rax)
jmp 0x44a6ae
movq %rbp, %rdi
movl $0x89, %esi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x439c0e
movq %rax, 0x60(%r15)
andl $0x0, 0x10(%r15)
leaq 0x48(%rsp), %rdx
movq %rbp, %rdi
movq %r15, %rsi
callq 0x43b73c
testl %eax, %eax
je 0x44a6ce
xorl %ebp, %ebp
jmp 0x44a777
movl 0x4c(%rsp), %ebp
movl 0x10(%rsp), %r14d
jmp 0x44a753
cmpl $0x0, 0x38(%rsp)
movq 0x30(%rsp), %rdx
je 0x44a700
movzbl 0x1f(%rdx), %eax
cmpq $0x7, %rax
ja 0x44a700
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%rdx)
movl 0x38(%rsp), %ecx
movl %ecx, 0xc4(%rdx,%rax,4)
testl %r15d, %r15d
movl 0x24(%rsp), %r12d
movq 0x18(%rsp), %r13
je 0x44a733
movzbl 0x1f(%rdx), %eax
cmpq $0x7, %rax
ja 0x44a733
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%rdx)
movl %r15d, 0xc4(%rdx,%rax,4)
jmp 0x44a733
movl 0x24(%rsp), %r12d
movq 0x18(%rsp), %r13
movl 0x10(%rsp), %r14d
movq 0x28(%rsp), %rdx
xorl %ebp, %ebp
testq %rdx, %rdx
je 0x44a753
pushq $-0x9
popq %rcx
movq %rbx, %rdi
movl 0x40(%rsp), %esi
callq 0x40c982
testl %r12d, %r12d
je 0x44a767
movl 0x2c(%r13), %esi
movq %rbx, %rdi
movl %r12d, %edx
callq 0x44cd8e
testl %r14d, %r14d
js 0x44a777
movq %rbx, %rdi
movl %r14d, %esi
callq 0x4485a5
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $0x8, %r12
xorl %r14d, %r14d
testl %r15d, %r15d
cmovlel %r14d, %r15d
movq %r13, %rbp
movq 0x18(%rsp), %r13
cmpq %r14, %r15
je 0x44a7d2
movq 0x38(%rsp), %rdi
movl %r14d, %esi
callq 0x44b949
movq (%r12), %rdx
movq %rbp, %rdi
movq %rax, %rsi
callq 0x40f27c
movq 0x28(%rsp), %rcx
movq %rax, 0x20(%rcx,%r14,8)
incq %r14
addq $0x20, %r12
jmp 0x44a79e
movl 0x24(%rsp), %r12d
jmp 0x44a733