// File: /workspace/github_c_makefile_star2_O1/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
setae %r15b
movq %rdi, %r13
jae 0x48456
movzbl (%r13), %eax
cmpl $0x25, %eax
je 0x48456
cmpl $0x2b, %eax
je 0x48456
incq %r13
cmpq %r12, %r13
setae %r15b
jb 0x4843b
cmpq %rdi, %r13
je 0x4846e
movl %r13d, %esi
subl %edi, %esi
movq %rbx, %rdx
callq *%r14
testl %eax, %eax
setne %al
orb %al, %r15b
testb $0x1, %r15b
jne 0x48655
cmpb $0x2b, (%r13)
jne 0x4848b
movb $0x20, -0x32(%rbp)
incq %r13
jmp 0x485a4
leaq 0x2(%r13), %rcx
cmpq %r12, %rcx
jae 0x48655
movsbl 0x1(%r13), %edx
leal -0x61(%rdx), %eax
cmpl $0x5, %eax
ja 0x484ae
addl $-0x57, %edx
movl %edx, %eax
xorl %edi, %edi
jmp 0x484c9
leal -0x30(%rdx), %eax
cmpl $0xa, %eax
movl $0x0, %edi
jb 0x484c9
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 0x484d9
addl $-0x57, %ecx
jmp 0x484ed
leal -0x30(%rcx), %edx
cmpl $0xa, %edx
jb 0x484ef
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 0x48507
movb %cl, -0x32(%rbp)
jmp 0x485a4
addl $0xffffff40, %ecx       # imm = 0xFFFFFF40
leaq 0x2c93c(%rip), %rax     # 0x74e50
movzbl (%rcx,%rax), %eax
cmpb $0x25, (%r13)
jne 0x48596
movsbl 0x1(%r13), %edx
leal -0x61(%rdx), %ecx
cmpl $0x5, %ecx
ja 0x48531
addl $-0x57, %edx
jmp 0x48545
leal -0x30(%rdx), %ecx
cmpl $0xa, %ecx
jb 0x48547
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 0x48559
addl $-0x57, %edx
jmp 0x4856d
leal -0x30(%rdx), %esi
cmpl $0xa, %esi
jb 0x4856f
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 0x48596
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 0x4851f
jmp 0x48599
movq %r13, %rcx
cmpl $0x7f, %eax
jg 0x485c4
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 0x4842f
jmp 0x48655
movl %eax, %edx
cmpl $0x7ff, %eax            # imm = 0x7FF
jg 0x485e9
shrl $0x6, %edx
andb $0x1f, %dl
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 0x485a8
cmpl $0xffff, %eax           # imm = 0xFFFF
jg 0x4861a
shrl $0xc, %edx
andb $0xf, %dl
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 0x485a8
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 0x485a8
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq