// File: /workspace/github_c_makefile_star2_O3/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
testl %edx, %edx
jle 0x51c4d
movq (%rsi), %r13
movslq %edx, %rax
addq %r13, %rax
leaq -0x3(%rax), %rcx
xorl %r14d, %r14d
leaq (%r14,%r13), %rdx
cmpq %rcx, %rdx
jae 0x51c3e
cmpb $0x3a, (%rdx)
jne 0x51c3e
cmpb $0x2f, 0x1(%r13,%r14)
jne 0x51c3e
cmpb $0x2f, 0x2(%r13,%r14)
je 0x51c66
leaq (%r14,%r13), %rdx
incq %rdx
incq %r14
cmpq %rax, %rdx
jb 0x51c20
movq 0x488(%rdi), %r9
movq %r9, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, -0x48(%rbp)
movq %rsi, -0x40(%rbp)
testl %r14d, %r14d
je 0x51cbb
leaq -0x1(%r14), %rax
movl %eax, %eax
addq %r13, %rax
incq %rax
movq %rax, -0x30(%rbp)
movl %r14d, %ebx
movq %r13, %r12
movsbq (%r12), %r15
cmpq $-0x41, %r15
ja 0x51cb3
callq 0xc170
movq (%rax), %rax
testb $0x20, 0x1(%rax,%r15,2)
je 0x51cb3
incq %r12
decl %ebx
jne 0x51c89
xorl %ebx, %ebx
movq -0x30(%rbp), %r15
jmp 0x51cb6
movq %r12, %r15
movl %ebx, %r12d
jmp 0x51cc1
xorl %r12d, %r12d
movq %r13, %r15
leaq (%r14,%r13), %rax
addq $0x3, %rax
movq %rax, -0x38(%rbp)
movl %r12d, %ebx
notl %ebx
movq %r12, %r14
subq $0x1, %r14
jb 0x51d03
movsbq -0x1(%r15,%r12), %r13
cmpq $-0x41, %r13
ja 0x51d06
callq 0xc170
movq (%rax), %rax
incl %ebx
testb $0x20, 0x1(%rax,%r13,2)
movq %r14, %r12
jne 0x51cd5
negl %ebx
movl %ebx, %r12d
jmp 0x51d06
xorl %r12d, %r12d
movq -0x48(%rbp), %rax
movl 0x470(%rax), %r14d
testq %r14, %r14
je 0x51d92
movq %r15, -0x30(%rbp)
movq 0x468(%rax), %r13
xorl %r9d, %r9d
xorl %ebx, %ebx
movq (%r13,%rbx,8), %r15
movq (%r15), %rsi
cmpb $0x0, (%rsi)
movq %rsi, %rcx
je 0x51d69
leaq 0x2(%rsi), %rcx
cmpb $0x0, -0x1(%rcx)
je 0x51d61
cmpb $0x0, (%rcx)
je 0x51d69
cmpb $0x0, 0x1(%rcx)
je 0x51d66
leaq 0x4(%rcx), %rax
cmpb $0x0, 0x2(%rcx)
movq %rax, %rcx
jne 0x51d3a
addq $-0x2, %rax
movq %rax, %rcx
jmp 0x51d69
decq %rcx
jmp 0x51d69
incq %rcx
subl %esi, %ecx
movl %r12d, %eax
subl %ecx, %eax
jne 0x51d81
movq -0x30(%rbp), %rdi
movl %r12d, %edx
callq 0x39f3f
xorl %r9d, %r9d
testl %eax, %eax
je 0x51d9a
incq %rbx
cmpq %r14, %rbx
jne 0x51d26
jmp 0x51c54
xorl %r9d, %r9d
jmp 0x51c54
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rcx, (%rax)
movq %r15, %r9
jmp 0x51c54