// File: /workspace/github_c_makefile_star2_O1/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: VmJsonDecode
static sxi32 VmJsonDecode(
	json_decoder *pDecoder, /* JSON decoder */      
	jx9_value *pArrayKey    /* Key for the decoded array */
	){
	jx9_value *pWorker; /* Worker variable */
	sxi32 rc;
	/* Check if we do not nest to much */
	if( pDecoder->rec_count > 31 ){
		/* Nesting limit reached, abort decoding immediately */
		return SXERR_ABORT;
	}
	if( pDecoder->pIn->nType & (JSON_TK_STR|JSON_TK_ID|JSON_TK_TRUE|JSON_TK_FALSE|JSON_TK_NULL|JSON_TK_NUM) ){
		/* Scalar value */
		pWorker = jx9_context_new_scalar(pDecoder->pCtx);
		if( pWorker == 0 ){
			jx9_context_throw_error(pDecoder->pCtx, JX9_CTX_ERR, "JX9 is running out of memory");
			/* Abort the decoding operation immediately */
			return SXERR_ABORT;
		}
		/* Reflect the JSON image */
		if( pDecoder->pIn->nType & JSON_TK_NULL ){
			/* Nullify the value.*/
			jx9_value_null(pWorker);
		}else if( pDecoder->pIn->nType & (JSON_TK_TRUE|JSON_TK_FALSE) ){
			/* Boolean value */
			jx9_value_bool(pWorker, (pDecoder->pIn->nType & JSON_TK_TRUE) ? 1 : 0 );
		}else if( pDecoder->pIn->nType & JSON_TK_NUM ){
			SyString *pStr = &pDecoder->pIn->sData;
			/* 
			 * Numeric value.
			 * Get a string representation first then try to get a numeric
			 * value.
			 */
			jx9_value_string(pWorker, pStr->zString, (int)pStr->nByte);
			/* Obtain a numeric representation */
			jx9MemObjToNumeric(pWorker);
		}else if( pDecoder->pIn->nType & JSON_TK_ID ){
			SyString *pStr = &pDecoder->pIn->sData;
			jx9_value_string(pWorker, pStr->zString, (int)pStr->nByte);
		}else{
			/* Dequote the string */
			VmJsonDequoteString(&pDecoder->pIn->sData, pWorker);
		}
		/* Invoke the consumer callback */
		rc = pDecoder->xConsumer(pDecoder->pCtx, pArrayKey, pWorker, pDecoder->pUserData);
		if( rc == SXERR_ABORT ){
			return SXERR_ABORT;
		}
		/* All done, advance the stream cursor */
		pDecoder->pIn++;
	}else if( pDecoder->pIn->nType & JSON_TK_OSB /*'[' */) {
		ProcJSONConsumer xOld;
		void *pOld;
		/* Array representation*/
		pDecoder->pIn++;
		/* Create a working array */
		pWorker = jx9_context_new_array(pDecoder->pCtx);
		if( pWorker == 0 ){
			jx9_context_throw_error(pDecoder->pCtx, JX9_CTX_ERR, "JX9 is running out of memory");
			/* Abort the decoding operation immediately */
			return SXERR_ABORT;
		}
		/* Save the old consumer */
		xOld = pDecoder->xConsumer;
		pOld = pDecoder->pUserData;
		/* Set the new consumer */
		pDecoder->xConsumer = VmJsonArrayDecoder;
		pDecoder->pUserData = pWorker;
		/* Decode the array */
		for(;;){
			/* Jump trailing comma. Note that the standard JX9 engine will not let you
			 * do this.
			 */
			while( (pDecoder->pIn < pDecoder->pEnd) && (pDecoder->pIn->nType & JSON_TK_COMMA) ){
				pDecoder->pIn++;
			}
			if( pDecoder->pIn >= pDecoder->pEnd || (pDecoder->pIn->nType & JSON_TK_CSB) /*']'*/ ){
				if( pDecoder->pIn < pDecoder->pEnd ){
					pDecoder->pIn++; /* Jump the trailing ']' */
				}
				break;
			}
			/* Recurse and decode the entry */
			pDecoder->rec_count++;
			rc = VmJsonDecode(pDecoder, 0);
			pDecoder->rec_count--;
			if( rc == SXERR_ABORT ){
				/* Abort processing immediately */
				return SXERR_ABORT;
			}
			/*The cursor is automatically advanced by the VmJsonDecode() function */
			if( (pDecoder->pIn < pDecoder->pEnd) &&
				((pDecoder->pIn->nType & (JSON_TK_CSB/*']'*/|JSON_TK_COMMA/*','*/))==0) ){
					/* Unexpected token, abort immediatley */
					*pDecoder->pErr = SXERR_SYNTAX;
					return SXERR_ABORT;
			}
		}
		/* Restore the old consumer */
		pDecoder->xConsumer = xOld;
		pDecoder->pUserData = pOld;
		/* Invoke the old consumer on the decoded array */
		xOld(pDecoder->pCtx, pArrayKey, pWorker, pOld);
	}else if( pDecoder->pIn->nType & JSON_TK_OCB /*'{' */) {
		ProcJSONConsumer xOld;
		jx9_value *pKey;
		void *pOld;
		/* Object representation*/
		pDecoder->pIn++;
		/* Create a working array */
		pWorker = jx9_context_new_array(pDecoder->pCtx);
		pKey = jx9_context_new_scalar(pDecoder->pCtx);
		if( pWorker == 0 || pKey == 0){
			jx9_context_throw_error(pDecoder->pCtx, JX9_CTX_ERR, "JX9 is running out of memory");
			/* Abort the decoding operation immediately */
			return SXERR_ABORT;
		}
		/* Save the old consumer */
		xOld = pDecoder->xConsumer;
		pOld = pDecoder->pUserData;
		/* Set the new consumer */
		pDecoder->xConsumer = VmJsonArrayDecoder;
		pDecoder->pUserData = pWorker;
		/* Decode the object */
		for(;;){
			/* Jump trailing comma. Note that the standard JX9 engine will not let you
			 * do this.
			 */
			while( (pDecoder->pIn < pDecoder->pEnd) && (pDecoder->pIn->nType & JSON_TK_COMMA) ){
				pDecoder->pIn++;
			}
			if( pDecoder->pIn >= pDecoder->pEnd || (pDecoder->pIn->nType & JSON_TK_CCB) /*'}'*/ ){
				if( pDecoder->pIn < pDecoder->pEnd ){
					pDecoder->pIn++; /* Jump the trailing ']' */
				}
				break;
			}
			if( (pDecoder->pIn->nType & (JSON_TK_ID|JSON_TK_STR)) == 0 || &pDecoder->pIn[1] >= pDecoder->pEnd
				|| (pDecoder->pIn[1].nType & JSON_TK_COLON) == 0){
					/* Syntax error, return immediately */
					*pDecoder->pErr = SXERR_SYNTAX;
					return SXERR_ABORT;
			}
			if( pDecoder->pIn->nType & JSON_TK_ID ){
				SyString *pStr = &pDecoder->pIn->sData;
				jx9_value_string(pKey, pStr->zString, (int)pStr->nByte);
			}else{
				/* Dequote the key */
				VmJsonDequoteString(&pDecoder->pIn->sData, pKey);
			}
			/* Jump the key and the colon */
			pDecoder->pIn += 2; 
			/* Recurse and decode the value */
			pDecoder->rec_count++;
			rc = VmJsonDecode(pDecoder, pKey);
			pDecoder->rec_count--;
			if( rc == SXERR_ABORT ){
				/* Abort processing immediately */
				return SXERR_ABORT;
			}
			/* Reset the internal buffer of the key */
			jx9_value_reset_string_cursor(pKey);
			/*The cursor is automatically advanced by the VmJsonDecode() function */
		}
		/* Restore the old consumer */
		pDecoder->xConsumer = xOld;
		pDecoder->pUserData = pOld;
		/* Invoke the old consumer on the decoded object*/
		xOld(pDecoder->pCtx, pArrayKey, pWorker, pOld);
		/* Release the key */
		jx9_context_release_value(pDecoder->pCtx, pKey);
	}else{
		/* Unexpected token */
		return SXERR_ABORT; /* Abort immediately */
	}
	/* Release the worker variable */
	jx9_context_release_value(pDecoder->pCtx, pWorker);
	return SXRET_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl $0xfffffff6, %ebx       # imm = 0xFFFFFFF6
cmpl $0x1f, 0x30(%rdi)
jg 0x5284c
movq %rsi, %r15
movq %rdi, %r14
movq 0x20(%rdi), %rax
movl 0x10(%rax), %ecx
testl $0x81f, %ecx            # imm = 0x81F
je 0x524f8
movq (%r14), %rdi
callq 0x317a5
testq %rax, %rax
je 0x52776
movq %rax, %r12
movq 0x20(%r14), %rdi
movl 0x10(%rdi), %r13d
testb $0x8, %r13b
jne 0x52662
testb $0x3, %r13b
je 0x5279a
andl $0x1, %r13d
movq %r12, %rdi
callq 0x309f2
movq %r13, (%r12)
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%r12), %eax
orl $0x8, %eax
movl %eax, 0x8(%r12)
jmp 0x5266a
testb %cl, %cl
js 0x5268e
testb $0x20, %cl
je 0x5284c
addq $0x20, %rax
movq %rax, 0x20(%r14)
movq (%r14), %rdi
callq 0x317eb
movq %rax, %r12
movq (%r14), %rdi
callq 0x317a5
movq %rax, %r13
testq %r12, %r12
sete %al
testq %r13, %r13
sete %cl
orb %al, %cl
cmpb $0x1, %cl
je 0x52776
movq 0x8(%r14), %r8
movq 0x10(%r14), %rcx
leaq 0x3cd(%rip), %rax       # 0x5291a
movq %rax, 0x8(%r14)
movq %r12, 0x10(%r14)
movq 0x28(%r14), %rax
movq 0x20(%r14), %rdi
cmpq %rax, %rdi
setb %sil
jae 0x52820
movq %r8, -0x30(%rbp)
movq %rcx, -0x38(%rbp)
testb $0x4, 0x11(%rdi)
je 0x525a1
addq $0x20, %rdi
cmpq %rax, %rdi
setb %sil
jae 0x5281c
leaq 0x20(%rdi), %rdx
testb $0x4, 0x11(%rdi)
movq %rdx, %rdi
jne 0x5257c
addq $-0x20, %rdx
movq %rdx, 0x20(%r14)
movq %rdx, %rdi
testb $0x1, %sil
je 0x52820
movl 0x10(%rdi), %edx
testb $0x40, %dl
jne 0x52812
testl $0x804, %edx            # imm = 0x804
je 0x527e2
leaq 0x20(%rdi), %rsi
cmpq %rax, %rsi
jae 0x527e2
testb $0x2, 0x31(%rdi)
je 0x527e2
btl $0xb, %edx
jb 0x525ea
movq %r13, %rsi
callq 0x5285d
jmp 0x525f8
movq (%rdi), %rsi
movl 0x8(%rdi), %edx
movq %r13, %rdi
callq 0x3087c
addq $0x40, 0x20(%r14)
incl 0x30(%r14)
movq %r14, %rdi
movq %r13, %rsi
callq 0x5246c
decl 0x30(%r14)
cmpl $-0xa, %eax
je 0x5284c
movl $0x0, 0x28(%r13)
movl 0x30(%r13), %eax
testb $0x4, %al
je 0x52640
movq $0x0, 0x20(%r13)
movl $0x0, 0x2c(%r13)
andl $-0x5, %eax
movl %eax, 0x30(%r13)
movq 0x20(%r14), %rdi
movq 0x28(%r14), %rax
cmpq %rax, %rdi
setb %sil
movq -0x30(%rbp), %r8
movq -0x38(%rbp), %rcx
jb 0x52572
jmp 0x52820
movq %r12, %rdi
callq 0x309f2
movq (%r14), %rdi
movq 0x10(%r14), %rcx
movq %r15, %rsi
movq %r12, %rdx
callq *0x8(%r14)
cmpl $-0xa, %eax
je 0x5284c
addq $0x20, 0x20(%r14)
jmp 0x5283f
addq $0x20, %rax
movq %rax, 0x20(%r14)
movq (%r14), %rdi
callq 0x317eb
testq %rax, %rax
je 0x52776
movq %rax, %r12
movq 0x8(%r14), %r13
movq 0x10(%r14), %rcx
leaq 0x261(%rip), %rax       # 0x5291a
movq %rax, 0x8(%r14)
movq %r12, 0x10(%r14)
movq 0x28(%r14), %rdx
movq 0x20(%r14), %rax
cmpq %rdx, %rax
setb %dil
jae 0x527fc
movq %r12, -0x30(%rbp)
testb $0x4, 0x11(%rax)
je 0x52709
addq $0x20, %rax
cmpq %rdx, %rax
setb %dil
jae 0x527f8
leaq 0x20(%rax), %rsi
testb $0x4, 0x11(%rax)
movq %rsi, %rax
jne 0x526e4
addq $-0x20, %rsi
movq %rsi, 0x20(%r14)
movq %rsi, %rax
testb $0x1, %dil
je 0x527fc
testb $0x1, 0x11(%rax)
jne 0x527ee
movq %r15, %r12
movq %rcx, %r15
incl 0x30(%r14)
movq %r14, %rdi
xorl %esi, %esi
callq 0x5246c
decl 0x30(%r14)
cmpl $-0xa, %eax
je 0x5284c
movq 0x20(%r14), %rax
cmpq 0x28(%r14), %rax
jae 0x52752
testb $0x5, 0x11(%rax)
je 0x527e2
movq 0x20(%r14), %rax
movq 0x28(%r14), %rdx
cmpq %rdx, %rax
setb %dil
movq %r15, %rcx
movq %r12, %r15
movq -0x30(%rbp), %r12
jb 0x526da
jmp 0x527fc
movq (%r14), %rax
movq (%rax), %rsi
movq 0x60(%rax), %rdi
addq $0x8, %rsi
leaq 0x25b3a(%rip), %rcx     # 0x782c5
movl $0x1, %edx
callq 0x4153c
jmp 0x5284c
testb $0x10, %r13b
jne 0x527b4
btl $0xb, %r13d
jb 0x527cf
movq %r12, %rsi
callq 0x5285d
jmp 0x5266a
movq (%rdi), %rsi
movl 0x8(%rdi), %edx
movq %r12, %rdi
callq 0x3087c
movq %r12, %rdi
callq 0x4494c
jmp 0x5266a
movq (%rdi), %rsi
movl 0x8(%rdi), %edx
movq %r12, %rdi
callq 0x3087c
jmp 0x5266a
movq 0x38(%r14), %rax
movl $0xfffffff4, (%rax)     # imm = 0xFFFFFFF4
jmp 0x5284c
testb $0x1, %dil
je 0x527fc
addq $0x20, %rax
movq %rax, 0x20(%r14)
movq %r13, 0x8(%r14)
movq %rcx, 0x10(%r14)
movq (%r14), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq *%r13
jmp 0x5283f
testb $0x1, %sil
je 0x52820
addq $0x20, %rdi
movq %rdi, 0x20(%r14)
movq %r8, 0x8(%r14)
movq %rcx, 0x10(%r14)
movq (%r14), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq *%r8
movq (%r14), %rdi
movq %r13, %rsi
callq 0x31831
movq (%r14), %rdi
movq %r12, %rsi
callq 0x31831
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq