// File: /workspace/github_c_makefile_star2_O3/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: selectColumnsFromExprList
static int selectColumnsFromExprList(
  Parse *pParse,          /* Parsing context */
  ExprList *pEList,       /* Expr list from which to derive column names */
  i16 *pnCol,             /* Write the number of columns here */
  Column **paCol          /* Write the new column list here */
){
  sqlite3 *db = pParse->db;   /* Database connection */
  int i, j;                   /* Loop counters */
  int cnt;                    /* Index added to make the name unique */
  Column *aCol, *pCol;        /* For looping over result columns */
  int nCol;                   /* Number of columns in the result set */
  Expr *p;                    /* Expression for a single result column */
  char *zName;                /* Column name */
  int nName;                  /* Size of name in zName[] */

  if( pEList ){
    nCol = pEList->nExpr;
    aCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol);
    testcase( aCol==0 );
  }else{
    nCol = 0;
    aCol = 0;
  }
  *pnCol = nCol;
  *paCol = aCol;

  for(i=0, pCol=aCol; i<nCol; i++, pCol++){
    /* Get an appropriate name for the column
    */
    p = sqlite3ExprSkipCollate(pEList->a[i].pExpr);
    if( (zName = pEList->a[i].zName)!=0 ){
      /* If the column contains an "AS <name>" phrase, use <name> as the name */
      zName = sqlite3DbStrDup(db, zName);
    }else{
      Expr *pColExpr = p;  /* The expression that is the result column name */
      Table *pTab;         /* Table associated with this expression */
      while( pColExpr->op==TK_DOT ){
        pColExpr = pColExpr->pRight;
        assert( pColExpr!=0 );
      }
      if( pColExpr->op==TK_COLUMN && ALWAYS(pColExpr->pTab!=0) ){
        /* For columns use the column name name */
        int iCol = pColExpr->iColumn;
        pTab = pColExpr->pTab;
        if( iCol<0 ) iCol = pTab->iPKey;
        zName = sqlite3MPrintf(db, "%s",
                 iCol>=0 ? pTab->aCol[iCol].zName : "rowid");
      }else if( pColExpr->op==TK_ID ){
        assert( !ExprHasProperty(pColExpr, EP_IntValue) );
        zName = sqlite3MPrintf(db, "%s", pColExpr->u.zToken);
      }else{
        /* Use the original text of the column expression as its name */
        zName = sqlite3MPrintf(db, "%s", pEList->a[i].zSpan);
      }
    }
    if( db->mallocFailed ){
      sqlite3DbFree(db, zName);
      break;
    }

    /* Make sure the column name is unique.  If the name is not unique,
    ** append a integer to the name so that it becomes unique.
    */
    nName = sqlite3Strlen30(zName);
    for(j=cnt=0; j<i; j++){
      if( sqlite3StrICmp(aCol[j].zName, zName)==0 ){
        char *zNewName;
        int k;
        for(k=nName-1; k>1 && sqlite3Isdigit(zName[k]); k--){}
        if( zName[k]==':' ) nName = k;
        zName[nName] = 0;
        zNewName = sqlite3MPrintf(db, "%s:%d", zName, ++cnt);
        sqlite3DbFree(db, zName);
        zName = zNewName;
        j = -1;
        if( zName==0 ) break;
      }
    }
    pCol->zName = zName;
  }
  if( db->mallocFailed ){
    for(j=0; j<i; j++){
      sqlite3DbFree(db, aCol[j].zName);
    }
    sqlite3DbFree(db, aCol);
    *paCol = 0;
    *pnCol = 0;
    return SQLITE_NOMEM;
  }
  return SQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r15
movq %rdi, %r12
testq %rsi, %rsi
movq %rcx, -0x50(%rbp)
je 0x4a3f6
movq %rsi, -0x60(%rbp)
movl (%rsi), %r14d
movl %r14d, %eax
shll $0x4, %eax
leal (%rax,%rax,2), %ebx
movq %r12, %rdi
movl %ebx, %esi
callq 0x11721
movq %rax, %r13
testq %rax, %rax
je 0x4a12d
movslq %ebx, %rdx
movq %r13, %rdi
xorl %esi, %esi
callq 0x8200
movw %r14w, (%r15)
movq -0x50(%rbp), %rax
movq %r13, (%rax)
testl %r14d, %r14d
jle 0x4a406
movq %r15, -0x48(%rbp)
leaq 0x2bf64(%rip), %r15     # 0x760b0
xorl %ebx, %ebx
movq %r13, %rcx
movq %r12, -0x40(%rbp)
movq %r13, -0x30(%rbp)
movq %r14, -0x58(%rbp)
movq %rcx, -0x68(%rbp)
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
movq %rbx, %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %rdx
testq %rdx, %rdx
je 0x4a18c
movzbl (%rdx), %esi
cmpl $0x5c, %esi
je 0x4a186
cmpl $0x18, %esi
jne 0x4a18e
movq 0x10(%rdx), %rdx
jmp 0x4a174
xorl %edx, %edx
movq 0x8(%rax,%rcx), %r13
testq %r13, %r13
movq %rbx, -0x38(%rbp)
je 0x4a1e4
xorl %ebx, %ebx
cmpb $0x0, (%r13,%rbx)
leaq 0x1(%rbx), %rbx
jne 0x4a19e
decl %ebx
andl $0x3fffffff, %ebx       # imm = 0x3FFFFFFF
incl %ebx
movq %r12, %rdi
movl %ebx, %esi
callq 0x11721
testq %rax, %rax
je 0x4a233
movq %rax, %r14
movl %ebx, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x82f0
movq -0x30(%rbp), %r13
movq -0x38(%rbp), %rbx
jmp 0x4a288
movq 0x18(%rdx), %rdx
movzbl (%rdx), %esi
cmpl $0x76, %esi
je 0x4a1e0
cmpl $0x1a, %esi
je 0x4a26c
cmpl $0x98, %esi
movq -0x30(%rbp), %r13
jne 0x4a251
movq 0x40(%rdx), %rsi
testq %rsi, %rsi
je 0x4a251
movzwl 0x30(%rdx), %eax
testw %ax, %ax
jns 0x4a21f
movzwl 0x40(%rsi), %eax
leaq 0x2fd5a(%rip), %rdx     # 0x79f74
testw %ax, %ax
js 0x4a256
movzwl %ax, %eax
movq 0x8(%rsi), %rcx
leaq (%rax,%rax,2), %rax
shll $0x4, %eax
movq (%rcx,%rax), %rdx
jmp 0x4a256
xorl %r14d, %r14d
cmpb $0x0, 0x50(%r12)
movl $0x0, %r12d
movq -0x30(%rbp), %r13
movq -0x38(%rbp), %rbx
je 0x4a2ba
jmp 0x4a40a
movq 0x10(%rax,%rcx), %rdx
movq %r12, %rdi
leaq 0x2f479(%rip), %rsi     # 0x796d9
xorl %eax, %eax
callq 0x11900
movq %rax, %r14
jmp 0x4a288
movq 0x8(%rdx), %rdx
movq %r12, %rdi
leaq 0x2f45f(%rip), %rsi     # 0x796d9
xorl %eax, %eax
callq 0x11900
movq %rax, %r14
movq -0x30(%rbp), %r13
cmpb $0x0, 0x50(%r12)
jne 0x4a40a
testq %r14, %r14
je 0x4a2b4
xorl %r12d, %r12d
cmpb $0x0, (%r14,%r12)
leaq 0x1(%r12), %r12
jne 0x4a29c
decl %r12d
andl $0x3fffffff, %r12d      # imm = 0x3FFFFFFF
jmp 0x4a2ba
xorl %r14d, %r14d
xorl %r12d, %r12d
testq %rbx, %rbx
je 0x4a3d5
xorl %eax, %eax
xorl %ecx, %ecx
movslq %eax, %rdx
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %rdx
movq (%r13,%rdx), %rdx
movb (%rdx), %sil
testb %sil, %sil
je 0x4a307
incq %rdx
movq %r14, %r9
movzbl %sil, %esi
movb (%rsi,%r15), %dil
movzbl (%r9), %r8d
cmpb (%r8,%r15), %dil
jne 0x4a30c
incq %r9
movb (%rdx), %sil
incq %rdx
testb %sil, %sil
jne 0x4a2e5
jmp 0x4a30a
movq %r14, %r9
xorl %esi, %esi
movb (%rsi,%r15), %dl
movzbl (%r9), %esi
cmpb (%rsi,%r15), %dl
jne 0x4a3b3
cmpl $0x2, %r12d
movl $0x2, %eax
cmovll %r12d, %eax
movl %r12d, %edi
decl %eax
decq %rdi
movl %r12d, %edx
cmpl $0x3, %edx
jl 0x4a353
movl %edi, %esi
movzbl (%r14,%rsi), %esi
addq $-0x3a, %rsi
decl %edx
decq %rdi
cmpq $-0xb, %rsi
ja 0x4a336
jmp 0x4a355
movl %eax, %edx
movslq %edx, %rax
cmpb $0x3a, (%r14,%rax)
cmovel %eax, %r12d
movslq %r12d, %rax
movb $0x0, (%r14,%rax)
incl %ecx
movq -0x40(%rbp), %r13
movq %r13, %rdi
leaq 0x30e18(%rip), %rsi     # 0x7b191
movq %r14, %rdx
movl %ecx, %r15d
xorl %eax, %eax
callq 0x11900
movq %rax, %rbx
movq %r13, %rdi
movq %r14, %rsi
callq 0x9ca4
testq %rbx, %rbx
je 0x4a3c3
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rbx, %r14
movq -0x30(%rbp), %r13
movq -0x38(%rbp), %rbx
movl %r15d, %ecx
leaq 0x2bcfd(%rip), %r15     # 0x760b0
incl %eax
movslq %eax, %rdx
cmpq %rdx, %rbx
jg 0x4a2c7
jmp 0x4a3d5
xorl %r14d, %r14d
movq -0x30(%rbp), %r13
movq -0x38(%rbp), %rbx
leaq 0x2bcdb(%rip), %r15     # 0x760b0
movq -0x68(%rbp), %rcx
movq %r14, (%rcx)
incq %rbx
addq $0x30, %rcx
movq -0x58(%rbp), %rax
cmpq %rax, %rbx
movq -0x40(%rbp), %r12
jne 0x4a15d
jmp 0x4a41b
movw $0x0, (%r15)
movq $0x0, (%rcx)
xorl %r13d, %r13d
xorl %eax, %eax
jmp 0x4a41f
movq -0x40(%rbp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x9ca4
movl %ebx, %eax
movq -0x48(%rbp), %r15
cmpb $0x0, 0x50(%r12)
je 0x4a46a
testl %eax, %eax
je 0x4a44e
movl %eax, %eax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rbx
xorl %r14d, %r14d
movq (%r13,%r14), %rsi
movq %r12, %rdi
callq 0x9ca4
addq $0x30, %r14
cmpq %r14, %rbx
jne 0x4a438
movq %r12, %rdi
movq %r13, %rsi
callq 0x9ca4
movq -0x50(%rbp), %rax
movq $0x0, (%rax)
movw $0x0, (%r15)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq