// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r9d, -0x3c(%rbp)
movq %r8, %r12
movq %rcx, %rbx
movq %rsi, -0x48(%rbp)
movq 0x8(%rsi), %rax
movslq %edx, %r13
shlq $0x5, %r13
movq (%rax,%r13), %r14
movq %rdi, -0x30(%rbp)
movq (%rdi), %rdi
movq %rdi, -0x38(%rbp)
movq %r14, %rsi
xorl %edx, %edx
callq 0x440d6
testq %rax, %rax
je 0x440c7
movq %rax, %r15
cmpb $-0x68, (%r14)
je 0x44066
cmpb $0x47, (%r12)
je 0x44066
movl -0x3c(%rbp), %ecx
testl %ecx, %ecx
jle 0x44010
xorps %xmm0, %xmm0
leaq -0x70(%rbp), %rdi
movups %xmm0, 0x18(%rdi)
movups %xmm0, 0x8(%rdi)
leaq 0x8d0(%rip), %rax       # 0x448d2
movq %rax, (%rdi)
movl %ecx, 0x20(%rdi)
movq %r15, %rsi
callq 0x4336b
pushq $0x18
popq %rsi
movq -0x30(%rbp), %rdi
movq %r15, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x36a09
testq %rax, %rax
je 0x440c7
movq %rax, %r15
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rcx
movzwl 0x1c(%rcx,%r13), %eax
testw %ax, %ax
jne 0x4405f
addq %r13, %rcx
addq $0x1c, %rcx
movq -0x30(%rbp), %rdx
movl 0x208(%rdx), %eax
incl %eax
movl %eax, 0x208(%rdx)
movw %ax, (%rcx)
movzwl %ax, %eax
movl %eax, 0x2c(%r15)
movq -0x38(%rbp), %r14
cmpb $0x5c, (%rbx)
jne 0x44082
movq 0x8(%rbx), %rdx
movq -0x30(%rbp), %rdi
movq %r15, %rsi
callq 0x440df
movq %rax, %r15
orb $-0x80, 0x3(%rbx)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2f476
pushq $0x9
popq %rcx
movq %rbx, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
testb $0x4, 0x3(%rbx)
jne 0x440bc
movq 0x8(%rbx), %rsi
testq %rsi, %rsi
je 0x440bc
movq %r14, %rdi
callq 0xf173
movq %rax, 0x8(%rbx)
orb $0x1, 0x36(%rbx)
movq %r14, %rdi
movq %r15, %rsi
callq 0x968b
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq