// File: /workspace/github_c_makefile_star2_O0/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
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x60(%rbp)
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x7d602
movq -0x40(%rbp), %rcx
xorl %eax, %eax
cmpq -0x38(%rbp), %rcx
movb %al, -0x61(%rbp)
jae 0x7d632
movq -0x40(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x25, %ecx
movb %al, -0x61(%rbp)
je 0x7d632
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2b, %eax
setne %al
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
testb $0x1, %al
jne 0x7d63b
jmp 0x7d649
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x7d602
movq -0x40(%rbp), %rax
cmpq -0x30(%rbp), %rax
je 0x7d67e
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rdi
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %rdx
subq %rdx, %rcx
movl %ecx, %esi
movq -0x20(%rbp), %rdx
callq *%rax
movl %eax, -0x60(%rbp)
cmpl $0x0, -0x60(%rbp)
je 0x7d67c
jmp 0x7d99c
jmp 0x7d67e
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jb 0x7d694
movl $0x0, -0x60(%rbp)
jmp 0x7d99c
leaq -0x52(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2b, %eax
jne 0x7d6cb
movq -0x48(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x48(%rbp)
movb $0x20, (%rax)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x7d969
movq -0x40(%rbp), %rax
addq $0x2, %rax
cmpq -0x38(%rbp), %rax
jb 0x7d6e5
movl $0xfffffff1, -0x60(%rbp) # imm = 0xFFFFFFF1
jmp 0x7d99c
movq -0x40(%rbp), %rax
movsbl 0x1(%rax), %edi
callq 0x7d9b0
shll $0x4, %eax
movl %eax, -0x68(%rbp)
movq -0x40(%rbp), %rax
movsbl 0x2(%rax), %edi
callq 0x7d9b0
movl %eax, %ecx
movl -0x68(%rbp), %eax
orl %ecx, %eax
movl %eax, -0x58(%rbp)
movq -0x40(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x40(%rbp)
cmpl $0xc0, -0x58(%rbp)
jge 0x7d73f
movl -0x58(%rbp), %eax
movb %al, %cl
movq -0x48(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x48(%rbp)
movb %cl, (%rax)
jmp 0x7d967
movl -0x58(%rbp), %eax
subl $0xc0, %eax
movslq %eax, %rcx
leaq 0x43b5f(%rip), %rax     # 0xc12b0
movzbl (%rax,%rcx), %eax
movl %eax, -0x58(%rbp)
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x25, %eax
jne 0x7d7be
movq -0x40(%rbp), %rax
movsbl 0x1(%rax), %edi
callq 0x7d9b0
shll $0x4, %eax
movl %eax, -0x6c(%rbp)
movq -0x40(%rbp), %rax
movsbl 0x2(%rax), %edi
callq 0x7d9b0
movl %eax, %ecx
movl -0x6c(%rbp), %eax
orl %ecx, %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
andl $0xc0, %eax
cmpl $0x80, %eax
je 0x7d79f
jmp 0x7d7be
movl -0x58(%rbp), %eax
shll $0x6, %eax
movl -0x5c(%rbp), %ecx
andl $0x3f, %ecx
addl %ecx, %eax
movl %eax, -0x58(%rbp)
movq -0x40(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x40(%rbp)
jmp 0x7d758
cmpl $0x0, -0x24(%rbp)
jne 0x7d7df
movl -0x58(%rbp), %eax
movb %al, %cl
movq -0x48(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x48(%rbp)
movb %cl, (%rax)
jmp 0x7d965
cmpl $0x80, -0x58(%rbp)
jge 0x7d808
movl -0x58(%rbp), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x48(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x48(%rbp)
movb %cl, (%rax)
jmp 0x7d963
cmpl $0x800, -0x58(%rbp)     # imm = 0x800
jge 0x7d85b
movl -0x58(%rbp), %eax
sarl $0x6, %eax
andl $0x1f, %eax
movzbl %al, %eax
addl $0xc0, %eax
movb %al, %cl
movq -0x48(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x48(%rbp)
movb %cl, (%rax)
movl -0x58(%rbp), %eax
andl $0x3f, %eax
movzbl %al, %eax
addl $0x80, %eax
movb %al, %cl
movq -0x48(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x48(%rbp)
movb %cl, (%rax)
jmp 0x7d961
cmpl $0x10000, -0x58(%rbp)   # imm = 0x10000
jge 0x7d8d2
movl -0x58(%rbp), %eax
sarl $0xc, %eax
andl $0xf, %eax
movzbl %al, %eax
addl $0xe0, %eax
movb %al, %cl
movq -0x48(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x48(%rbp)
movb %cl, (%rax)
movl -0x58(%rbp), %eax
sarl $0x6, %eax
andl $0x3f, %eax
movzbl %al, %eax
addl $0x80, %eax
movb %al, %cl
movq -0x48(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x48(%rbp)
movb %cl, (%rax)
movl -0x58(%rbp), %eax
andl $0x3f, %eax
movzbl %al, %eax
addl $0x80, %eax
movb %al, %cl
movq -0x48(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x48(%rbp)
movb %cl, (%rax)
jmp 0x7d95f
movl -0x58(%rbp), %eax
sarl $0x12, %eax
andl $0x7, %eax
movzbl %al, %eax
addl $0xf0, %eax
movb %al, %cl
movq -0x48(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x48(%rbp)
movb %cl, (%rax)
movl -0x58(%rbp), %eax
sarl $0xc, %eax
andl $0x3f, %eax
movzbl %al, %eax
addl $0x80, %eax
movb %al, %cl
movq -0x48(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x48(%rbp)
movb %cl, (%rax)
movl -0x58(%rbp), %eax
sarl $0x6, %eax
andl $0x3f, %eax
movzbl %al, %eax
addl $0x80, %eax
movb %al, %cl
movq -0x48(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x48(%rbp)
movb %cl, (%rax)
movl -0x58(%rbp), %eax
andl $0x3f, %eax
movzbl %al, %eax
addl $0x80, %eax
movb %al, %cl
movq -0x48(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x48(%rbp)
movb %cl, (%rax)
jmp 0x7d961
jmp 0x7d963
jmp 0x7d965
jmp 0x7d967
jmp 0x7d969
movq -0x18(%rbp), %rax
leaq -0x52(%rbp), %rdi
movq -0x48(%rbp), %rcx
leaq -0x52(%rbp), %rdx
subq %rdx, %rcx
movl %ecx, %esi
movq -0x20(%rbp), %rdx
callq *%rax
movl %eax, -0x60(%rbp)
cmpl $0x0, -0x60(%rbp)
je 0x7d98f
jmp 0x7d99c
movq -0x40(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x7d600
movl -0x60(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)