// File: /workspace/github_c_makefile_star2_O3/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 0x510eb
movq %rsi, %r15
movq %rdi, %r14
movq 0x20(%rdi), %rax
movl 0x10(%rax), %ecx
testl $0x81f, %ecx            # imm = 0x81F
je 0x50e02
movq (%r14), %rdi
callq 0x311eb
testq %rax, %rax
je 0x5102c
movq %rax, %r12
movq 0x20(%r14), %rax
movl 0x10(%rax), %r13d
testb $0x8, %r13b
jne 0x50f47
testb $0x3, %r13b
je 0x51050
andl $0x1, %r13d
movq %r12, %rdi
callq 0x30465
movq %r13, (%r12)
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%r12), %eax
orl $0x8, %eax
movl %eax, 0x8(%r12)
jmp 0x50f4f
testb %cl, %cl
js 0x50f73
testb $0x20, %cl
je 0x510eb
addq $0x20, %rax
movq %rax, 0x20(%r14)
movq (%r14), %rdi
callq 0x31231
movq %rax, %r12
movq (%r14), %rdi
callq 0x311eb
movq %rax, %r13
testq %r12, %r12
sete %al
testq %r13, %r13
sete %cl
orb %al, %cl
cmpb $0x1, %cl
je 0x5102c
movq 0x8(%r14), %r8
movq 0x10(%r14), %rcx
leaq 0x363(%rip), %rax       # 0x511ba
movq %rax, 0x8(%r14)
movq %r12, 0x10(%r14)
movq 0x28(%r14), %rdi
movq 0x20(%r14), %rax
cmpq %rdi, %rax
jae 0x510bf
movl 0x10(%rax), %edx
btl $0xa, %edx
jb 0x50f3a
testb $0x40, %dl
jne 0x510b7
testl $0x804, %edx            # imm = 0x804
je 0x5101d
leaq 0x20(%rax), %rsi
cmpq %rdi, %rsi
jae 0x5101d
testb $0x2, 0x31(%rax)
je 0x5101d
movq %rcx, -0x38(%rbp)
movq %r8, -0x30(%rbp)
btl $0xb, %edx
movq (%rax), %rsi
movl 0x8(%rax), %edx
jb 0x50ecc
movq %rsi, %rdi
movl %edx, %esi
movq %r13, %rdx
callq 0x510fc
jmp 0x50ed4
movq %r13, %rdi
callq 0x302f6
addq $0x40, 0x20(%r14)
incl 0x30(%r14)
movq %r14, %rdi
movq %r13, %rsi
callq 0x50d76
decl 0x30(%r14)
cmpl $-0xa, %eax
je 0x510eb
movl $0x0, 0x28(%r13)
movl 0x30(%r13), %eax
testb $0x4, %al
je 0x50f1c
movq $0x0, 0x20(%r13)
movl $0x0, 0x2c(%r13)
andl $-0x5, %eax
movl %eax, 0x30(%r13)
movq 0x20(%r14), %rax
movq 0x28(%r14), %rdi
cmpq %rdi, %rax
movq -0x30(%rbp), %r8
movq -0x38(%rbp), %rcx
jb 0x50e70
jmp 0x510bf
addq $0x20, %rax
movq %rax, 0x20(%r14)
jmp 0x50e67
movq %r12, %rdi
callq 0x30465
movq (%r14), %rdi
movq 0x10(%r14), %rcx
movq %r15, %rsi
movq %r12, %rdx
callq *0x8(%r14)
cmpl $-0xa, %eax
je 0x510eb
addq $0x20, 0x20(%r14)
jmp 0x510de
addq $0x20, %rax
movq %rax, 0x20(%r14)
movq (%r14), %rdi
callq 0x31231
testq %rax, %rax
je 0x5102c
movq %rax, %r12
movq 0x8(%r14), %r13
movq 0x10(%r14), %rcx
leaq 0x21c(%rip), %rax       # 0x511ba
movq %rax, 0x8(%r14)
movq %r12, 0x10(%r14)
movq 0x28(%r14), %rsi
movq 0x20(%r14), %rax
cmpq %rsi, %rax
jae 0x510a1
addq $0x20, %rax
movl -0x10(%rax), %edx
btl $0xa, %edx
jae 0x50fd9
movq %rax, 0x20(%r14)
leaq 0x20(%rax), %rdx
cmpq %rsi, %rax
movq %rdx, %rax
jb 0x50fbb
jmp 0x510a1
btl $0x8, %edx
jb 0x5109d
movq %rcx, -0x30(%rbp)
incl 0x30(%r14)
movq %r14, %rdi
xorl %esi, %esi
callq 0x50d76
decl 0x30(%r14)
cmpl $-0xa, %eax
je 0x510eb
movq 0x20(%r14), %rax
movq 0x28(%r14), %rsi
cmpq %rsi, %rax
movq -0x30(%rbp), %rcx
jae 0x510a1
testb $0x5, 0x11(%rax)
jne 0x50fb7
movq 0x38(%r14), %rax
movl $0xfffffff4, (%rax)     # imm = 0xFFFFFFF4
jmp 0x510eb
movq (%r14), %rax
movq (%rax), %rsi
movq 0x60(%rax), %rdi
addq $0x8, %rsi
leaq 0x2528f(%rip), %rcx     # 0x762d0
movl $0x1, %edx
callq 0x40afa
jmp 0x510eb
testb $0x10, %r13b
jne 0x51075
btl $0xb, %r13d
movq (%rax), %rsi
movl 0x8(%rax), %edx
jb 0x51090
movq %rsi, %rdi
movl %edx, %esi
movq %r12, %rdx
callq 0x510fc
jmp 0x50f4f
movq (%rax), %rsi
movl 0x8(%rax), %edx
movq %r12, %rdi
callq 0x302f6
movq %r12, %rdi
callq 0x43b00
jmp 0x50f4f
movq %r12, %rdi
callq 0x302f6
jmp 0x50f4f
movq %rax, 0x20(%r14)
movq %r13, 0x8(%r14)
movq %rcx, 0x10(%r14)
movq (%r14), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq *%r13
jmp 0x510de
addq $0x20, %rax
movq %rax, 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 0x31277
movq (%r14), %rdi
movq %r12, %rsi
callq 0x31277
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq