// File: /workspace/github_c_makefile_star2_O1/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, 0x8a82e(%rip)     # 0x94560
jne 0xa0c5
movl $0x1, 0x8a826(%rip)     # 0x94568
xorl %ebx, %ebx
cmpl $0x0, 0x8a821(%rip)     # 0x9456c
jne 0x9e6b
cmpq $0x0, 0x8a6c7(%rip)     # 0x94420
jne 0x9d6e
leaq 0x899ee(%rip), %rsi     # 0x93750
movl $0x4, %edi
xorl %eax, %eax
callq 0x14454
xorps %xmm0, %xmm0
movups %xmm0, 0x8bfe0(%rip)    # 0x95d58
movups %xmm0, 0x8bfc9(%rip)    # 0x95d48
movups %xmm0, 0x8bfb2(%rip)    # 0x95d38
movq $0x0, 0x8bfd7(%rip) # 0x95d68
cmpl $0x0, 0x8a66c(%rip)     # 0x94404
je 0x9da5
movq $0x8, 0x8bf93(%rip) # 0x95d38
movq 0x8a78c(%rip), %rax     # 0x94538
testq %rax, %rax
setne %sil
movl 0x8a787(%rip), %edx     # 0x94540
cmpl $0x64, %edx
setge %dil
movl 0x8a77e(%rip), %ecx     # 0x94544
testl %ecx, %ecx
setg %r8b
andb %dil, %r8b
andb %sil, %r8b
cmpb $0x1, %r8b
jne 0x9e0a
movl %edx, %edx
andl $0x7ffffff8, %edx       # imm = 0x7FFFFFF8
movl %edx, 0x8a75a(%rip)     # 0x94540
movq %rax, 0x8bf73(%rip)     # 0x95d60
movl %ecx, 0x8bf75(%rip)     # 0x95d68
cmpl $0x2, %ecx
jl 0x9e1e
decl %ecx
leaq (%rax,%rdx), %rsi
movq %rsi, (%rax)
movq %rsi, %rax
decl %ecx
jne 0x9dfa
jmp 0x9e21
movq $0x0, 0x8bf43(%rip) # 0x95d58
movups %xmm0, 0x8a71c(%rip)    # 0x94538
jmp 0x9e33
movq %rax, %rsi
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8bf25(%rip)     # 0x95d58
cmpq $0x0, 0x8a70d(%rip)     # 0x94548
je 0x9e52
cmpl $0x200, 0x8a709(%rip)   # imm = 0x200
jl 0x9e52
cmpl $0x0, 0x8a704(%rip)     # 0x94554
jg 0x9e5c
xorps %xmm0, %xmm0
movups %xmm0, 0x8a6ec(%rip)    # 0x94548
movq 0x8a5f5(%rip), %rdi     # 0x94458
callq *0x8a5df(%rip)          # 0x94448
movl %eax, %ebx
testl %ebx, %ebx
jne 0x9e90
movl $0x1, 0x8a6f3(%rip)     # 0x9456c
xorl %ebx, %ebx
cmpq $0x0, 0x8a6f5(%rip)     # 0x94578
jne 0x9e90
movq $0x8, 0x8a6e8(%rip) # 0x94578
testl %ebx, %ebx
jne 0xa0c5
incl 0x8a6e2(%rip)           # 0x94580
movl 0x8a6c0(%rip), %eax     # 0x94564
xorl %ebx, %ebx
orl 0x8a6b4(%rip), %eax     # 0x94560
jne 0xa0a6
movl $0x1, 0x8a6a8(%rip)     # 0x94564
leaq 0x8bfd5(%rip), %rbx     # 0x95e98
xorl %r14d, %r14d
movl $0xb8, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x8200
leaq 0x8abe4(%rip), %r15     # 0x94ac0
leaq (%r15,%r14), %rsi
movq %rbx, %rdi
callq 0x651b1
addq $0x48, %r14
cmpq $0xee8, %r14            # imm = 0xEE8
jne 0x9edc
xorl %r14d, %r14d
leaq 0x8bab1(%rip), %r15     # 0x959b0
leaq 0x8bf92(%rip), %rbx     # 0x95e98
leaq (%r15,%r14), %rsi
movq %rbx, %rdi
callq 0x651b1
addq $0x48, %r14
cmpq $0x240, %r14            # imm = 0x240
jne 0x9f06
xorl %r14d, %r14d
leaq 0x8bcc7(%rip), %r15     # 0x95bf0
leaq 0x8bf68(%rip), %rbx     # 0x95e98
leaq (%r15,%r14), %rsi
movq %rbx, %rdi
callq 0x651b1
addq $0x48, %r14
cmpq $0xd8, %r14
jne 0x9f30
xorl %ebx, %ebx
cmpl $0x0, 0x8a61e(%rip)     # 0x94570
jne 0x9f80
cmpq $0x0, 0x8a55c(%rip)     # 0x944b8
jne 0x9f71
leaq 0x8982b(%rip), %rsi     # 0x93790
movl $0x12, %edi
xorl %eax, %eax
callq 0x14454
movq 0x8a538(%rip), %rdi     # 0x944b0
callq *0x8a53a(%rip)          # 0x944b8
movl %eax, %ebx
testl %ebx, %ebx
jne 0x9fe7
movl $0x1, 0x8a5e2(%rip)     # 0x94570
callq 0x9d1f
testl %eax, %eax
je 0x9f9b
xorl %edi, %edi
jmp 0x9fa8
movl $0xa, %edi
callq 0xa2a2
movq %rax, %rdi
testq %rdi, %rdi
je 0x9fe2
callq 0xa2e8
xorl %ebx, %ebx
leaq 0x8a5e5(%rip), %r14     # 0x945a0
xorl %r15d, %r15d
leaq (%r14,%r15), %rdi
xorl %esi, %esi
testq %r15, %r15
sete %sil
callq 0xa0d2
addq $0xa8, %r15
cmpq $0x2a0, %r15            # imm = 0x2A0
jne 0x9fbe
jmp 0x9fe7
movl $0x7, %ebx
testl %ebx, %ebx
jne 0xa09c
cmpl $0x0, 0x8bfa2(%rip)     # 0x95f98
je 0xa092
movq 0x8a545(%rip), %rax     # 0x94548
movl 0x8a54b(%rip), %edx     # 0x94554
movslq 0x8a540(%rip), %rcx     # 0x94550
andq $-0x8, %rcx
movl %ecx, 0x8bf82(%rip)     # 0x95f9c
movl %edx, 0x8bfa8(%rip)     # 0x95fc8
movl %edx, 0x8bf7a(%rip)     # 0x95fa0
movl $0xa, %esi
cmpl $0x5a, %edx
jg 0xa049
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, 0x8bf55(%rip)     # 0x95fa4
movq %rax, 0x8bf52(%rip)     # 0x95fa8
movq $0x0, 0x8bf5f(%rip) # 0x95fc0
movl $0x0, 0x8bf61(%rip)     # 0x95fcc
testl %edx, %edx
je 0xa08b
xorl %esi, %esi
movq %rsi, (%rax)
movq %rax, %rsi
addq %rcx, %rax
decl %edx
jne 0xa071
movq %rax, %rdx
subq %rcx, %rdx
movq %rdx, 0x8bf35(%rip)     # 0x95fc0
movq %rax, 0x8bf1e(%rip)     # 0x95fb0
movl $0x1, 0x8a4c4(%rip)     # 0x94560
movl $0x0, 0x8a4be(%rip)     # 0x94564
movl 0x8a4d4(%rip), %eax     # 0x94580
leal -0x1(%rax), %ecx
movl %ecx, 0x8a4cb(%rip)     # 0x94580
cmpl $0x1, %eax
jg 0xa0c5
movq $0x0, 0x8a4b3(%rip) # 0x94578
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq