// File: /workspace/github_c_makefile_star2_O1/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), %r14
testl %edx, %edx
setg %al
jle 0x533bf
movslq %edx, %rcx
addq %r14, %rcx
leaq -0x3(%rcx), %rdx
movq %r14, %r13
cmpq %rdx, %r13
jae 0x533b2
cmpb $0x3a, (%r13)
jne 0x533b2
cmpb $0x2f, 0x1(%r13)
jne 0x533b2
cmpb $0x2f, 0x2(%r13)
je 0x534f4
incq %r13
cmpq %rcx, %r13
setb %al
jb 0x53394
jmp 0x533c2
movq %r14, %r13
movq %r14, %r12
testb $0x1, %al
je 0x53437
subl %r14d, %r13d
movq %r15, -0x38(%rbp)
movq %r12, -0x30(%rbp)
movq %rdi, -0x40(%rbp)
je 0x533fe
movsbq (%r14), %rbx
cmpq $-0x41, %rbx
ja 0x533fe
callq 0xc170
movq (%rax), %rax
testb $0x20, 0x1(%rax,%rbx,2)
je 0x533fe
incq %r14
decl %r13d
jne 0x533da
xorl %r13d, %r13d
movl %r13d, %r12d
notl %r13d
movq %r12, %rbx
subq $0x1, %rbx
jb 0x53443
movsbq -0x1(%r14,%r12), %r15
cmpq $-0x41, %r15
ja 0x53446
callq 0xc170
movq (%rax), %rax
incl %r13d
testb $0x20, 0x1(%rax,%r15,2)
movq %rbx, %r12
jne 0x53407
negl %r13d
movl %r13d, %r12d
jmp 0x53446
movq 0x488(%rdi), %r8
jmp 0x534e2
xorl %r12d, %r12d
movq -0x40(%rbp), %rax
movl 0x470(%rax), %edi
testq %rdi, %rdi
je 0x534d2
movq 0x468(%rax), %r13
xorl %ebx, %ebx
movq %rdi, -0x48(%rbp)
movq (%r13,%rbx,8), %r8
movq (%r8), %rsi
cmpb $0x0, (%rsi)
movq %rsi, %rdx
je 0x534a5
leaq 0x2(%rsi), %rdx
cmpb $0x0, -0x1(%rdx)
je 0x5349d
cmpb $0x0, (%rdx)
je 0x534a5
cmpb $0x0, 0x1(%rdx)
je 0x534a2
leaq 0x4(%rdx), %rax
cmpb $0x0, 0x2(%rdx)
movq %rax, %rdx
jne 0x53476
addq $-0x2, %rax
movq %rax, %rdx
jmp 0x534a5
decq %rdx
jmp 0x534a5
incq %rdx
subl %esi, %edx
movl %r12d, %eax
subl %edx, %eax
jne 0x534c6
movq %r14, %rdi
movq %r14, %r15
movq %r8, %r14
callq 0x3a837
movq %r14, %r8
movq %r15, %r14
movq -0x48(%rbp), %rdi
testl %eax, %eax
je 0x534d7
incq %rbx
cmpq %rdi, %rbx
jne 0x53462
xorl %r8d, %r8d
jmp 0x534e2
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, (%rax)
movq %r8, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3(%r13), %r12
jmp 0x533c5