// File: /workspace/github_c_makefile_star2_O3/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: unqliteCollectionFetchRecordById
UNQLITE_PRIVATE int unqliteCollectionFetchRecordById(
	unqlite_col *pCol, /* Target collection */
	jx9_int64 nId,     /* Unique record ID */
	jx9_value *pValue  /* OUT: record value */
	)
{
	SyBlob *pWorker = &pCol->sWorker;
	unqlite_col_record *pRec;
	int rc;
	jx9_value_null(pValue);
	/* Perform a cache lookup first */
	pRec = CollectionCacheFetchRecord(pCol,nId);
	if( pRec ){
		/* Copy record value */
		jx9MemObjStore(&pRec->sValue,pValue);
		return UNQLITE_OK;
	}
	/* Reset the working buffer */
	SyBlobReset(pWorker);
	/* Generate the unique ID */
	SyBlobFormat(pWorker,"%z_%qd",&pCol->sName,nId);
	/* Reset the cursor */
	unqlite_kv_cursor_reset(pCol->pCursor);
	/* Seek the cursor to the desired location */
	rc = unqlite_kv_cursor_seek(pCol->pCursor,
		SyBlobData(pWorker),SyBlobLength(pWorker),
		UNQLITE_CURSOR_MATCH_EXACT
		);
	if( rc != UNQLITE_OK ){
		return rc;
	}
	/* Consume the binary JSON */
	SyBlobReset(pWorker);
	unqlite_kv_cursor_data_callback(pCol->pCursor,unqliteDataConsumer,pWorker);
	if( SyBlobLength(pWorker) < 1 ){
		unqliteGenErrorFormat(pCol->pVm->pDb,
			"Empty record '%qd'",nId
			);
		jx9_value_null(pValue);
	}else{
		/* Decode the binary JSON */
		rc = FastJsonDecode(SyBlobData(pWorker),SyBlobLength(pWorker),pValue,0,0);
		if( rc == UNQLITE_OK ){
			/* Install the record in the cache */
			CollectionCacheInstallRecord(pCol,nId,pValue);
		}
	}
	return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movq %rdx, %rdi
callq 0x30465
cmpl $0x0, 0xd8(%r15)
je 0x4051b
movq 0xc8(%r15), %rax
movl 0xdc(%r15), %ecx
decl %ecx
movl %r14d, %edx
andl %ecx, %edx
movq (%rax,%rdx,8), %rdi
testq %rdi, %rdi
je 0x4051b
cmpq %r14, 0x8(%rdi)
je 0x40626
movq 0x50(%rdi), %rdi
jmp 0x40506
leaq 0x68(%r15), %r12
movl $0x0, 0x78(%r15)
movl 0x80(%r15), %eax
testb $0x4, %al
je 0x4054c
movq $0x0, 0x70(%r15)
movl $0x0, 0x7c(%r15)
andl $-0x5, %eax
movl %eax, 0x80(%r15)
leaq 0x8(%r15), %rdx
leaq 0x33b81(%rip), %rsi     # 0x740d8
movq %r12, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x3e26d
movq 0x118(%r15), %rdi
movq (%rdi), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq 0xa8(%rax), %rax
testq %rax, %rax
je 0x4058a
callq *%rax
movq 0x118(%r15), %rdi
movq 0x70(%r15), %rsi
movl 0x78(%r15), %edx
movl $0x1, %ecx
callq 0x32448
testl %eax, %eax
je 0x405a8
movl %eax, %r13d
jmp 0x40659
movl $0x0, 0x78(%r15)
movl 0x80(%r15), %eax
testb $0x4, %al
je 0x405d5
movq $0x0, 0x70(%r15)
movl $0x0, 0x7c(%r15)
andl $-0x5, %eax
movl %eax, 0x80(%r15)
movq 0x118(%r15), %rdi
movq (%rdi), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
leaq -0xe8c6(%rip), %rsi     # 0x31d27
movq %r12, %rdx
callq *0xa0(%rax)
movl 0x78(%r15), %esi
testl %esi, %esi
je 0x40637
movq 0x70(%r15), %rdi
xorl %r13d, %r13d
movq %rbx, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3e491
testl %eax, %eax
jne 0x405a0
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x4066b
jmp 0x40659
addq $0x10, %rdi
movq %rbx, %rsi
callq 0x3e19f
xorl %r13d, %r13d
jmp 0x40659
movq (%r15), %rax
movq (%rax), %rdi
leaq 0x33a9b(%rip), %rsi     # 0x740df
xorl %r13d, %r13d
movq %r14, %rdx
xorl %eax, %eax
callq 0x3a376
movq %rbx, %rdi
callq 0x30465
movl %r13d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq