// File: /workspace/github_c_makefile_star2_O3/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, -0x30(%rbp)
testq %rsi, %rsi
je 0x51fb6
movl %ecx, %r11d
movq %rsi, %r10
movq %rdi, %rbx
movq 0x18(%rbp), %r14
movl 0x10(%rbp), %r15d
movq %rdx, -0x68(%rbp)
movb (%rdx), %al
testb %al, %al
je 0x51e24
leaq 0x2(%rdx), %rcx
cmpb $0x0, -0x1(%rcx)
je 0x51f4d
cmpb $0x0, (%rcx)
je 0x51f55
cmpb $0x0, 0x1(%rcx)
je 0x51f52
leaq 0x4(%rcx), %rsi
cmpb $0x0, 0x2(%rcx)
movq %rsi, %rcx
jne 0x51dee
addq $-0x2, %rsi
movq %rsi, %rcx
jmp 0x51f55
movl $0x0, -0x60(%rbp)
testl %r8d, %r8d
je 0x51f97
movl %r11d, -0x38(%rbp)
movq %r9, -0x70(%rbp)
movq %r10, -0x78(%rbp)
xorps %xmm0, %xmm0
leaq -0x58(%rbp), %r12
movups %xmm0, 0x8(%r12)
movq %rbx, (%r12)
xorl %eax, %eax
movl %eax, 0x18(%r12)
movl %eax, 0x42c(%rbx)
movl $0xfffffffe, -0x34(%rbp) # imm = 0xFFFFFFFE
leaq -0x68(%rbp), %r15
leaq 0x20d60(%rip), %r14     # 0x72bd0
movl 0x42c(%rbx), %eax
cmpl 0x420(%rbx), %eax
jae 0x51f1c
movl 0x428(%rbx), %edx
imull %eax, %edx
addq 0x418(%rbx), %rdx
incl %eax
movl %eax, 0x42c(%rbx)
movq %r12, %rdi
leaq 0x2457e(%rip), %rsi     # 0x76422
movl $0x2f, %ecx
movq %r15, %r8
xorl %eax, %eax
callq 0x3e26d
movl -0x48(%rbp), %r13d
movq %r12, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0x359ad
testl %eax, %eax
jne 0x51e70
movl %r13d, -0x48(%rbp)
movq -0x50(%rbp), %rdi
movl -0x38(%rbp), %esi
movq -0x70(%rbp), %rdx
leaq -0x30(%rbp), %rcx
movq -0x78(%rbp), %rax
callq *0x10(%rax)
testl %eax, %eax
je 0x52000
movl %eax, -0x34(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x40(%rbp), %eax
testb $0x4, %al
je 0x51e70
movq $0x0, -0x50(%rbp)
movl $0x0, -0x44(%rbp)
andl $-0x5, %eax
movl %eax, -0x40(%rbp)
jmp 0x51e70
movl $0x0, 0x42c(%rbx)
movq 0x18(%rbp), %r14
movl 0x10(%rbp), %r15d
movl -0x34(%rbp), %r12d
testb $0x6, -0x40(%rbp)
jne 0x51f77
cmpl $0x0, -0x44(%rbp)
je 0x51f77
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x3490d
jmp 0x51f77
decq %rcx
jmp 0x51f55
incq %rcx
subl %edx, %ecx
movl %ecx, -0x60(%rbp)
testl %r8d, %r8d
je 0x51f97
cmpb $0x2f, %al
jne 0x51fc7
leaq -0x30(%rbp), %rcx
movq %rdx, %rdi
movl %r11d, %esi
movq %r9, %rdx
callq *0x10(%r10)
movl %eax, %r12d
testl %r15d, %r15d
je 0x51fab
testl %r12d, %r12d
jne 0x51fab
movq -0x68(%rbp), %rsi
movl -0x60(%rbp), %edx
movq %rbx, %rdi
xorl %ecx, %ecx
movq %r14, %r8
callq 0x47ec3
jmp 0x51fb0
leaq -0x30(%rbp), %rcx
movq %rdx, %rdi
movl %r11d, %esi
movq %r9, %rdx
callq *0x10(%r10)
movl %eax, %r12d
testl %r12d, %r12d
jne 0x51fb6
movq -0x30(%rbp), %rax
jmp 0x51fb8
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x2e, %al
jne 0x51fd6
cmpl $0x2, %ecx
jb 0x51fd6
cmpb $0x2f, 0x1(%rdx)
je 0x51f63
cmpb $0x2e, %al
jne 0x51e34
cmpl $0x3, %ecx
jb 0x51e34
cmpb $0x2e, 0x1(%rdx)
jne 0x51e34
cmpb $0x2f, 0x2(%rdx)
jne 0x51e34
jmp 0x51f63
movl 0x10(%rbp), %r15d
testl %r15d, %r15d
je 0x52029
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 0x47ec3
jmp 0x51f32
xorl %r12d, %r12d
movq 0x18(%rbp), %r14
jmp 0x51f32