// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: SyUriDecode
JX9_PRIVATE sxi32 SyUriDecode(const char *zSrc, sxu32 nLen, ProcConsumer xConsumer, void *pUserData, int bUTF8)
{
	static const sxu8 Utf8Trans[] = {
		0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
		0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
		0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 
		0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 
		0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
		0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
		0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
		0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00
	};
	const char *zIn = zSrc;
	const char *zEnd;
	const char *zCur;
	sxu8 *zOutPtr;
	sxu8 zOut[10];
	sxi32 c, d;
	sxi32 rc;
#if defined(UNTRUST)
	if( SX_EMPTY_STR(zSrc) || xConsumer == 0 ){
		return SXERR_EMPTY;
	}
#endif
	rc = SXRET_OK;
	zEnd = &zSrc[nLen];
	zCur = zIn;
	for(;;){
		while(zCur < zEnd && zCur[0] != '%' && zCur[0] != '+' ){
			zCur++;
		}
		if( zCur != zIn ){
			/* Consume input */
			rc = xConsumer(zIn, (unsigned int)(zCur-zIn), pUserData);
			if( rc != SXRET_OK ){
				/* User consumer routine request an operation abort */
				break;
			}
		}
		if( zCur >= zEnd ){
			rc = SXRET_OK;
			break;
		}
		/* Decode unsafe HTTP characters */
		zOutPtr = zOut;
		if( zCur[0] == '+' ){
			*zOutPtr++ = ' ';
			zCur++;
		}else{
			if( &zCur[2] >= zEnd ){
				rc = SXERR_OVERFLOW;
				break;
			}
			c = (SyAsciiToHex(zCur[1]) <<4) | SyAsciiToHex(zCur[2]);
			zCur += 3;
			if( c < 0x000C0 ){
				*zOutPtr++ = (sxu8)c;
			}else{
				c = Utf8Trans[c-0xC0];
				while( zCur[0] == '%' ){
					d = (SyAsciiToHex(zCur[1]) <<4) | SyAsciiToHex(zCur[2]);
					if( (d&0xC0) != 0x80 ){
						break;
					}
					c = (c<<6) + (0x3f & d);
					zCur += 3;
				}
				if( bUTF8 == FALSE ){
					*zOutPtr++ = (sxu8)c;
				}else{
					SX_WRITE_UTF8(zOutPtr, c);
				}
			}
			
		}
		/* Consume the decoded characters */
		rc = xConsumer((const void *)zOut, (unsigned int)(zOutPtr-zOut), pUserData);
		if( rc != SXRET_OK ){
			break;
		}
		/* Synchronize pointers */
		zIn = zCur;
	}
	return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, -0x40(%rbp)
movq %rdx, %r14
movq %rdi, %r15
movl %esi, %r12d
addq %rdi, %r12
xorl %r13d, %r13d
leaq (%r15,%r13), %rbx
cmpq %r12, %rbx
jae 0x3e03f
movzbl (%rbx), %eax
cmpl $0x25, %eax
je 0x3e030
cmpl $0x2b, %eax
je 0x3e030
incq %r13
jmp 0x3e015
testq %r13, %r13
jne 0x3e048
cmpq %r12, %rbx
jb 0x3e066
jmp 0x3e1ae
testq %r13, %r13
je 0x3e1ae
movq %r15, %rdi
movl %r13d, %esi
movq -0x40(%rbp), %rdx
callq *%r14
cmpq %r12, %rbx
jae 0x3e1ae
testl %eax, %eax
jne 0x3e1ae
cmpb $0x2b, (%r15,%r13)
jne 0x3e07c
movb $0x20, -0x32(%rbp)
addq %r13, %r15
incq %r15
jmp 0x3e110
leaq (%r15,%r13), %rax
addq $0x2, %rax
cmpq %r12, %rax
jae 0x3e1ae
addq %r13, %r15
addq $0x3, %r15
movsbl -0x2(%r15), %edi
callq 0x3e1bd
movl %eax, %r13d
movl %eax, %ebx
shll $0x4, %ebx
movsbl -0x1(%r15), %edi
callq 0x3e1bd
orl %ebx, %eax
cmpl $0xb, %r13d
ja 0x3e0bd
movb %al, -0x32(%rbp)
jmp 0x3e110
addl $0xffffff40, %eax       # imm = 0xFFFFFF40
leaq 0x24d77(%rip), %rcx     # 0x62e40
movzbl (%rax,%rcx), %ebx
cmpb $0x25, (%r15)
jne 0x3e108
movsbl 0x1(%r15), %edi
callq 0x3e1bd
movl %eax, %r13d
andl $0xc, %eax
cmpl $0x8, %eax
jne 0x3e108
movsbl 0x2(%r15), %edi
callq 0x3e1bd
shll $0x4, %r13d
shll $0x6, %ebx
andl $0x30, %r13d
orl %eax, %ebx
orl %r13d, %ebx
addq $0x3, %r15
jmp 0x3e0cd
cmpl $0x7f, %ebx
jg 0x3e12e
movb %bl, -0x32(%rbp)
leaq -0x31(%rbp), %rsi
leaq -0x32(%rbp), %rdi
subl %edi, %esi
movq -0x40(%rbp), %rdx
callq *%r14
testl %eax, %eax
je 0x3e012
jmp 0x3e1ae
movl %ebx, %eax
cmpl $0x7ff, %ebx            # imm = 0x7FF
ja 0x3e14f
shrl $0x6, %eax
orb $-0x40, %al
movb %al, -0x32(%rbp)
andb $0x3f, %bl
orb $-0x80, %bl
movb %bl, -0x31(%rbp)
leaq -0x30(%rbp), %rsi
jmp 0x3e114
cmpl $0xffff, %ebx           # imm = 0xFFFF
ja 0x3e17a
shrl $0xc, %eax
orb $-0x20, %al
movb %al, -0x32(%rbp)
movl %ebx, %eax
shrl $0x6, %eax
andb $0x3f, %al
orb $-0x80, %al
movb %al, -0x31(%rbp)
andb $0x3f, %bl
orb $-0x80, %bl
movb %bl, -0x30(%rbp)
leaq -0x2f(%rbp), %rsi
jmp 0x3e114
shrl $0x12, %eax
andb $0x7, %al
orb $-0x10, %al
movb %al, -0x32(%rbp)
movl %ebx, %eax
shrl $0xc, %eax
andb $0x3f, %al
orb $-0x80, %al
movb %al, -0x31(%rbp)
movl %ebx, %eax
shrl $0x6, %eax
andb $0x3f, %al
orb $-0x80, %al
movb %al, -0x30(%rbp)
andb $0x3f, %bl
orb $-0x80, %bl
movb %bl, -0x2f(%rbp)
leaq -0x2e(%rbp), %rsi
jmp 0x3e114
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq