// File: /workspace/github_c_makefile_star2_O1/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 $0x58, %rsp
movq $0x0, -0x38(%rbp)
testq %rsi, %rsi
je 0x5372b
movl %ecx, %r11d
movq %rsi, %r10
movq %rdi, %rbx
movq %rdx, -0x70(%rbp)
movb (%rdx), %al
movq %rdx, %rcx
testb %al, %al
je 0x53568
leaq 0x2(%rdx), %rcx
cmpb $0x0, -0x1(%rcx)
je 0x53560
cmpb $0x0, (%rcx)
je 0x53568
cmpb $0x0, 0x1(%rcx)
je 0x53565
leaq 0x4(%rcx), %rsi
cmpb $0x0, 0x2(%rcx)
movq %rsi, %rcx
jne 0x53539
addq $-0x2, %rsi
movq %rsi, %rcx
jmp 0x53568
decq %rcx
jmp 0x53568
incq %rcx
subl %edx, %ecx
movl %ecx, -0x68(%rbp)
testl %r8d, %r8d
je 0x53597
movq 0x18(%rbp), %r14
movl 0x10(%rbp), %r15d
cmpb $0x2f, %al
jne 0x535b0
leaq -0x38(%rbp), %rcx
movq %rdx, %rdi
movl %r11d, %esi
movq %r9, %rdx
callq *0x10(%r10)
movl %eax, %r12d
jmp 0x536ff
leaq -0x38(%rbp), %rcx
movq %rdx, %rdi
movl %r11d, %esi
movq %r9, %rdx
callq *0x10(%r10)
movl %eax, %r12d
jmp 0x53720
cmpb $0x2e, %al
jne 0x535bf
cmpl $0x2, %ecx
jb 0x535bf
cmpb $0x2f, 0x1(%rdx)
je 0x5357e
cmpb $0x2e, %al
jne 0x535d4
cmpl $0x3, %ecx
jb 0x535d4
cmpb $0x2e, 0x1(%rdx)
jne 0x535d4
cmpb $0x2f, 0x2(%rdx)
je 0x5357e
movl %r11d, -0x5c(%rbp)
movq %r9, -0x78(%rbp)
movq %r10, -0x80(%rbp)
leaq -0x50(%rbp), %rcx
xorps %xmm0, %xmm0
movups %xmm0, (%rcx)
movq %rbx, -0x8(%rcx)
xorl %eax, %eax
movl %eax, 0x10(%rcx)
movl %eax, 0x42c(%rbx)
movl $0xfffffffe, -0x2c(%rbp) # imm = 0xFFFFFFFE
leaq -0x58(%rbp), %r13
leaq 0x215b9(%rip), %r14     # 0x74bc4
movl 0x420(%rbx), %eax
movl 0x42c(%rbx), %ecx
xorl %edx, %edx
cmpl %eax, %ecx
jae 0x53632
movl 0x428(%rbx), %r12d
imull %ecx, %r12d
addq 0x418(%rbx), %r12
leal 0x1(%rcx), %edx
movl %edx, 0x42c(%rbx)
cmpl %eax, %ecx
jae 0x536c6
movq %r13, %rdi
leaq 0x24dcd(%rip), %rsi     # 0x78417
movq %r12, %rdx
movl $0x2f, %ecx
leaq -0x70(%rbp), %r8
xorl %eax, %eax
callq 0x3ec96
movl -0x48(%rbp), %r15d
movq %r13, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0x360ae
testl %eax, %eax
jne 0x5360b
movl %r15d, -0x48(%rbp)
movq -0x50(%rbp), %rdi
movl -0x5c(%rbp), %esi
movq -0x78(%rbp), %rdx
leaq -0x38(%rbp), %rcx
movq -0x80(%rbp), %rax
callq *0x10(%rax)
movl %eax, -0x2c(%rbp)
testl %eax, %eax
je 0x5373c
movl $0x0, -0x48(%rbp)
movl -0x40(%rbp), %eax
testb $0x4, %al
je 0x5360b
movq $0x0, -0x50(%rbp)
movl $0x0, -0x44(%rbp)
andl $-0x5, %eax
movl %eax, -0x40(%rbp)
jmp 0x5360b
movq 0x18(%rbp), %r14
movl 0x10(%rbp), %r15d
movl -0x2c(%rbp), %r12d
leaq -0x50(%rbp), %r13
testb $0x6, -0x40(%rbp)
jne 0x536ef
cmpl $0x0, -0x44(%rbp)
je 0x536ef
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x3503f
xorps %xmm0, %xmm0
movups %xmm0, (%r13)
movl $0x0, 0x10(%r13)
testl %r15d, %r15d
je 0x53720
testl %r12d, %r12d
jne 0x53720
movq -0x70(%rbp), %rsi
movl -0x68(%rbp), %edx
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %ecx, %ecx
movq %r14, %r8
callq 0x48f38
testl %r12d, %r12d
jne 0x5372b
movq -0x38(%rbp), %rax
jmp 0x5372d
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x10(%rbp), %r15d
testl %r15d, %r15d
je 0x53765
movq -0x50(%rbp), %rsi
movl -0x48(%rbp), %edx
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %ecx, %ecx
movq 0x18(%rbp), %r14
movq %r14, %r8
callq 0x48f38
jmp 0x536d2
xorl %r12d, %r12d
movq 0x18(%rbp), %r14
jmp 0x536d2