// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: VmHttpSplitURI
static sxi32 VmHttpSplitURI(SyhttpUri *pOut, const char *zUri, sxu32 nLen)
 {
	 const char *zEnd = &zUri[nLen];
	 sxu8 bHostOnly = FALSE;
	 sxu8 bIPv6 = FALSE	; 
	 const char *zCur;
	 SyString *pComp;
	 sxu32 nPos = 0;
	 sxi32 rc;
	 /* Zero the structure first */
	 SyZero(pOut, sizeof(SyhttpUri));
	 /* Remove leading and trailing white spaces  */
	 SyStringInitFromBuf(&pOut->sRaw, zUri, nLen);
	 SyStringFullTrim(&pOut->sRaw);
	 /* Find the first '/' separator */
	 rc = SyByteFind(zUri, (sxu32)(zEnd - zUri), '/', &nPos);
	 if( rc != SXRET_OK ){
		 /* Assume a host name only */
		 zCur = zEnd;
		 bHostOnly = TRUE;
		 goto ProcessHost;
	 }
	 zCur = &zUri[nPos];
	 if( zUri != zCur && zCur[-1] == ':' ){
		 /* Extract a scheme:
		  * Not that we can get an invalid scheme here.
		  * Fortunately the caller can discard any URI by comparing this scheme with its 
		  * registered schemes and will report the error as soon as his comparison function
		  * fail.
		  */
	 	pComp = &pOut->sScheme;
		SyStringInitFromBuf(pComp, zUri, (sxu32)(zCur - zUri - 1));
		SyStringLeftTrim(pComp);		
	 }
	 if( zCur[1] != '/' ){
		 if( zCur == zUri || zCur[-1] == ':' ){
		  /* No authority */
		  goto PathSplit;
		}
		 /* There is something here , we will assume its an authority
		  * and someone has forgot the two prefix slashes "//", 
		  * sooner or later we will detect if we are dealing with a malicious
		  * user or not, but now assume we are dealing with an authority
		  * and let the caller handle all the validation process.
		  */
		 goto ProcessHost;
	 }	 
	 zUri = &zCur[2];
	 zCur = zEnd;
	 rc = SyByteFind(zUri, (sxu32)(zEnd - zUri), '/', &nPos);
	 if( rc == SXRET_OK ){
		 zCur = &zUri[nPos];
	 }
 ProcessHost:
	 /* Extract user information if present */
	 rc = SyByteFind(zUri, (sxu32)(zCur - zUri), '@', &nPos);
	 if( rc == SXRET_OK ){
		 if( nPos > 0 ){
			 sxu32 nPassOfft; /* Password offset */
			 pComp = &pOut->sUser;
			 SyStringInitFromBuf(pComp, zUri, nPos);
			 /* Extract the password if available */
			 rc = SyByteFind(zUri, (sxu32)(zCur - zUri), ':', &nPassOfft);
			 if( rc == SXRET_OK && nPassOfft < nPos){
				 pComp->nByte = nPassOfft;
				 pComp = &pOut->sPass;
				 pComp->zString = &zUri[nPassOfft+sizeof(char)];
				 pComp->nByte = nPos - nPassOfft - 1;
			 }
			 /* Update the cursor */
			 zUri = &zUri[nPos+1];
		 }else{
			 zUri++;
		 }
	 }
	 pComp = &pOut->sHost;
	 while( zUri < zCur && SyisSpace(zUri[0])){
		 zUri++;
	 }	
	 SyStringInitFromBuf(pComp, zUri, (sxu32)(zCur - zUri));
	 if( pComp->zString[0] == '[' ){
		 /* An IPv6 Address: Make a simple naive test
		  */
		 zUri++; pComp->zString++; pComp->nByte = 0;
		 while( ((unsigned char)zUri[0] < 0xc0 && SyisHex(zUri[0])) || zUri[0] == ':' ){
			 zUri++; pComp->nByte++;
		 }
		 if( zUri[0] != ']' ){
			 return SXERR_CORRUPT; /* Malformed IPv6 address */
		 }
		 zUri++;
		 bIPv6 = TRUE;
	 }
	 /* Extract a port number if available */
	 rc = SyByteFind(zUri, (sxu32)(zCur - zUri), ':', &nPos);
	 if( rc == SXRET_OK ){
		 if( bIPv6 == FALSE ){
			 pComp->nByte = (sxu32)(&zUri[nPos] - zUri);
		 }
		 pComp = &pOut->sPort;
		 SyStringInitFromBuf(pComp, &zUri[nPos+1], (sxu32)(zCur - &zUri[nPos+1]));	
	 }
	 if( bHostOnly == TRUE ){
		 return SXRET_OK;
	 }
PathSplit:
	 zUri = zCur;
	 pComp = &pOut->sPath;
	 SyStringInitFromBuf(pComp, zUri, (sxu32)(zEnd-zUri));
	 if( pComp->nByte == 0 ){
		 return SXRET_OK; /* Empty path */
	 }
	 if( SXRET_OK == SyByteFind(zUri, (sxu32)(zEnd-zUri), '?', &nPos) ){
		 pComp->nByte = nPos; /* Update path length */
		 pComp = &pOut->sQuery;
		 SyStringInitFromBuf(pComp, &zUri[nPos+1], (sxu32)(zEnd-&zUri[nPos+1]));
	 }
	 if( SXRET_OK == SyByteFind(zUri, (sxu32)(zEnd-zUri), '#', &nPos) ){
		 /* Update path or query length */
		 if( pComp == &pOut->sPath ){
			 pComp->nByte = nPos;
		 }else{
			 if( &zUri[nPos] < (char *)SyStringData(pComp) ){
				 /* Malformed syntax : Query must be present before fragment */
				 return SXERR_SYNTAX;
			 }
			 pComp->nByte -= (sxu32)(zEnd - &zUri[nPos]);
		 }
		 pComp = &pOut->sFragment;
		 SyStringInitFromBuf(pComp, &zUri[nPos+1], (sxu32)(zEnd-&zUri[nPos+1]))
	 }
	 return SXRET_OK;
 }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %r14d
movq %rsi, %r12
movq %rdi, %rbx
movl %edx, %r15d
leaq (%rsi,%r15), %rax
movq %rax, -0x48(%rbp)
andl $0x0, -0x2c(%rbp)
movl $0x90, %esi
callq 0x27aea
movq %r12, 0x80(%rbx)
movl %r14d, 0x88(%rbx)
movq %r14, -0x40(%rbp)
leal -0x1(%r14), %r13d
movq %r12, -0x38(%rbp)
testl %r15d, %r15d
je 0x3dc2c
movsbq (%r12), %r14
cmpq $-0x41, %r14
ja 0x3dc2c
callq 0xc190
movq (%rax), %rax
testb $0x20, 0x1(%rax,%r14,2)
je 0x3dc2c
decq %r15
movl %r15d, 0x88(%rbx)
incq %r12
movq %r12, 0x80(%rbx)
decl %r13d
jmp 0x3dbc8
movl %r13d, %r13d
movsbq (%r12,%r13), %r14
cmpq $-0x41, %r14
ja 0x3dc31
callq 0xc190
movq (%rax), %rax
testb $0x20, 0x1(%rax,%r14,2)
je 0x3dc31
decq %r15
movl %r15d, 0x88(%rbx)
decl %r13d
testq %r15, %r15
jne 0x3dc01
pushq $0x2f
popq %rdx
leaq -0x2c(%rbp), %rcx
movq -0x38(%rbp), %r12
movq %r12, %rdi
movq -0x40(%rbp), %rsi
callq 0x3df83
movl %eax, -0x40(%rbp)
testl %eax, %eax
je 0x3dcd5
movq -0x48(%rbp), %r13
movl %r13d, %r14d
subl %r12d, %r14d
pushq $0x40
popq %rdx
leaq -0x2c(%rbp), %rcx
movq %r12, %rdi
movl %r14d, %esi
callq 0x3df83
testl %eax, %eax
movq %rbx, -0x38(%rbp)
jne 0x3dd57
movq %r12, %r15
movl -0x2c(%rbp), %r12d
testl %r12d, %r12d
je 0x3dd51
movq %r15, 0x60(%rbx)
movl %r12d, 0x68(%rbx)
pushq $0x3a
popq %rdx
leaq -0x50(%rbp), %rcx
movq %r15, %rdi
movl %r14d, %esi
callq 0x3df83
testl %eax, %eax
jne 0x3dcc7
movl -0x50(%rbp), %eax
cmpl %r12d, %eax
jae 0x3dcc7
movl %eax, 0x68(%rbx)
leaq (%rax,%r15), %rcx
incq %rcx
movq %rcx, 0x70(%rbx)
notl %eax
addl %r12d, %eax
movl %eax, 0x78(%rbx)
incl %r12d
addq %r12, %r15
movq %r15, %r12
jmp 0x3dd57
movl -0x2c(%rbp), %r14d
leaq (%r12,%r14), %r13
testq %r14, %r14
movq -0x48(%rbp), %r15
je 0x3dd41
cmpb $0x3a, -0x1(%r13)
jne 0x3de95
movq %r12, 0x50(%rbx)
leal -0x1(%r14), %eax
movl %eax, 0x58(%rbx)
incq %r12
addl $-0x2, %r14d
cmpl $-0x1, %r14d
je 0x3dea2
movsbq -0x1(%r12), %r15
cmpq $-0x41, %r15
ja 0x3dea2
callq 0xc190
movq (%rax), %rax
testb $0x20, 0x1(%rax,%r15,2)
je 0x3dea2
movl %r14d, 0x58(%rbx)
movq %r12, 0x50(%rbx)
incq %r12
decl %r14d
jmp 0x3dd03
cmpb $0x2f, 0x1(%r13)
jne 0x3de58
jmp 0x3deb5
movq %r15, %r12
incq %r12
movq %r13, %rbx
movl %r13d, %r14d
movq %r12, %r15
subl %r12d, %r14d
leal -0x2(%r14), %eax
movl %eax, -0x4c(%rbp)
xorl %r12d, %r12d
leaq (%r15,%r12), %r13
cmpq %rbx, %r13
jae 0x3dd8f
callq 0xc190
movq (%rax), %rax
movsbq (%r13), %rcx
testb $0x20, 0x1(%rax,%rcx,2)
je 0x3dd8f
incq %r12
jmp 0x3dd6d
movq -0x38(%rbp), %rcx
movq %r13, (%rcx)
subq %r12, %r14
movl %r14d, 0x8(%rcx)
movb (%r15,%r12), %al
movb %al, -0x2d(%rbp)
cmpb $0x5b, %al
jne 0x3de05
movl -0x4c(%rbp), %r14d
subq %r12, %r14
leaq (%r15,%r12), %r13
addq $0x2, %r13
leaq (%r15,%r12), %rax
incq %rax
movq %rax, (%rcx)
xorl %r12d, %r12d
movq -0x38(%rbp), %rax
movl %r12d, 0x8(%rax)
movsbq -0x1(%r13), %r15
cmpq $-0x41, %r15
ja 0x3dde7
callq 0xc190
movq (%rax), %rax
testb $0x10, 0x1(%rax,%r15,2)
jne 0x3dded
cmpb $0x3a, %r15b
jne 0x3ddf8
incl %r12d
decl %r14d
incq %r13
jmp 0x3ddc4
movzbl %r15b, %eax
cmpl $0x5d, %eax
jne 0x3de8c
movq -0x48(%rbp), %r15
pushq $0x3a
popq %rdx
leaq -0x2c(%rbp), %rcx
movq %r13, %rdi
movl %r14d, %esi
callq 0x3df83
testl %eax, %eax
jne 0x3de44
movl -0x2c(%rbp), %eax
cmpb $0x5b, -0x2d(%rbp)
je 0x3de2f
movq -0x38(%rbp), %rcx
movl %eax, 0x8(%rcx)
incl %eax
addq %rax, %r13
movq -0x38(%rbp), %rcx
movq %r13, 0x10(%rcx)
movl %ebx, %eax
subl %r13d, %eax
movl %eax, 0x18(%rcx)
xorl %r14d, %r14d
cmpl $0x0, -0x40(%rbp)
movq %rbx, %r13
movq -0x38(%rbp), %rbx
jne 0x3df71
movq %r13, 0x20(%rbx)
xorl %r14d, %r14d
movl %r15d, %r12d
subl %r13d, %r12d
movl %r12d, 0x28(%rbx)
je 0x3df71
pushq $0x3f
popq %rdx
leaq -0x2c(%rbp), %rcx
movq %r13, %rdi
movl %r12d, %esi
callq 0x3df83
movl %eax, -0x38(%rbp)
testl %eax, %eax
je 0x3dedd
pushq $0x20
jmp 0x3def6
pushq $-0x18
popq %r14
jmp 0x3df71
cmpb $0x2f, 0x1(%r13)
jne 0x3dc57
jmp 0x3deb5
cmpb $0x2f, 0x1(%r13)
movq -0x48(%rbp), %r15
movq -0x38(%rbp), %r12
jne 0x3df35
addq $0x2, %r13
movl %r15d, %esi
subl %r13d, %esi
pushq $0x2f
popq %rdx
leaq -0x2c(%rbp), %rcx
movq %r13, %rdi
callq 0x3df83
testl %eax, %eax
je 0x3df24
movq %r13, %r12
movq %r15, %r13
jmp 0x3dc57
movl -0x2c(%rbp), %eax
movl %eax, 0x28(%rbx)
incl %eax
addq %r13, %rax
movq %rax, 0x30(%rbx)
movl %r15d, %ecx
subl %eax, %ecx
movl %ecx, 0x38(%rbx)
pushq $0x30
popq %rax
movq %rax, -0x40(%rbp)
pushq $0x23
popq %rdx
leaq -0x2c(%rbp), %rcx
movq %r13, %rdi
movl %r12d, %esi
callq 0x3df83
testl %eax, %eax
jne 0x3df71
movl -0x2c(%rbp), %eax
cmpl $0x0, -0x38(%rbp)
je 0x3df45
movq -0x40(%rbp), %rcx
movl %eax, 0x8(%rbx,%rcx)
jmp 0x3df61
movl -0x2c(%rbp), %eax
addq %r13, %rax
movq %r13, %r12
movq %rax, %r13
jmp 0x3dc57
cmpb $0x3a, -0x1(%r13)
jne 0x3dc57
jmp 0x3de58
leaq (%rax,%r13), %rcx
movq -0x40(%rbp), %rsi
cmpq (%rbx,%rsi), %rcx
jae 0x3df5a
pushq $-0xc
jmp 0x3de8e
subl %r15d, %ecx
addl %ecx, 0x8(%rbx,%rsi)
incl %eax
addq %rax, %r13
movq %r13, 0x40(%rbx)
subl %r13d, %r15d
movl %r15d, 0x48(%rbx)
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq