// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
movq %rdx, -0x48(%rbp)
movq %rsi, -0x30(%rbp)
movq %rdi, %r12
movq 0x8(%rdi), %r13
movq 0x10(%rdi), %rbx
movq %r13, %r15
cmpq %rbx, %r15
jae 0x4625a
movzbl (%r15), %r14d
cmpq $0xbf, %r14
ja 0x46221
callq 0xc190
movq (%rax), %rax
testb $0x20, 0x1(%rax,%r14,2)
je 0x46221
cmpl $0xa, %r14d
jne 0x46214
incl 0x18(%r12)
incq %r15
movq %r15, 0x8(%r12)
incq %r13
jmp 0x461e7
movq %r12, -0x38(%rbp)
movl 0x18(%r12), %r14d
movq -0x30(%rbp), %rcx
movl %r14d, 0x14(%rcx)
andq $0x0, 0x18(%rcx)
movq %r15, (%rcx)
andl $0x0, 0x8(%rcx)
movzbl (%r15), %r12d
cmpq $0xbf, %r12
movq %r15, -0x40(%rbp)
jbe 0x46262
movq %r15, %r12
movq %r15, %r14
jmp 0x4650c
pushq $-0x12
popq %rbx
jmp 0x465f4
callq 0xc190
cmpq $0x5f, %r12
je 0x462b5
movq (%rax), %rcx
movzwl (%rcx,%r12,2), %ecx
movl %ecx, %edx
andl $0x400, %edx            # imm = 0x400
jne 0x462b5
cmpq $0x22, %r12
je 0x462de
cmpl $0x2c, %r12d
je 0x46367
cmpl $0x3a, %r12d
je 0x46360
cmpl $0x5b, %r12d
je 0x462c2
cmpl $0x5d, %r12d
je 0x462d4
cmpl $0x7d, %r12d
je 0x462cc
cmpl $0x7b, %r12d
jne 0x4632f
pushq $0x20
jmp 0x462ce
movq -0x40(%rbp), %rax
leaq 0x1(%rax), %r14
jmp 0x46501
movl $0x80, %eax
jmp 0x4636c
pushq $0x40
popq %rax
jmp 0x4636c
movl $0x100, %eax            # imm = 0x100
jmp 0x4636c
movq -0x40(%rbp), %rcx
incq %rcx
movq -0x38(%rbp), %rsi
movq %rcx, 0x8(%rsi)
movq -0x30(%rbp), %rdx
movq %rcx, (%rdx)
xorl %eax, %eax
cmpq %rbx, %rcx
jae 0x4638d
movq %rcx, %rdi
movzbl (%rcx), %ecx
cmpl $0xa, %ecx
je 0x4631a
cmpl $0x22, %ecx
jne 0x46321
cmpb $0x5c, -0x1(%rdi)
je 0x46321
jmp 0x463f3
incl %r14d
movl %r14d, 0x18(%rsi)
movq %rdi, %rcx
incq %rcx
movq %rcx, 0x8(%rsi)
incl %eax
jmp 0x462f6
btl $0xb, %ecx
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %r8
jb 0x463af
movl $0x1000, 0x10(%rdi)     # imm = 0x1000
movq -0x40(%rbp), %rax
incq %rax
movq %rax, 0x8(%r8)
movq -0x48(%rbp), %rax
movl $0xfffffff4, (%rax)     # imm = 0xFFFFFFF4
pushq $-0xa
jmp 0x4625c
movl $0x200, %eax            # imm = 0x200
jmp 0x4636c
movl $0x400, %eax            # imm = 0x400
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rcx
movl %eax, 0x10(%rdi)
movq -0x40(%rbp), %rsi
incq %rsi
movq %rsi, 0x8(%rcx)
subl %r13d, %esi
movl %esi, 0x8(%rdi)
jmp 0x465f2
movl $0x1000, 0x10(%rdx)     # imm = 0x1000
movq -0x48(%rbp), %rcx
movl $0xfffffff4, (%rcx)     # imm = 0xFFFFFFF4
xorl %ebx, %ebx
cmpl $0x4, 0x10(%rdx)
movl %eax, 0x8(%rdx)
jne 0x465f4
jmp 0x46403
movq -0x40(%rbp), %rcx
incq %rcx
movq %rcx, 0x8(%r8)
movl $0x10, 0x10(%rdi)
cmpq %rbx, %rcx
jae 0x464f9
movq %rcx, %rsi
movzbl (%rcx), %ecx
cmpq $0xbf, %rcx
ja 0x46471
movq (%rax), %rdx
testb $0x8, 0x1(%rdx,%rcx,2)
je 0x4640d
movq %rsi, %rcx
incq %rcx
movq %rcx, 0x8(%r8)
jmp 0x463c1
movl $0x4, 0x10(%rdx)
incq %rdi
movq %rdi, 0x8(%rsi)
incl %eax
decl %eax
movl %eax, 0x8(%rdx)
jmp 0x465f2
cmpl $0x2e, %ecx
jne 0x46471
movq %rsi, %rdx
incq %rdx
movq %rdx, %r10
movq %rdx, 0x8(%r8)
cmpq %rbx, %rdx
jae 0x464a3
movzbl (%r10), %ecx
cmpq $0xbf, %rcx
ja 0x4643f
movq (%rax), %rsi
leaq 0x1(%r10), %rdx
testb $0x8, 0x1(%rsi,%rcx,2)
jne 0x46418
andb $-0x21, %cl
cmpb $0x45, %cl
jne 0x464a3
leaq 0x1(%r10), %rcx
movq %rcx, 0x8(%r8)
cmpq %rbx, %rcx
jae 0x464f9
movzbl (%rcx), %edx
cmpl $0x2b, %edx
je 0x46465
cmpl $0x2d, %edx
jne 0x464af
movq %r10, %rdx
addq $0x2, %rdx
movq %rdx, %rcx
jmp 0x464ab
andb $-0x21, %cl
cmpb $0x45, %cl
jne 0x46382
leaq 0x1(%rsi), %rcx
movq %rcx, 0x8(%r8)
cmpq %rbx, %rcx
jae 0x464f9
movzbl (%rcx), %edx
cmpl $0x2b, %edx
je 0x46497
cmpl $0x2d, %edx
jne 0x464d6
movq %rsi, %rdx
addq $0x2, %rdx
movq %rdx, %rcx
jmp 0x464d2
movq %r10, %rsi
jmp 0x46382
movq %rdx, 0x8(%r8)
cmpq %rbx, %rcx
jae 0x464f9
movzbl (%rcx), %edx
cmpq $0xbf, %rdx
ja 0x464f9
movq (%rax), %rsi
testb $0x8, 0x1(%rsi,%rdx,2)
je 0x464f9
incq %rcx
movq %rcx, %rdx
jmp 0x464ab
movq %rdx, 0x8(%r8)
cmpq %rbx, %rcx
jae 0x464f9
movzbl (%rcx), %edx
cmpq $0xbf, %rdx
ja 0x464f9
movq (%rax), %rsi
testb $0x8, 0x1(%rsi,%rdx,2)
je 0x464f9
incq %rcx
movq %rcx, %rdx
jmp 0x464d2
movq %rcx, %rsi
jmp 0x46382
movq -0x38(%rbp), %rax
movq %r14, 0x8(%rax)
movq %r14, %r12
cmpb $-0x40, (%r12)
jb 0x4652e
leaq 0x1(%r12), %rax
movq %rax, %r14
cmpq %rbx, %rax
jae 0x4652e
movb (%r14), %cl
andb $-0x40, %cl
leaq 0x1(%r14), %rax
negb %cl
jo 0x46518
cmpq %rbx, %r14
jae 0x4655d
movzbl (%r14), %r15d
cmpq $0xbf, %r15
ja 0x4655d
callq 0xc190
cmpq $0x5f, %r15
je 0x46558
movq (%rax), %rax
movzwl (%rax,%r15,2), %eax
andl $0x8, %eax
je 0x4655d
incq %r14
jmp 0x4652e
cmpq %r12, %r14
jne 0x46501
subq %r13, %r12
movq -0x30(%rbp), %rax
movl %r12d, 0x8(%rax)
movl $0x800, 0x10(%rax)      # imm = 0x800
cmpl $0x4, %r12d
jne 0x46591
leaq 0x1b6ed(%rip), %rsi     # 0x61c6e
pushq $0x4
popq %rdx
movq -0x40(%rbp), %rdi
callq 0x32436
testl %eax, %eax
je 0x465e7
xorl %ebx, %ebx
cmpl $0x4, %r12d
je 0x465c3
cmpl $0x5, %r12d
movq -0x40(%rbp), %rdi
jne 0x465f4
leaq 0x1b6c9(%rip), %rsi     # 0x61c73
pushq $0x5
popq %rdx
callq 0x32436
testl %eax, %eax
jne 0x465f4
movq -0x30(%rbp), %rax
movl $0x2, 0x10(%rax)
jmp 0x465f4
leaq 0x204f5(%rip), %rsi     # 0x66abf
pushq $0x4
popq %rdx
movq -0x40(%rbp), %rdi
callq 0x32436
testl %eax, %eax
jne 0x465f4
movq -0x30(%rbp), %rax
movl $0x8, 0x10(%rax)
jmp 0x465f4
movq -0x30(%rbp), %rax
movl $0x1, 0x10(%rax)
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq