// File: /workspace/github_c_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
andq $0x0, -0x40(%rbp)
andq $0x0, -0x38(%rbp)
andq $0x0, -0x30(%rbp)
testq %rsi, %rsi
je 0x4655f
cmpq $0x0, 0x8(%rdi)
je 0x4655f
movq %r8, %rbx
movq %rcx, %r14
movq %rdx, %r15
movzbl (%rsi), %eax
cmpl $0x74, %eax
je 0x465a5
cmpl $0x9a, %eax
je 0x46514
cmpl $0x98, %eax
jne 0x4660d
movswl 0x30(%rsi), %eax
xorl %edx, %edx
xorl %ecx, %ecx
testq %rdi, %rdi
je 0x46567
testq %rdx, %rdx
jne 0x46567
movq 0x8(%rdi), %r8
movzbl (%r8), %edx
imulq $0x68, %rdx, %rdx
xorl %r9d, %r9d
cmpq %r9, %rdx
je 0x4654b
movl 0x44(%r8,%r9), %r10d
cmpl 0x2c(%rsi), %r10d
je 0x46553
addq $0x68, %r9
jmp 0x46535
movq 0x20(%rdi), %rdi
xorl %edx, %edx
jmp 0x4651c
movq 0x28(%r8,%r9), %rdx
movq 0x30(%r8,%r9), %rcx
jmp 0x4651c
xorl %r12d, %r12d
jmp 0x4662a
testq %rdx, %rdx
je 0x4660d
testq %rcx, %rcx
je 0x465e2
testw %ax, %ax
js 0x4660d
movq (%rcx), %rdx
cmpl %eax, (%rdx)
jle 0x4660d
movq 0x8(%rdx), %rdx
movl %eax, %eax
shlq $0x5, %rax
movq (%rdx,%rax), %rsi
movq 0x28(%rcx), %rcx
leaq -0x78(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x465bf
movq 0x20(%rsi), %rax
movq (%rax), %rcx
movq 0x28(%rax), %rdx
movq 0x8(%rcx), %rax
movq (%rax), %rsi
leaq -0x78(%rbp), %rax
movq %rdx, 0x8(%rax)
movq %rdi, 0x20(%rax)
movq (%rdi), %rcx
movq %rcx, (%rax)
leaq -0x40(%rbp), %rdx
leaq -0x38(%rbp), %rcx
leaq -0x30(%rbp), %r8
movq %rax, %rdi
callq 0x464c1
movq %rax, %r12
jmp 0x46610
movq 0x68(%rdx), %rsi
testq %rsi, %rsi
je 0x4660d
testw %ax, %ax
jns 0x465f4
movswl 0x40(%rdx), %eax
testl %eax, %eax
js 0x4663c
movq 0x8(%rdx), %rcx
movl %eax, %eax
imulq $0x30, %rax, %r8
movq (%rcx,%r8), %rax
movq 0x18(%rcx,%r8), %r12
jmp 0x4664a
xorl %r12d, %r12d
testq %r15, %r15
je 0x4662a
movq -0x40(%rbp), %rax
movq %rax, (%r15)
movq -0x38(%rbp), %rax
movq %rax, (%r14)
movq -0x30(%rbp), %rax
movq %rax, (%rbx)
movq %r12, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x26c4d(%rip), %r12     # 0x6d290
leaq 0x2594a(%rip), %rax     # 0x6bf94
movq %rax, -0x30(%rbp)
movq (%rdx), %rax
movq %rax, -0x38(%rbp)
movq (%rdi), %rax
testq %rax, %rax
je 0x46610
movq (%rax), %r13
movq %r13, %rdi
callq 0x1064e
movq 0x20(%r13), %rcx
cltq
shlq $0x5, %rax
movq (%rcx,%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x46610