// File: /workspace/github_c_makefile_star2_O0/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
subq $0x80, %rsp
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x8e825
movq $0x0, -0x8(%rbp)
jmp 0x8e9e2
movq -0x20(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rdi
callq 0x55d10
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0x8e9ae
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
je 0x8e89a
cmpl $0x1, -0x40(%rbp)
jbe 0x8e86e
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x8e86e
movq -0x48(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2f, %eax
je 0x8e89a
cmpl $0x2, -0x40(%rbp)
jbe 0x8e8bb
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x8e8bb
movq -0x48(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2e, %eax
jne 0x8e8bb
movq -0x48(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x2f, %eax
jne 0x8e8bb
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
movq -0x30(%rbp), %rdx
leaq -0x38(%rbp), %rcx
callq *%rax
movl %eax, -0x4c(%rbp)
jmp 0x8e988
movq -0x10(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x58bb0
movq -0x10(%rbp), %rdi
addq $0x410, %rdi            # imm = 0x410
callq 0x7bf40
movl $0xfffffffe, -0x4c(%rbp) # imm = 0xFFFFFFFE
movq -0x10(%rbp), %rdi
addq $0x410, %rdi            # imm = 0x410
leaq -0x58(%rbp), %rsi
callq 0x7bf60
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x8e97f
movq -0x58(%rbp), %rdx
leaq -0x78(%rbp), %rdi
leaq 0x35ff5(%rip), %rsi     # 0xc4903
movl $0x2f, %ecx
leaq -0x48(%rbp), %r8
movb $0x0, %al
callq 0x6e820
leaq -0x78(%rbp), %rdi
callq 0x6b880
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x8e931
jmp 0x8e8df
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x70(%rbp), %rdi
movl -0x24(%rbp), %esi
movq -0x30(%rbp), %rdx
leaq -0x38(%rbp), %rcx
callq *%rax
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jne 0x8e971
cmpl $0x0, 0x10(%rbp)
je 0x8e96f
movq -0x10(%rbp), %rdi
movq -0x70(%rbp), %rsi
movl -0x68(%rbp), %edx
movq 0x18(%rbp), %r8
xorl %ecx, %ecx
callq 0x7e030
jmp 0x8e97f
leaq -0x78(%rbp), %rdi
callq 0x65e00
jmp 0x8e8df
leaq -0x78(%rbp), %rdi
callq 0x58c00
cmpl $0x0, -0x4c(%rbp)
jne 0x8e9ac
cmpl $0x0, 0x10(%rbp)
je 0x8e9aa
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl -0x40(%rbp), %edx
movq 0x18(%rbp), %r8
xorl %ecx, %ecx
callq 0x7e030
jmp 0x8e9ac
jmp 0x8e9ca
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
movq -0x30(%rbp), %rdx
leaq -0x38(%rbp), %rcx
callq *%rax
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0x8e9da
movq $0x0, -0x8(%rbp)
jmp 0x8e9e2
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nop