// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9VmGetStreamDevice
JX9_PRIVATE const jx9_io_stream * jx9VmGetStreamDevice(
	jx9_vm *pVm,           /* Target VM */
	const char **pzDevice, /* Full path, URI, ... */
	int nByte              /* *pzDevice length*/
	)
{
	const char *zIn, *zEnd, *zCur, *zNext;
	jx9_io_stream **apStream, *pStream;
	SyString sDev, sCur;
	sxu32 n, nEntry;
	int rc;
	/* Check if a scheme [i.e: file://, http://, zip://...] is available */
	zNext = zCur = zIn = *pzDevice;
	zEnd = &zIn[nByte];
	while( zIn < zEnd ){
		if( zIn < &zEnd[-3]/*://*/ && zIn[0] == ':' && zIn[1] == '/' && zIn[2] == '/' ){
			/* Got one */
			zNext = &zIn[sizeof("://")-1];
			break;
		}
		/* Advance the cursor */
		zIn++;
	}
	if( zIn >= zEnd ){
		/* No such scheme, return the default stream */
		return pVm->pDefStream;
	}
	SyStringInitFromBuf(&sDev, zCur, zIn-zCur);
	/* Remove leading and trailing white spaces */
	SyStringFullTrim(&sDev);
	/* Perform a linear lookup on the installed stream devices */
	apStream = (jx9_io_stream **)SySetBasePtr(&pVm->aIOstream);
	nEntry = SySetUsed(&pVm->aIOstream);
	for( n = 0 ; n < nEntry ; n++ ){
		pStream = apStream[n];
		SyStringInitFromBuf(&sCur, pStream->zName, SyStrlen(pStream->zName));
		/* Perfrom a case-insensitive comparison */
		rc = SyStringCmp(&sDev, &sCur, SyStrnicmp);
		if( rc == 0 ){
			/* Stream device found */
			*pzDevice = zNext;
			return pStream;
		}
	}
	/* No such stream, return NULL */
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r15
movq (%rsi), %r13
movslq %edx, %rax
leaq (%rax,%r13), %rcx
leaq (%rax,%r13), %rdx
addq $-0x3, %rdx
xorl %eax, %eax
movq %r13, %rbx
cmpq %rcx, %rbx
jae 0x473a1
cmpq %rdx, %rbx
jae 0x4739a
cmpb $0x3a, (%rbx)
jne 0x4739a
cmpb $0x2f, 0x1(%rbx)
jne 0x4739a
cmpb $0x2f, 0x2(%rbx)
je 0x473ba
incq %rbx
incl %eax
jmp 0x4737f
movq 0x488(%rdi), %r14
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, -0x38(%rbp)
addq $0x3, %rbx
movl %eax, %r12d
leaq (%r12,%r13), %rax
movq %rax, -0x30(%rbp)
movq %r15, -0x40(%rbp)
testl %r12d, %r12d
je 0x473fd
movsbq (%r13), %r14
cmpq $-0x41, %r14
ja 0x473f9
callq 0xc190
movq (%rax), %rax
testb $0x20, 0x1(%rax,%r14,2)
je 0x473f9
incq %r13
decq %r12
jmp 0x473d1
movq %r13, -0x30(%rbp)
movl %r12d, %r15d
notl %r15d
movq %r12, %r13
subq $0x1, %r13
jb 0x4743a
movq -0x30(%rbp), %rax
movsbq -0x1(%rax,%r12), %r14
cmpq $-0x41, %r14
ja 0x4743d
callq 0xc190
movq (%rax), %rax
incl %r15d
testb $0x20, 0x1(%rax,%r14,2)
movq %r13, %r12
jne 0x47406
negl %r15d
movl %r15d, %r12d
jmp 0x4743d
xorl %r12d, %r12d
movq -0x38(%rbp), %rax
movq 0x468(%rax), %rcx
movq %rcx, -0x48(%rbp)
movl 0x470(%rax), %eax
movq %rax, -0x38(%rbp)
xorl %r15d, %r15d
cmpq %r15, -0x38(%rbp)
je 0x4749d
movq -0x48(%rbp), %rax
movq (%rax,%r15,8), %r14
movq (%r14), %r13
movq %r13, %rdi
callq 0x28e24
movl %eax, %ecx
movl %r12d, %eax
subl %ecx, %eax
jne 0x4748a
movq -0x30(%rbp), %rdi
movq %r13, %rsi
movl %r12d, %edx
callq 0x32436
incq %r15
testl %eax, %eax
jne 0x47459
movq -0x40(%rbp), %rax
movq %rbx, (%rax)
jmp 0x473a8
xorl %r14d, %r14d
jmp 0x473a8