// File: /workspace/github_c_makefile_star2_O0/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
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x63d2f
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x54(%rbp)
movq -0x30(%rbp), %rdi
movslq -0x54(%rbp), %rax
imulq $0x30, %rax, %rax
movl %eax, %esi
callq 0x11ca0
movq %rax, -0x48(%rbp)
jmp 0x63d3e
movl $0x0, -0x54(%rbp)
movq $0x0, -0x48(%rbp)
movl -0x54(%rbp), %eax
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, (%rax)
movq -0x48(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x34(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x54(%rbp), %eax
jge 0x6407b
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x34(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x648b0
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x34(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, %rax
je 0x63dc7
movq -0x30(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x11720
movq %rax, -0x68(%rbp)
jmp 0x63f00
movq -0x60(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x76, %eax
jne 0x63de9
movq -0x78(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x78(%rbp)
jmp 0x63dcf
movq -0x78(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x98, %eax
jne 0x63ea3
movq -0x78(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0x63ea3
movq -0x78(%rbp), %rax
movswl 0x30(%rax), %eax
movl %eax, -0x84(%rbp)
movq -0x78(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x80(%rbp)
cmpl $0x0, -0x84(%rbp)
jge 0x63e3b
movq -0x80(%rbp), %rax
movswl 0x40(%rax), %eax
movl %eax, -0x84(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0xa0(%rbp)
cmpl $0x0, -0x84(%rbp)
jl 0x63e71
movq -0x80(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x84(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0xa8(%rbp)
jmp 0x63e81
leaq 0x4abf8(%rip), %rax     # 0xaea70
movq %rax, -0xa8(%rbp)
jmp 0x63e81
movq -0xa0(%rbp), %rdi
movq -0xa8(%rbp), %rdx
leaq 0x4a33a(%rip), %rsi     # 0xae1d0
movb $0x0, %al
callq 0x137f0
movq %rax, -0x68(%rbp)
jmp 0x63efe
movq -0x78(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x1a, %eax
jne 0x63ecf
movq -0x30(%rbp), %rdi
movq -0x78(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x4a30e(%rip), %rsi     # 0xae1d0
movb $0x0, %al
callq 0x137f0
movq %rax, -0x68(%rbp)
jmp 0x63efc
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x34(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdx
leaq 0x4a2df(%rip), %rsi     # 0xae1d0
movb $0x0, %al
callq 0x137f0
movq %rax, -0x68(%rbp)
jmp 0x63efe
jmp 0x63f00
movq -0x30(%rbp), %rax
cmpb $0x0, 0x50(%rax)
je 0x63f1c
movq -0x30(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x9cd0
jmp 0x6407b
movq -0x68(%rbp), %rdi
callq 0x92f0
movl %eax, -0x6c(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x64056
movq -0x48(%rbp), %rax
movslq -0x38(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
movq -0x68(%rbp), %rsi
callq 0xc970
cmpl $0x0, %eax
jne 0x64046
movl -0x6c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x94(%rbp)
xorl %eax, %eax
cmpl $0x1, -0x94(%rbp)
movb %al, -0xa9(%rbp)
jle 0x63fae
movq -0x68(%rbp), %rax
movslq -0x94(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x46aa5(%rip), %rax     # 0xaaa40
movzbl (%rax,%rcx), %eax
andl $0x4, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0xa9(%rbp)
movb -0xa9(%rbp), %al
testb $0x1, %al
jne 0x63fba
jmp 0x63fcd
jmp 0x63fbc
movl -0x94(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x63f72
movq -0x68(%rbp), %rax
movslq -0x94(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3a, %eax
jne 0x63fea
movl -0x94(%rbp), %eax
movl %eax, -0x6c(%rbp)
movq -0x68(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x30(%rbp), %rdi
movq -0x68(%rbp), %rdx
movl -0x3c(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x3c(%rbp)
leaq 0x4bc7f(%rip), %rsi     # 0xafc8d
movb $0x0, %al
callq 0x137f0
movq %rax, -0x90(%rbp)
movq -0x30(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x9cd0
movq -0x90(%rbp), %rax
movq %rax, -0x68(%rbp)
movl $0xffffffff, -0x38(%rbp) # imm = 0xFFFFFFFF
cmpq $0x0, -0x68(%rbp)
jne 0x64044
jmp 0x64056
jmp 0x64046
jmp 0x64048
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x63f36
movq -0x68(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, (%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x50(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x50(%rbp)
jmp 0x63d65
movq -0x30(%rbp), %rax
cmpb $0x0, 0x50(%rax)
je 0x640e4
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x640ba
movq -0x30(%rbp), %rdi
movq -0x48(%rbp), %rax
movslq -0x38(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rsi
callq 0x9cd0
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x6408c
movq -0x30(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x9cd0
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movq -0x20(%rbp), %rax
movw $0x0, (%rax)
movl $0x7, -0x4(%rbp)
jmp 0x640eb
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopw (%rax,%rax)