// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movq %rsi, %r15
movq %rdi, %rbx
movl %edx, %eax
addq %rsi, %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x2c(%rbp)
movq $-0x4, %rax
movl $0x0, 0x4(%rbx,%rax)
addq $0x4, %rax
cmpq $0x8c, %rax
jb 0x47fb7
movq %r15, 0x80(%rbx)
movl %edx, 0x88(%rbx)
movq %rdx, -0x38(%rbp)
testl %edx, %edx
je 0x48025
movq 0x80(%rbx), %r12
incq %r12
movq -0x38(%rbp), %rax
leal -0x1(%rax), %r13d
movsbq -0x1(%r12), %r14
cmpq $-0x41, %r14
ja 0x48025
callq 0xc170
movq (%rax), %rax
testb $0x20, 0x1(%rax,%r14,2)
je 0x48025
movl %r13d, 0x88(%rbx)
movq %r12, 0x80(%rbx)
incq %r12
addl $-0x1, %r13d
jb 0x47ff2
movl 0x88(%rbx), %r12d
testq %r12, %r12
je 0x48066
movq 0x80(%rbx), %r13
decq %r12
movl %r12d, %eax
movsbq (%r13,%rax), %r14
cmpq $-0x41, %r14
ja 0x48066
callq 0xc170
movq (%rax), %rax
testb $0x20, 0x1(%rax,%r14,2)
je 0x48066
movl %r12d, 0x88(%rbx)
testl %r12d, %r12d
jne 0x48038
leaq -0x2c(%rbp), %rcx
movq %r15, %rdi
movq -0x38(%rbp), %rsi
movl $0x2f, %edx
callq 0x4838e
movl %eax, -0x38(%rbp)
testl %eax, %eax
je 0x48101
movq -0x40(%rbp), %r12
movl %r12d, %r13d
subl %r15d, %r13d
leaq -0x2c(%rbp), %rcx
movq %r15, %rdi
movl %r13d, %esi
movl $0x40, %edx
callq 0x4838e
testl %eax, %eax
jne 0x481c9
movq %r12, %r14
movl -0x2c(%rbp), %r12d
testl %r12d, %r12d
je 0x481c3
movq %r15, 0x60(%rbx)
movl %r12d, 0x68(%rbx)
leaq -0x54(%rbp), %rcx
movq %r15, %rdi
movl %r13d, %esi
movl $0x3a, %edx
callq 0x4838e
testl %eax, %eax
jne 0x480f6
movl -0x54(%rbp), %eax
cmpl %r12d, %eax
jae 0x480f6
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
jmp 0x481c6
movl -0x2c(%rbp), %ecx
leaq (%r15,%rcx), %rax
movq %rax, -0x48(%rbp)
movq %rcx, -0x50(%rbp)
testq %rcx, %rcx
je 0x4816a
movq -0x48(%rbp), %rax
cmpb $0x3a, -0x1(%rax)
jne 0x4816a
movq %r15, 0x50(%rbx)
movq -0x50(%rbp), %rax
decl %eax
movl %eax, 0x58(%rbx)
je 0x4816a
movq 0x50(%rbx), %r12
incq %r12
movq -0x50(%rbp), %rax
leal -0x2(%rax), %r13d
movsbq -0x1(%r12), %r14
cmpq $-0x41, %r14
ja 0x4816a
callq 0xc170
movq (%rax), %rax
testb $0x20, 0x1(%rax,%r14,2)
je 0x4816a
movl %r13d, 0x58(%rbx)
movq %r12, 0x50(%rbx)
incq %r12
addl $-0x1, %r13d
jb 0x4813d
movq -0x48(%rbp), %r12
cmpb $0x2f, 0x1(%r12)
jne 0x481a8
addq $0x2, %r12
movq -0x40(%rbp), %r14
movl %r14d, %esi
subl %r12d, %esi
leaq -0x2c(%rbp), %rcx
movq %r12, %rdi
movl $0x2f, %edx
callq 0x4838e
testl %eax, %eax
je 0x48338
movq %r12, %r15
movq %r14, %r12
jmp 0x48086
cmpl $0x0, -0x50(%rbp)
je 0x482a6
cmpb $0x3a, -0x1(%r12)
jne 0x48086
jmp 0x482a6
incq %r15
movq %r14, %r12
cmpq %r12, %r15
jae 0x481f2
callq 0xc170
movq (%rax), %rax
movq %r12, %rcx
subq %r15, %rcx
movsbq (%r15), %rdx
testb $0x20, 0x1(%rax,%rdx,2)
je 0x481f2
incq %r15
decq %rcx
jne 0x481dc
movq %r12, %r15
movq %r15, (%rbx)
movl %r12d, %eax
subl %r15d, %eax
movl %eax, 0x8(%rbx)
movb (%r15), %r14b
cmpb $0x5b, %r14b
jne 0x4825d
movb %r14b, -0x48(%rbp)
movq %r12, %r14
leaq 0x1(%r15), %rax
movq %rax, (%rbx)
addq $0x2, %r15
xorl %r12d, %r12d
movl %r12d, 0x8(%rbx)
movsbq -0x1(%r15), %r13
cmpq $-0x41, %r13
ja 0x4823b
callq 0xc170
movq (%rax), %rax
testb $0x10, 0x1(%rax,%r13,2)
jne 0x48241
cmpb $0x3a, %r13b
jne 0x48249
incl %r12d
incq %r15
jmp 0x4821c
movzbl %r13b, %eax
cmpl $0x5d, %eax
jne 0x48330
movq %r14, %r12
movb -0x48(%rbp), %r14b
movl %r12d, %esi
subl %r15d, %esi
leaq -0x2c(%rbp), %rcx
movq %r15, %rdi
movl $0x3a, %edx
callq 0x4838e
testl %eax, %eax
jne 0x48299
cmpb $0x5b, %r14b
je 0x48284
movl -0x2c(%rbp), %eax
movl %eax, 0x8(%rbx)
movl -0x2c(%rbp), %eax
incl %eax
addq %rax, %r15
movq %r15, 0x10(%rbx)
movl %r12d, %eax
subl %r15d, %eax
movl %eax, 0x18(%rbx)
xorl %r15d, %r15d
cmpl $0x0, -0x38(%rbp)
jne 0x4837c
movq %r12, 0x20(%rbx)
xorl %r15d, %r15d
movq %r12, %r14
movq -0x40(%rbp), %rax
movl %eax, %r12d
subl %r14d, %r12d
movl %r12d, 0x28(%rbx)
je 0x4837c
leaq -0x2c(%rbp), %rcx
movq %r14, %rdi
movl %r12d, %esi
movl $0x3f, %edx
callq 0x4838e
movl %eax, %r13d
movl $0x20, %eax
testl %r13d, %r13d
jne 0x48302
movl -0x2c(%rbp), %eax
movl %eax, 0x28(%rbx)
incl %eax
addq %r14, %rax
movq %rax, 0x30(%rbx)
movq -0x40(%rbp), %rcx
subl %eax, %ecx
movl %ecx, 0x38(%rbx)
movl $0x30, %eax
movq %rax, -0x38(%rbp)
leaq -0x2c(%rbp), %rcx
movq %r14, %rdi
movl %r12d, %esi
movl $0x23, %edx
callq 0x4838e
testl %eax, %eax
jne 0x4837c
movl -0x2c(%rbp), %eax
testl %r13d, %r13d
je 0x48349
movq -0x38(%rbp), %rcx
movl %eax, 0x8(%rbx,%rcx)
jmp 0x48363
movl $0xffffffe8, %r15d      # imm = 0xFFFFFFE8
jmp 0x4837c
movl -0x2c(%rbp), %eax
addq %r12, %rax
movq %r12, %r15
movq %rax, %r12
jmp 0x48086
addq %r14, %rax
movl $0xfffffff4, %r15d      # imm = 0xFFFFFFF4
movq -0x38(%rbp), %rdx
cmpq (%rbx,%rdx), %rax
jb 0x4837c
subl -0x40(%rbp), %eax
addl %eax, 0x8(%rbx,%rdx)
movl -0x2c(%rbp), %eax
incl %eax
addq %rax, %r14
movq %r14, 0x40(%rbx)
movq -0x40(%rbp), %rax
subl %r14d, %eax
movl %eax, 0x48(%rbx)
xorl %r15d, %r15d
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq