// File: /workspace/github_c_makefile_star2_O1/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: FastJsonDecode
UNQLITE_PRIVATE sxi32 FastJsonDecode(
	const void *pIn,  /* Binary JSON  */
	sxu32 nByte,      /* Chunk delimiter */
	jx9_value *pOut,  /* Decoded value */
	const unsigned char **pzPtr,
	int iNest /* Nesting limit */
	)
{
	const unsigned char *zIn = (const unsigned char *)pIn;
	const unsigned char *zEnd = &zIn[nByte];
	sxi32 rc = SXRET_OK;
	int c;
	if( iNest >= UNQLITE_FAST_JSON_NEST_LIMIT ){
		/* Nesting limit reached */
		return SXERR_LIMIT;
	}
	c = zIn[0];
	/* Advance the stream cursor */
	zIn++;
	/* Process the binary token */
	switch(c){
	case FJSON_NULL:
		/* null */
		jx9_value_null(pOut);
		break;
	case FJSON_FALSE:
		/* Boolean FALSE */
		jx9_value_bool(pOut,0);
		break;
	case FJSON_TRUE:
		/* Boolean TRUE */
		jx9_value_bool(pOut,1);
		break;
	case FJSON_INT64: {
		/* 64Bit integer */
		sxu64 iVal;
		/* Sanity check */
		if( &zIn[8] >= zEnd ){
			/* Corrupt chunk */
			rc = SXERR_CORRUPT;
			break;
		}
		SyBigEndianUnpack64(zIn,&iVal);
		/* Advance the pointer */
		zIn += 8;
		jx9_value_int64(pOut,(jx9_int64)iVal);
		break;
					  }
	case FJSON_REAL: {
		/* Real number */
		double iVal = 0; /* cc warning */
		sxu16 iLen;
		/* Sanity check */
		if( &zIn[2] >= zEnd ){
			/* Corrupt chunk */
			rc = SXERR_CORRUPT;
			break;
		}
		SyBigEndianUnpack16(zIn,&iLen);
		if( &zIn[iLen] >= zEnd ){
			/* Corrupt chunk */
			rc = SXERR_CORRUPT;
			break;
		}
		zIn += 2;
		SyStrToReal((const char *)zIn,(sxu32)iLen,&iVal,0);
		/* Advance the pointer */
		zIn += iLen;
		jx9_value_double(pOut,iVal);
		break;
					 }
	case FJSON_STRING: {
		/* UTF-8/Binary chunk */
		sxu32 iLength;
		/* Sanity check */
		if( &zIn[4] >= zEnd ){
			/* Corrupt chunk */
			rc = SXERR_CORRUPT;
			break;
		}
		SyBigEndianUnpack32(zIn,&iLength);
		if( &zIn[iLength] >= zEnd ){
			/* Corrupt chunk */
			rc = SXERR_CORRUPT;
			break;
		}
		zIn += 4;
		/* Invalidate any prior representation */
		if( pOut->iFlags & MEMOBJ_STRING ){
			/* Reset the string cursor */
			SyBlobReset(&pOut->sBlob);
		}
		rc = jx9MemObjStringAppend(pOut,(const char *)zIn,iLength);
		/* Update pointer */
		zIn += iLength;
		break;
					   }
	case FJSON_ARRAY_START: {
		/* Binary JSON array */
		jx9_hashmap *pMap;
		jx9_value sVal;
		/* Allocate a new hashmap */
		pMap = (jx9_hashmap *)jx9NewHashmap(pOut->pVm,0,0);
		if( pMap == 0 ){
			rc = SXERR_MEM;
			break;
		}
		jx9MemObjInit(pOut->pVm,&sVal);
		jx9MemObjRelease(pOut);
		MemObjSetType(pOut,MEMOBJ_HASHMAP);
		pOut->x.pOther = pMap;
		rc = SXRET_OK;
		for(;;){
			/* Jump leading binary commas */
			while (zIn < zEnd && zIn[0] == FJSON_COMMA ){
				zIn++;
			}
			if( zIn >= zEnd || zIn[0] == FJSON_ARRAY_END ){
				if( zIn < zEnd ){
					zIn++; /* Jump the trailing binary ] */
				}
				break;
			}
			/* Decode the value */
			rc = FastJsonDecode((const void *)zIn,(sxu32)(zEnd-zIn),&sVal,&zIn,iNest+1);
			if( rc != SXRET_OK ){
				break;
			}
			/* Insert the decoded value */
			rc = jx9HashmapInsert(pMap,0,&sVal);
			if( rc != UNQLITE_OK ){
				break;
			}
		}
		if( rc != SXRET_OK ){
			jx9MemObjRelease(pOut);
		}
		jx9MemObjRelease(&sVal);
		break;
							}
	case FJSON_DOC_START: {
		/* Binary JSON object */
		jx9_value sVal,sKey;
		jx9_hashmap *pMap;
		/* Allocate a new hashmap */
		pMap = (jx9_hashmap *)jx9NewHashmap(pOut->pVm,0,0);
		if( pMap == 0 ){
			rc = SXERR_MEM;
			break;
		}
		jx9MemObjInit(pOut->pVm,&sVal);
		jx9MemObjInit(pOut->pVm,&sKey);
		jx9MemObjRelease(pOut);
		MemObjSetType(pOut,MEMOBJ_HASHMAP);
		pOut->x.pOther = pMap;
		rc = SXRET_OK;
		for(;;){
			/* Jump leading binary commas */
			while (zIn < zEnd && zIn[0] == FJSON_COMMA ){
				zIn++;
			}
			if( zIn >= zEnd || zIn[0] == FJSON_DOC_END ){
				if( zIn < zEnd ){
					zIn++; /* Jump the trailing binary } */
				}
				break;
			}
			/* Extract the key */
			rc = FastJsonDecode((const void *)zIn,(sxu32)(zEnd-zIn),&sKey,&zIn,iNest+1);
			if( rc != UNQLITE_OK ){
				break;
			}
			if( zIn >= zEnd || zIn[0] != FJSON_COLON ){
				rc = UNQLITE_CORRUPT;
				break;
			}
			zIn++; /* Jump the binary colon ':' */
			if( zIn >= zEnd ){
				rc = UNQLITE_CORRUPT;
				break;
			}
			/* Decode the value */
			rc = FastJsonDecode((const void *)zIn,(sxu32)(zEnd-zIn),&sVal,&zIn,iNest+1);
			if( rc != SXRET_OK ){
				break;
			}
			/* Insert the key and its associated value */
			rc = jx9HashmapInsert(pMap,&sKey,&sVal);
			if( rc != UNQLITE_OK ){
				break;
			}
		}
		if( rc != SXRET_OK ){
			jx9MemObjRelease(pOut);
		}
		jx9MemObjRelease(&sVal);
		jx9MemObjRelease(&sKey);
		break;
						  }
	default:
		/* Corrupt data */
		rc = SXERR_CORRUPT;
		break;
	}
	if( pzPtr ){
		*pzPtr = zIn;
	}
	return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, -0x30(%rbp)
movl $0xfffffff9, %r15d      # imm = 0xFFFFFFF9
cmpl $0x3f, %r8d
jg 0x3f350
movq %rdx, %r14
movq %rdi, %r13
movl %esi, %ebx
addq %rdi, %rbx
movzbl (%rdi), %edi
leaq 0x1(%r13), %rax
movq %rax, -0x30(%rbp)
movl $0xffffffe8, %r15d      # imm = 0xFFFFFFE8
leal -0x1(%rdi), %edx
cmpl $0x9, %edx
jbe 0x3ef8e
addl $-0x12, %edi
cmpl $0x7, %edi
ja 0x3f344
leaq 0x356ad(%rip), %rdx     # 0x745cc
movslq (%rdx,%rdi,4), %rdi
addq %rdx, %rdi
jmpq *%rdi
movq $0x0, -0x80(%rbp)
movl $0xffffffe8, %r15d      # imm = 0xFFFFFFE8
cmpl $0x4, %esi
jb 0x3f344
movzwl 0x1(%r13), %edx
rolw $0x8, %dx
movzwl %dx, %r12d
addq %r12, %rax
cmpq %rbx, %rax
jae 0x3f344
addq $0x3, %r13
movq %r13, -0x30(%rbp)
leaq -0x80(%rbp), %r15
movq %r13, %rdi
movl %r12d, %esi
movq %r15, %rdx
movq %rcx, %rbx
callq 0x3f365
addq %r12, %r13
movq %r13, -0x30(%rbp)
movsd (%r15), %xmm0
movq %r14, %rdi
callq 0x30837
jmp 0x3f2e2
movl %r8d, %r12d
leaq 0x3560c(%rip), %rdi     # 0x745a4
movslq (%rdi,%rdx,4), %rdx
addq %rdi, %rdx
jmpq *%rdx
movq %rcx, -0x40(%rbp)
movq 0x10(%r14), %rdi
callq 0x3f840
testq %rax, %rax
je 0x3f2ea
movq %rax, %r15
movq 0x10(%r14), %rax
xorps %xmm0, %xmm0
leaq -0x80(%rbp), %rsi
movaps %xmm0, 0x10(%rsi)
movaps %xmm0, 0x30(%rsi)
movaps %xmm0, (%rsi)
movaps %xmm0, 0x20(%rsi)
movq %rax, 0x10(%rsi)
movq %rax, 0x18(%rsi)
xorl %ecx, %ecx
movl %ecx, 0x30(%rsi)
movl $0x20, %edx
movl %edx, 0x8(%rsi)
leaq -0xc0(%rbp), %rsi
movaps %xmm0, 0x10(%rsi)
movaps %xmm0, 0x30(%rsi)
movaps %xmm0, (%rsi)
movaps %xmm0, 0x20(%rsi)
movq %rax, 0x10(%rsi)
movq %rax, 0x18(%rsi)
movl %ecx, 0x30(%rsi)
movl %edx, 0x8(%rsi)
movq %r14, %rdi
callq 0x309f2
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%r14), %eax
orl $0x40, %eax
movl %eax, 0x8(%r14)
movq %r15, -0x38(%rbp)
movq %r15, (%r14)
incl %r12d
movq -0x30(%rbp), %rdi
cmpq %rbx, %rdi
setb %al
jae 0x3f31b
cmpb $0x6, (%rdi)
jne 0x3f069
incq %rdi
movq %rdi, -0x30(%rbp)
cmpq %rbx, %rdi
setb %al
jae 0x3f31b
leaq 0x1(%rdi), %rcx
cmpb $0x6, (%rdi)
movq %rcx, %rdi
je 0x3f047
decq %rcx
movq %rcx, %rdi
testb %al, %al
je 0x3f31b
cmpb $0x2, (%rdi)
je 0x3f310
movl %ebx, %esi
subl %edi, %esi
leaq -0xc0(%rbp), %rdx
leaq -0x30(%rbp), %rcx
movl %r12d, %r8d
callq 0x3eebc
testl %eax, %eax
jne 0x3f0f7
movq -0x30(%rbp), %rdi
movl $0xffffffe8, %r15d      # imm = 0xFFFFFFE8
cmpq %rbx, %rdi
jae 0x3f31e
cmpb $0x5, (%rdi)
jne 0x3f31e
incq %rdi
movq %rdi, -0x30(%rbp)
cmpq %rbx, %rdi
jae 0x3f31e
movl %ebx, %esi
subl %edi, %esi
leaq -0x80(%rbp), %r13
movq %r13, %rdx
leaq -0x30(%rbp), %rcx
movl %r12d, %r8d
callq 0x3eebc
testl %eax, %eax
jne 0x3f0f7
movq -0x38(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
movq %r13, %rdx
callq 0x3f924
testl %eax, %eax
je 0x3f02f
movl %eax, %r15d
jmp 0x3f31e
cmpl $0xa, %esi
jb 0x3f344
movq 0x1(%r13), %rbx
addq $0x9, %r13
bswapq %rbx
movq %r13, -0x30(%rbp)
movq %r14, %rdi
movq %rcx, %r15
callq 0x309f2
movq %r15, %rcx
movq %rbx, (%r14)
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%r14), %eax
orl $0x2, %eax
jmp 0x3f2d1
cmpl $0x6, %esi
jb 0x3f344
movl 0x1(%r13), %r12d
bswapl %r12d
addq %r12, %rax
cmpq %rbx, %rax
jae 0x3f344
movq %rcx, %rbx
addq $0x5, %r13
movq %r13, -0x30(%rbp)
testb $0x1, 0x8(%r14)
je 0x3f18e
movl $0x0, 0x28(%r14)
movl 0x30(%r14), %eax
testb $0x4, %al
je 0x3f18e
movq $0x0, 0x20(%r14)
movl $0x0, 0x2c(%r14)
andl $-0x5, %eax
movl %eax, 0x30(%r14)
movq %r14, %rdi
movq %r13, %rsi
movl %r12d, %edx
callq 0x3f7f6
movl %eax, %r15d
addq %r12, -0x30(%rbp)
movq %rbx, %rcx
jmp 0x3f344
movq %rcx, -0x40(%rbp)
movq 0x10(%r14), %rdi
callq 0x3f840
testq %rax, %rax
je 0x3f2ea
movq %rax, %r15
movq 0x10(%r14), %rax
xorps %xmm0, %xmm0
leaq -0x80(%rbp), %r13
movaps %xmm0, 0x10(%r13)
movaps %xmm0, 0x30(%r13)
movaps %xmm0, (%r13)
movaps %xmm0, 0x20(%r13)
movq %rax, 0x10(%r13)
movq %rax, 0x18(%r13)
movl $0x0, 0x30(%r13)
movl $0x20, 0x8(%r13)
movq %r14, %rdi
callq 0x309f2
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%r14), %eax
orl $0x40, %eax
movl %eax, 0x8(%r14)
movq %r15, -0x38(%rbp)
movq %r15, (%r14)
incl %r12d
xorl %r15d, %r15d
movq -0x30(%rbp), %rdi
cmpq %rbx, %rdi
setb %al
jae 0x3f2fd
cmpb $0x6, (%rdi)
jne 0x3f25a
incq %rdi
movq %rdi, -0x30(%rbp)
cmpq %rbx, %rdi
setb %al
jae 0x3f2fd
leaq 0x1(%rdi), %rcx
cmpb $0x6, (%rdi)
movq %rcx, %rdi
je 0x3f238
decq %rcx
movq %rcx, %rdi
testb %al, %al
je 0x3f2fd
cmpb $0x4, (%rdi)
je 0x3f2f2
movl %ebx, %esi
subl %edi, %esi
movq %r13, %rdx
leaq -0x30(%rbp), %rcx
movl %r12d, %r8d
callq 0x3eebc
testl %eax, %eax
jne 0x3f294
movq -0x38(%rbp), %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x3f924
testl %eax, %eax
je 0x3f220
movl %eax, %r15d
jmp 0x3f2fd
movq %r14, %rdi
movq %rcx, %rbx
callq 0x309f2
movq %rbx, %rcx
movq $0x0, (%r14)
jmp 0x3f2c5
movq %r14, %rdi
movq %rcx, %rbx
callq 0x309f2
movq %rbx, %rcx
movq $0x1, (%r14)
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%r14), %eax
orl $0x8, %eax
movl %eax, 0x8(%r14)
jmp 0x3f2e5
movq %r14, %rdi
movq %rcx, %rbx
callq 0x309f2
movq %rbx, %rcx
xorl %r15d, %r15d
jmp 0x3f344
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x3f340
testb %al, %al
je 0x3f2fd
incq %rdi
movq %rdi, -0x30(%rbp)
testl %r15d, %r15d
je 0x3f30a
movq %r14, %rdi
callq 0x309f2
leaq -0x80(%rbp), %rdi
jmp 0x3f33b
testb %al, %al
je 0x3f31b
incq %rdi
movq %rdi, -0x30(%rbp)
xorl %r15d, %r15d
testl %r15d, %r15d
je 0x3f32b
movq %r14, %rdi
callq 0x309f2
leaq -0x80(%rbp), %rdi
callq 0x309f2
leaq -0xc0(%rbp), %rdi
callq 0x309f2
movq -0x40(%rbp), %rcx
testq %rcx, %rcx
je 0x3f350
movq -0x30(%rbp), %rax
movq %rax, (%rcx)
movl %r15d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq