// File: /workspace/github_c_makefile_star2_O2/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, %r12d
cmpl $0x3f, %r8d
jle 0x35fe6
pushq $-0x7
popq %r13
jmp 0x363c9
movq %rdx, %r8
movq %rdi, %rbx
movl %esi, %r15d
addq %rdi, %r15
movzbl (%rdi), %eax
leaq 0x1(%rdi), %r14
movq %r14, -0x30(%rbp)
pushq $-0x18
popq %r13
leal -0x1(%rax), %edx
cmpl $0x9, %edx
jbe 0x36091
addl $-0x12, %eax
cmpl $0x7, %eax
ja 0x363bd
leaq 0x2c59c(%rip), %rdx     # 0x625bc
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
andq $0x0, -0x88(%rbp)
cmpl $0x4, %esi
jb 0x363bd
movzwl 0x1(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %r12d
addq %r12, %r14
cmpq %r15, %r14
jae 0x363bd
addq $0x3, %rbx
movq %rbx, -0x30(%rbp)
leaq -0x88(%rbp), %r14
movq %rbx, %rdi
movl %r12d, %esi
movq %r14, %rdx
movq %rcx, %r15
movq %r8, %r13
callq 0x36406
addq %r12, %rbx
movq %rbx, -0x30(%rbp)
movsd (%r14), %xmm0
movq %r13, %rdi
callq 0x29543
movq %r15, %rcx
jmp 0x3637f
leaq 0x2c4fc(%rip), %rax     # 0x62594
movslq (%rax,%rdx,4), %rdx
addq %rax, %rdx
jmpq *%rdx
movl %esi, %r14d
movq %rcx, -0x40(%rbp)
movq 0x10(%r8), %rdi
movq %r8, %r13
callq 0x368e4
testq %rax, %rax
je 0x36384
movq 0x10(%r13), %rdi
leaq -0x88(%rbp), %rsi
movq %rax, -0x48(%rbp)
callq 0x35772
movq 0x10(%r13), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x35772
movq %r13, %rdi
callq 0x296af
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%r13), %eax
orl $0x40, %eax
movl %eax, 0x8(%r13)
movq -0x48(%rbp), %rax
movq %rax, (%r13)
incl %r12d
addl %ebx, %r14d
leaq -0x30(%rbp), %rcx
movq %r13, %rdx
movq -0x30(%rbp), %rdi
movl %r14d, %esi
subl %edi, %esi
xorl %r13d, %r13d
cmpq %r15, %rdi
jae 0x363a1
movzbl (%rdi), %eax
cmpl $0x6, %eax
jne 0x36136
incq %rdi
movq %rdi, -0x30(%rbp)
decl %esi
jmp 0x36117
cmpl $0x2, %eax
je 0x3639a
movl %r14d, -0x38(%rbp)
movq %rdx, %r13
leaq -0xc8(%rbp), %rdx
movq %rcx, %rbx
movl %r12d, %r8d
callq 0x35fc0
testl %eax, %eax
jne 0x363e3
movq -0x30(%rbp), %rdi
cmpq %r15, %rdi
movq %r13, %rdx
jae 0x363de
cmpb $0x5, (%rdi)
jne 0x363de
incq %rdi
movq %rdi, -0x30(%rbp)
cmpq %r15, %rdi
jae 0x363de
movl %r15d, %esi
subl %edi, %esi
leaq -0x88(%rbp), %r14
movq %r14, %rdx
movq %rbx, %rcx
movl %r12d, %r8d
callq 0x35fc0
testl %eax, %eax
jne 0x363e3
movq -0x48(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
movq %r14, %rdx
callq 0x36999
testl %eax, %eax
movq %r13, %rdx
movl -0x38(%rbp), %r14d
movq %rbx, %rcx
je 0x3610e
movl %eax, %ebx
jmp 0x363e8
cmpl $0xa, %esi
jb 0x363bd
addq $0x9, %rbx
leaq -0x88(%rbp), %r15
movq %r14, %rdi
movq %r15, %rsi
movq %rcx, %r14
movq %r8, %r12
callq 0x2f685
movq %rbx, -0x30(%rbp)
movq (%r15), %rsi
movq %r12, %rdi
callq 0x294c2
movq %r14, %rcx
jmp 0x3637f
cmpl $0x6, %esi
jb 0x363bd
movq %r8, -0x38(%rbp)
leaq -0x88(%rbp), %r12
movq %r14, %rdi
movq %r12, %rsi
movq %rcx, -0x40(%rbp)
callq 0x2f679
movq -0x40(%rbp), %rcx
movl (%r12), %r12d
addq %r12, %r14
cmpq %r15, %r14
jae 0x363bd
addq $0x5, %rbx
movq -0x38(%rbp), %rdi
testb $0x1, 0x8(%rdi)
je 0x36265
addq $0x18, %rdi
callq 0x31b1e
movq -0x38(%rbp), %rdi
movq %rbx, %rsi
movl %r12d, %edx
callq 0x3689a
movl %eax, %r13d
addq %r12, %rbx
movq %rbx, -0x30(%rbp)
jmp 0x363b9
movl %esi, %r14d
movq %rcx, -0x40(%rbp)
movq 0x10(%r8), %rdi
movq %r8, %r13
callq 0x368e4
testq %rax, %rax
je 0x36384
movq 0x10(%r13), %rdi
leaq -0x88(%rbp), %rsi
movq %rax, -0x48(%rbp)
callq 0x35772
movq %r13, %rdi
callq 0x296af
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%r13), %eax
orl $0x40, %eax
movl %eax, 0x8(%r13)
movq -0x48(%rbp), %rax
movq %rax, (%r13)
incl %r12d
addl %ebx, %r14d
leaq -0x30(%rbp), %rcx
movq %r13, %r8
movq -0x30(%rbp), %rdi
movl %r14d, %esi
subl %edi, %esi
leaq -0x88(%rbp), %rdx
xorl %r13d, %r13d
cmpq %r15, %rdi
jae 0x36391
movzbl (%rdi), %eax
cmpl $0x6, %eax
jne 0x3630b
incq %rdi
movq %rdi, -0x30(%rbp)
decl %esi
jmp 0x362ec
cmpl $0x4, %eax
je 0x3638a
movq %r8, -0x38(%rbp)
movq %rcx, %rbx
movl %r12d, %r8d
callq 0x35fc0
testl %eax, %eax
jne 0x363f5
movq -0x48(%rbp), %rdi
xorl %esi, %esi
leaq -0x88(%rbp), %rdx
callq 0x36999
testl %eax, %eax
movq -0x38(%rbp), %r8
movq %rbx, %rcx
je 0x362dc
movl %eax, %r13d
jmp 0x363fc
xorl %r13d, %r13d
movq %r8, %rdi
xorl %esi, %esi
movq %rcx, %rbx
callq 0x294f9
movq %rbx, %rcx
jmp 0x363bd
pushq $0x1
popq %rsi
movq %r8, %rdi
movq %rcx, %rbx
callq 0x294f9
jmp 0x3637c
movq %r8, %rdi
movq %rcx, %rbx
callq 0x296af
movq %rbx, %rcx
xorl %r13d, %r13d
jmp 0x363bd
pushq $-0x1
popq %r13
jmp 0x363b9
incq %rdi
movq %rdi, -0x30(%rbp)
leaq -0x88(%rbp), %rdi
jmp 0x363b4
incq %rdi
movq %rdi, -0x30(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x296af
leaq -0xc8(%rbp), %rdi
callq 0x296af
movq -0x40(%rbp), %rcx
testq %rcx, %rcx
je 0x363c9
movq -0x30(%rbp), %rax
movq %rax, (%rcx)
movl %r13d, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $-0x18
popq %rbx
jmp 0x363e8
movl %eax, %ebx
movq %r13, %rdx
movq %rdx, %rdi
callq 0x296af
movl %ebx, %r13d
jmp 0x363a1
movl %eax, %r13d
movq -0x38(%rbp), %r8
movq %r8, %rdi
callq 0x296af
jmp 0x36391