// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: resolveAlias
static void resolveAlias(
  Parse *pParse,         /* Parsing context */
  ExprList *pEList,      /* A result set */
  int iCol,              /* A column in the result set.  0..pEList->nExpr-1 */
  Expr *pExpr,           /* Transform this into an alias to the result set */
  const char *zType,     /* "GROUP" or "ORDER" or "" */
  int nSubquery          /* Number of subqueries that the label is moving */
){
  Expr *pOrig;           /* The iCol-th column of the result set */
  Expr *pDup;            /* Copy of pOrig */
  sqlite3 *db;           /* The database connection */

  assert( iCol>=0 && iCol<pEList->nExpr );
  pOrig = pEList->a[iCol].pExpr;
  assert( pOrig!=0 );
  assert( pOrig->flags & EP_Resolved );
  db = pParse->db;
  pDup = sqlite3ExprDup(db, pOrig, 0);
  if( pDup==0 ) return;
  if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
    incrAggFunctionDepth(pDup, nSubquery);
    pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0);
    if( pDup==0 ) return;
    if( pEList->a[iCol].iAlias==0 ){
      pEList->a[iCol].iAlias = (u16)(++pParse->nAlias);
    }
    pDup->iTable = pEList->a[iCol].iAlias;
  }
  if( pExpr->op==TK_COLLATE ){
    pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
  }

  /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This 
  ** prevents ExprDelete() from deleting the Expr structure itself,
  ** allowing it to be repopulated by the memcpy() on the following line.
  ** The pExpr->u.zToken might point into memory that will be freed by the
  ** sqlite3DbFree(db, pDup) on the last line of this block, so be sure to
  ** make a copy of the token before doing the sqlite3DbFree().
  */
  ExprSetProperty(pExpr, EP_Static);
  sqlite3ExprDelete(db, pExpr);
  memcpy(pExpr, pDup, sizeof(*pExpr));
  if( !ExprHasProperty(pExpr, EP_IntValue) && pExpr->u.zToken!=0 ){
    assert( (pExpr->flags & (EP_Reduced|EP_TokenOnly))==0 );
    pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken);
    pExpr->flags2 |= EP2_MallocedToken;
  }
  sqlite3DbFree(db, pDup);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x14(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rsi
xorl %edx, %edx
callq 0x61690
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x61393
jmp 0x614fe
movq -0x38(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x98, %eax
je 0x61452
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x47, %eax
je 0x61452
movq -0x40(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x616c0
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rdx
movl $0x18, %esi
xorl %eax, %eax
movl %eax, %r8d
movq %r8, %rcx
callq 0x508b0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x613eb
jmp 0x614fe
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x14(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movzwl 0x1c(%rax), %eax
cmpl $0x0, %eax
jne 0x61434
movq -0x8(%rbp), %rcx
movl 0x208(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x208(%rcx)
movw %ax, %cx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x14(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rax
movw %cx, 0x1c(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x14(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movzwl 0x1c(%rax), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0x20(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x5c, %eax
jne 0x61477
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x61710
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movzwl 0x2(%rax), %ecx
orl $0x8000, %ecx           # imm = 0x8000
movw %cx, 0x2(%rax)
movq -0x48(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x47330
movq -0x20(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl $0x48, %edx
callq 0x82f0
movq -0x20(%rbp), %rax
movzwl 0x2(%rax), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x400, %eax            # imm = 0x400
je 0x614f1
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x614f1
movq -0x48(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x11720
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movzbl 0x36(%rax), %ecx
orl $0x1, %ecx
movb %cl, 0x36(%rax)
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x9cd0
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)