// File: /workspace/github_c_makefile_star2_O3/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
movl %edx, %eax
movq %rax, -0x50(%rbp)
addq %rsi, %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x2c(%rbp)
movq $-0x4, %rax
movl $0x0, 0x4(%rdi,%rax)
addq $0x4, %rax
cmpq $0x8c, %rax
jb 0x46f0c
movq %rsi, -0x38(%rbp)
movq %rsi, 0x80(%rdi)
movq %rdi, -0x40(%rbp)
movl %edx, 0x88(%rdi)
movq %rdx, -0x60(%rbp)
testl %edx, %edx
je 0x46fc3
movq -0x60(%rbp), %rax
leal -0x1(%rax), %r13d
movq -0x38(%rbp), %r15
movsbq (%r15), %rbx
cmpq $-0x41, %rbx
ja 0x46f87
callq 0xc170
movq (%rax), %rax
testb $0x20, 0x1(%rax,%rbx,2)
je 0x46f87
movq -0x40(%rbp), %rax
movl %r13d, 0x88(%rax)
incq %r15
movq %r15, 0x80(%rax)
decq -0x50(%rbp)
addl $-0x1, %r13d
jb 0x46f4d
jmp 0x46fc3
xorl %ebx, %ebx
movq -0x50(%rbp), %r12
movl %r13d, %eax
movsbq (%r15,%rax), %r14
cmpq $-0x41, %r14
ja 0x46fc3
callq 0xc170
movq (%rax), %rax
testb $0x20, 0x1(%rax,%r14,2)
je 0x46fc3
decq %r12
movq -0x40(%rbp), %rax
movl %r12d, 0x88(%rax)
incl %ebx
decl %r13d
cmpl %ebx, -0x50(%rbp)
jne 0x46f8d
leaq -0x2c(%rbp), %rcx
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
movq -0x60(%rbp), %rsi
movl $0x2f, %edx
callq 0x47327
movl %eax, %r12d
testl %eax, %eax
je 0x47021
movq -0x48(%rbp), %rbx
movq %rbx, %r13
movq -0x40(%rbp), %r14
movl %r12d, -0x40(%rbp)
movq %r13, %r12
movq -0x38(%rbp), %rdi
subl %edi, %r13d
leaq -0x2c(%rbp), %rcx
movl %r13d, %esi
movl $0x40, %edx
callq 0x47327
testl %eax, %eax
je 0x470b7
movq %r12, %r15
movq -0x38(%rbp), %r13
jmp 0x47126
movl -0x2c(%rbp), %r15d
leaq (%rbx,%r15), %r13
testq %r15, %r15
movq -0x40(%rbp), %r14
movq -0x48(%rbp), %rbx
je 0x4710c
cmpb $0x3a, -0x1(%r13)
jne 0x47277
movq -0x38(%rbp), %rax
movq %rax, 0x50(%r14)
movl %r15d, %eax
decl %eax
movl %eax, 0x58(%r14)
je 0x47094
movq -0x38(%rbp), %rax
leaq 0x1(%rax), %rbx
addl $-0x2, %r15d
movsbq -0x1(%rbx), %r14
cmpq $-0x41, %r14
ja 0x47094
callq 0xc170
movq (%rax), %rax
testb $0x20, 0x1(%rax,%r14,2)
je 0x47094
movq -0x40(%rbp), %rax
movl %r15d, 0x58(%rax)
movq %rbx, 0x50(%rax)
incq %rbx
addl $-0x1, %r15d
jb 0x47064
cmpb $0x2f, 0x1(%r13)
movq -0x40(%rbp), %r14
movq -0x48(%rbp), %rbx
je 0x47282
cmpb $0x3a, -0x1(%r13)
jne 0x46fee
jmp 0x47215
movl -0x2c(%rbp), %r15d
testl %r15d, %r15d
je 0x4711c
movq -0x38(%rbp), %rdi
movq %rdi, 0x60(%r14)
movl %r15d, 0x68(%r14)
leaq -0x54(%rbp), %rcx
movl %r13d, %esi
movq %rdi, %r13
movl $0x3a, %edx
callq 0x47327
testl %eax, %eax
jne 0x47104
movl -0x54(%rbp), %eax
cmpl %r15d, %eax
jae 0x47104
movl %eax, 0x68(%r14)
leaq (%rax,%r13), %rcx
incq %rcx
movq %rcx, 0x70(%r14)
notl %eax
addl %r15d, %eax
movl %eax, 0x78(%r14)
incl %r15d
addq %r15, %r13
jmp 0x47123
cmpb $0x2f, 0x1(%r13)
jne 0x47215
jmp 0x47282
movq -0x38(%rbp), %r13
incq %r13
movq %r12, %r15
cmpq %r15, %r13
jae 0x47150
callq 0xc170
movq (%rax), %rax
movq %r15, %rcx
subq %r13, %rcx
movsbq (%r13), %rdx
testb $0x20, 0x1(%rax,%rdx,2)
je 0x47150
incq %r13
decq %rcx
jne 0x47139
movq %r15, %r13
movq %r13, (%r14)
movl %r15d, %esi
subl %r13d, %esi
movl %esi, 0x8(%r14)
cmpb $0x5b, (%r13)
jne 0x471a1
leaq 0x1(%r13), %rax
movq %rax, (%r14)
movq %r13, -0x38(%rbp)
addq $0x2, %r13
xorl %r15d, %r15d
movl %r15d, 0x8(%r14)
movsbq -0x1(%r13), %rbx
cmpq $-0x41, %rbx
ja 0x47194
callq 0xc170
movq (%rax), %rax
testb $0x10, 0x1(%rax,%rbx,2)
jne 0x47199
cmpb $0x3a, %bl
jne 0x471bf
incl %r15d
incq %r13
jmp 0x47176
leaq -0x2c(%rbp), %rcx
movq %r13, %rdi
movl $0x3a, %edx
callq 0x47327
testl %eax, %eax
jne 0x47205
movl -0x2c(%rbp), %eax
movl %eax, 0x8(%r14)
jmp 0x471f3
movzbl %bl, %eax
cmpl $0x5d, %eax
jne 0x4726c
movl %r12d, %esi
subl -0x38(%rbp), %esi
subl %r15d, %esi
addl $-0x2, %esi
leaq -0x2c(%rbp), %rcx
movq %r13, %rdi
movl $0x3a, %edx
callq 0x47327
testl %eax, %eax
movq -0x48(%rbp), %rbx
jne 0x47205
movl -0x2c(%rbp), %eax
incl %eax
addq %r13, %rax
movq %rax, 0x10(%r14)
movl %r12d, %ecx
subl %eax, %ecx
movl %ecx, 0x18(%r14)
xorl %r15d, %r15d
cmpl $0x0, -0x40(%rbp)
movq %r12, %r13
jne 0x47303
movq %r13, 0x20(%r14)
xorl %r15d, %r15d
movl %ebx, %r12d
subl %r13d, %r12d
movl %r12d, 0x28(%r14)
je 0x47303
leaq -0x2c(%rbp), %rcx
movq %r13, %rdi
movl %r12d, %esi
movl $0x3f, %edx
callq 0x47327
leaq -0x2c(%rbp), %rcx
testl %eax, %eax
je 0x472ac
movq %r13, %rdi
movl %r12d, %esi
movl $0x23, %edx
callq 0x47327
testl %eax, %eax
jne 0x47303
movl -0x2c(%rbp), %eax
movl %eax, 0x28(%r14)
jmp 0x472f0
movl $0xffffffe8, %r15d      # imm = 0xFFFFFFE8
jmp 0x47303
cmpb $0x2f, 0x1(%r13)
jne 0x46fee
addq $0x2, %r13
movl %ebx, %esi
subl %r13d, %esi
leaq -0x2c(%rbp), %rcx
movq %r13, %rdi
movl $0x2f, %edx
callq 0x47327
testl %eax, %eax
je 0x47315
movq %r13, -0x38(%rbp)
movq %rbx, %r13
jmp 0x46fee
movl (%rcx), %eax
movl %eax, 0x28(%r14)
incl %eax
addq %r13, %rax
movq %rax, 0x30(%r14)
movl %ebx, %edx
subl %eax, %edx
movl %edx, 0x38(%r14)
movq %r13, %rdi
movl %r12d, %esi
movl $0x23, %edx
callq 0x47327
testl %eax, %eax
jne 0x47303
movl -0x2c(%rbp), %eax
leaq (%rax,%r13), %rcx
movl $0xfffffff4, %r15d      # imm = 0xFFFFFFF4
cmpq 0x30(%r14), %rcx
jb 0x47303
subl %ebx, %ecx
addl %ecx, 0x38(%r14)
incl %eax
addq %rax, %r13
movq %r13, 0x40(%r14)
subl %r13d, %ebx
movl %ebx, 0x48(%r14)
xorl %r15d, %r15d
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl -0x2c(%rbp), %eax
addq %r13, %rax
movq %r13, -0x38(%rbp)
movq %rax, %r13
jmp 0x46fee