// File: /workspace/github_c_makefile_star2_O1/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, %r14
movq %rcx, %r13
movq %rdx, -0x30(%rbp)
movq %rdi, %rbx
movq 0x50(%rsi), %rax
movq %rax, -0x68(%rbp)
movl 0x4c(%rsi), %r12d
movq $0x0, -0x50(%rbp)
movq %rsi, -0x40(%rbp)
movq (%rsi), %rdx
leaq 0x4421a(%rip), %rsi     # 0x796d9
xorl %eax, %eax
callq 0x117e2
testq %rax, %rax
je 0x35547
movq %rax, %r15
movq %r13, -0x60(%rbp)
movq %rbx, %rdi
movl $0x30, %esi
callq 0x115e9
testq %rax, %rax
je 0x35552
movq %rax, %r13
movq %r14, -0x48(%rbp)
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, (%r13)
movups %xmm0, 0x20(%r13)
movups %xmm0, 0x10(%r13)
movq %rbx, (%r13)
movq -0x30(%rbp), %r8
movq %r8, 0x8(%r13)
movq -0x40(%rbp), %rdi
movq 0x68(%rdi), %rcx
testq %rcx, %rcx
movq %rbx, -0x38(%rbp)
movq %r15, -0x58(%rbp)
je 0x35560
movl 0x28(%rbx), %edx
testl %edx, %edx
jle 0x35567
movq 0x20(%rbx), %rsi
addq $0x18, %rsi
xorl %eax, %eax
cmpq %rcx, (%rsi)
je 0x35569
incq %rax
addq $0x20, %rsi
cmpq %rax, %rdx
jne 0x35532
movl %edx, %eax
jmp 0x35569
movl $0x7, %r12d
jmp 0x35699
movl $0x7, %r12d
movq %rbx, %r13
jmp 0x3568e
movl $0xfff0bdc0, %eax       # imm = 0xFFF0BDC0
jmp 0x35569
xorl %eax, %eax
movq -0x38(%rbp), %r15
movq 0x20(%r15), %rcx
cltq
shlq $0x5, %rax
movq (%rcx,%rax), %rax
movq 0x50(%rdi), %rcx
movq %rax, 0x8(%rcx)
leaq -0x78(%rbp), %rax
movq %rdi, 0x8(%rax)
movq %r14, (%rax)
movq 0x1c0(%r15), %rbx
movq %rax, 0x1c0(%r15)
movq 0x10(%r8), %rsi
addq $0x10, %r13
leaq -0x50(%rbp), %r9
movq %r15, %rdi
movl %r12d, %edx
movq -0x68(%rbp), %rcx
movq %r13, %r8
callq *-0x60(%rbp)
movq %rbx, 0x1c0(%r15)
testl %eax, %eax
je 0x35608
movl %eax, %r12d
cmpl $0x7, %eax
movq -0x38(%rbp), %r13
movq -0x58(%rbp), %r15
jne 0x355d8
movb $0x1, 0x50(%r13)
movq -0x50(%rbp), %rdx
testq %rdx, %rdx
je 0x35668
leaq 0x440ed(%rip), %rsi     # 0x796d9
movq %r13, %rdi
xorl %eax, %eax
callq 0x117e2
movq -0x48(%rbp), %rcx
movq %rax, (%rcx)
movq -0x50(%rbp), %rdi
callq 0xa2e8
jmp 0x35683
movq (%r13), %rax
xorl %r12d, %r12d
testq %rax, %rax
movq -0x58(%rbp), %r15
je 0x356ab
movq -0x30(%rbp), %rcx
movq (%rcx), %rcx
movq %rcx, (%rax)
movl $0x1, 0x18(%r14)
cmpq $0x0, -0x70(%rbp)
movq -0x38(%rbp), %r13
je 0x356b1
movq -0x40(%rbp), %rax
movq (%rax), %rdx
leaq 0x452ef(%rip), %rsi     # 0x7a936
movq %r13, %rdi
xorl %eax, %eax
callq 0x117e2
movq -0x48(%rbp), %rcx
movq %rax, (%rcx)
movq %r14, %rdi
callq 0x23229
movl $0x1, %r12d
jmp 0x3568e
leaq 0x452a9(%rip), %rsi     # 0x7a918
movq %r13, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x117e2
movq -0x48(%rbp), %rcx
movq %rax, (%rcx)
movq %r13, %rdi
movq %r14, %rsi
callq 0x9c3a
movq %r13, %rdi
movq %r15, %rsi
callq 0x9c3a
movl %r12d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x38(%rbp), %r13
jmp 0x3568e
movq -0x40(%rbp), %rsi
movq 0x58(%rsi), %rax
movq %rax, 0x28(%r14)
movq %r14, 0x58(%rsi)
cmpw $0x0, 0x42(%rsi)
jle 0x3568e
xorl %eax, %eax
leaq 0x4098f(%rip), %rdx     # 0x76060
movq 0x8(%rsi), %rcx
leaq (%rax,%rax,2), %r9
shlq $0x4, %r9
movq 0x18(%rcx,%r9), %r10
testq %r10, %r10
je 0x35871
xorl %ecx, %ecx
movq $-0x1, %r14
movl %ecx, %r11d
leal 0x1(%r11), %ecx
cmpb $0x0, 0x1(%r10,%r14)
leaq 0x1(%r14), %r14
jne 0x356f4
movl %r14d, %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movl %ecx, -0x30(%rbp)
leaq 0x6(%r10), %r13
movl $0x6, %esi
leaq 0x45242(%rip), %r8      # 0x7a965
movq %r10, %rcx
movzbl (%r8), %edi
movb (%rdi,%rdx), %dil
movzbl (%rcx), %ebx
cmpb (%rbx,%rdx), %dil
jne 0x3574e
incq %rcx
incq %r8
decq %rsi
jne 0x35726
xorl %esi, %esi
leaq 0x45220(%rip), %r8      # 0x7a96b
movq %r13, %rcx
testl %esi, %esi
jle 0x35763
movzbl (%r8), %esi
movb (%rsi,%rdx), %sil
movzbl (%rcx), %ecx
cmpb (%rcx,%rdx), %sil
jne 0x35775
movzbl (%r13), %ecx
testb $-0x21, %cl
jne 0x35775
xorl %r11d, %r11d
jmp 0x357fb
movl -0x30(%rbp), %r8d
testl %r8d, %r8d
je 0x357f0
andl $0x3fffffff, %r11d      # imm = 0x3FFFFFFF
xorl %r13d, %r13d
leaq (%r10,%r13), %rsi
leaq (%r10,%r13), %rcx
addq $0x7, %rcx
movl $0x7, %r8d
leaq 0x451c3(%rip), %rdi     # 0x7a964
movzbl (%rdi), %ebx
movb (%rbx,%rdx), %bl
movzbl (%rsi), %r12d
cmpb (%r12,%rdx), %bl
jne 0x357c9
incq %rsi
incq %rdi
decq %r8
jne 0x357a1
xorl %r8d, %r8d
leaq 0x451a5(%rip), %rdi     # 0x7a96b
movq %rcx, %rsi
testl %r8d, %r8d
jle 0x357de
movzbl (%rdi), %edi
movb (%rdi,%rdx), %dil
movzbl (%rsi), %esi
cmpb (%rsi,%rdx), %dil
jne 0x357e6
movzbl (%rcx), %ecx
testb $-0x21, %cl
je 0x357f5
incq %r13
cmpq %r11, %r13
jne 0x35788
jmp 0x357fb
xorl %r11d, %r11d
jmp 0x357ff
incl %r13d
movl %r13d, %r11d
movl -0x30(%rbp), %r8d
cmpl %r8d, %r11d
movq -0x38(%rbp), %r13
movq -0x40(%rbp), %rsi
jge 0x35871
movslq %r11d, %rcx
cmpb $0x1, 0x6(%r10,%rcx)
movl $0x7, %esi
sbbl $0x0, %esi
leal (%r11,%rsi), %edi
cmpl %r8d, %edi
jg 0x3584d
movl %esi, %esi
andl $0x3fffffff, %r14d      # imm = 0x3FFFFFFF
leaq (%r10,%rsi), %rdi
movq %rcx, %r8
movb (%rdi,%r8), %bl
movb %bl, (%r10,%r8)
leaq (%rsi,%r8), %rbx
incq %rbx
incq %r8
cmpq %r14, %rbx
jbe 0x35836
testl %r11d, %r11d
jle 0x35862
cmpb $0x0, (%r10,%rcx)
jne 0x35862
movl %r11d, %ecx
movb $0x0, -0x1(%r10,%rcx)
movq -0x40(%rbp), %rsi
movq 0x8(%rsi), %rcx
orw $0x2, 0x2a(%rcx,%r9)
incq %rax
movswq 0x42(%rsi), %rcx
xorl %r12d, %r12d
cmpq %rcx, %rax
jl 0x356d1
jmp 0x3568e