// File: /workspace/github_c_makefile_star2_O0/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
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movl -0x14(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
cmpl $0x40, -0x2c(%rbp)
jl 0x6ecbd
movl $0xfffffff9, -0x4(%rbp) # imm = 0xFFFFFFF9
jmp 0x6f20e
movq -0x38(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x38(%rbp), %rax
incq %rax
movq %rax, -0x38(%rbp)
movl -0x48(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x138(%rbp)
subl $0x18, %eax
ja 0x6f1ef
movq -0x138(%rbp), %rax
leaq 0x51a85(%rip), %rcx     # 0xc077c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x20(%rbp), %rdi
callq 0x56880
jmp 0x6f1f6
movq -0x20(%rbp), %rdi
xorl %esi, %esi
callq 0x56800
jmp 0x6f1f6
movq -0x20(%rbp), %rdi
movl $0x1, %esi
callq 0x56800
jmp 0x6f1f6
movq -0x38(%rbp), %rax
addq $0x8, %rax
cmpq -0x40(%rbp), %rax
jb 0x6ed4b
movl $0xffffffe8, -0x44(%rbp) # imm = 0xFFFFFFE8
jmp 0x6f1f6
movq -0x38(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x61db0
movq -0x38(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x56780
jmp 0x6f1f6
xorps %xmm0, %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0x38(%rbp), %rax
addq $0x2, %rax
cmpq -0x40(%rbp), %rax
jb 0x6ed98
movl $0xffffffe8, -0x44(%rbp) # imm = 0xFFFFFFE8
jmp 0x6f1f6
movq -0x38(%rbp), %rdi
leaq -0x5a(%rbp), %rsi
callq 0x64c70
movq -0x38(%rbp), %rax
movzwl -0x5a(%rbp), %ecx
addq %rcx, %rax
cmpq -0x40(%rbp), %rax
jb 0x6edc2
movl $0xffffffe8, -0x44(%rbp) # imm = 0xFFFFFFE8
jmp 0x6f1f6
movq -0x38(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movzwl -0x5a(%rbp), %esi
leaq -0x58(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x6f220
movzwl -0x5a(%rbp), %ecx
movq -0x38(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rdi
movsd -0x58(%rbp), %xmm0
callq 0x568d0
jmp 0x6f1f6
movq -0x38(%rbp), %rax
addq $0x4, %rax
cmpq -0x40(%rbp), %rax
jb 0x6ee22
movl $0xffffffe8, -0x44(%rbp) # imm = 0xFFFFFFE8
jmp 0x6f1f6
movq -0x38(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x61d60
movq -0x38(%rbp), %rax
movl -0x60(%rbp), %ecx
addq %rcx, %rax
cmpq -0x40(%rbp), %rax
jb 0x6ee4b
movl $0xffffffe8, -0x44(%rbp) # imm = 0xFFFFFFE8
jmp 0x6f1f6
movq -0x38(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x6ee73
movq -0x20(%rbp), %rdi
addq $0x18, %rdi
callq 0x65e00
movq -0x20(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x60(%rbp), %edx
callq 0x6f9b0
movl %eax, -0x44(%rbp)
movl -0x60(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
jmp 0x6f1f6
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x6fa20
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0x6eec6
movl $0xffffffff, -0x44(%rbp) # imm = 0xFFFFFFFF
jmp 0x6f1f6
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x6da90
movq -0x20(%rbp), %rdi
callq 0x56ab0
movq -0x20(%rbp), %rax
movl 0x8(%rax), %ecx
andl $0xfffffe90, %ecx       # imm = 0xFFFFFE90
orl $0x40, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x68(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x44(%rbp)
jmp 0x6ef0e
movq -0x38(%rbp), %rcx
xorl %eax, %eax
cmpq -0x40(%rbp), %rcx
movb %al, -0x139(%rbp)
jae 0x6ef33
movq -0x38(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x6, %eax
sete %al
movb %al, -0x139(%rbp)
movb -0x139(%rbp), %al
testb $0x1, %al
jne 0x6ef3f
jmp 0x6ef4d
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x6ef0e
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x6ef63
movq -0x38(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x4, %eax
jne 0x6ef7b
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x6ef79
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x6efd3
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rcx, %rax
movl %eax, %esi
movl -0x2c(%rbp), %r8d
addl $0x1, %r8d
leaq -0xa8(%rbp), %rdx
leaq -0x38(%rbp), %rcx
callq 0x6ec70
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x6efaf
jmp 0x6efd3
movq -0x68(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq -0xa8(%rbp), %rdx
callq 0x6faf0
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x6efce
jmp 0x6efd3
jmp 0x6ef0c
cmpl $0x0, -0x44(%rbp)
je 0x6efe2
movq -0x20(%rbp), %rdi
callq 0x56ab0
leaq -0xa8(%rbp), %rdi
callq 0x56ab0
jmp 0x6f1f6
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x6fa20
movq %rax, -0x130(%rbp)
cmpq $0x0, -0x130(%rbp)
jne 0x6f024
movl $0xffffffff, -0x44(%rbp) # imm = 0xFFFFFFFF
jmp 0x6f1f6
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x6da90
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x128(%rbp), %rsi
callq 0x6da90
movq -0x20(%rbp), %rdi
callq 0x56ab0
movq -0x20(%rbp), %rax
movl 0x8(%rax), %ecx
andl $0xfffffe90, %ecx       # imm = 0xFFFFFE90
orl $0x40, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x130(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x44(%rbp)
jmp 0x6f083
movq -0x38(%rbp), %rcx
xorl %eax, %eax
cmpq -0x40(%rbp), %rcx
movb %al, -0x13a(%rbp)
jae 0x6f0a8
movq -0x38(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x6, %eax
sete %al
movb %al, -0x13a(%rbp)
movb -0x13a(%rbp), %al
testb $0x1, %al
jne 0x6f0b4
jmp 0x6f0c2
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x6f083
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x6f0d8
movq -0x38(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x2, %eax
jne 0x6f0f3
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x6f0ee
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x6f1c6
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rcx, %rax
movl %eax, %esi
movl -0x2c(%rbp), %r8d
addl $0x1, %r8d
leaq -0x128(%rbp), %rdx
leaq -0x38(%rbp), %rcx
callq 0x6ec70
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x6f12a
jmp 0x6f1c6
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x6f140
movq -0x38(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x5, %eax
je 0x6f149
movl $0xffffffe8, -0x44(%rbp) # imm = 0xFFFFFFE8
jmp 0x6f1c6
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jb 0x6f168
movl $0xffffffe8, -0x44(%rbp) # imm = 0xFFFFFFE8
jmp 0x6f1c6
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rcx, %rax
movl %eax, %esi
movl -0x2c(%rbp), %r8d
addl $0x1, %r8d
leaq -0xe8(%rbp), %rdx
leaq -0x38(%rbp), %rcx
callq 0x6ec70
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x6f19c
jmp 0x6f1c6
movq -0x130(%rbp), %rdi
leaq -0x128(%rbp), %rsi
leaq -0xe8(%rbp), %rdx
callq 0x6faf0
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x6f1c1
jmp 0x6f1c6
jmp 0x6f081
cmpl $0x0, -0x44(%rbp)
je 0x6f1d5
movq -0x20(%rbp), %rdi
callq 0x56ab0
leaq -0xe8(%rbp), %rdi
callq 0x56ab0
leaq -0x128(%rbp), %rdi
callq 0x56ab0
jmp 0x6f1f6
movl $0xffffffe8, -0x44(%rbp) # imm = 0xFFFFFFE8
cmpq $0x0, -0x28(%rbp)
je 0x6f208
movq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nopw (%rax,%rax)