// File: /workspace/github_c_makefile_star2_O0/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
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x65571
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x6557e
movq $0x0, -0x8(%rbp)
jmp 0x658ce
movq -0x18(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x10c(%rbp)
subl $0x74, %eax
je 0x65829
jmp 0x65596
movl -0x10c(%rbp), %eax
subl $0x98, %eax
je 0x655b8
jmp 0x655a5
movl -0x10c(%rbp), %eax
subl $0x9a, %eax
jne 0x6589e
jmp 0x655b8
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x18(%rbp), %rax
movswl 0x30(%rax), %eax
movl %eax, -0x6c(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x10(%rbp)
movb %al, -0x10d(%rbp)
je 0x655f2
cmpq $0x0, -0x60(%rbp)
setne %al
xorb $-0x1, %al
movb %al, -0x10d(%rbp)
movb -0x10d(%rbp), %al
testb $0x1, %al
jne 0x65601
jmp 0x656c0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x78(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %ecx
movq -0x78(%rbp), %rax
movzbl (%rax), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x10e(%rbp)
jge 0x65650
movq -0x78(%rbp), %rax
addq $0x8, %rax
movslq -0x54(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movl 0x3c(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x2c(%rcx), %eax
setne %al
movb %al, -0x10e(%rbp)
movb -0x10e(%rbp), %al
testb $0x1, %al
jne 0x6565c
jmp 0x65669
jmp 0x6565e
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x65614
movl -0x54(%rbp), %eax
movq -0x78(%rbp), %rcx
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x656af
movq -0x78(%rbp), %rax
addq $0x8, %rax
movslq -0x54(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq 0x20(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x78(%rbp), %rax
addq $0x8, %rax
movslq -0x54(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq 0x28(%rax), %rax
movq %rax, -0x68(%rbp)
jmp 0x656bb
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x10(%rbp)
jmp 0x655d3
cmpq $0x0, -0x60(%rbp)
jne 0x656cc
jmp 0x6589e
cmpq $0x0, -0x68(%rbp)
je 0x6575b
cmpl $0x0, -0x6c(%rbp)
jl 0x65756
movl -0x6c(%rbp), %eax
movq -0x68(%rbp), %rcx
movq (%rcx), %rcx
cmpl (%rcx), %eax
jge 0x65756
movq -0x68(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movslq -0x6c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0xb8(%rbp)
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xb0(%rbp)
movq -0xb8(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
leaq -0x40(%rbp), %rdx
leaq -0x48(%rbp), %rcx
leaq -0x50(%rbp), %r8
callq 0x65520
movq %rax, -0x38(%rbp)
jmp 0x65827
movq -0x60(%rbp), %rax
cmpq $0x0, 0x68(%rax)
je 0x65825
cmpl $0x0, -0x6c(%rbp)
jge 0x6577b
movq -0x60(%rbp), %rax
movswl 0x40(%rax), %eax
movl %eax, -0x6c(%rbp)
cmpl $0x0, -0x6c(%rbp)
jge 0x65799
leaq 0x4a5e4(%rip), %rax     # 0xafd6c
movq %rax, -0x38(%rbp)
leaq 0x492dd(%rip), %rax     # 0xaea70
movq %rax, -0x50(%rbp)
jmp 0x657ce
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x6c(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x6c(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x60(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x65823
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rdi
movq -0x60(%rbp), %rax
movq 0x68(%rax), %rsi
callq 0x13940
movl %eax, -0xbc(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rax), %rax
movslq -0xbc(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x65825
jmp 0x65827
jmp 0x6589e
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq %rax, -0x108(%rbp)
movq -0x100(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0xf0(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xf8(%rbp)
movq -0x108(%rbp), %rsi
leaq -0xf8(%rbp), %rdi
leaq -0x40(%rbp), %rdx
leaq -0x48(%rbp), %rcx
leaq -0x50(%rbp), %r8
callq 0x65520
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x658c6
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x48(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x50(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopl (%rax,%rax)