// File: /workspace/github_c_makefile_star2_O3/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, 0x28(%rsp)
movl %edx, %ebp
movq %rsi, %r13
movq %rdi, %r12
callq 0x44dbe5
testq %rax, %rax
je 0x450111
movq %rax, %rbx
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
testb $0x20, 0x4(%r13)
jne 0x44ffc8
movq %rbx, %rdi
movl $0x11, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x43a65f
movl %eax, (%rsp)
cmpb $0x31, (%r13)
movl %ebp, 0x34(%rsp)
jne 0x450007
movq 0x10(%r13), %r14
movb (%r14), %al
cmpb $-0x5c, %al
jne 0x44ffe2
movb 0x36(%r14), %al
cmpb $0x7f, %al
je 0x450121
movzbl %al, %eax
movl $0x1, %r15d
cmpl $0xa5, %eax
jne 0x45012b
leaq 0x20(%r14), %rax
jmp 0x450125
movq 0x20(%r13), %r15
cmpl $0x0, (%rsp)
leaq 0x122337(%rip), %rax    # 0x57234d
leaq 0x102365(%rip), %rcx    # 0x552382
cmovnsq %rax, %rcx
leaq 0x102366(%rip), %rdx    # 0x55238e
movl $0x1, %ebp
movq %r12, %rdi
movl $0x1, %esi
xorl %eax, %eax
callq 0x452db2
movb (%r13), %al
cmpb $0x7f, %al
jne 0x450049
movq (%r15), %rcx
movl (%rcx), %ebp
movl 0x38(%r12), %r8d
leal 0x1(%r8), %ecx
addl %ebp, %r8d
movl %ecx, 0x3c(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rsp)
movl %r8d, 0x38(%r12)
movq %r13, %r14
cmpb $0x7f, %al
jne 0x450088
movl %ecx, 0x40(%rsp)
movl %ebp, 0x44(%rsp)
movq %rbx, %rdi
movl $0x49, %esi
xorl %edx, %edx
callq 0x43a65f
movb $0xa, %al
jmp 0x45009c
movq %rbx, %rdi
movl $0x46, %esi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x43a65f
movb $0x3, %al
movb %al, 0x38(%rsp)
movq (%r12), %rdi
leaq 0x14e2f5(%rip), %rdx    # 0x59e3a0
movl $0x8f, %esi
xorl %ecx, %ecx
callq 0x4443be
movq %rax, %r13
movq 0x60(%r15), %rax
testq %rax, %rax
je 0x4500df
movq 0x10(%rax), %rsi
testq %rsi, %rsi
je 0x4500d9
movq (%r12), %rdi
callq 0x4381eb
movq 0x60(%r15), %rax
movq %r13, 0x10(%rax)
jmp 0x4500f5
movq %r12, %rdi
movl $0x89, %esi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x43fbb4
movq %rax, 0x60(%r15)
movl $0x0, 0x10(%r15)
leaq 0x38(%rsp), %rdx
movq %r12, %rdi
movq %r15, %rsi
callq 0x441cb2
testl %eax, %eax
je 0x450118
xorl %ebp, %ebp
jmp 0x4505b5
movl 0x3c(%rsp), %ebp
jmp 0x450571
movq 0x20(%r14), %rax
movq (%rax), %rax
movl (%rax), %r15d
movl 0x34(%r12), %edx
leal 0x1(%rdx), %eax
movl %eax, 0x34(%r12)
movl %edx, 0x2c(%r13)
movq $0x0, 0x20(%rsp)
movl 0x28(%rsp), %ebp
testl %ebp, %ebp
movl $0x0, %ecx
cmovel %r15d, %ecx
movq %rbx, %rdi
movl $0x71, %esi
xorl %r8d, %r8d
callq 0x43a65f
movl %eax, 0x14(%rsp)
testl %ebp, %ebp
je 0x450171
movl %r15d, %ebp
jmp 0x45018a
movq (%r12), %rdi
movl %r15d, %ebp
movl %r15d, %esi
movl $0x1, %edx
callq 0x44e160
movq %rax, 0x20(%rsp)
testb $0x8, 0x5(%r13)
movq %r13, 0x8(%rsp)
movq 0x20(%r13), %r13
jne 0x450222
testq %r13, %r13
je 0x45054f
movq %r14, %rdi
callq 0x451a72
testb %al, %al
movzbl %al, %eax
movl $0x41, %ecx
cmovnel %eax, %ecx
movb %cl, 0x7(%rsp)
movq 0x20(%rsp), %r14
testq %r14, %r14
je 0x4501df
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rsi
movq %r12, %rdi
callq 0x43b88c
movq %rax, 0x20(%r14)
movb 0x1f(%r12), %al
testb %al, %al
je 0x4502df
leal -0x1(%rax), %ecx
movb %cl, 0x1f(%r12)
movzbl %cl, %ecx
movl 0xc4(%r12,%rcx,4), %edx
movl %edx, 0x18(%rsp)
testb %cl, %cl
je 0x4502ef
addb $-0x2, %al
movb %al, 0x1f(%r12)
movzbl %al, %eax
movl 0xc4(%r12,%rax,4), %r15d
jmp 0x4502fc
movq %r14, 0x18(%rsp)
movq (%r13), %r14
cmpl $0x0, (%rsp)
leaq 0x122117(%rip), %rax    # 0x57234d
leaq 0x102145(%rip), %rcx    # 0x552382
cmovnsq %rax, %rcx
leaq 0x10212a(%rip), %rdx    # 0x552372
movq %r12, %rdi
movl $0x1, %esi
xorl %eax, %eax
callq 0x452db2
cmpl %ebp, (%r14)
jne 0x45054f
movl %ebp, %r15d
movq 0x8(%rsp), %rsi
movl 0x2c(%rsi), %eax
leaq 0x38(%rsp), %rbp
movb $0xb, (%rbp)
movl %eax, 0x4(%rbp)
movq $0x0, 0x8(%rbp)
movq %r12, %rdi
callq 0x452ea2
movq %rax, 0x10(%rbp)
movl $0x0, 0x10(%r13)
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x441cb2
movq 0x10(%rbp), %rsi
testl %eax, %eax
je 0x4504f5
testq %rsi, %rsi
je 0x4502bb
movq (%r12), %rdi
callq 0x415f0a
movq 0x20(%rsp), %rsi
testq %rsi, %rsi
je 0x450111
decl (%rsi)
jne 0x450111
movq 0x10(%rsi), %rdi
callq 0x415f0a
jmp 0x450111
movl 0x38(%r12), %eax
incl %eax
movl %eax, 0x18(%rsp)
movl %eax, 0x38(%r12)
movl 0x38(%r12), %r15d
incl %r15d
movl %r15d, 0x38(%r12)
cmpl $0x0, 0x28(%rsp)
je 0x45032e
movq %rbx, %rdi
movl $0x4b, %esi
xorl %edx, %edx
movl %r15d, %ecx
xorl %r8d, %r8d
callq 0x43a65f
leaq 0x12202e(%rip), %rdx    # 0x57234d
movq %rbx, %rdi
movl %eax, %esi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x40e765
movl (%r13), %r14d
testl %r14d, %r14d
jle 0x4504a6
addq $0x8, %r13
incl %r14d
movq (%r13), %rbp
cmpl $0x0, (%rsp)
js 0x45039c
movb $0x1, 0x5c(%rsp)
leaq 0x181c(%rip), %rax      # 0x451b74
movq %rax, 0x40(%rsp)
leaq 0x18ca(%rip), %rax      # 0x451c2e
movq %rax, 0x48(%rsp)
movl $0x0, 0x60(%rsp)
testq %rbp, %rbp
je 0x45039c
leaq 0x38(%rsp), %rdi
movq %rbp, %rsi
callq 0x451c38
cmpb $0x0, 0x5c(%rsp)
jne 0x45039c
movq %rbx, %rdi
movl (%rsp), %esi
callq 0x452f7b
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
cmpl $0x0, 0x28(%rsp)
je 0x4503d5
movq %rbp, %rdi
leaq 0x38(%rsp), %rsi
callq 0x452fbf
testl %eax, %eax
je 0x45044e
movq 0x8(%rsp), %rax
movl 0x2c(%rax), %edx
movl 0x38(%rsp), %r8d
movq %rbx, %rdi
movl $0x7b, %esi
movl %r15d, %ecx
jmp 0x450490
movq %r12, %rdi
movq %rbp, %rsi
movl 0x18(%rsp), %edx
callq 0x44e26d
movl %eax, %ebp
movq %rbx, %rdi
movl $0x66, %esi
movl %eax, %edx
movl $0x1, %ecx
movl %r15d, %r8d
callq 0x43a65f
movq %rbx, %rdi
movl %eax, %esi
leaq 0x7(%rsp), %rdx
movl $0x1, %ecx
callq 0x40e765
movq 0x8(%rsp), %rax
movl 0x2c(%rax), %edx
movq %rbx, %rdi
movl $0x85, %esi
movl %r15d, %ecx
movl %ebp, %r8d
callq 0x43a65f
movq (%rbx), %rcx
cmpb $0x0, 0x61(%rcx)
jne 0x450495
movq 0x68(%rbx), %rcx
cltq
leaq (%rax,%rax,2), %rax
movb $-0x3, 0x1(%rcx,%rax,8)
movl $0x1, 0x10(%rcx,%rax,8)
jmp 0x450495
movq %r12, %rdi
movq %rbp, %rsi
movl 0x18(%rsp), %edx
callq 0x44e26d
movl %eax, %ebp
movl 0xb8(%rbx), %ecx
addl $0x2, %ecx
movq %rbx, %rdi
movl $0xf, %esi
movl %eax, %edx
xorl %r8d, %r8d
callq 0x43a65f
movq 0x8(%rsp), %rax
movl 0x2c(%rax), %edx
movq %rbx, %rdi
movl $0x7a, %esi
movl %r15d, %ecx
movl %ebp, %r8d
callq 0x43a65f
addq $0x20, %r13
decl %r14d
cmpl $0x1, %r14d
jg 0x450342
cmpl $0x0, 0x18(%rsp)
je 0x4504cd
movzbl 0x1f(%r12), %eax
cmpq $0x7, %rax
ja 0x4504cd
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%r12)
movl 0x18(%rsp), %ecx
movl %ecx, 0xc4(%r12,%rax,4)
testl %r15d, %r15d
movq 0x8(%rsp), %r14
je 0x450554
movzbl 0x1f(%r12), %eax
cmpq $0x7, %rax
ja 0x450554
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%r12)
movl %r15d, 0xc4(%r12,%rax,4)
jmp 0x450554
testq %rsi, %rsi
je 0x450503
movq (%r12), %rdi
callq 0x415f0a
movl %r15d, %eax
testl %r15d, %r15d
movq 0x20(%rsp), %r15
movq 0x18(%rsp), %rbp
jle 0x45054f
addq $0x8, %r14
movl %eax, %eax
movq %rax, 0x28(%rsp)
xorl %r13d, %r13d
movq %rbp, %rdi
movl %r13d, %esi
callq 0x451a1c
movq (%r14), %rdx
movq %r12, %rdi
movq %rax, %rsi
callq 0x4117a7
movq %rax, 0x20(%r15,%r13,8)
incq %r13
addq $0x20, %r14
cmpq %r13, 0x28(%rsp)
jne 0x450523
movq 0x8(%rsp), %r14
movl 0x14(%rsp), %esi
xorl %ebp, %ebp
movq 0x20(%rsp), %rdx
testq %rdx, %rdx
je 0x450571
movq %rbx, %rdi
movl $0xfffffff7, %ecx       # imm = 0xFFFFFFF7
callq 0x40e765
movl 0x34(%rsp), %edx
testl %edx, %edx
je 0x450585
movl 0x2c(%r14), %esi
movq %rbx, %rdi
callq 0x453020
cmpl $0x0, (%rsp)
js 0x4505b5
movl 0xb8(%rbx), %eax
movq (%rbx), %rcx
cmpb $0x0, 0x61(%rcx)
je 0x4505a3
leaq 0x154867(%rip), %rcx    # 0x5a4e08
jmp 0x4505b2
movl (%rsp), %ecx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x68(%rbx), %rcx
movl %eax, 0x8(%rcx)
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq