// File: /workspace/github_c_makefile_star2_O1/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: resolveExprStep
static int resolveExprStep(Walker *pWalker, Expr *pExpr){
  NameContext *pNC;
  Parse *pParse;

  pNC = pWalker->u.pNC;
  assert( pNC!=0 );
  pParse = pNC->pParse;
  assert( pParse==pWalker->pParse );

  if( ExprHasAnyProperty(pExpr, EP_Resolved) ) return WRC_Prune;
  ExprSetProperty(pExpr, EP_Resolved);
#ifndef NDEBUG
  if( pNC->pSrcList && pNC->pSrcList->nAlloc>0 ){
    SrcList *pSrcList = pNC->pSrcList;
    int i;
    for(i=0; i<pNC->pSrcList->nSrc; i++){
      assert( pSrcList->a[i].iCursor>=0 && pSrcList->a[i].iCursor<pParse->nTab);
    }
  }
#endif
  switch( pExpr->op ){

#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
    /* The special operator TK_ROW means use the rowid for the first
    ** column in the FROM clause.  This is used by the LIMIT and ORDER BY
    ** clause processing on UPDATE and DELETE statements.
    */
    case TK_ROW: {
      SrcList *pSrcList = pNC->pSrcList;
      struct SrcList_item *pItem;
      assert( pSrcList && pSrcList->nSrc==1 );
      pItem = pSrcList->a; 
      pExpr->op = TK_COLUMN;
      pExpr->pTab = pItem->pTab;
      pExpr->iTable = pItem->iCursor;
      pExpr->iColumn = -1;
      pExpr->affinity = SQLITE_AFF_INTEGER;
      break;
    }
#endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) */

    /* A lone identifier is the name of a column.
    */
    case TK_ID: {
      return lookupName(pParse, 0, 0, pExpr->u.zToken, pNC, pExpr);
    }
  
    /* A table name and column name:     ID.ID
    ** Or a database, table and column:  ID.ID.ID
    */
    case TK_DOT: {
      const char *zColumn;
      const char *zTable;
      const char *zDb;
      Expr *pRight;

      /* if( pSrcList==0 ) break; */
      pRight = pExpr->pRight;
      if( pRight->op==TK_ID ){
        zDb = 0;
        zTable = pExpr->pLeft->u.zToken;
        zColumn = pRight->u.zToken;
      }else{
        assert( pRight->op==TK_DOT );
        zDb = pExpr->pLeft->u.zToken;
        zTable = pRight->pLeft->u.zToken;
        zColumn = pRight->pRight->u.zToken;
      }
      return lookupName(pParse, zDb, zTable, zColumn, pNC, pExpr);
    }

    /* Resolve function names
    */
    case TK_CONST_FUNC:
    case TK_FUNCTION: {
      ExprList *pList = pExpr->x.pList;    /* The argument list */
      int n = pList ? pList->nExpr : 0;    /* Number of arguments */
      int no_such_func = 0;       /* True if no such function exists */
      int wrong_num_args = 0;     /* True if wrong number of arguments */
      int is_agg = 0;             /* True if is an aggregate function */
      int auth;                   /* Authorization to use the function */
      int nId;                    /* Number of characters in function name */
      const char *zId;            /* The function name. */
      FuncDef *pDef;              /* Information about the function */
      u8 enc = ENC(pParse->db);   /* The database encoding */

      testcase( pExpr->op==TK_CONST_FUNC );
      assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
      notValidPartIdxWhere(pParse, pNC, "functions");
      zId = pExpr->u.zToken;
      nId = sqlite3Strlen30(zId);
      pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
      if( pDef==0 ){
        pDef = sqlite3FindFunction(pParse->db, zId, nId, -2, enc, 0);
        if( pDef==0 ){
          no_such_func = 1;
        }else{
          wrong_num_args = 1;
        }
      }else{
        is_agg = pDef->xFunc==0;
      }
#ifndef SQLITE_OMIT_AUTHORIZATION
      if( pDef ){
        auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0);
        if( auth!=SQLITE_OK ){
          if( auth==SQLITE_DENY ){
            sqlite3ErrorMsg(pParse, "not authorized to use function: %s",
                                    pDef->zName);
            pNC->nErr++;
          }
          pExpr->op = TK_NULL;
          return WRC_Prune;
        }
      }
#endif
      if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
        sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
        pNC->nErr++;
        is_agg = 0;
      }else if( no_such_func && pParse->db->init.busy==0 ){
        sqlite3ErrorMsg(pParse, "no such function: %.*s", nId, zId);
        pNC->nErr++;
      }else if( wrong_num_args ){
        sqlite3ErrorMsg(pParse,"wrong number of arguments to function %.*s()",
             nId, zId);
        pNC->nErr++;
      }
      if( is_agg ) pNC->ncFlags &= ~NC_AllowAgg;
      sqlite3WalkExprList(pWalker, pList);
      if( is_agg ){
        NameContext *pNC2 = pNC;
        pExpr->op = TK_AGG_FUNCTION;
        pExpr->op2 = 0;
        while( pNC2 && !sqlite3FunctionUsesThisSrc(pExpr, pNC2->pSrcList) ){
          pExpr->op2++;
          pNC2 = pNC2->pNext;
        }
        if( pNC2 ) pNC2->ncFlags |= NC_HasAgg;
        pNC->ncFlags |= NC_AllowAgg;
      }
      /* FIX ME:  Compute pExpr->affinity based on the expected return
      ** type of the function 
      */
      return WRC_Prune;
    }
#ifndef SQLITE_OMIT_SUBQUERY
    case TK_SELECT:
    case TK_EXISTS:  testcase( pExpr->op==TK_EXISTS );
#endif
    case TK_IN: {
      testcase( pExpr->op==TK_IN );
      if( ExprHasProperty(pExpr, EP_xIsSelect) ){
        int nRef = pNC->nRef;
        notValidCheckConstraint(pParse, pNC, "subqueries");
        notValidPartIdxWhere(pParse, pNC, "subqueries");
        sqlite3WalkSelect(pWalker, pExpr->x.pSelect);
        assert( pNC->nRef>=nRef );
        if( nRef!=pNC->nRef ){
          ExprSetProperty(pExpr, EP_VarSelect);
        }
      }
      break;
    }
    case TK_VARIABLE: {
      notValidCheckConstraint(pParse, pNC, "parameters");
      notValidPartIdxWhere(pParse, pNC, "parameters");
      break;
    }
  }
  return (pParse->nErr || pParse->db->mallocFailed) ? WRC_Abort : WRC_Continue;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movzwl 0x2(%rsi), %eax
movl $0x1, %r12d
testb $0x4, %al
jne 0x46d25
movq %rsi, %r14
movq 0x20(%rdi), %r15
movq (%r15), %r13
movl %eax, %ecx
orl $0x4, %ecx
movw %cx, 0x2(%rsi)
movzbl (%rsi), %ecx
cmpl $0x75, %ecx
jg 0x46954
cmpl $0x47, %ecx
jg 0x469bc
cmpl $0x14, %ecx
je 0x469ca
cmpl $0x1a, %ecx
jne 0x46a57
movq 0x8(%r14), %rcx
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
jmp 0x46c2c
cmpl $0x96, %ecx
jg 0x46a32
cmpl $0x76, %ecx
je 0x46a7f
cmpl $0x85, %ecx
jne 0x46a57
testb $0x4, 0x30(%r15)
je 0x46994
leaq 0x346f6(%rip), %rsi     # 0x7b079
leaq 0x3460d(%rip), %rdx     # 0x7af97
movq %r13, %rdi
xorl %eax, %eax
callq 0x11724
testb $0x10, 0x30(%r15)
je 0x46a57
leaq 0x346a6(%rip), %rsi     # 0x7b04c
leaq 0x345ea(%rip), %rdx     # 0x7af97
movq %r13, %rdi
xorl %eax, %eax
callq 0x11724
jmp 0x46a57
cmpl $0x48, %ecx
je 0x469ca
cmpl $0x74, %ecx
jne 0x46a57
btl $0xb, %eax
jae 0x46a57
movq %rdi, %r12
movl 0x28(%r15), %ebx
testb $0x4, 0x30(%r15)
je 0x469fa
leaq 0x34690(%rip), %rsi     # 0x7b079
leaq 0x3459c(%rip), %rdx     # 0x7af8c
movq %r13, %rdi
xorl %eax, %eax
callq 0x11724
testb $0x10, 0x30(%r15)
je 0x46a19
leaq 0x34644(%rip), %rsi     # 0x7b04c
leaq 0x3457d(%rip), %rdx     # 0x7af8c
movq %r13, %rdi
xorl %eax, %eax
callq 0x11724
movq 0x20(%r14), %rsi
movq %r12, %rdi
callq 0x47c6e
cmpl 0x28(%r15), %ebx
je 0x46a57
orb $0x20, 0x2(%r14)
jmp 0x46a57
cmpl $0x97, %ecx
je 0x46a42
cmpl $0x9b, %ecx
jne 0x46a57
movq 0x20(%r14), %rax
testq %rax, %rax
movq %rdi, -0x50(%rbp)
movq %rax, -0x70(%rbp)
je 0x46a96
movl (%rax), %ecx
jmp 0x46a98
movl $0x2, %r12d
cmpl $0x0, 0x50(%r13)
jne 0x46d25
movq (%r13), %rax
xorl %r12d, %r12d
cmpb $0x0, 0x50(%rax)
setne %r12b
addl %r12d, %r12d
jmp 0x46d25
movq 0x18(%r14), %rax
cmpb $0x1a, (%rax)
jne 0x46c0e
xorl %esi, %esi
movq %r14, %rdx
jmp 0x46c1d
xorl %ecx, %ecx
movq (%r13), %rax
movq 0x20(%rax), %rax
movq 0x18(%rax), %rax
movb 0x71(%rax), %sil
testb $0x10, 0x30(%r15)
je 0x46ad3
movb %sil, -0x38(%rbp)
leaq 0x34592(%rip), %rsi     # 0x7b04c
leaq 0x34436(%rip), %rdx     # 0x7aef7
movq %r13, %rdi
xorl %eax, %eax
movl %ecx, %ebx
callq 0x11724
movb -0x38(%rbp), %sil
movl %ebx, %ecx
movq 0x8(%r14), %rdx
testq %rdx, %rdx
movq %r15, -0x48(%rbp)
je 0x46afe
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movq %rdx, %rax
incl %r15d
cmpb $0x0, (%rax)
leaq 0x1(%rax), %rax
jne 0x46ae9
andl $0x3fffffff, %r15d      # imm = 0x3FFFFFFF
jmp 0x46b01
xorl %r15d, %r15d
movq (%r13), %rdi
movq %r13, -0x38(%rbp)
movzbl %sil, %r8d
movq %rdx, %r13
movq %rdx, %rsi
movl %r15d, %edx
movl %r8d, -0x3c(%rbp)
xorl %r9d, %r9d
callq 0x154a0
testq %rax, %rax
movq %r13, -0x68(%rbp)
je 0x46b42
movq %rax, %rbx
xorl %eax, %eax
cmpq $0x0, 0x18(%rbx)
sete %al
movl %eax, -0x2c(%rbp)
movb $0x1, %cl
movb $0x1, %r13b
jmp 0x46b74
movl $0x0, -0x2c(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movq %r13, %rsi
movl %r15d, %edx
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
movl -0x3c(%rbp), %r8d
xorl %r9d, %r9d
callq 0x154a0
movq %rax, %rbx
testq %rax, %rax
sete %r13b
setne %cl
testq %rbx, %rbx
je 0x46bc5
movb %cl, -0x3c(%rbp)
movq 0x30(%rbx), %rcx
movq -0x38(%rbp), %rdi
movl $0x1f, %esi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x45d75
movb -0x3c(%rbp), %cl
testl %eax, %eax
je 0x46bc5
cmpl $0x1, %eax
jne 0x46bbc
movq 0x30(%rbx), %rdx
leaq 0x34357(%rip), %rsi     # 0x7af01
movq -0x38(%rbp), %rdi
xorl %eax, %eax
callq 0x11724
movq -0x48(%rbp), %rax
incl 0x2c(%rax)
movb $0x62, (%r14)
jmp 0x46d25
cmpl $0x0, -0x2c(%rbp)
je 0x46bec
movq -0x48(%rbp), %rax
testb $0x1, 0x30(%rax)
jne 0x46bec
xorl %r13d, %r13d
leaq 0x34345(%rip), %rsi     # 0x7af24
movq -0x48(%rbp), %rbx
movq -0x38(%rbp), %rdi
jmp 0x46c75
testb %cl, %cl
je 0x46c45
testb %r13b, %r13b
movq -0x48(%rbp), %rbx
movq -0x38(%rbp), %rdi
movl -0x2c(%rbp), %r13d
jne 0x46c86
leaq 0x34353(%rip), %rsi     # 0x7af5f
jmp 0x46c75
movq 0x10(%r14), %rcx
movq 0x8(%rcx), %rsi
movq %rax, %rdx
movq 0x18(%rax), %rax
movq 0x8(%rax), %rcx
movq 0x10(%rdx), %rax
movq 0x8(%rax), %rdx
movq %r13, %rdi
movq %r15, %r8
movq %r14, %r9
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4715c
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
cmpb $0x0, 0x99(%rax)
setne %al
leaq 0x34302(%rip), %rcx     # 0x7af5f
leaq 0x342e4(%rip), %rsi     # 0x7af48
cmovneq %rcx, %rsi
testb %r13b, %al
movq -0x48(%rbp), %rbx
movl -0x2c(%rbp), %r13d
jne 0x46c86
movl %r15d, %edx
movq -0x68(%rbp), %rcx
xorl %eax, %eax
callq 0x11724
incl 0x2c(%rbx)
testl %r13d, %r13d
movq -0x70(%rbp), %rsi
je 0x46d0d
andb $-0x2, 0x30(%rbx)
movq -0x50(%rbp), %rdi
callq 0x47c1b
movb $-0x67, (%r14)
movb $0x0, 0x37(%r14)
movq %rbx, %r15
leaq -0x60(%rbp), %r13
leaq -0xa0(%rbp), %rbx
movq 0x8(%r15), %rax
xorps %xmm0, %xmm0
movaps %xmm0, -0xa0(%rbp)
movaps %xmm0, -0x90(%rbp)
leaq 0x1db0(%rip), %rcx      # 0x48a7f
movq %rcx, -0xa0(%rbp)
movq %r13, -0x80(%rbp)
movq %rax, -0x60(%rbp)
movq $0x0, -0x58(%rbp)
movq 0x20(%r14), %rsi
movq %rbx, %rdi
callq 0x47c1b
cmpl $0x0, -0x58(%rbp)
jg 0x46d18
cmpl $0x0, -0x54(%rbp)
je 0x46d18
incb 0x37(%r14)
movq 0x20(%r15), %r15
testq %r15, %r15
jne 0x46cb3
jmp 0x46d1d
movq -0x50(%rbp), %rdi
callq 0x47c1b
jmp 0x46d25
orb $0x2, 0x30(%r15)
movq -0x48(%rbp), %rax
orb $0x1, 0x30(%rax)
movl %r12d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq