// File: /workspace/github_c_makefile_star2_O3/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 $0xa8, %rsp
movl %r8d, %r13d
movl $0xfffffff9, %r15d      # imm = 0xFFFFFFF9
cmpl $0x3f, %r8d
jg 0x3e931
movq %rdx, %r8
movl %esi, %r12d
movq %rdi, %rbx
movl %esi, %r14d
addq %rdi, %r14
movzbl (%rdi), %esi
leaq 0x1(%rdi), %rax
movq %rax, -0x30(%rbp)
movl $0xffffffe8, %r15d      # imm = 0xFFFFFFE8
leal -0x1(%rsi), %edx
cmpl $0x9, %edx
jbe 0x3e572
addl $-0x12, %esi
cmpl $0x7, %esi
ja 0x3e925
leaq 0x340e1(%rip), %rdx     # 0x725d8
movslq (%rdx,%rsi,4), %rsi
addq %rdx, %rsi
jmpq *%rsi
movq $0x0, -0x90(%rbp)
movl $0xffffffe8, %r15d      # imm = 0xFFFFFFE8
cmpl $0x4, %r12d
jb 0x3e925
movzwl 0x1(%rbx), %edx
rolw $0x8, %dx
movzwl %dx, %r12d
addq %r12, %rax
cmpq %r14, %rax
jae 0x3e925
addq $0x3, %rbx
movq %rbx, -0x30(%rbp)
leaq -0x90(%rbp), %r15
movq %rbx, %rdi
movl %r12d, %esi
movq %r15, %rdx
movq %rcx, %r14
movq %r8, %r13
callq 0x3e968
addq %r12, %rbx
movq %rbx, -0x30(%rbp)
movsd (%r15), %xmm0
movq %r13, %rdi
callq 0x302b1
movq %r14, %rcx
jmp 0x3e8e5
leaq 0x34037(%rip), %rsi     # 0x725b0
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
movq %rcx, -0x48(%rbp)
movq 0x10(%r8), %rdi
movq %r8, %r15
callq 0x3ee3d
testq %rax, %rax
je 0x3e8ea
movq 0x10(%r15), %rdx
xorps %xmm0, %xmm0
leaq -0x90(%rbp), %rsi
movaps %xmm0, 0x10(%rsi)
movaps %xmm0, (%rsi)
movaps %xmm0, 0x30(%rsi)
movaps %xmm0, 0x20(%rsi)
movq %rdx, 0x10(%rsi)
movq %rdx, 0x18(%rsi)
movl $0x20, %ecx
movl %ecx, 0x8(%rsi)
leaq -0xd0(%rbp), %rsi
movaps %xmm0, 0x10(%rsi)
movaps %xmm0, (%rsi)
movaps %xmm0, 0x20(%rsi)
movaps %xmm0, 0x30(%rsi)
movq %rdx, 0x10(%rsi)
movq %rdx, 0x18(%rsi)
movl %ecx, 0x8(%rsi)
movq %r15, %rdi
movq %rax, -0x40(%rbp)
callq 0x30465
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%r15), %eax
orl $0x40, %eax
movl %eax, 0x8(%r15)
movq -0x40(%rbp), %rax
movq %rax, (%r15)
incl %r13d
addl %ebx, %r12d
leaq -0x30(%rbp), %rcx
movq %r15, %rdx
movq -0x30(%rbp), %rdi
xorl %r15d, %r15d
cmpq %r14, %rdi
jae 0x3e909
movl %r12d, %esi
subl %edi, %esi
movzbl (%rdi), %eax
cmpl $0x6, %eax
jne 0x3e649
incq %rdi
movq %rdi, -0x30(%rbp)
decl %esi
cmpq %r14, %rdi
jb 0x3e62e
jmp 0x3e909
cmpl $0x2, %eax
je 0x3e902
movq %rdx, -0x38(%rbp)
leaq -0xd0(%rbp), %rdx
movq %rcx, %rbx
movl %r13d, %r8d
callq 0x3e491
testl %eax, %eax
jne 0x3e946
movq -0x30(%rbp), %rdi
movl $0xffffffe8, %r15d      # imm = 0xFFFFFFE8
cmpq %r14, %rdi
movq -0x38(%rbp), %rdx
jae 0x3e94d
cmpb $0x5, (%rdi)
jne 0x3e94d
incq %rdi
movq %rdi, -0x30(%rbp)
cmpq %r14, %rdi
jae 0x3e94d
movl %r14d, %esi
subl %edi, %esi
leaq -0x90(%rbp), %rdx
movq %rbx, %rcx
movl %r13d, %r8d
callq 0x3e491
testl %eax, %eax
jne 0x3e946
movq -0x40(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0x3ef1d
testl %eax, %eax
movq -0x38(%rbp), %rdx
movq %rbx, %rcx
je 0x3e619
movl %eax, %r15d
jmp 0x3e94d
cmpl $0xa, %r12d
jb 0x3e925
movq 0x1(%rbx), %r14
addq $0x9, %rbx
bswapq %r14
movq %rbx, -0x30(%rbp)
movq %r8, %rdi
movq %rcx, %rbx
movq %r8, %r15
callq 0x30465
movq %rbx, %rcx
movq %r14, (%r15)
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%r15), %eax
orl $0x2, %eax
movl %eax, 0x8(%r15)
jmp 0x3e8e5
cmpl $0x6, %r12d
jb 0x3e925
movl 0x1(%rbx), %r12d
bswapl %r12d
addq %r12, %rax
cmpq %r14, %rax
jae 0x3e925
movq %rcx, %r14
addq $0x5, %rbx
testb $0x1, 0x8(%r8)
je 0x3e781
movl $0x0, 0x28(%r8)
movl 0x30(%r8), %eax
testb $0x4, %al
je 0x3e781
movq $0x0, 0x20(%r8)
movl $0x0, 0x2c(%r8)
andl $-0x5, %eax
movl %eax, 0x30(%r8)
movq %r8, %rdi
movq %rbx, %rsi
movl %r12d, %edx
callq 0x3edf3
movl %eax, %r15d
addq %r12, %rbx
movq %rbx, -0x30(%rbp)
movq %r14, %rcx
jmp 0x3e925
movq %rcx, -0x48(%rbp)
movq 0x10(%r8), %rdi
movq %r8, -0x38(%rbp)
callq 0x3ee3d
testq %rax, %rax
je 0x3e8ea
movq %rax, %r15
movq -0x38(%rbp), %rcx
movq 0x10(%rcx), %rax
movq %rcx, %rdi
xorps %xmm0, %xmm0
leaq -0x90(%rbp), %rcx
movaps %xmm0, 0x10(%rcx)
movaps %xmm0, (%rcx)
movaps %xmm0, 0x30(%rcx)
movaps %xmm0, 0x20(%rcx)
movq %rax, 0x10(%rcx)
movq %rax, 0x18(%rcx)
movl $0x20, 0x8(%rcx)
callq 0x30465
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
movq -0x38(%rbp), %r8
andl 0x8(%r8), %eax
orl $0x40, %eax
movl %eax, 0x8(%r8)
movq %r15, -0x40(%rbp)
movq %r15, (%r8)
incl %r13d
addl %ebx, %r12d
leaq -0x30(%rbp), %rcx
xorl %r15d, %r15d
movq -0x30(%rbp), %rdi
cmpq %r14, %rdi
jae 0x3e8f9
movl %r12d, %esi
subl %edi, %esi
leaq -0x90(%rbp), %rdx
movzbl (%rdi), %eax
cmpl $0x6, %eax
jne 0x3e852
incq %rdi
movq %rdi, -0x30(%rbp)
decl %esi
cmpq %r14, %rdi
jb 0x3e837
jmp 0x3e8f9
cmpl $0x4, %eax
je 0x3e8f2
movq %rcx, %rbx
movl %r13d, %r8d
callq 0x3e491
testl %eax, %eax
jne 0x3e957
movq -0x40(%rbp), %rdi
xorl %esi, %esi
leaq -0x90(%rbp), %rdx
callq 0x3ef1d
testl %eax, %eax
movq -0x38(%rbp), %r8
movq %rbx, %rcx
je 0x3e81e
movl %eax, %r15d
jmp 0x3e95e
movq %r8, %rdi
movq %rcx, %rbx
movq %r8, %r14
callq 0x30465
movq %rbx, %rcx
movq $0x0, (%r14)
jmp 0x3e8c5
movq %r8, %rdi
movq %rcx, %rbx
movq %r8, %r14
callq 0x30465
movq %rbx, %rcx
movq $0x1, (%r14)
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%r14), %eax
orl $0x8, %eax
movl %eax, 0x8(%r14)
jmp 0x3e8e5
movq %r8, %rdi
movq %rcx, %rbx
callq 0x30465
movq %rbx, %rcx
xorl %r15d, %r15d
jmp 0x3e925
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x3e921
incq %rdi
movq %rdi, -0x30(%rbp)
leaq -0x90(%rbp), %rdi
jmp 0x3e91c
incq %rdi
movq %rdi, -0x30(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x30465
leaq -0xd0(%rbp), %rdi
callq 0x30465
movq -0x48(%rbp), %rcx
testq %rcx, %rcx
je 0x3e931
movq -0x30(%rbp), %rax
movq %rax, (%rcx)
movl %r15d, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %r15d
movq -0x38(%rbp), %rdx
movq %rdx, %rdi
callq 0x30465
jmp 0x3e909
movl %eax, %r15d
movq -0x38(%rbp), %r8
movq %r8, %rdi
callq 0x30465
jmp 0x3e8f9