// File: /workspace/github_c_makefile_star2_O3/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: columnType
static const char *columnType(
  NameContext *pNC, 
  Expr *pExpr,
  const char **pzOriginDb,
  const char **pzOriginTab,
  const char **pzOriginCol
){
  char const *zType = 0;
  char const *zOriginDb = 0;
  char const *zOriginTab = 0;
  char const *zOriginCol = 0;
  int j;
  if( NEVER(pExpr==0) || pNC->pSrcList==0 ) return 0;

  switch( pExpr->op ){
    case TK_AGG_COLUMN:
    case TK_COLUMN: {
      /* The expression is a column. Locate the table the column is being
      ** extracted from in NameContext.pSrcList. This table may be real
      ** database table or a subquery.
      */
      Table *pTab = 0;            /* Table structure column is extracted from */
      Select *pS = 0;             /* Select the column is extracted from */
      int iCol = pExpr->iColumn;  /* Index of column in pTab */
      testcase( pExpr->op==TK_AGG_COLUMN );
      testcase( pExpr->op==TK_COLUMN );
      while( pNC && !pTab ){
        SrcList *pTabList = pNC->pSrcList;
        for(j=0;j<pTabList->nSrc && pTabList->a[j].iCursor!=pExpr->iTable;j++);
        if( j<pTabList->nSrc ){
          pTab = pTabList->a[j].pTab;
          pS = pTabList->a[j].pSelect;
        }else{
          pNC = pNC->pNext;
        }
      }

      if( pTab==0 ){
        /* At one time, code such as "SELECT new.x" within a trigger would
        ** cause this condition to run.  Since then, we have restructured how
        ** trigger code is generated and so this condition is no longer 
        ** possible. However, it can still be true for statements like
        ** the following:
        **
        **   CREATE TABLE t1(col INTEGER);
        **   SELECT (SELECT t1.col) FROM FROM t1;
        **
        ** when columnType() is called on the expression "t1.col" in the 
        ** sub-select. In this case, set the column type to NULL, even
        ** though it should really be "INTEGER".
        **
        ** This is not a problem, as the column type of "t1.col" is never
        ** used. When columnType() is called on the expression 
        ** "(SELECT t1.col)", the correct type is returned (see the TK_SELECT
        ** branch below.  */
        break;
      }

      assert( pTab && pExpr->pTab==pTab );
      if( pS ){
        /* The "table" is actually a sub-select or a view in the FROM clause
        ** of the SELECT statement. Return the declaration type and origin
        ** data for the result-set column of the sub-select.
        */
        if( iCol>=0 && ALWAYS(iCol<pS->pEList->nExpr) ){
          /* If iCol is less than zero, then the expression requests the
          ** rowid of the sub-select or view. This expression is legal (see 
          ** test case misc2.2.2) - it always evaluates to NULL.
          */
          NameContext sNC;
          Expr *p = pS->pEList->a[iCol].pExpr;
          sNC.pSrcList = pS->pSrc;
          sNC.pNext = pNC;
          sNC.pParse = pNC->pParse;
          zType = columnType(&sNC, p, &zOriginDb, &zOriginTab, &zOriginCol); 
        }
      }else if( ALWAYS(pTab->pSchema) ){
        /* A real table */
        assert( !pS );
        if( iCol<0 ) iCol = pTab->iPKey;
        assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
        if( iCol<0 ){
          zType = "INTEGER";
          zOriginCol = "rowid";
        }else{
          zType = pTab->aCol[iCol].zType;
          zOriginCol = pTab->aCol[iCol].zName;
        }
        zOriginTab = pTab->zName;
        if( pNC->pParse ){
          int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
          zOriginDb = pNC->pParse->db->aDb[iDb].zName;
        }
      }
      break;
    }
#ifndef SQLITE_OMIT_SUBQUERY
    case TK_SELECT: {
      /* The expression is a sub-select. Return the declaration type and
      ** origin info for the single column in the result set of the SELECT
      ** statement.
      */
      NameContext sNC;
      Select *pS = pExpr->x.pSelect;
      Expr *p = pS->pEList->a[0].pExpr;
      assert( ExprHasProperty(pExpr, EP_xIsSelect) );
      sNC.pSrcList = pS->pSrc;
      sNC.pNext = pNC;
      sNC.pParse = pNC->pParse;
      zType = columnType(&sNC, p, &zOriginDb, &zOriginTab, &zOriginCol); 
      break;
    }
#endif
  }
  
  if( pzOriginDb ){
    assert( pzOriginTab && pzOriginCol );
    *pzOriginDb = zOriginDb;
    *pzOriginTab = zOriginTab;
    *pzOriginCol = zOriginCol;
  }
  return zType;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x58, %rsp
xorl %eax, %eax
movq %rax, -0x30(%rbp)
movq %rax, -0x28(%rbp)
movq %rax, -0x20(%rbp)
testq %rsi, %rsi
je 0x4b127
cmpq $0x0, 0x8(%rdi)
je 0x4b09b
movq %r8, %rbx
movq %rcx, %r14
movq %rdx, %r15
movzbl (%rsi), %eax
cmpl $0x74, %eax
je 0x4b0a2
cmpl $0x9a, %eax
je 0x4b014
cmpl $0x98, %eax
jne 0x4b10b
movswl 0x30(%rsi), %eax
xorl %ecx, %ecx
movq 0x8(%rdi), %r8
movzbl (%r8), %r9d
testq %r9, %r9
je 0x4b041
movl 0x2c(%rsi), %edx
imulq $0x68, %r9, %r10
xorl %r9d, %r9d
cmpl %edx, 0x44(%r8,%r9)
je 0x4b049
addq $0x68, %r9
cmpq %r9, %r10
jne 0x4b031
movq 0x20(%rdi), %rdi
xorl %edx, %edx
jmp 0x4b053
movq 0x28(%r8,%r9), %rdx
movq 0x30(%r8,%r9), %rcx
testq %rdi, %rdi
je 0x4b05d
testq %rdx, %rdx
je 0x4b01a
testq %rdx, %rdx
je 0x4b10b
testq %rcx, %rcx
je 0x4b0dc
testw %ax, %ax
js 0x4b10b
movq (%rcx), %rdx
cmpl %eax, (%rdx)
jle 0x4b10b
movq 0x8(%rdx), %rdx
movl %eax, %eax
shlq $0x5, %rax
movq (%rdx,%rax), %rsi
movq 0x28(%rcx), %rcx
leaq -0x68(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x4b0bc
xorl %eax, %eax
jmp 0x4b127
movq 0x20(%rsi), %rax
movq (%rax), %rcx
movq 0x28(%rax), %rdx
movq 0x8(%rcx), %rax
movq (%rax), %rsi
leaq -0x68(%rbp), %rax
movq %rdx, 0x8(%rax)
movq %rdi, 0x20(%rax)
movq (%rdi), %rcx
movq %rcx, (%rax)
leaq -0x30(%rbp), %rdx
leaq -0x28(%rbp), %rcx
leaq -0x20(%rbp), %r8
movq %rax, %rdi
callq 0x4afbe
jmp 0x4b10d
movq 0x68(%rdx), %rcx
testq %rcx, %rcx
je 0x4b10b
testw %ax, %ax
jns 0x4b0ee
movswl 0x40(%rdx), %eax
testl %eax, %eax
js 0x4b132
movq 0x8(%rdx), %r8
movl %eax, %eax
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
movq (%r8,%rax), %rsi
movq 0x18(%r8,%rax), %rax
jmp 0x4b140
xorl %eax, %eax
testq %r15, %r15
je 0x4b127
movq -0x30(%rbp), %rcx
movq %rcx, (%r15)
movq -0x28(%rbp), %rcx
movq %rcx, (%r14)
movq -0x20(%rbp), %rcx
movq %rcx, (%rbx)
addq $0x58, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x30137(%rip), %rax     # 0x7b270
leaq 0x2ee34(%rip), %rsi     # 0x79f74
movq %rsi, -0x20(%rbp)
movq (%rdx), %rdx
movq %rdx, -0x28(%rbp)
movq (%rdi), %rdx
testq %rdx, %rdx
je 0x4b10d
movq (%rdx), %rdx
movl 0x28(%rdx), %esi
movq 0x20(%rdx), %rdx
testl %esi, %esi
jle 0x4b17c
leaq 0x18(%rdx), %r8
xorl %edi, %edi
cmpq %rcx, (%r8)
je 0x4b17e
incq %rdi
addq $0x20, %r8
cmpq %rdi, %rsi
jne 0x4b167
movl %esi, %edi
jmp 0x4b17e
xorl %edi, %edi
movslq %edi, %rcx
shlq $0x5, %rcx
movq (%rdx,%rcx), %rcx
movq %rcx, -0x30(%rbp)
jmp 0x4b10d