// File: /workspace/github_c_makefile_star2_O1/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
xorl %eax, %eax
movq %rax, -0x40(%rbp)
movq %rax, -0x38(%rbp)
movq %rax, -0x30(%rbp)
testq %rsi, %rsi
je 0x4af3a
cmpq $0x0, 0x8(%rdi)
je 0x4aed6
movq %r8, %rbx
movq %rcx, %r14
movq %rdx, %r15
movzbl (%rsi), %eax
cmpl $0x74, %eax
je 0x4aeda
cmpl $0x9a, %eax
je 0x4ae53
cmpl $0x98, %eax
jne 0x4af1e
testq %rdi, %rdi
je 0x4af14
xorl %eax, %eax
xorl %ecx, %ecx
movq 0x8(%rdi), %rdx
movzbl (%rdx), %r8d
testq %r8, %r8
setne %r11b
je 0x4aec0
movl 0x2c(%rsi), %r10d
cmpl %r10d, 0x44(%rdx)
jne 0x4ae80
xorl %r9d, %r9d
jmp 0x4aeab
leaq 0xac(%rdx), %r12
leaq -0x1(%r8), %r11
xorl %r9d, %r9d
cmpq %r9, %r11
je 0x4aec0
leaq 0x68(%r12), %r13
incq %r9
cmpl %r10d, (%r12)
movq %r13, %r12
jne 0x4ae8e
cmpq %r8, %r9
setb %r11b
testb %r11b, %r11b
je 0x4aec0
imulq $0x68, %r9, %rax
movq 0x28(%rdx,%rax), %rcx
movq 0x30(%rdx,%rax), %rax
jmp 0x4aec4
movq 0x20(%rdi), %rdi
testq %rcx, %rcx
sete %dl
testq %rdi, %rdi
je 0x4af1a
testq %rcx, %rcx
je 0x4ae60
jmp 0x4af1a
xorl %eax, %eax
jmp 0x4af3a
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 0x4adf9
jmp 0x4af20
movb $0x1, %dl
xorl %ecx, %ecx
xorl %eax, %eax
testb %dl, %dl
je 0x4af49
xorl %eax, %eax
testq %r15, %r15
je 0x4af3a
movq -0x40(%rbp), %rcx
movq %rcx, (%r15)
movq -0x38(%rbp), %rcx
movq %rcx, (%r14)
movq -0x30(%rbp), %rcx
movq %rcx, (%rbx)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movswl 0x30(%rsi), %esi
testq %rax, %rax
je 0x4af78
testw %si, %si
js 0x4af1e
movq (%rax), %rcx
cmpl %esi, (%rcx)
jle 0x4af1e
movq (%rax), %rcx
movq 0x28(%rax), %rdx
movq 0x8(%rcx), %rax
movl %esi, %ecx
shlq $0x5, %rcx
movq (%rax,%rcx), %rsi
jmp 0x4aeec
movq 0x68(%rcx), %rdx
testq %rdx, %rdx
je 0x4af1e
testw %si, %si
jns 0x4af8a
movswl 0x40(%rcx), %esi
testl %esi, %esi
js 0x4afa7
movq 0x8(%rcx), %rax
movl %esi, %esi
leaq (%rsi,%rsi,2), %r8
shlq $0x4, %r8
movq (%rax,%r8), %rsi
movq 0x18(%rax,%r8), %rax
jmp 0x4afb5
leaq 0x302c2(%rip), %rax     # 0x7b270
leaq 0x2efbf(%rip), %rsi     # 0x79f74
movq %rsi, -0x30(%rbp)
movq (%rcx), %rcx
movq %rcx, -0x38(%rbp)
movq (%rdi), %rcx
testq %rcx, %rcx
je 0x4af20
movq (%rcx), %rcx
movl 0x28(%rcx), %esi
testl %esi, %esi
jle 0x4aff5
movq 0x20(%rcx), %r8
addq $0x18, %r8
xorl %edi, %edi
cmpq %rdx, (%r8)
je 0x4aff7
incq %rdi
addq $0x20, %r8
cmpq %rdi, %rsi
jne 0x4afe0
movl %esi, %edi
jmp 0x4aff7
xorl %edi, %edi
movq 0x20(%rcx), %rcx
movslq %edi, %rdx
shlq $0x5, %rdx
movq (%rcx,%rdx), %rcx
movq %rcx, -0x40(%rbp)
jmp 0x4af20