// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: FastJsonEncode
UNQLITE_PRIVATE sxi32 FastJsonEncode(
	jx9_value *pValue, /* Value to encode */
	SyBlob *pOut,      /* Store encoded value here */
	int iNest          /* Nesting limit */ 
	)
{
	sxi32 iType = pValue ? pValue->iFlags : MEMOBJ_NULL;
	sxi32 rc = SXRET_OK;
	int c;
	if( iNest >= UNQLITE_FAST_JSON_NEST_LIMIT ){
		/* Nesting limit reached */
		return SXERR_LIMIT;
	}
	if( iType & (MEMOBJ_NULL|MEMOBJ_RES) ){
		/*
		 * Resources are encoded as null also.
		 */
		c = FJSON_NULL;
		rc = SyBlobAppend(pOut,(const void *)&c,sizeof(char));
	}else if( iType & MEMOBJ_BOOL ){
		c = pValue->x.iVal ? FJSON_TRUE : FJSON_FALSE;
		rc = SyBlobAppend(pOut,(const void *)&c,sizeof(char));
	}else if( iType & MEMOBJ_STRING ){
		unsigned char zBuf[sizeof(sxu32)]; /* String length */
		c = FJSON_STRING;
		SyBigEndianPack32(zBuf,SyBlobLength(&pValue->sBlob));
		rc = SyBlobAppend(pOut,(const void *)&c,sizeof(char));
		if( rc == SXRET_OK ){
			rc = SyBlobAppend(pOut,(const void *)zBuf,sizeof(zBuf));
			if( rc == SXRET_OK ){
				rc = SyBlobAppend(pOut,SyBlobData(&pValue->sBlob),SyBlobLength(&pValue->sBlob));
			}
		}
	}else if( iType & MEMOBJ_INT ){
		unsigned char zBuf[8];
		/* 64bit big endian integer */
		c = FJSON_INT64;
		rc = SyBlobAppend(pOut,(const void *)&c,sizeof(char));
		if( rc == SXRET_OK ){
			SyBigEndianPack64(zBuf,(sxu64)pValue->x.iVal);
			rc = SyBlobAppend(pOut,(const void *)zBuf,sizeof(zBuf));
		}
	}else if( iType & MEMOBJ_REAL ){
		/* Real number */
		c = FJSON_REAL;
		rc = SyBlobAppend(pOut,(const void *)&c,sizeof(char));
		if( rc == SXRET_OK ){
			sxu32 iOfft = SyBlobLength(pOut);
			rc = SyBlobAppendBig16(pOut,0);
			if( rc == SXRET_OK ){
				unsigned char *zBlob;
				SyBlobFormat(pOut,"%.15g",pValue->x.rVal);
				zBlob = (unsigned char *)SyBlobDataAt(pOut,iOfft);
				SyBigEndianPack16(zBlob,(sxu16)(SyBlobLength(pOut) - ( 2 + iOfft)));
			}
		}
	}else if( iType & MEMOBJ_HASHMAP ){
		/* A JSON object or array */
		jx9_hashmap *pMap = (jx9_hashmap *)pValue->x.pOther;
		jx9_hashmap_node *pNode;
		jx9_value *pEntry;
		/* Reset the hashmap loop cursor */
		jx9HashmapResetLoopCursor(pMap);
		if( pMap->iFlags & HASHMAP_JSON_OBJECT ){
			jx9_value sKey;
			/* A JSON object */
			c = FJSON_DOC_START; /* { */
			rc = SyBlobAppend(pOut,(const void *)&c,sizeof(char));
			if( rc == SXRET_OK ){
				jx9MemObjInit(pMap->pVm,&sKey);
				/* Encode object entries */
				while((pNode = jx9HashmapGetNextEntry(pMap)) != 0 ){
					/* Extract the key */
					jx9HashmapExtractNodeKey(pNode,&sKey);
					/* Encode it */
					rc = FastJsonEncode(&sKey,pOut,iNest+1);
					if( rc != SXRET_OK ){
						break;
					}
					c = FJSON_COLON;
					rc = SyBlobAppend(pOut,(const void *)&c,sizeof(char));
					if( rc != SXRET_OK ){
						break;
					}
					/* Extract the value */
					pEntry = jx9HashmapGetNodeValue(pNode);
					/* Encode it */
					rc = FastJsonEncode(pEntry,pOut,iNest+1);
					if( rc != SXRET_OK ){
						break;
					}
					/* Delimit the entry */
					c = FJSON_COMMA;
					rc = SyBlobAppend(pOut,(const void *)&c,sizeof(char));
					if( rc != SXRET_OK ){
						break;
					}
				}
				jx9MemObjRelease(&sKey);
				if( rc == SXRET_OK ){
					c = FJSON_DOC_END; /* } */
					rc = SyBlobAppend(pOut,(const void *)&c,sizeof(char));
				}
			}
		}else{
			/* A JSON array */
			c = FJSON_ARRAY_START; /* [ */
			rc = SyBlobAppend(pOut,(const void *)&c,sizeof(char));
			if( rc == SXRET_OK ){
				/* Encode array entries */
				while( (pNode = jx9HashmapGetNextEntry(pMap)) != 0 ){
					/* Extract the value */
					pEntry = jx9HashmapGetNodeValue(pNode);
					/* Encode it */
					rc = FastJsonEncode(pEntry,pOut,iNest+1);
					if( rc != SXRET_OK ){
						break;
					}
					/* Delimit the entry */
					c = FJSON_COMMA;
					rc = SyBlobAppend(pOut,(const void *)&c,sizeof(char));
					if( rc != SXRET_OK ){
						break;
					}
				}
				if( rc == SXRET_OK ){
					c = FJSON_ARRAY_END; /* ] */
					rc = SyBlobAppend(pOut,(const void *)&c,sizeof(char));
				}
			}
		}
	}
	return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x6e30c
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x9c(%rbp)
jmp 0x6e319
movl $0x20, %eax
movl %eax, -0x9c(%rbp)
jmp 0x6e319
movl -0x9c(%rbp), %eax
movl %eax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x40, -0x1c(%rbp)
jl 0x6e33b
movl $0xfffffff9, -0x4(%rbp) # imm = 0xFFFFFFF9
jmp 0x6e73f
movl -0x20(%rbp), %eax
andl $0x120, %eax            # imm = 0x120
cmpl $0x0, %eax
je 0x6e369
movl $0x17, -0x28(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0x1, %edx
callq 0x5d9d0
movl %eax, -0x24(%rbp)
jmp 0x6e739
movl -0x20(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x6e3a9
movq -0x10(%rbp), %rax
movq (%rax), %rdx
movl $0x19, %eax
movl $0x18, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0x1, %edx
callq 0x5d9d0
movl %eax, -0x24(%rbp)
jmp 0x6e737
movl -0x20(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x6e423
movl $0x8, -0x28(%rbp)
leaq -0x2c(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x28(%rax), %esi
callq 0x61bf0
movq -0x18(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0x1, %edx
callq 0x5d9d0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x6e41e
movq -0x18(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
movl $0x4, %edx
callq 0x5d9d0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x6e41c
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x10(%rbp), %rax
movl 0x28(%rax), %edx
callq 0x5d9d0
movl %eax, -0x24(%rbp)
jmp 0x6e41e
jmp 0x6e735
movl -0x20(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x6e47a
movl $0xa, -0x28(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0x1, %edx
callq 0x5d9d0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x6e475
leaq -0x34(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x61c60
movq -0x18(%rbp), %rdi
leaq -0x34(%rbp), %rsi
movl $0x8, %edx
callq 0x5d9d0
movl %eax, -0x24(%rbp)
jmp 0x6e733
movl -0x20(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x6e517
movl $0x12, -0x28(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0x1, %edx
callq 0x5d9d0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x6e512
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0x6e180
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x6e510
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movsd (%rax), %xmm0
leaq 0x54073(%rip), %rsi     # 0xc254f
movb $0x1, %al
callq 0x6e820
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x38(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl -0x38(%rbp), %ecx
addl $0x2, %ecx
subl %ecx, %eax
movzwl %ax, %esi
callq 0x63d00
jmp 0x6e512
jmp 0x6e731
movl -0x20(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x6e72f
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x6e8e0
movq -0x48(%rbp), %rax
movl 0x40(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x6e67b
movl $0x1, -0x28(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0x1, %edx
callq 0x5d9d0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x6e676
movq -0x48(%rbp), %rax
movq (%rax), %rdi
leaq -0x98(%rbp), %rsi
callq 0x6da90
movq -0x48(%rbp), %rdi
callq 0x6e900
movq %rax, -0x50(%rbp)
cmpq $0x0, %rax
je 0x6e646
movq -0x50(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x6e950
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
addl $0x1, %edx
leaq -0x98(%rbp), %rdi
callq 0x6e2e0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x6e5ce
jmp 0x6e646
movl $0x5, -0x28(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0x1, %edx
callq 0x5d9d0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x6e5f2
jmp 0x6e646
movq -0x50(%rbp), %rdi
callq 0x6e9f0
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
addl $0x1, %edx
callq 0x6e2e0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x6e61d
jmp 0x6e646
movl $0x6, -0x28(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0x1, %edx
callq 0x5d9d0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x6e641
jmp 0x6e646
jmp 0x6e586
leaq -0x98(%rbp), %rdi
callq 0x56ab0
cmpl $0x0, -0x24(%rbp)
jne 0x6e674
movl $0x2, -0x28(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0x1, %edx
callq 0x5d9d0
movl %eax, -0x24(%rbp)
jmp 0x6e676
jmp 0x6e72d
movl $0x3, -0x28(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0x1, %edx
callq 0x5d9d0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x6e72b
jmp 0x6e6a3
movq -0x48(%rbp), %rdi
callq 0x6e900
movq %rax, -0x50(%rbp)
cmpq $0x0, %rax
je 0x6e707
movq -0x50(%rbp), %rdi
callq 0x6e9f0
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
addl $0x1, %edx
callq 0x6e2e0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x6e6e1
jmp 0x6e707
movl $0x6, -0x28(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0x1, %edx
callq 0x5d9d0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x6e705
jmp 0x6e707
jmp 0x6e6a3
cmpl $0x0, -0x24(%rbp)
jne 0x6e729
movl $0x4, -0x28(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0x1, %edx
callq 0x5d9d0
movl %eax, -0x24(%rbp)
jmp 0x6e72b
jmp 0x6e72d
jmp 0x6e72f
jmp 0x6e731
jmp 0x6e733
jmp 0x6e735
jmp 0x6e737
jmp 0x6e739
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax,%rax)