// File: /workspace/github_c_makefile_star2_O2/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: vtabCallConstructor
static int vtabCallConstructor(
  sqlite3 *db, 
  Table *pTab,
  Module *pMod,
  int (*xConstruct)(sqlite3*,void*,int,const char*const*,sqlite3_vtab**,char**),
  char **pzErr
){
  VtabCtx sCtx, *pPriorCtx;
  VTable *pVTable;
  int rc;
  const char *const*azArg = (const char *const*)pTab->azModuleArg;
  int nArg = pTab->nModuleArg;
  char *zErr = 0;
  char *zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
  int iDb;

  if( !zModuleName ){
    return SQLITE_NOMEM;
  }

  pVTable = sqlite3DbMallocZero(db, sizeof(VTable));
  if( !pVTable ){
    sqlite3DbFree(db, zModuleName);
    return SQLITE_NOMEM;
  }
  pVTable->db = db;
  pVTable->pMod = pMod;

  iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
  pTab->azModuleArg[1] = db->aDb[iDb].zName;

  /* Invoke the virtual table constructor */
  assert( &db->pVtabCtx );
  assert( xConstruct );
  sCtx.pTab = pTab;
  sCtx.pVTable = pVTable;
  pPriorCtx = db->pVtabCtx;
  db->pVtabCtx = &sCtx;
  rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
  db->pVtabCtx = pPriorCtx;
  if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;

  if( SQLITE_OK!=rc ){
    if( zErr==0 ){
      *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
    }else {
      *pzErr = sqlite3MPrintf(db, "%s", zErr);
      sqlite3_free(zErr);
    }
    sqlite3DbFree(db, pVTable);
  }else if( ALWAYS(pVTable->pVtab) ){
    /* Justification of ALWAYS():  A correct vtab constructor must allocate
    ** the sqlite3_vtab object if successful.  */
    pVTable->pVtab->pModule = pMod->pModule;
    pVTable->nRef = 1;
    if( sCtx.pTab ){
      const char *zFormat = "vtable constructor did not declare schema: %s";
      *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
      sqlite3VtabUnlock(pVTable);
      rc = SQLITE_ERROR;
    }else{
      int iCol;
      /* If everything went according to plan, link the new VTable structure
      ** into the linked list headed by pTab->pVTable. Then loop through the 
      ** columns of the table to see if any of them contain the token "hidden".
      ** If so, set the Column COLFLAG_HIDDEN flag and remove the token from
      ** the type string.  */
      pVTable->pNext = pTab->pVTable;
      pTab->pVTable = pVTable;

      for(iCol=0; iCol<pTab->nCol; iCol++){
        char *zType = pTab->aCol[iCol].zType;
        int nType;
        int i = 0;
        if( !zType ) continue;
        nType = sqlite3Strlen30(zType);
        if( sqlite3StrNICmp("hidden", zType, 6)||(zType[6] && zType[6]!=' ') ){
          for(i=0; i<nType; i++){
            if( (0==sqlite3StrNICmp(" hidden", &zType[i], 7))
             && (zType[i+7]=='\0' || zType[i+7]==' ')
            ){
              i++;
              break;
            }
          }
        }
        if( i<nType ){
          int j;
          int nDel = 6 + (zType[i+6] ? 1 : 0);
          for(j=i; (j+nDel)<=nType; j++){
            zType[j] = zType[j+nDel];
          }
          if( zType[i]=='\0' && i>0 ){
            assert(zType[i-1]==' ');
            zType[i-1] = '\0';
          }
          pTab->aCol[iCol].colFlags |= COLFLAG_HIDDEN;
        }
      }
    }
  }

  sqlite3DbFree(db, zModuleName);
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, %r15
movq %rcx, -0x58(%rbp)
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %r14
movq 0x50(%rsi), %rax
movq %rax, -0x50(%rbp)
movl 0x4c(%rsi), %eax
movl %eax, -0x34(%rbp)
andq $0x0, -0x60(%rbp)
movq (%rsi), %rdx
leaq 0x3b062(%rip), %rsi     # 0x6b6f9
xorl %eax, %eax
callq 0x10594
movq %rax, %rbx
pushq $0x7
popq %rax
testq %rbx, %rbx
je 0x3083c
movq %r13, -0x30(%rbp)
movq %r15, -0x48(%rbp)
movq %rax, %r13
pushq $0x30
popq %rsi
movq %r14, %rdi
callq 0xf4ae
testq %rax, %rax
je 0x3078d
movq %rax, %r15
movq %rbx, -0x68(%rbp)
movq %r14, (%rax)
movq -0x30(%rbp), %r13
movq %r13, 0x8(%rax)
movq 0x68(%r12), %rsi
movq %r14, %rdi
callq 0x1064e
movq 0x20(%r14), %rcx
cltq
shlq $0x5, %rax
movq (%rcx,%rax), %rax
movq 0x50(%r12), %rcx
movq %rax, 0x8(%rcx)
leaq -0x78(%rbp), %rax
movq %r12, 0x8(%rax)
movq %r15, (%rax)
movq 0x1c0(%r14), %rbx
movq %rax, 0x1c0(%r14)
movq 0x10(%r13), %rsi
movq %r15, %r13
addq $0x10, %r13
leaq -0x60(%rbp), %r9
movq %r14, %rdi
movl -0x34(%rbp), %edx
movq -0x50(%rbp), %rcx
movq %r13, %r8
callq *-0x58(%rbp)
movq %r14, -0x40(%rbp)
movq %rbx, 0x1c0(%r14)
testl %eax, %eax
je 0x307a0
cmpl $0x7, %eax
movq -0x40(%rbp), %rbx
jne 0x30756
movb $0x1, 0x50(%rbx)
movq %rax, -0x30(%rbp)
movq -0x60(%rbp), %rdx
testq %rdx, %rdx
je 0x307f7
leaq 0x3af8b(%rip), %rsi     # 0x6b6f9
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10594
movq -0x48(%rbp), %rcx
movq %rax, (%rcx)
movq -0x60(%rbp), %rdi
callq 0x9c7b
jmp 0x30813
movq %r14, %rdi
movq %rbx, %rsi
callq 0x968b
movq %r13, %rax
jmp 0x3083c
movq (%r13), %rax
testq %rax, %rax
je 0x30820
movq -0x30(%rbp), %rcx
movq (%rcx), %rcx
movq %rcx, (%rax)
movl $0x1, 0x18(%r15)
cmpq $0x0, -0x70(%rbp)
movq -0x40(%rbp), %rbx
je 0x3084b
movq (%r12), %rdx
leaq 0x3c181(%rip), %rsi     # 0x6c956
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10594
movq -0x48(%rbp), %rcx
movq %rax, (%rcx)
movq %r15, %rdi
callq 0x1fc99
pushq $0x1
popq %rax
movq %rax, -0x30(%rbp)
jmp 0x3082c
leaq 0x3c13a(%rip), %rsi     # 0x6c938
movq %rbx, %rdi
movq -0x68(%rbp), %rdx
xorl %eax, %eax
callq 0x10594
movq -0x48(%rbp), %rcx
movq %rax, (%rcx)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x968b
jmp 0x3082c
movq $0x0, -0x30(%rbp)
movq -0x40(%rbp), %rbx
movq %rbx, %rdi
movq -0x68(%rbp), %rsi
callq 0x968b
movq -0x30(%rbp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x58(%r12), %rax
movq %rax, 0x28(%r15)
movq %r15, 0x58(%r12)
movq $0x0, -0x30(%rbp)
pushq $0x7
popq %r14
xorl %ecx, %ecx
movswq 0x42(%r12), %rax
cmpq %rax, %rcx
jge 0x30828
movq 0x8(%r12), %rax
movq %rcx, -0x58(%rbp)
imulq $0x30, %rcx, %rcx
movq %rcx, -0x50(%rbp)
movq 0x18(%rax,%rcx), %r15
testq %r15, %r15
je 0x30950
movq %r15, %rdi
callq 0x8f8e
movl %eax, %ebx
leaq 0x3c0e3(%rip), %rdi     # 0x6c985
movq %r15, %rsi
pushq $0x6
popq %rdx
callq 0x8f45
movl %ebx, -0x34(%rbp)
movl %ebx, %ebx
testl %eax, %eax
je 0x308e8
xorl %r13d, %r13d
cmpq %r13, %rbx
je 0x30950
leaq (%r15,%r13), %rsi
leaq 0x3c0b7(%rip), %rdi     # 0x6c984
movl %r14d, %edx
callq 0x8f45
testl %eax, %eax
jne 0x308e3
movzbl 0x7(%r15,%r13), %eax
testb $-0x21, %al
je 0x308f6
incq %r13
jmp 0x308b9
movzbl 0x6(%r15), %eax
xorl %r13d, %r13d
testb $-0x21, %al
je 0x308f9
jmp 0x308b6
incl %r13d
cmpl -0x34(%rbp), %r13d
jge 0x30950
movslq %r13d, %rax
cmpb $0x1, 0x6(%r15,%rax)
pushq $0x7
popq %rcx
sbbq $0x0, %rcx
leaq (%r15,%rcx), %rdx
movq %rax, %rsi
leaq (%rcx,%rsi), %rdi
cmpq %rbx, %rdi
ja 0x3092c
movb (%rdx,%rsi), %dil
movb %dil, (%r15,%rsi)
incq %rsi
jmp 0x30916
testl %r13d, %r13d
jle 0x30941
cmpb $0x0, (%r15,%rax)
jne 0x30941
movl %r13d, %eax
movb $0x0, -0x1(%r15,%rax)
movq 0x8(%r12), %rax
movq -0x50(%rbp), %rcx
orw $0x2, 0x2a(%rax,%rcx)
movq -0x58(%rbp), %rcx
incq %rcx
jmp 0x30867