// File: /workspace/github_c_makefile_star2_O1/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 0x309f2
cmpl $0x0, 0xd8(%r15)
je 0x40f34
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 0x40f34
cmpq %r14, 0x8(%rdi)
je 0x40f36
movq 0x50(%rdi), %rdi
jmp 0x40f23
xorl %edi, %edi
testq %rdi, %rdi
je 0x40f4f
addq $0x10, %rdi
movq %rbx, %rsi
callq 0x3ebc8
xorl %r13d, %r13d
jmp 0x40fd7
leaq 0x68(%r15), %r12
movl $0x0, 0x78(%r15)
movl 0x80(%r15), %eax
testb $0x4, %al
je 0x40f80
movq $0x0, 0x70(%r15)
movl $0x0, 0x7c(%r15)
andl $-0x5, %eax
movl %eax, 0x80(%r15)
leaq 0x8(%r15), %rdx
leaq 0x35145(%rip), %rsi     # 0x760d0
movq %r12, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x3ec96
movq 0x118(%r15), %rdi
movq (%rdi), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq 0xa8(%rax), %rax
testq %rax, %rax
je 0x40fb7
callq *%rax
movq 0x118(%r15), %rdi
movq 0x70(%r15), %rsi
movl 0x78(%r15), %edx
movl $0x1, %ecx
callq 0x32a37
testl %eax, %eax
je 0x40fe9
movl %eax, %r13d
movl %r13d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x0, 0x78(%r15)
movl 0x80(%r15), %eax
testb $0x4, %al
je 0x41016
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 -0xed1c(%rip), %rsi     # 0x32312
movq %r12, %rdx
callq *0xa0(%rax)
movl 0x78(%r15), %esi
testl %esi, %esi
je 0x4106e
movq 0x70(%r15), %rdi
xorl %r13d, %r13d
movq %rbx, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3eebc
testl %eax, %eax
jne 0x40fd4
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x41095
jmp 0x40fd7
movq (%r15), %rax
movq (%rax), %rdi
leaq 0x3505c(%rip), %rsi     # 0x760d7
xorl %r13d, %r13d
movq %r14, %rdx
xorl %eax, %eax
callq 0x3ac51
movq %rbx, %rdi
callq 0x309f2
jmp 0x40fd7