// File: /workspace/github_c_makefile_star2_O1/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, -0x50(%rbp)
movq %rdx, %r15
movq (%rdi), %r12
xorl %r9d, %r9d
testq %rsi, %rsi
movq %rsi, -0x38(%rbp)
je 0x49fb6
movl (%rsi), %r14d
movl %r14d, %eax
shll $0x4, %eax
leal (%rax,%rax,2), %ebx
movq %r12, %rdi
movl %ebx, %esi
callq 0x115e9
movq %rax, %r13
testq %rax, %rax
je 0x49fad
movslq %ebx, %rdx
movq %r13, %rdi
xorl %esi, %esi
callq 0x8200
xorl %r9d, %r9d
movq -0x38(%rbp), %rsi
jmp 0x49fbc
xorl %r13d, %r13d
xorl %r14d, %r14d
movw %r14w, (%r15)
movq -0x50(%rbp), %rax
movq %r13, (%rax)
testl %r14d, %r14d
jle 0x4a270
movq %r15, -0x48(%rbp)
movl %r14d, %eax
movq %rax, -0x60(%rbp)
leaq 0x2c07e(%rip), %r15     # 0x76060
xorl %r9d, %r9d
movq %r13, %r8
movq %r13, -0x40(%rbp)
movq %r12, -0x58(%rbp)
movq 0x8(%rsi), %rax
movq %r9, %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %rdx
testq %rdx, %rdx
je 0x4a017
movzbl (%rdx), %esi
cmpl $0x5c, %esi
je 0x4a011
cmpl $0x18, %esi
jne 0x4a017
movq 0x10(%rdx), %rdx
jmp 0x49fff
movq 0x8(%rax,%rcx), %r14
testq %r14, %r14
movq %r9, -0x30(%rbp)
movq %r8, -0x68(%rbp)
je 0x4a076
xorl %r13d, %r13d
cmpb $0x0, (%r14,%r13)
leaq 0x1(%r13), %r13
jne 0x4a02c
decl %r13d
andl $0x3fffffff, %r13d      # imm = 0x3FFFFFFF
incl %r13d
movq %r12, %rdi
movl %r13d, %esi
callq 0x115e9
movq %rax, %rbx
testq %rax, %rax
je 0x4a065
movl %r13d, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x82f0
movq -0x40(%rbp), %r13
movq -0x30(%rbp), %r9
jmp 0x4a0fe
movq 0x18(%rdx), %rdx
movzbl (%rdx), %edi
cmpl $0x76, %edi
je 0x4a072
cmpl $0x1a, %edi
je 0x4a0db
cmpl $0x98, %edi
jne 0x4a0e1
movq 0x40(%rdx), %rsi
testq %rsi, %rsi
je 0x4a0d5
movzwl 0x30(%rdx), %eax
testw %ax, %ax
jns 0x4a0a1
movzwl 0x40(%rsi), %eax
leaq 0x2fecc(%rip), %rdx     # 0x79f74
testw %ax, %ax
js 0x4a0bf
movzwl %ax, %eax
movq 0x8(%rsi), %rcx
leaq (%rax,%rax,2), %rax
shll $0x4, %eax
movq (%rcx,%rax), %rdx
movq %r12, %rdi
leaq 0x2f610(%rip), %rsi     # 0x796d9
xorl %eax, %eax
callq 0x117e2
movq %rax, %rbx
jmp 0x4a069
cmpb $0x1a, %dil
jne 0x4a0e1
movq 0x8(%rdx), %rdx
jmp 0x4a0e6
movq 0x10(%rax,%rcx), %rdx
movq %r12, %rdi
leaq 0x2f5e9(%rip), %rsi     # 0x796d9
xorl %eax, %eax
callq 0x117e2
movq -0x30(%rbp), %r9
movq %rax, %rbx
cmpb $0x0, 0x50(%r12)
jne 0x4a25d
testq %rbx, %rbx
je 0x4a12d
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq %rbx, %rax
incl %r12d
cmpb $0x0, (%rax)
leaq 0x1(%rax), %rax
jne 0x4a118
andl $0x3fffffff, %r12d      # imm = 0x3FFFFFFF
jmp 0x4a130
xorl %r12d, %r12d
testq %r9, %r9
je 0x4a238
xorl %eax, %eax
xorl %ecx, %ecx
movslq %eax, %rdx
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %rdx
movq (%r13,%rdx), %rsi
movb (%rsi), %r10b
testb %r10b, %r10b
je 0x4a17d
incq %rsi
movq %rbx, %rdx
movzbl %r10b, %edi
movb (%rdi,%r15), %dil
movzbl (%rdx), %r8d
cmpb (%r8,%r15), %dil
jne 0x4a180
incq %rdx
movb (%rsi), %r10b
incq %rsi
testb %r10b, %r10b
jne 0x4a15b
jmp 0x4a180
movq %rbx, %rdx
movzbl %r10b, %esi
movb (%rsi,%r15), %sil
movzbl (%rdx), %edx
cmpb (%rdx,%r15), %sil
jne 0x4a1c5
cmpl $0x2, %r12d
movl $0x2, %eax
cmovll %r12d, %eax
movl %r12d, %edi
decl %eax
decq %rdi
movl %r12d, %edx
cmpl $0x3, %edx
jl 0x4a1ca
movl %edi, %esi
movzbl (%rbx,%rsi), %esi
addq $-0x3a, %rsi
decl %edx
decq %rdi
cmpq $-0xb, %rsi
ja 0x4a1a9
jmp 0x4a1cc
movq %rbx, %r14
jmp 0x4a228
movl %eax, %edx
movslq %edx, %rax
cmpb $0x3a, (%rbx,%rax)
cmovel %eax, %r12d
movslq %r12d, %rax
movb $0x0, (%rbx,%rax)
incl %ecx
movq -0x58(%rbp), %r13
movq %r13, %rdi
leaq 0x30fa3(%rip), %rsi     # 0x7b191
movq %rbx, %rdx
xorl %eax, %eax
movl %ecx, %r15d
callq 0x117e2
movq %rax, %r14
movq %r13, %rdi
movq %rbx, %rsi
callq 0x9c3a
movl %r15d, %ecx
leaq 0x2be4d(%rip), %r15     # 0x76060
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %r14, %rbx
testq %r14, %r14
movq -0x40(%rbp), %r13
movq -0x30(%rbp), %r9
je 0x4a23b
incl %eax
movslq %eax, %rdx
cmpq %rdx, %r9
jg 0x4a13d
jmp 0x4a23b
movq %rbx, %r14
movq -0x68(%rbp), %r8
movq %r14, (%r8)
incq %r9
addq $0x30, %r8
cmpq -0x60(%rbp), %r9
movq -0x58(%rbp), %r12
movq -0x38(%rbp), %rsi
jne 0x49ff0
jmp 0x4a26c
movq %r12, %rdi
movq %rbx, %rsi
callq 0x9c3a
movq -0x30(%rbp), %r9
movq -0x48(%rbp), %r15
cmpb $0x0, 0x50(%r12)
je 0x4a2bd
testl %r9d, %r9d
je 0x4a2a1
movl %r9d, %eax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rbx
xorl %r14d, %r14d
movq (%r13,%r14), %rsi
movq %r12, %rdi
callq 0x9c3a
addq $0x30, %r14
cmpq %r14, %rbx
jne 0x4a28b
movq %r12, %rdi
movq %r13, %rsi
callq 0x9c3a
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