// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9StreamOpenHandle
JX9_PRIVATE void * jx9StreamOpenHandle(jx9_vm *pVm, const jx9_io_stream *pStream, const char *zFile, 
	int iFlags, int use_include, jx9_value *pResource, int bPushInclude, int *pNew)
{
	void *pHandle = 0; /* cc warning */
	SyString sFile;
	int rc;
	if( pStream == 0 ){
		/* No such stream device */
		return 0;
	}
	SyStringInitFromBuf(&sFile, zFile, SyStrlen(zFile));
	if( use_include ){
		if(	sFile.zString[0] == '/' ||
#ifdef __WINNT__
			(sFile.nByte > 2 && sFile.zString[1] == ':' && (sFile.zString[2] == '\\' || sFile.zString[2] == '/') ) ||
#endif
			(sFile.nByte > 1 && sFile.zString[0] == '.' && sFile.zString[1] == '/') ||
			(sFile.nByte > 2 && sFile.zString[0] == '.' && sFile.zString[1] == '.' && sFile.zString[2] == '/') ){
				/*  Open the file directly */
				rc = pStream->xOpen(zFile, iFlags, pResource, &pHandle);
		}else{
			SyString *pPath;
			SyBlob sWorker;
#ifdef __WINNT__
			static const int c = '\\';
#else
			static const int c = '/';
#endif
			/* Init the path builder working buffer */
			SyBlobInit(&sWorker, &pVm->sAllocator);
			/* Build a path from the set of include path */
			SySetResetCursor(&pVm->aPaths);
			rc = SXERR_IO;
			while( SXRET_OK == SySetGetNextEntry(&pVm->aPaths, (void **)&pPath) ){
				/* Build full path */
				SyBlobFormat(&sWorker, "%z%c%z", pPath, c, &sFile);
				/* Append null terminator */
				if( SXRET_OK != SyBlobNullAppend(&sWorker) ){
					continue;
				}
				/* Try to open the file */
				rc = pStream->xOpen((const char *)SyBlobData(&sWorker), iFlags, pResource, &pHandle);
				if( rc == JX9_OK ){
					if( bPushInclude ){
						/* Mark as included */
						jx9VmPushFilePath(pVm, (const char *)SyBlobData(&sWorker), SyBlobLength(&sWorker), FALSE, pNew);
					}
					break;
				}
				/* Reset the working buffer */
				SyBlobReset(&sWorker);
				/* Check the next path */
			}
			SyBlobRelease(&sWorker);
		}
		if( rc == JX9_OK ){
			if( bPushInclude ){
				/* Mark as included */
				jx9VmPushFilePath(pVm, sFile.zString, sFile.nByte, FALSE, pNew);
			}
		}
	}else{
		/* Open the URI direcly */
		rc = pStream->xOpen(zFile, iFlags, pResource, &pHandle);
	}
	if( rc != JX9_OK ){
		/* IO error */
		return 0;
	}
	/* Return the file handle */
	return pHandle;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
andq $0x0, -0x38(%rbp)
testq %rsi, %rsi
je 0x47659
movq %r9, %r12
movl %r8d, %r14d
movq %rdx, %rbx
movq %rsi, %r13
movq %rdi, %r15
movl %ecx, -0x2c(%rbp)
movq %rdx, -0x80(%rbp)
movq %rdx, %rdi
callq 0x28e24
movl %eax, -0x78(%rbp)
testl %r14d, %r14d
je 0x47516
movq %r12, -0x50(%rbp)
movq 0x18(%rbp), %r14
movl 0x10(%rbp), %r12d
movb (%rbx), %cl
cmpb $0x2f, %cl
jne 0x4752e
leaq -0x38(%rbp), %rcx
movq %rbx, %rdi
movl -0x2c(%rbp), %esi
movq -0x50(%rbp), %rdx
callq *0x10(%r13)
movl %eax, %ebx
jmp 0x47630
leaq -0x38(%rbp), %rcx
movq %rbx, %rdi
movl -0x2c(%rbp), %esi
movq %r12, %rdx
callq *0x10(%r13)
movl %eax, %ebx
jmp 0x4764f
cmpl $0x2, %eax
setb %dl
cmpb $0x2e, %cl
setne %sil
orb %dl, %sil
jne 0x47546
cmpb $0x2f, 0x1(%rbx)
je 0x474fd
cmpb $0x2e, %cl
setne %cl
cmpl $0x3, %eax
setb %al
orb %cl, %al
jne 0x47562
cmpb $0x2e, 0x1(%rbx)
jne 0x47562
cmpb $0x2f, 0x2(%rbx)
je 0x474fd
movq %r13, -0x88(%rbp)
xorps %xmm0, %xmm0
leaq -0x70(%rbp), %rbx
movups %xmm0, 0x8(%rbx)
movq %r15, (%rbx)
andl $0x0, 0x18(%rbx)
andl $0x0, 0x42c(%r15)
movq %r15, -0x48(%rbp)
leaq 0x410(%r15), %r12
pushq $-0x2
popq %rax
movl %eax, -0x3c(%rbp)
leaq -0x90(%rbp), %r13
pushq $0x2f
popq %r15
leaq -0x80(%rbp), %r14
movq %r12, %rdi
movq %r13, %rsi
callq 0x3d7ff
testl %eax, %eax
jne 0x47618
movq -0x90(%rbp), %rdx
movq %rbx, %rdi
leaq 0x1ee3f(%rip), %rsi     # 0x66402
movl %r15d, %ecx
movq %r14, %r8
xorl %eax, %eax
callq 0x35d7b
movq %rbx, %rdi
callq 0x34133
testl %eax, %eax
jne 0x475a3
movq -0x68(%rbp), %rdi
movl -0x2c(%rbp), %esi
movq -0x50(%rbp), %rdx
leaq -0x38(%rbp), %rcx
movq -0x88(%rbp), %rax
callq *0x10(%rax)
movl %eax, -0x3c(%rbp)
testl %eax, %eax
je 0x4766a
andl $0x0, -0x60(%rbp)
movl -0x58(%rbp), %eax
testb $0x4, %al
je 0x475a3
andq $0x0, -0x68(%rbp)
andl $0x0, -0x5c(%rbp)
andl $-0x5, %eax
movl %eax, -0x58(%rbp)
jmp 0x475a3
movq -0x48(%rbp), %r15
movq 0x18(%rbp), %r14
movl 0x10(%rbp), %r12d
movl -0x3c(%rbp), %ebx
leaq -0x70(%rbp), %rdi
callq 0x2a72f
testl %r12d, %r12d
je 0x4764f
testl %ebx, %ebx
jne 0x4764f
movq -0x80(%rbp), %rsi
movl -0x78(%rbp), %edx
movq %r15, %rdi
xorl %ecx, %ecx
movq %r14, %r8
callq 0x3e9f3
jmp 0x47653
testl %ebx, %ebx
jne 0x47659
movq -0x38(%rbp), %rax
jmp 0x4765b
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x10(%rbp), %r12d
testl %r12d, %r12d
je 0x47693
movq -0x68(%rbp), %rsi
movl -0x60(%rbp), %edx
xorl %ebx, %ebx
movq -0x48(%rbp), %r15
movq %r15, %rdi
xorl %ecx, %ecx
movq 0x18(%rbp), %r14
movq %r14, %r8
callq 0x3e9f3
jmp 0x47627
xorl %ebx, %ebx
movq -0x48(%rbp), %r15
movq 0x18(%rbp), %r14
jmp 0x47627