// File: /workspace/github_c_makefile_star2_O3/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: VmJsonTokenize
static sxi32 VmJsonTokenize(SyStream *pStream, SyToken *pToken, void *pUserData, void *pCtxData)
{
	int *pJsonErr = (int *)pUserData;
	SyString *pStr;
	int c;
	/* Ignore leading white spaces */
	while( pStream->zText < pStream->zEnd && pStream->zText[0] < 0xc0 && SyisSpace(pStream->zText[0]) ){
		/* Advance the stream cursor */
		if( pStream->zText[0] == '\n' ){
			/* Update line counter */
			pStream->nLine++;
		}
		pStream->zText++;
	}
	if( pStream->zText >= pStream->zEnd ){
		/* End of input reached */
		SXUNUSED(pCtxData); /* cc warning */
		return SXERR_EOF;
	}
	/* Record token starting position and line */
	pToken->nLine = pStream->nLine;
	pToken->pUserData = 0;
	pStr = &pToken->sData;
	SyStringInitFromBuf(pStr, pStream->zText, 0);
	if( pStream->zText[0] >= 0xc0 || SyisAlpha(pStream->zText[0]) || pStream->zText[0] == '_' ){
		/* The following code fragment is taken verbatim from the xPP source tree.
		 * xPP is a modern embeddable macro processor with advanced features useful for
		 * application seeking for a production quality, ready to use macro processor.
		 * xPP is a widely used library developed and maintened by Symisc Systems.
		 * You can reach the xPP home page by following this link:
		 * http://xpp.symisc.net/
		 */
		const unsigned char *zIn;
		/* Isolate UTF-8 or alphanumeric stream */
		if( pStream->zText[0] < 0xc0 ){
			pStream->zText++;
		}
		for(;;){
			zIn = pStream->zText;
			if( zIn[0] >= 0xc0 ){
				zIn++;
				/* UTF-8 stream */
				while( zIn < pStream->zEnd && ((zIn[0] & 0xc0) == 0x80) ){
					zIn++;
				}
			}
			/* Skip alphanumeric stream */
			while( zIn < pStream->zEnd && zIn[0] < 0xc0 && (SyisAlphaNum(zIn[0]) || zIn[0] == '_') ){
				zIn++;
			}
			if( zIn == pStream->zText ){
				/* Not an UTF-8 or alphanumeric stream */
				break;
			}
			/* Synchronize pointers */
			pStream->zText = zIn;
		}
		/* Record token length */
		pStr->nByte = (sxu32)((const char *)pStream->zText-pStr->zString);
		/* A simple identifier */
		pToken->nType = JSON_TK_ID;
		if( pStr->nByte == sizeof("true") -1 && SyStrnicmp(pStr->zString, "true", sizeof("true")-1) == 0 ){
			/* boolean true */
			pToken->nType = JSON_TK_TRUE;
		}else if( pStr->nByte == sizeof("false") -1 && SyStrnicmp(pStr->zString,"false", sizeof("false")-1) == 0 ){
			/* boolean false */
			pToken->nType = JSON_TK_FALSE;
		}else if( pStr->nByte == sizeof("null") -1 && SyStrnicmp(pStr->zString,"null", sizeof("null")-1) == 0 ){
			/* NULL */
			pToken->nType = JSON_TK_NULL;
		}
		return SXRET_OK;
	}
	if( pStream->zText[0] == '{' || pStream->zText[0] == '[' || pStream->zText[0] == '}' || pStream->zText[0] == ']'
		|| pStream->zText[0] == ':' || pStream->zText[0] == ',' ){
			/* Single character */
			c = pStream->zText[0];
			/* Set token type */
			switch(c){
			case '[': pToken->nType = JSON_TK_OSB;   break;
			case '{': pToken->nType = JSON_TK_OCB;   break;
			case '}': pToken->nType = JSON_TK_CCB;   break;
			case ']': pToken->nType = JSON_TK_CSB;   break;
			case ':': pToken->nType = JSON_TK_COLON; break;
			case ',': pToken->nType = JSON_TK_COMMA; break;
			default:
				break;
			}
			/* Advance the stream cursor */
			pStream->zText++;
	}else if( pStream->zText[0] == '"') {
		/* JSON string */
		pStream->zText++;
		pStr->zString++;
		/* Delimit the string */
		while( pStream->zText < pStream->zEnd ){
			if( pStream->zText[0] == '"' && pStream->zText[-1] != '\\' ){
				break;
			}
			if( pStream->zText[0] == '\n' ){
				/* Update line counter */
				pStream->nLine++;
			}
			pStream->zText++;
		}
		if( pStream->zText >= pStream->zEnd ){
			/* Missing closing '"' */
			pToken->nType = JSON_TK_INVALID;
			*pJsonErr = SXERR_SYNTAX;
		}else{
			pToken->nType = JSON_TK_STR;
			pStream->zText++; /* Jump the closing double quotes */
		}
	}else if( pStream->zText[0] < 0xc0 && SyisDigit(pStream->zText[0]) ){
		/* Number */
		pStream->zText++;
		pToken->nType = JSON_TK_NUM;
		while( pStream->zText < pStream->zEnd && pStream->zText[0] < 0xc0 && SyisDigit(pStream->zText[0]) ){
			pStream->zText++;
		}
		if( pStream->zText < pStream->zEnd ){
			c = pStream->zText[0];
			if( c == '.' ){
					/* Real number */
					pStream->zText++;
					while( pStream->zText < pStream->zEnd && pStream->zText[0] < 0xc0 && SyisDigit(pStream->zText[0]) ){
						pStream->zText++;
					}
					if( pStream->zText < pStream->zEnd ){
						c = pStream->zText[0];
						if( c=='e' || c=='E' ){
							pStream->zText++;
							if( pStream->zText < pStream->zEnd ){
								c = pStream->zText[0];
								if( c =='+' || c=='-' ){
									pStream->zText++;
								}
								while( pStream->zText < pStream->zEnd && pStream->zText[0] < 0xc0 && SyisDigit(pStream->zText[0]) ){
									pStream->zText++;
								}
							}
						}
					}					
				}else if( c=='e' || c=='E' ){
					/* Real number */
					pStream->zText++;
					if( pStream->zText < pStream->zEnd ){
						c = pStream->zText[0];
						if( c =='+' || c=='-' ){
							pStream->zText++;
						}
						while( pStream->zText < pStream->zEnd && pStream->zText[0] < 0xc0 && SyisDigit(pStream->zText[0]) ){
							pStream->zText++;
						}
					}					
				}
			}
	}else{
		/* Unexpected token */
		pToken->nType = JSON_TK_INVALID;
		/* Advance the stream cursor */
		pStream->zText++;
		*pJsonErr = SXERR_SYNTAX;
		/* Abort processing immediatley */
		return SXERR_ABORT;
	}
	/* record token length */
	pStr->nByte = (sxu32)((const char *)pStream->zText-pStr->zString);
	if( pToken->nType == JSON_TK_STR ){
		pStr->nByte--;
	}
	/* Return to the lexer */
	return SXRET_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq 0x8(%rdi), %r15
movq %rdi, -0x30(%rbp)
movq 0x10(%rdi), %r14
movl $0xffffffee, %r13d      # imm = 0xFFFFFFEE
cmpq %r14, %r15
jae 0x50d54
movq %rdx, -0x50(%rbp)
movq %rsi, -0x38(%rbp)
xorl %r12d, %r12d
movzbl (%r15,%r12), %ebx
cmpq $0xbf, %rbx
ja 0x508d2
callq 0xc170
movq (%rax), %rax
testb $0x20, 0x1(%rax,%rbx,2)
je 0x508d2
cmpl $0xa, %ebx
jne 0x508b6
movq -0x30(%rbp), %rax
incl 0x18(%rax)
leaq (%r15,%r12), %rax
incq %rax
movq -0x30(%rbp), %rcx
movq %rax, 0x8(%rcx)
incq %r12
cmpq %r14, %rax
jne 0x5088d
jmp 0x50d54
movq -0x30(%rbp), %rax
movl 0x18(%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x14(%rax)
movq $0x0, 0x18(%rax)
leaq (%r15,%r12), %rbx
movq %rbx, (%rax)
movl $0x0, 0x8(%rax)
movzbl (%r15,%r12), %r13d
movq %rbx, -0x58(%rbp)
cmpq $0xbf, %r13
movq %r15, -0x48(%rbp)
movq %r12, -0x40(%rbp)
ja 0x50c4c
movl %ecx, %ebx
callq 0xc170
cmpq $0x5f, %r13
je 0x50966
movq (%rax), %rcx
movzwl (%rcx,%r13,2), %ecx
movl %ecx, %edx
andl $0x400, %edx            # imm = 0x400
jne 0x50966
cmpl $0x5a, %r13d
jle 0x50972
cmpl $0x7a, %r13d
movq -0x38(%rbp), %r8
jg 0x5099a
movl $0x80, %edx
cmpl $0x5b, %r13d
je 0x50a7c
cmpl $0x5d, %r13d
jne 0x50a3e
movl $0x100, %edx            # imm = 0x100
jmp 0x50a7c
leaq (%r15,%r12), %r13
incq %r13
jmp 0x50c41
cmpl $0x22, %r13d
movq -0x38(%rbp), %r8
je 0x509b8
cmpl $0x2c, %r13d
je 0x50a77
cmpl $0x3a, %r13d
jne 0x50a3e
movl $0x200, %edx            # imm = 0x200
jmp 0x50a7c
cmpl $0x7d, %r13d
je 0x50a70
cmpl $0x7b, %r13d
jne 0x50a3e
movl $0x20, %edx
jmp 0x50a7c
leaq (%r15,%r12), %rax
incq %rax
movq -0x30(%rbp), %rcx
movq %rax, 0x8(%rcx)
movq %rax, (%r8)
cmpq %r14, %rax
jae 0x50a09
movl $0x1, %ecx
movl %ebx, %esi
movzbl (%rax), %edx
cmpl $0xa, %edx
je 0x509ee
cmpl $0x22, %edx
jne 0x509f7
cmpb $0x5c, -0x1(%rax)
je 0x509f7
jmp 0x50ae1
incl %esi
movq -0x30(%rbp), %rdx
movl %esi, 0x18(%rdx)
incq %rax
movq -0x30(%rbp), %rdx
movq %rax, 0x8(%rdx)
incl %ecx
cmpq %r14, %rax
jb 0x509d6
movl $0x1000, 0x10(%r8)      # imm = 0x1000
movq -0x50(%rbp), %rcx
movl $0xfffffff4, (%rcx)     # imm = 0xFFFFFFF4
notl %r15d
addq %rax, %r15
subq %r12, %r15
xorl %r13d, %r13d
cmpl $0x4, 0x10(%r8)
movl %r15d, 0x8(%r8)
jne 0x50d54
movl %r15d, %ecx
jmp 0x50af4
btl $0xb, %ecx
jb 0x50a9e
movl $0x1000, 0x10(%r8)      # imm = 0x1000
leaq (%r15,%r12), %rax
incq %rax
movq -0x30(%rbp), %rcx
movq %rax, 0x8(%rcx)
movq -0x50(%rbp), %rax
movl $0xfffffff4, (%rax)     # imm = 0xFFFFFFF4
movl $0xfffffff6, %r13d      # imm = 0xFFFFFFF6
jmp 0x50d54
movl $0x40, %edx
jmp 0x50a7c
movl $0x400, %edx            # imm = 0x400
movl %edx, 0x10(%r8)
leaq (%r15,%r12), %rcx
incq %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
subl %r15d, %ecx
subl %r12d, %ecx
movl %ecx, 0x8(%r8)
jmp 0x50d51
leaq (%r15,%r12), %rcx
incq %rcx
movq -0x30(%rbp), %rdx
movq %rcx, 0x8(%rdx)
movl $0x10, 0x10(%r8)
cmpq %r14, %rcx
jae 0x50a8f
movzbl (%rcx), %edx
cmpq $0xbf, %rdx
ja 0x50bbb
movq (%rax), %rsi
testb $0x8, 0x1(%rsi,%rdx,2)
je 0x50aff
incq %rcx
movq -0x30(%rbp), %rdx
movq %rcx, 0x8(%rdx)
jmp 0x50ab5
movl $0x4, 0x10(%r8)
incq %rax
movq -0x30(%rbp), %rdx
movq %rax, 0x8(%rdx)
decl %ecx
movl %ecx, 0x8(%r8)
jmp 0x50d51
cmpl $0x2e, %edx
jne 0x50bbb
incq %rcx
movq %rcx, %rsi
movq %rsi, %rcx
movq -0x30(%rbp), %rdx
movq %rsi, 0x8(%rdx)
cmpq %r14, %rsi
jae 0x50a8f
movzbl (%rcx), %edx
cmpq $0xbf, %rdx
ja 0x50b3c
movq (%rax), %rdi
leaq 0x1(%rcx), %rsi
testb $0x8, 0x1(%rdi,%rdx,2)
jne 0x50b0e
andb $-0x21, %dl
cmpb $0x45, %dl
jne 0x50a8f
leaq 0x1(%rcx), %rdx
movq -0x30(%rbp), %rsi
movq %rdx, 0x8(%rsi)
cmpq %r14, %rdx
jae 0x50c2d
movzbl (%rdx), %esi
cmpl $0x2b, %esi
je 0x50b6a
cmpl $0x2d, %esi
jne 0x50b79
addq $0x2, %rcx
movq -0x30(%rbp), %rdx
movq %rcx, 0x8(%rdx)
movq %rcx, %rdx
cmpq %r14, %rdx
jae 0x50c35
movq %r14, %rcx
subq %rdx, %rcx
movzbl (%rdx), %esi
cmpq $0xbf, %rsi
ja 0x50c35
movq (%rax), %rdi
testb $0x8, 0x1(%rdi,%rsi,2)
je 0x50c35
incq %rdx
movq -0x30(%rbp), %rsi
movq %rdx, 0x8(%rsi)
decq %rcx
jne 0x50b88
movq %r14, %rcx
jmp 0x50c38
andb $-0x21, %dl
cmpb $0x45, %dl
jne 0x50a8f
leaq 0x1(%rcx), %rdx
movq -0x30(%rbp), %rsi
movq %rdx, 0x8(%rsi)
cmpq %r14, %rdx
jae 0x50c2d
movzbl (%rdx), %esi
cmpl $0x2b, %esi
je 0x50be5
cmpl $0x2d, %esi
jne 0x50bf4
addq $0x2, %rcx
movq -0x30(%rbp), %rdx
movq %rcx, 0x8(%rdx)
movq %rcx, %rdx
cmpq %r14, %rdx
jae 0x50c2d
movq %r14, %rcx
subq %rdx, %rcx
movzbl (%rdx), %esi
cmpq $0xbf, %rsi
ja 0x50c2d
movq (%rax), %rdi
testb $0x8, 0x1(%rdi,%rsi,2)
je 0x50c2d
incq %rdx
movq -0x30(%rbp), %rsi
movq %rdx, 0x8(%rsi)
decq %rcx
jne 0x50bff
movq %r14, %rcx
jmp 0x50a8f
movq %rdx, %rcx
jmp 0x50a8f
movq %rdx, %rcx
movq -0x38(%rbp), %r8
jmp 0x50a8f
movq -0x30(%rbp), %rax
movq %r13, 0x8(%rax)
movq %r13, %rbx
cmpb $-0x40, (%rbx)
movq %rbx, %r13
jb 0x50c6f
leaq 0x1(%rbx), %rax
movq %rax, %r13
cmpq %r14, %rax
jae 0x50c6f
movb (%r13), %cl
andb $-0x40, %cl
leaq 0x1(%r13), %rax
negb %cl
jo 0x50c58
cmpq %r14, %r13
jae 0x50cb3
movq %r14, %r12
subq %r13, %r12
movzbl (%r13), %r15d
cmpq $0xbf, %r15
ja 0x50cab
callq 0xc170
cmpq $0x5f, %r15
je 0x50ca0
movq (%rax), %rax
movzwl (%rax,%r15,2), %eax
andl $0x8, %eax
je 0x50cab
incq %r13
decq %r12
jne 0x50c7a
movq %r14, %r13
movq -0x48(%rbp), %r15
movq -0x40(%rbp), %r12
cmpq %rbx, %r13
jne 0x50c41
movl %ebx, %eax
subl %r15d, %eax
subl %r12d, %eax
negl %r15d
addq %rbx, %r15
subq %r12, %r15
movq -0x38(%rbp), %rbx
movl %r15d, 0x8(%rbx)
movl $0x800, 0x10(%rbx)      # imm = 0x800
cmpl $0x4, %eax
movq -0x58(%rbp), %r14
jne 0x50cf9
leaq 0x20f8c(%rip), %rsi     # 0x71c74
movq %r14, %rdi
movl $0x4, %edx
callq 0x39f3f
testl %eax, %eax
je 0x50d4a
xorl %r13d, %r13d
cmpl $0x4, %r15d
je 0x50d29
cmpl $0x5, %r15d
jne 0x50d54
leaq 0x20f6a(%rip), %rsi     # 0x71c79
movq %r14, %rdi
movl $0x5, %edx
callq 0x39f3f
testl %eax, %eax
jne 0x50d54
movl $0x2, 0x10(%rbx)
jmp 0x50d54
leaq 0x25daf(%rip), %rsi     # 0x76adf
movq %r14, %rdi
movl $0x4, %edx
callq 0x39f3f
testl %eax, %eax
jne 0x50d54
movl $0x8, 0x10(%rbx)
jmp 0x50d54
movl $0x1, 0x10(%rbx)
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq