// File: /workspace/github_c_makefile_star2_O2/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 %rcx, -0x48(%rbp)
movq %rdx, -0x50(%rbp)
movq %rsi, %r13
movq (%rdi), %r15
xorl %ebx, %ebx
testq %rsi, %rsi
je 0x45851
movl (%r13), %r12d
imull $0x30, %r12d, %esi
movq %r15, %rdi
callq 0xf4ae
movq %rax, %rcx
jmp 0x45856
xorl %ecx, %ecx
xorl %r12d, %r12d
movq -0x50(%rbp), %rax
movw %r12w, (%rax)
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
testl %r12d, %r12d
cmovlel %ebx, %r12d
xorl %edx, %edx
movq %rcx, -0x30(%rbp)
movq %rcx, %rax
movq %r15, -0x40(%rbp)
movq %r12, -0x68(%rbp)
movq %r13, -0x60(%rbp)
cmpq %r12, %rdx
je 0x45a29
movq %rax, -0x58(%rbp)
movq 0x8(%r13), %rbx
movq %rdx, -0x38(%rbp)
movq %rdx, %r14
shlq $0x5, %r14
movq (%rbx,%r14), %rdi
callq 0x45e0b
movq 0x8(%rbx,%r14), %rsi
testq %rsi, %rsi
je 0x458be
movq %r15, %rdi
callq 0xf173
jmp 0x45922
movq 0x18(%rax), %rax
movzbl (%rax), %ecx
cmpl $0x76, %ecx
je 0x458ba
cmpl $0x1a, %ecx
je 0x4590d
cmpl $0x98, %ecx
jne 0x45906
movq 0x40(%rax), %rcx
testq %rcx, %rcx
je 0x45906
movzwl 0x30(%rax), %eax
testw %ax, %ax
jns 0x458f5
movzwl 0x40(%rcx), %eax
leaq 0x266a4(%rip), %rdx     # 0x6bf94
testw %ax, %ax
js 0x45911
movzwl %ax, %eax
movq 0x8(%rcx), %rcx
imulq $0x30, %rax, %rax
movq (%rcx,%rax), %rdx
jmp 0x45911
movq 0x10(%rbx,%r14), %rdx
jmp 0x45911
movq 0x8(%rax), %rdx
movq %r15, %rdi
leaq 0x25dde(%rip), %rsi     # 0x6b6f9
xorl %eax, %eax
callq 0x10594
movq %rax, %rbx
cmpb $0x0, 0x50(%r15)
jne 0x45a1a
movq %rbx, %rdi
callq 0x8f8e
movl %eax, %r13d
xorl %r14d, %r14d
xorl %r12d, %r12d
movq -0x30(%rbp), %r15
movq -0x38(%rbp), %rdx
movslq %r12d, %rax
cmpq %rax, %rdx
jle 0x459ef
imulq $0x30, %rax, %rax
movq (%r15,%rax), %rdi
movq %rbx, %rsi
callq 0xb1bf
testl %eax, %eax
jne 0x459e7
movl %r13d, %edx
leal -0x1(%r13), %eax
movslq %eax, %rcx
addq %rbx, %rcx
movq -0x40(%rbp), %r12
movq %rdx, %rax
cmpl $0x2, %eax
jle 0x4599b
leaq -0x1(%rax), %rdx
movl %edx, %esi
movzbl (%rbx,%rsi), %esi
leaq -0x3a(%rsi), %rdi
decq %rcx
cmpq $-0xb, %rdi
ja 0x4597a
jmp 0x4599e
movb (%rcx), %sil
decl %eax
cmpb $0x3a, %sil
cmovel %eax, %r13d
movslq %r13d, %rax
movb $0x0, (%rbx,%rax)
incl %r14d
movq %r12, %rdi
leaq 0x277f5(%rip), %rsi     # 0x6d1b1
movq %rbx, %rdx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x10594
movq %rax, %r15
movq %r12, %rdi
movq %rbx, %rsi
callq 0x968b
pushq $-0x1
popq %r12
movq %r15, %rbx
testq %r15, %r15
movq -0x30(%rbp), %r15
je 0x459f5
incl %r12d
jmp 0x45945
movq -0x40(%rbp), %r15
jmp 0x459ff
xorl %ebx, %ebx
movq -0x40(%rbp), %r15
movq -0x38(%rbp), %rdx
movq -0x58(%rbp), %rax
movq %rbx, (%rax)
incq %rdx
addq $0x30, %rax
movq -0x68(%rbp), %r12
movq -0x60(%rbp), %r13
jmp 0x45881
movq %r15, %rdi
movq %rbx, %rsi
callq 0x968b
movq -0x38(%rbp), %r12
cmpb $0x0, 0x50(%r15)
je 0x45a71
movl %r12d, %eax
imulq $0x30, %rax, %rbx
xorl %r14d, %r14d
cmpq %r14, %rbx
je 0x45a55
movq -0x30(%rbp), %rax
movq (%rax,%r14), %rsi
movq %r15, %rdi
callq 0x968b
addq $0x30, %r14
jmp 0x45a3a
movq %r15, %rdi
movq -0x30(%rbp), %rsi
callq 0x968b
movq -0x48(%rbp), %rax
andq $0x0, (%rax)
movq -0x50(%rbp), %rax
andw $0x0, (%rax)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq