// File: /workspace/github_c_makefile_star2_O1/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, %r14
movq %rcx, %rbx
movq %rsi, -0x48(%rbp)
movq 0x8(%rsi), %rax
movslq %edx, %r13
shlq $0x5, %r13
movq (%rax,%r13), %r12
movq %rdi, -0x38(%rbp)
movq (%rdi), %rdi
movq %rdi, -0x30(%rbp)
movq %r12, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x48163
testq %rax, %rax
je 0x48118
movq %rax, %r15
cmpb $-0x68, (%r12)
je 0x4807c
cmpb $0x47, (%r14)
je 0x4807c
movl -0x3c(%rbp), %ecx
testl %ecx, %ecx
jle 0x48029
xorps %xmm0, %xmm0
leaq -0x70(%rbp), %rdi
movaps %xmm0, (%rdi)
movaps %xmm0, 0x10(%rdi)
movq $0x0, 0x20(%rdi)
leaq 0x973(%rip), %rax       # 0x4898e
movq %rax, (%rdi)
movl %ecx, 0x20(%rdi)
movq %r15, %rsi
callq 0x470d7
movq -0x38(%rbp), %rdi
movl $0x18, %esi
movq %r15, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x39f77
testq %rax, %rax
je 0x48118
movq %rax, %r15
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
addq %r13, %rax
addq $0x1c, %rax
cmpw $0x0, (%rax)
jne 0x48075
movq -0x38(%rbp), %rdx
movl 0x208(%rdx), %ecx
incl %ecx
movl %ecx, 0x208(%rdx)
movw %cx, (%rax)
movzwl (%rax), %eax
movl %eax, 0x2c(%r15)
movq -0x30(%rbp), %r13
cmpb $0x5c, (%rbx)
jne 0x48098
movq 0x8(%rbx), %rdx
movq -0x38(%rbp), %rdi
movq %r15, %rsi
callq 0x48127
movq %rax, %r15
orb $-0x80, 0x3(%rbx)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x34068
movl $0x9, %ecx
movq %rbx, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
testb $0x4, 0x3(%rbx)
jne 0x4810d
movq 0x8(%rbx), %r14
testq %r14, %r14
je 0x4810d
xorl %r12d, %r12d
cmpb $0x0, (%r14,%r12)
leaq 0x1(%r12), %r12
jne 0x480c7
decl %r12d
andl $0x3fffffff, %r12d      # imm = 0x3FFFFFFF
incl %r12d
movq %r13, %rdi
movl %r12d, %esi
callq 0x115e9
movq %rax, %r13
testq %rax, %rax
je 0x48101
movl %r12d, %edx
movq %r13, %rdi
movq %r14, %rsi
callq 0x82f0
movq %r13, 0x8(%rbx)
orb $0x1, 0x36(%rbx)
movq -0x30(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x9c3a
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq