// File: /workspace/github_c_makefile_star2_O3/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, -0x34(%rbp)
movq %r8, %r14
movq %rcx, %rbx
movq %rsi, -0x48(%rbp)
movq 0x8(%rsi), %rax
movslq %edx, %r13
shlq $0x5, %r13
movq (%rax,%r13), %r12
movq %rdi, -0x30(%rbp)
movq (%rdi), %rdi
movq %rdi, -0x40(%rbp)
movq %r12, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x4848c
testq %rax, %rax
je 0x48441
movq %rax, %r15
cmpb $-0x68, (%r12)
je 0x483a5
cmpb $0x47, (%r14)
je 0x483a5
movl -0x34(%rbp), %ecx
testl %ecx, %ecx
jle 0x4834d
xorps %xmm0, %xmm0
leaq -0x70(%rbp), %rdi
movups %xmm0, 0x18(%rdi)
movups %xmm0, 0x8(%rdi)
leaq 0x96a(%rip), %rax       # 0x48ca9
movq %rax, (%rdi)
movl %ecx, 0x20(%rdi)
movq %r15, %rsi
callq 0x473bb
movq -0x30(%rbp), %rdi
movl $0x18, %esi
movq %r15, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3a637
testq %rax, %rax
je 0x48441
movq %rax, %r15
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rcx
movzwl 0x1c(%rcx,%r13), %eax
testw %ax, %ax
jne 0x4839e
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)
cmpb $0x5c, (%rbx)
movq -0x40(%rbp), %r13
jne 0x483c1
movq 0x8(%rbx), %rdx
movq -0x30(%rbp), %rdi
movq %r15, %rsi
callq 0x48450
movq %rax, %r15
orb $-0x80, 0x3(%rbx)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x3479d
movl $0x9, %ecx
movq %rbx, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
testb $0x4, 0x3(%rbx)
jne 0x48436
movq 0x8(%rbx), %r14
testq %r14, %r14
je 0x48436
xorl %r12d, %r12d
cmpb $0x0, (%r14,%r12)
leaq 0x1(%r12), %r12
jne 0x483f0
decl %r12d
andl $0x3fffffff, %r12d      # imm = 0x3FFFFFFF
incl %r12d
movq %r13, %rdi
movl %r12d, %esi
callq 0x11721
movq %rax, %r13
testq %rax, %rax
je 0x4842a
movl %r12d, %edx
movq %r13, %rdi
movq %r14, %rsi
callq 0x82f0
movq %r13, 0x8(%rbx)
orb $0x1, 0x36(%rbx)
movq -0x40(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x9ca4
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq