// File: /workspace/github_c_makefile_star2_O3/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, %rbx
movq %rdx, %r14
movl %esi, %r12d
addq %rdi, %r12
cmpq %r12, %rdi
jae 0x475fa
xorl %eax, %eax
movzbl (%rdi,%rax), %ecx
cmpl $0x25, %ecx
je 0x473fb
cmpl $0x2b, %ecx
je 0x473fb
leaq (%rdi,%rax), %rcx
incq %rcx
incq %rax
cmpq %r12, %rcx
jb 0x473d3
addq %rdi, %rax
movb $0x1, %r15b
movq %rax, %r13
jmp 0x47407
leaq (%rdi,%rax), %r13
testq %rax, %rax
je 0x47423
xorl %r15d, %r15d
movl %r13d, %esi
subl %edi, %esi
movq %rbx, %rdx
callq *%r14
testb %r15b, %r15b
jne 0x475fa
testl %eax, %eax
jne 0x475fa
cmpb $0x2b, (%r13)
jne 0x47436
movb $0x20, -0x32(%rbp)
incq %r13
jmp 0x4754f
leaq 0x2(%r13), %rcx
cmpq %r12, %rcx
jae 0x475fa
movsbl 0x1(%r13), %edx
leal -0x61(%rdx), %eax
cmpl $0x5, %eax
ja 0x47459
addl $-0x57, %edx
movl %edx, %eax
xorl %edi, %edi
jmp 0x47474
leal -0x30(%rdx), %eax
cmpl $0xa, %eax
movl $0x0, %edi
jb 0x47474
leal -0x41(%rdx), %eax
addl $-0x37, %edx
cmpl $0x6, %eax
cmovael %edi, %edx
movl %edx, %eax
movsbl (%rcx), %ecx
leal -0x61(%rcx), %edx
cmpl $0x5, %edx
ja 0x47484
addl $-0x57, %ecx
jmp 0x47498
leal -0x30(%rcx), %edx
cmpl $0xa, %edx
jb 0x4749a
leal -0x41(%rcx), %edx
addl $-0x37, %ecx
cmpl $0x6, %edx
cmovael %edi, %ecx
movl %ecx, %edx
movl %eax, %ecx
shll $0x4, %ecx
addl %edx, %ecx
addq $0x3, %r13
cmpl $0xb, %eax
ja 0x474b2
movb %cl, -0x32(%rbp)
jmp 0x4754f
addl $0xffffff40, %ecx       # imm = 0xFFFFFF40
leaq 0x2b9a1(%rip), %rax     # 0x72e60
movzbl (%rcx,%rax), %eax
cmpb $0x25, (%r13)
jne 0x47541
movsbl 0x1(%r13), %edx
leal -0x61(%rdx), %ecx
cmpl $0x5, %ecx
ja 0x474dc
addl $-0x57, %edx
jmp 0x474f0
leal -0x30(%rdx), %ecx
cmpl $0xa, %ecx
jb 0x474f2
leal -0x41(%rdx), %ecx
addl $-0x37, %edx
cmpl $0x6, %ecx
cmovael %edi, %edx
movl %edx, %ecx
movsbl 0x2(%r13), %edx
leal -0x61(%rdx), %esi
cmpl $0x5, %esi
ja 0x47504
addl $-0x57, %edx
jmp 0x47518
leal -0x30(%rdx), %esi
cmpl $0xa, %esi
jb 0x4751a
leal -0x41(%rdx), %esi
addl $-0x37, %edx
cmpl $0x6, %esi
cmovael %edi, %edx
movl %edx, %esi
movl %ecx, %edx
andl $0xc, %edx
cmpl $0x8, %edx
jne 0x47541
shll $0x4, %ecx
shll $0x6, %eax
andl $0x30, %ecx
orl %esi, %ecx
addl %ecx, %eax
leaq 0x3(%r13), %rcx
cmpb $0x25, 0x3(%r13)
movq %rcx, %r13
je 0x474ca
jmp 0x47544
movq %r13, %rcx
cmpl $0x7f, %eax
jg 0x4756f
movb %al, -0x32(%rbp)
movq %rcx, %r13
leaq -0x31(%rbp), %rsi
leaq -0x32(%rbp), %rdi
subl %edi, %esi
movq %rbx, %rdx
callq *%r14
movq %r13, %rdi
testl %eax, %eax
je 0x473c8
jmp 0x475fa
movl %eax, %edx
cmpl $0x7ff, %eax            # imm = 0x7FF
ja 0x47591
shrl $0x6, %edx
orb $-0x40, %dl
movb %dl, -0x32(%rbp)
andb $0x3f, %al
orb $-0x80, %al
movb %al, -0x31(%rbp)
movq %rcx, %r13
leaq -0x30(%rbp), %rsi
jmp 0x47553
cmpl $0xffff, %eax           # imm = 0xFFFF
ja 0x475bf
shrl $0xc, %edx
orb $-0x20, %dl
movb %dl, -0x32(%rbp)
movl %eax, %edx
shrl $0x6, %edx
andb $0x3f, %dl
orb $-0x80, %dl
movb %dl, -0x31(%rbp)
andb $0x3f, %al
orb $-0x80, %al
movb %al, -0x30(%rbp)
movq %rcx, %r13
leaq -0x2f(%rbp), %rsi
jmp 0x47553
shrl $0x12, %edx
andb $0x7, %dl
orb $-0x10, %dl
movb %dl, -0x32(%rbp)
movl %eax, %edx
shrl $0xc, %edx
andb $0x3f, %dl
orb $-0x80, %dl
movb %dl, -0x31(%rbp)
movl %eax, %edx
shrl $0x6, %edx
andb $0x3f, %dl
orb $-0x80, %dl
movb %dl, -0x30(%rbp)
andb $0x3f, %al
orb $-0x80, %al
movb %al, -0x2f(%rbp)
movq %rcx, %r13
leaq -0x2e(%rbp), %rsi
jmp 0x47553
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq