// File: /workspace/github_c_makefile_star2_O3/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3_initialize
SQLITE_API int sqlite3_initialize(void){
  MUTEX_LOGIC( sqlite3_mutex *pMaster; )       /* The main static mutex */
  int rc;                                      /* Result code */
#ifdef SQLITE_EXTRA_INIT
  int bRunExtraInit = 0;                       /* Extra initialization needed */
#endif

#ifdef SQLITE_OMIT_WSD
  rc = sqlite3_wsd_init(4096, 24);
  if( rc!=SQLITE_OK ){
    return rc;
  }
#endif

  /* If SQLite is already completely initialized, then this call
  ** to sqlite3_initialize() should be a no-op.  But the initialization
  ** must be complete.  So isInit must not be set until the very end
  ** of this routine.
  */
  if( sqlite3GlobalConfig.isInit ) return SQLITE_OK;

#ifdef SQLITE_ENABLE_SQLLOG
  {
    extern void sqlite3_init_sqllog(void);
    sqlite3_init_sqllog();
  }
#endif

  /* Make sure the mutex subsystem is initialized.  If unable to 
  ** initialize the mutex subsystem, return early with the error.
  ** If the system is so sick that we are unable to allocate a mutex,
  ** there is not much SQLite is going to be able to do.
  **
  ** The mutex subsystem must take care of serializing its own
  ** initialization.
  */
  rc = sqlite3MutexInit();
  if( rc ) return rc;

  /* Initialize the malloc() system and the recursive pInitMutex mutex.
  ** This operation is protected by the STATIC_MASTER mutex.  Note that
  ** MutexAlloc() is called for a static mutex prior to initializing the
  ** malloc subsystem - this implies that the allocation of a static
  ** mutex must not require support from the malloc subsystem.
  */
  MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
  sqlite3_mutex_enter(pMaster);
  sqlite3GlobalConfig.isMutexInit = 1;
  if( !sqlite3GlobalConfig.isMallocInit ){
    rc = sqlite3MallocInit();
  }
  if( rc==SQLITE_OK ){
    sqlite3GlobalConfig.isMallocInit = 1;
    if( !sqlite3GlobalConfig.pInitMutex ){
      sqlite3GlobalConfig.pInitMutex =
           sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
      if( sqlite3GlobalConfig.bCoreMutex && !sqlite3GlobalConfig.pInitMutex ){
        rc = SQLITE_NOMEM;
      }
    }
  }
  if( rc==SQLITE_OK ){
    sqlite3GlobalConfig.nRefInitMutex++;
  }
  sqlite3_mutex_leave(pMaster);

  /* If rc is not SQLITE_OK at this point, then either the malloc
  ** subsystem could not be initialized or the system failed to allocate
  ** the pInitMutex mutex. Return an error in either case.  */
  if( rc!=SQLITE_OK ){
    return rc;
  }

  /* Do the rest of the initialization under the recursive mutex so
  ** that we will be able to handle recursive calls into
  ** sqlite3_initialize().  The recursive calls normally come through
  ** sqlite3_os_init() when it invokes sqlite3_vfs_register(), but other
  ** recursive calls might also be possible.
  **
  ** IMPLEMENTATION-OF: R-00140-37445 SQLite automatically serializes calls
  ** to the xInit method, so the xInit method need not be threadsafe.
  **
  ** The following mutex is what serializes access to the appdef pcache xInit
  ** methods.  The sqlite3_pcache_methods.xInit() all is embedded in the
  ** call to sqlite3PcacheInitialize().
  */
  sqlite3_mutex_enter(sqlite3GlobalConfig.pInitMutex);
  if( sqlite3GlobalConfig.isInit==0 && sqlite3GlobalConfig.inProgress==0 ){
    FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions);
    sqlite3GlobalConfig.inProgress = 1;
    memset(pHash, 0, sizeof(sqlite3GlobalFunctions));
    sqlite3RegisterGlobalFunctions();
    if( sqlite3GlobalConfig.isPCacheInit==0 ){
      rc = sqlite3PcacheInitialize();
    }
    if( rc==SQLITE_OK ){
      sqlite3GlobalConfig.isPCacheInit = 1;
      rc = sqlite3OsInit();
    }
    if( rc==SQLITE_OK ){
      sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage, 
          sqlite3GlobalConfig.szPage, sqlite3GlobalConfig.nPage);
      sqlite3GlobalConfig.isInit = 1;
#ifdef SQLITE_EXTRA_INIT
      bRunExtraInit = 1;
#endif
    }
    sqlite3GlobalConfig.inProgress = 0;
  }
  sqlite3_mutex_leave(sqlite3GlobalConfig.pInitMutex);

  /* Go back under the static mutex and clean up the recursive
  ** mutex to prevent a resource leak.
  */
  sqlite3_mutex_enter(pMaster);
  sqlite3GlobalConfig.nRefInitMutex--;
  if( sqlite3GlobalConfig.nRefInitMutex<=0 ){
    assert( sqlite3GlobalConfig.nRefInitMutex==0 );
    sqlite3_mutex_free(sqlite3GlobalConfig.pInitMutex);
    sqlite3GlobalConfig.pInitMutex = 0;
  }
  sqlite3_mutex_leave(pMaster);

  /* The following is just a sanity check to make sure SQLite has
  ** been compiled correctly.  It is important to run this code, but
  ** we don't want to run it too often and soak up CPU cycles for no
  ** reason.  So we run it once during initialization.
  */
#ifndef NDEBUG
#ifndef SQLITE_OMIT_FLOATING_POINT
  /* This section of code's only "output" is via assert() statements. */
  if ( rc==SQLITE_OK ){
    u64 x = (((u64)1)<<63)-1;
    double y;
    assert(sizeof(x)==8);
    assert(sizeof(x)==sizeof(y));
    memcpy(&y, &x, 8);
    assert( sqlite3IsNaN(y) );
  }
#endif
#endif

  /* Do extra initialization steps requested by the SQLITE_EXTRA_INIT
  ** compile-time option.
  */
#ifdef SQLITE_EXTRA_INIT
  if( bRunExtraInit ){
    int SQLITE_EXTRA_INIT(const char*);
    rc = SQLITE_EXTRA_INIT(0);
  }
#endif

  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
xorl %ebx, %ebx
cmpl $0x0, 0x8a7c7(%rip)     # 0x94560
je 0x9da8
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, 0x8a7b6(%rip)     # 0x94568
cmpl $0x0, 0x8a7b3(%rip)     # 0x9456c
je 0x9ee6
movl $0x1, 0x8a7a3(%rip)     # 0x9456c
cmpq $0x0, 0x8a7a7(%rip)     # 0x94578
jne 0x9dde
movq $0x8, 0x8a79a(%rip) # 0x94578
movl 0x8a79c(%rip), %eax     # 0x94580
incl %eax
movl %eax, 0x8a794(%rip)     # 0x94580
movl 0x8a772(%rip), %ecx     # 0x94564
xorl %ebx, %ebx
orl 0x8a766(%rip), %ecx     # 0x94560
jne 0xa169
movl $0x1, 0x8a75a(%rip)     # 0x94564
leaq 0x8c087(%rip), %rbx     # 0x95e98
xorl %r14d, %r14d
movl $0xb8, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x8200
leaq 0x8ac96(%rip), %r15     # 0x94ac0
leaq (%r15,%r14), %rsi
movq %rbx, %rdi
callq 0x64ff1
addq $0x48, %r14
cmpq $0xee8, %r14            # imm = 0xEE8
jne 0x9e2a
xorl %r14d, %r14d
leaq 0x8bb63(%rip), %r15     # 0x959b0
leaq 0x8c044(%rip), %rbx     # 0x95e98
leaq (%r15,%r14), %rsi
movq %rbx, %rdi
callq 0x64ff1
addq $0x48, %r14
cmpq $0x240, %r14            # imm = 0x240
jne 0x9e54
xorl %r14d, %r14d
leaq 0x8bd79(%rip), %r15     # 0x95bf0
leaq 0x8c01a(%rip), %rbx     # 0x95e98
leaq (%r15,%r14), %rsi
movq %rbx, %rdi
callq 0x64ff1
addq $0x48, %r14
cmpq $0xd8, %r14
jne 0x9e7e
cmpl $0x0, 0x8a6d2(%rip)     # 0x94570
je 0x9fb3
movl $0x1, 0x8a6c2(%rip)     # 0x94570
callq 0x9d86
movl $0x7, %ebx
testl %eax, %eax
jne 0xa159
cmpl $0x0, 0x8a539(%rip)     # 0x94400
je 0xa04b
leaq -0x20(%rbp), %r14
movl $0xa, %edi
movq %r14, %rsi
callq 0x171f8
movq (%r14), %rdi
jmp 0xa059
cmpq $0x0, 0x8a532(%rip)     # 0x94420
jne 0x9f03
leaq 0x89859(%rip), %rsi     # 0x93750
movl $0x4, %edi
xorl %eax, %eax
callq 0x143f6
xorps %xmm0, %xmm0
movups %xmm0, 0x8be4b(%rip)    # 0x95d58
movups %xmm0, 0x8be34(%rip)    # 0x95d48
movups %xmm0, 0x8be1d(%rip)    # 0x95d38
movq $0x0, 0x8be42(%rip) # 0x95d68
cmpl $0x0, 0x8a4d7(%rip)     # 0x94404
je 0x9f3a
movq $0x8, 0x8bdfe(%rip) # 0x95d38
movq 0x8a5f7(%rip), %rax     # 0x94538
testq %rax, %rax
setne %sil
movl 0x8a5f2(%rip), %edx     # 0x94540
cmpl $0x64, %edx
setge %dil
movl 0x8a5e9(%rip), %ecx     # 0x94544
testl %ecx, %ecx
setg %r8b
andb %dil, %r8b
andb %sil, %r8b
cmpb $0x1, %r8b
jne 0x9f9f
movl %edx, %edx
andl $0x7ffffff8, %edx       # imm = 0x7FFFFFF8
movl %edx, 0x8a5c5(%rip)     # 0x94540
movq %rax, 0x8bdde(%rip)     # 0x95d60
movl %ecx, 0x8bde0(%rip)     # 0x95d68
cmpl $0x2, %ecx
jb 0x9ff1
decl %ecx
leaq (%rax,%rdx), %rsi
movq %rsi, (%rax)
movq %rsi, %rax
decl %ecx
jne 0x9f8f
jmp 0x9ff4
movq $0x0, 0x8bdae(%rip) # 0x95d58
movups %xmm0, 0x8a587(%rip)    # 0x94538
jmp 0xa006
movq 0x8a4fe(%rip), %rax     # 0x944b8
testq %rax, %rax
jne 0x9fd9
leaq 0x897ca(%rip), %rsi     # 0x93790
movl $0x12, %edi
xorl %eax, %eax
callq 0x143f6
movq 0x8a4df(%rip), %rax     # 0x944b8
movq 0x8a4d0(%rip), %rdi     # 0x944b0
callq *%rax
movl %eax, %ebx
testl %eax, %eax
jne 0xa159
jmp 0x9ea4
movq %rax, %rsi
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8bd52(%rip)     # 0x95d58
cmpq $0x0, 0x8a53a(%rip)     # 0x94548
je 0xa025
cmpl $0x200, 0x8a536(%rip)   # imm = 0x200
jl 0xa025
cmpl $0x0, 0x8a531(%rip)     # 0x94554
jg 0xa02f
xorps %xmm0, %xmm0
movups %xmm0, 0x8a519(%rip)    # 0x94548
movq 0x8a422(%rip), %rdi     # 0x94458
callq *0x8a40c(%rip)          # 0x94448
movl %eax, %ebx
testl %eax, %eax
jne 0x9d9b
jmp 0x9dbf
movl $0xa, %edi
callq *0x8a3ca(%rip)          # 0x94420
movq %rax, %rdi
testq %rdi, %rdi
je 0xa159
callq 0xa3c7
xorl %ebx, %ebx
leaq 0x8a530(%rip), %r14     # 0x945a0
leaq (%r14,%rbx), %rdi
xorl %esi, %esi
testq %rbx, %rbx
sete %sil
callq 0xa18b
addq $0xa8, %rbx
cmpq $0x2a0, %rbx            # imm = 0x2A0
jne 0xa070
cmpl $0x0, 0x8beff(%rip)     # 0x95f98
je 0xa14d
movq 0x8a4a2(%rip), %rax     # 0x94548
movl 0x8a4a8(%rip), %edx     # 0x94554
movslq 0x8a49d(%rip), %rcx     # 0x94550
andq $-0x8, %rcx
movl %ecx, 0x8bedf(%rip)     # 0x95f9c
movl %edx, 0x8bf05(%rip)     # 0x95fc8
movl %edx, 0x8bed7(%rip)     # 0x95fa0
cmpl $0x5b, %edx
jl 0xa0eb
movl $0xa, 0x8becc(%rip)     # 0x95fa4
movq %rax, 0x8bec9(%rip)     # 0x95fa8
movl $0x0, 0x8bee3(%rip)     # 0x95fcc
jmp 0xa12a
movslq %edx, %rsi
imulq $0x66666667, %rsi, %rsi # imm = 0x66666667
movq %rsi, %rdi
sarq $0x22, %rdi
shrq $0x3f, %rsi
addl %edi, %esi
incl %esi
movl %esi, 0x8be9a(%rip)     # 0x95fa4
movq %rax, 0x8be97(%rip)     # 0x95fa8
movq $0x0, 0x8bea4(%rip) # 0x95fc0
movl $0x0, 0x8bea6(%rip)     # 0x95fcc
testl %edx, %edx
je 0xa146
xorl %esi, %esi
movq %rsi, (%rax)
movq %rax, %rsi
addq %rcx, %rax
decl %edx
jne 0xa12c
movq %rax, %rdx
subq %rcx, %rdx
movq %rdx, 0x8be7a(%rip)     # 0x95fc0
movq %rax, 0x8be63(%rip)     # 0x95fb0
movl $0x1, 0x8a409(%rip)     # 0x94560
xorl %ebx, %ebx
movl $0x0, 0x8a401(%rip)     # 0x94564
movl 0x8a417(%rip), %eax     # 0x94580
leal -0x1(%rax), %ecx
movl %ecx, 0x8a40e(%rip)     # 0x94580
cmpl $0x1, %eax
jg 0x9d9b
movq $0x0, 0x8a3f2(%rip) # 0x94578
jmp 0x9d9b