// File: /workspace/github_c_makefile_star2_O1/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, %r13d
movq %rsi, %r14
movq %rdi, %r12
callq 0x44e8aa
testq %rax, %rax
je 0x450d3c
movq %rax, %rbx
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
testb $0x20, 0x4(%r14)
jne 0x450cff
movq %rbx, %rdi
movl $0x11, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x43bae0
movl %eax, 0x4(%rsp)
cmpb $0x31, (%r14)
movq %r14, 0x20(%rsp)
jne 0x450d43
movq 0x10(%r14), %rcx
movb (%rcx), %al
cmpb $-0x5c, %al
jne 0x450d17
movb 0x36(%rcx), %al
cmpb $0x7f, %al
je 0x450e60
movzbl %al, %eax
movl $0x1, %r15d
cmpl $0xa5, %eax
jne 0x450e6a
leaq 0x20(%rcx), %rax
jmp 0x450e64
xorl %ebp, %ebp
jmp 0x45134d
movq 0x20(%r14), %r15
cmpl $0x0, 0x4(%rsp)
leaq 0x12151a(%rip), %rax    # 0x57226d
leaq 0x1015a4(%rip), %rcx    # 0x5522fe
cmovnsq %rax, %rcx
leaq 0x1015a5(%rip), %rdx    # 0x55230a
movl $0x1, %ebp
movq %r12, %rdi
movl $0x1, %esi
xorl %eax, %eax
callq 0x453b50
movb (%r14), %al
cmpb $0x7f, %al
jne 0x450d85
movq (%r15), %rcx
movl (%rcx), %ebp
movl 0x38(%r12), %r8d
leal 0x1(%r8), %ecx
addl %ebp, %r8d
movb $0x0, 0x38(%rsp)
movl %ecx, 0x3c(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rsp)
movl %r8d, 0x38(%r12)
cmpb $0x7f, %al
jne 0x450dc4
movb $0xa, 0x38(%rsp)
movl %ecx, 0x40(%rsp)
movl %ebp, 0x44(%rsp)
movq %rbx, %rdi
movl $0x49, %esi
xorl %edx, %edx
jmp 0x450dd6
movb $0x3, 0x38(%rsp)
movq %rbx, %rdi
movl $0x46, %esi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x43bae0
movq (%r12), %rdi
leaq 0x14d5ba(%rip), %rdx    # 0x59e3a0
movl $0x8f, %esi
xorl %ecx, %ecx
callq 0x445107
movq %rax, %r14
movq 0x60(%r15), %rax
testq %rax, %rax
je 0x450e1a
movq 0x10(%rax), %rsi
testq %rsi, %rsi
je 0x450e10
movq (%r12), %rdi
callq 0x439685
movq 0x60(%r15), %rax
movq %r14, 0x10(%rax)
jmp 0x450e30
movq %r12, %rdi
movl $0x89, %esi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x440fc7
movq %rax, 0x60(%r15)
xorl %ebp, %ebp
movl %ebp, 0x10(%r15)
leaq 0x38(%rsp), %rdx
movq %r12, %rdi
movq %r15, %rsi
callq 0x442f31
movl $0x0, %r14d
testl %eax, %eax
jne 0x450e55
movl 0x3c(%rsp), %r14d
jne 0x45134d
jmp 0x451300
movq 0x20(%rcx), %rax
movq (%rax), %rax
movl (%rax), %r15d
movq %rcx, 0x28(%rsp)
movl 0x34(%r12), %edx
leal 0x1(%rdx), %eax
movl %eax, 0x34(%r12)
movq 0x20(%rsp), %rax
movl %edx, 0x2c(%rax)
testl %ebp, %ebp
movl $0x0, %ecx
cmovel %r15d, %ecx
movq %rbx, %rdi
movl $0x71, %esi
xorl %r8d, %r8d
callq 0x43bae0
movl %eax, 0x34(%rsp)
testl %ebp, %ebp
movl %r13d, 0xc(%rsp)
je 0x450eba
movq $0x0, 0x18(%rsp)
movl %r15d, %r14d
jmp 0x450ed3
movq (%r12), %rdi
movl %r15d, %r14d
movl %r15d, %esi
movl $0x1, %edx
callq 0x44ee23
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rax
testb $0x8, 0x5(%rax)
movq 0x20(%rax), %r13
jne 0x450f4d
testq %r13, %r13
je 0x4512d0
movq 0x28(%rsp), %rdi
callq 0x4527cd
testb %al, %al
movzbl %al, %eax
movl $0x41, %ecx
cmovnel %eax, %ecx
movb %cl, 0xb(%rsp)
movq 0x18(%rsp), %r14
testq %r14, %r14
movq 0x20(%rsp), %rax
je 0x450f25
movq 0x10(%rax), %rsi
movq %r12, %rdi
callq 0x43cd2e
movq %rax, 0x20(%r14)
movb 0x1f(%r12), %al
testb %al, %al
je 0x451010
decb %al
movb %al, 0x1f(%r12)
movzbl %al, %eax
movl 0xc4(%r12,%rax,4), %eax
movl %eax, 0x28(%rsp)
jmp 0x451020
movq (%r13), %rbp
cmpl $0x0, 0x4(%rsp)
leaq 0x121310(%rip), %rax    # 0x57226d
leaq 0x10139a(%rip), %rcx    # 0x5522fe
cmovnsq %rax, %rcx
leaq 0x10137f(%rip), %rdx    # 0x5522ee
movq %r12, %rdi
movl $0x1, %esi
xorl %eax, %eax
callq 0x453b50
cmpl %r14d, (%rbp)
jne 0x4512d0
movl %r14d, %r15d
movq 0x20(%rsp), %rsi
movl 0x2c(%rsi), %eax
leaq 0x38(%rsp), %r14
movb $0xb, (%r14)
movl %eax, 0x4(%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r14)
movq %r12, %rdi
callq 0x453c40
movq %rax, 0x10(%r14)
movl $0x0, 0x10(%r13)
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x442f31
movq 0x10(%r14), %rsi
testl %eax, %eax
movl %eax, 0x30(%rsp)
je 0x451264
testq %rsi, %rsi
movq 0x18(%rsp), %r14
je 0x450fed
movq (%r12), %rdi
callq 0x415dca
testq %r14, %r14
je 0x4512bf
movq %r14, %rsi
decl (%r14)
jne 0x4512bf
movq 0x10(%rsi), %rdi
callq 0x415dca
jmp 0x4512bf
movl 0x38(%r12), %eax
incl %eax
movl %eax, 0x28(%rsp)
movl %eax, 0x38(%r12)
movb 0x1f(%r12), %al
testb %al, %al
je 0x451041
decb %al
movb %al, 0x1f(%r12)
movzbl %al, %eax
movl 0xc4(%r12,%rax,4), %eax
movl %eax, 0x10(%rsp)
jmp 0x451051
movl 0x38(%r12), %eax
incl %eax
movl %eax, 0x10(%rsp)
movl %eax, 0x38(%r12)
testl %ebp, %ebp
je 0x451081
movq %rbx, %rdi
movl $0x4b, %esi
xorl %edx, %edx
movl 0x10(%rsp), %ecx
xorl %r8d, %r8d
callq 0x43bae0
leaq 0x1211fb(%rip), %rdx    # 0x57226d
movq %rbx, %rdi
movl %eax, %esi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x40e507
movl (%r13), %r15d
testl %r15d, %r15d
jle 0x451202
addq $0x8, %r13
incl %r15d
movl %ebp, 0x30(%rsp)
movq (%r13), %r14
cmpl $0x0, 0x4(%rsp)
js 0x4510f6
movb $0x1, 0x5c(%rsp)
leaq 0x182b(%rip), %rax      # 0x4528db
movq %rax, 0x40(%rsp)
leaq 0x18d3(%rip), %rax      # 0x45298f
movq %rax, 0x48(%rsp)
movl $0x0, 0x60(%rsp)
testq %r14, %r14
je 0x4510db
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x452999
cmpb $0x0, 0x5c(%rsp)
jne 0x4510f6
movq %rbx, %rdi
movl 0x4(%rsp), %esi
callq 0x453d19
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
testl %ebp, %ebp
je 0x451126
movq %r14, %rdi
leaq 0x38(%rsp), %rsi
callq 0x453d5d
testl %eax, %eax
je 0x451126
movq 0x20(%rsp), %rax
movl 0x2c(%rax), %edx
movl 0x38(%rsp), %r8d
movq %rbx, %rdi
movl $0x7b, %esi
movl 0x10(%rsp), %ecx
jmp 0x45116f
movq %r12, %rdi
movq %r14, %rsi
movl 0x28(%rsp), %edx
callq 0x44ef27
movl %eax, %r14d
testl %ebp, %ebp
je 0x451187
movl 0xb8(%rbx), %ecx
addl $0x2, %ecx
movq %rbx, %rdi
movl $0xf, %esi
movl %r14d, %edx
xorl %r8d, %r8d
callq 0x43bae0
movq 0x20(%rsp), %rax
movl 0x2c(%rax), %edx
movq %rbx, %rdi
movl $0x7a, %esi
movl 0x10(%rsp), %ecx
movl %r14d, %r8d
callq 0x43bae0
addq $0x20, %r13
decl %r15d
cmpl $0x1, %r15d
jg 0x451099
jmp 0x451202
movq %rbx, %rdi
movl $0x66, %esi
movl %r14d, %edx
movl $0x1, %ecx
movq %r12, %rbp
movl 0x10(%rsp), %r12d
movl %r12d, %r8d
callq 0x43bae0
movq %rbx, %rdi
movl %eax, %esi
leaq 0xb(%rsp), %rdx
movl $0x1, %ecx
callq 0x40e507
movq 0x20(%rsp), %rax
movl 0x2c(%rax), %edx
movq %rbx, %rdi
movl $0x85, %esi
movl %r12d, %ecx
movq %rbp, %r12
movl 0x30(%rsp), %ebp
movl %r14d, %r8d
callq 0x43bae0
movq (%rbx), %rcx
cmpb $0x0, 0x61(%rcx)
jne 0x451174
movq 0x68(%rbx), %rcx
cltq
leaq (%rax,%rax,2), %rax
movb $-0x3, 0x1(%rcx,%rax,8)
movl $0x1, 0x10(%rcx,%rax,8)
jmp 0x451174
cmpl $0x0, 0x28(%rsp)
je 0x451229
movzbl 0x1f(%r12), %eax
cmpq $0x7, %rax
ja 0x451229
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%r12)
movl 0x28(%rsp), %ecx
movl %ecx, 0xc4(%r12,%rax,4)
cmpl $0x0, 0x10(%rsp)
movl 0xc(%rsp), %r13d
movq 0x18(%rsp), %rdx
je 0x4512da
movzbl 0x1f(%r12), %eax
cmpq $0x7, %rax
ja 0x4512da
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%r12)
movl 0x10(%rsp), %ecx
movl %ecx, 0xc4(%r12,%rax,4)
jmp 0x4512da
testq %rsi, %rsi
je 0x451272
movq (%r12), %rdi
callq 0x415dca
movl %r15d, %eax
testl %r15d, %r15d
movq 0x18(%rsp), %r15
movq 0x28(%rsp), %r13
jle 0x4512bf
addq $0x8, %rbp
movl %eax, %eax
movq %rax, 0x10(%rsp)
xorl %r14d, %r14d
movq %r13, %rdi
movl %r14d, %esi
callq 0x452777
movq (%rbp), %rdx
movq %r12, %rdi
movq %rax, %rsi
callq 0x41162f
movq %rax, 0x20(%r15,%r14,8)
incq %r14
addq $0x20, %rbp
cmpq %r14, 0x10(%rsp)
jne 0x451292
cmpl $0x0, 0x30(%rsp)
je 0x4512d0
xorl %r15d, %r15d
movl 0xc(%rsp), %r13d
jmp 0x4512f3
movl 0xc(%rsp), %r13d
movq 0x18(%rsp), %rdx
movb $0x1, %r15b
testq %rdx, %rdx
je 0x4512f3
movq %rbx, %rdi
movl 0x34(%rsp), %esi
movl $0xfffffff7, %ecx       # imm = 0xFFFFFFF7
callq 0x40e507
xorl %r14d, %r14d
movl $0x0, %ebp
testb %r15b, %r15b
je 0x45134d
testl %r13d, %r13d
je 0x451318
movq 0x20(%rsp), %rax
movl 0x2c(%rax), %esi
movq %rbx, %rdi
movl %r13d, %edx
callq 0x453db9
cmpl $0x0, 0x4(%rsp)
js 0x45134a
movl 0xb8(%rbx), %eax
movq (%rbx), %rcx
cmpb $0x0, 0x61(%rcx)
je 0x451337
leaq 0x153ad3(%rip), %rcx    # 0x5a4e08
jmp 0x451347
movl 0x4(%rsp), %ecx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x68(%rbx), %rcx
movl %eax, 0x8(%rcx)
movl %r14d, %ebp
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq