// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: unqlite_open
int unqlite_open(unqlite **ppDB,const char *zFilename,unsigned int iMode)
{
	unqlite *pHandle;
	int rc;
#if defined(UNTRUST)
	if( ppDB == 0 ){
		return UNQLITE_CORRUPT;
	}
#endif
	*ppDB = 0;
	/* One-time automatic library initialization */
	rc = unqliteCoreInitialize();
	if( rc != UNQLITE_OK ){
		return rc;
	}
	/* Allocate a new database handle */
	pHandle = (unqlite *)SyMemBackendPoolAlloc(&sUnqlMPGlobal.sAllocator, sizeof(unqlite));
	if( pHandle == 0 ){
		return UNQLITE_NOMEM;
	}
	/* Zero the structure */
	SyZero(pHandle,sizeof(unqlite));
	if( iMode < 1 ){
		/* Assume a read-only database */
		iMode = UNQLITE_OPEN_READONLY|UNQLITE_OPEN_MMAP;
	}
	/* Init the database */
	rc = unqliteInitDatabase(pHandle,&sUnqlMPGlobal.sAllocator,zFilename,iMode);
	if( rc != UNQLITE_OK ){
		goto Release;
	}
#if defined(UNQLITE_ENABLE_THREADS)
	if( !(iMode & UNQLITE_OPEN_NOMUTEX) && (sUnqlMPGlobal.nThreadingLevel > UNQLITE_THREAD_LEVEL_SINGLE) ){
		 /* Associate a recursive mutex with this instance */
		 pHandle->pMutex = SyMutexNew(sUnqlMPGlobal.pMutexMethods, SXMUTEX_TYPE_RECURSIVE);
		 if( pHandle->pMutex == 0 ){
			 rc = UNQLITE_NOMEM;
			 goto Release;
		 }
	 }
#endif
	/* Link to the list of active DB handles */
#if defined(UNQLITE_ENABLE_THREADS)
	/* Enter the global mutex */
	 SyMutexEnter(sUnqlMPGlobal.pMutexMethods, sUnqlMPGlobal.pMutex); /* NO-OP if sUnqlMPGlobal.nThreadingLevel == UNQLITE_THREAD_LEVEL_SINGLE */
#endif
	 MACRO_LD_PUSH(sUnqlMPGlobal.pDB,pHandle);
	 sUnqlMPGlobal.nDB++;
#if defined(UNQLITE_ENABLE_THREADS)
	/* Leave the global mutex */
	 SyMutexLeave(sUnqlMPGlobal.pMutexMethods, sUnqlMPGlobal.pMutex); /* NO-OP if sUnqlMPGlobal.nThreadingLevel == UNQLITE_THREAD_LEVEL_SINGLE */
#endif
	/* Set the magic number to identify a valid DB handle */
	 pHandle->nMagic = UNQLITE_DB_MAGIC;
	/* Make the handle available to the caller */
	*ppDB = pHandle;
	return UNQLITE_OK;
Release:
	SyMemBackendRelease(&pHandle->sMem);
	SyMemBackendPoolFree(&sUnqlMPGlobal.sAllocator,pHandle);
	return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq $0x0, (%rax)
callq 0x53c60
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x54057
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x541de
leaq 0x9a762(%rip), %rdi     # 0xee7c0
movl $0x128, %esi            # imm = 0x128
callq 0x541f0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x5407f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x541de
movq -0x28(%rbp), %rdi
movl $0x128, %esi            # imm = 0x128
callq 0x54280
cmpl $0x1, -0x1c(%rbp)
jae 0x5409a
movl $0x101, -0x1c(%rbp)     # imm = 0x101
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rdx
movl -0x1c(%rbp), %ecx
leaq 0x9a714(%rip), %rsi     # 0xee7c0
callq 0x54330
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x540bf
jmp 0x541bf
movl -0x1c(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
jne 0x5410c
cmpl $0x1, 0x9a7b7(%rip)     # 0xee888
jbe 0x5410c
movq 0x9a79e(%rip), %rax     # 0xee878
movl $0x2, %edi
callq *0x10(%rax)
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0xf8(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0xf8(%rax)
jne 0x5410a
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
jmp 0x541bf
jmp 0x5410c
cmpq $0x0, 0x9a76c(%rip)     # 0xee880
je 0x5412a
movq 0x9a75b(%rip), %rax     # 0xee878
movq 0x20(%rax), %rax
movq 0x9a758(%rip), %rdi     # 0xee880
callq *%rax
cmpq $0x0, 0x9a79e(%rip)     # 0xee8d0
jne 0x54141
movq -0x28(%rbp), %rax
movq %rax, 0x9a791(%rip)     # 0xee8d0
jmp 0x54170
movq 0x9a788(%rip), %rcx     # 0xee8d0
movq -0x28(%rbp), %rax
movq %rcx, 0x110(%rax)
movq -0x28(%rbp), %rcx
movq 0x9a772(%rip), %rax     # 0xee8d0
movq %rcx, 0x118(%rax)
movq -0x28(%rbp), %rax
movq %rax, 0x9a760(%rip)     # 0xee8d0
movl 0x9a752(%rip), %eax     # 0xee8c8
addl $0x1, %eax
movl %eax, 0x9a749(%rip)     # 0xee8c8
cmpq $0x0, 0x9a6f9(%rip)     # 0xee880
je 0x5419d
movq 0x9a6e8(%rip), %rax     # 0xee878
movq 0x30(%rax), %rax
movq 0x9a6e5(%rip), %rdi     # 0xee880
callq *%rax
movq -0x28(%rbp), %rax
movl $0xdb7c2712, 0x120(%rax) # imm = 0xDB7C2712
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x541de
movq -0x28(%rbp), %rdi
callq 0x543e0
movq -0x28(%rbp), %rsi
leaq 0x9a5ed(%rip), %rdi     # 0xee7c0
callq 0x54490
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)