// File: /workspace/github_c_makefile_star2_O0/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
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
addq $0x68, %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
callq 0x56880
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x72460
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x7234e
movq -0x30(%rbp), %rdi
addq $0x10, %rdi
movq -0x20(%rbp), %rsi
callq 0x6e750
movl $0x0, -0x4(%rbp)
jmp 0x72453
movq -0x28(%rbp), %rdi
callq 0x65e00
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rdx
addq $0x8, %rdx
movq -0x18(%rbp), %rcx
leaq 0x5023b(%rip), %rsi     # 0xc25a9
movb $0x0, %al
callq 0x6e820
movq -0x10(%rbp), %rax
movq 0x118(%rax), %rdi
callq 0x59b40
movq -0x10(%rbp), %rax
movq 0x118(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x28(%rbp), %rax
movl 0x10(%rax), %edx
movl $0x1, %ecx
callq 0x59ba0
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x723bd
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x72453
movq -0x28(%rbp), %rdi
callq 0x65e00
movq -0x10(%rbp), %rax
movq 0x118(%rax), %rdi
movq -0x28(%rbp), %rdx
leaq -0x1922c(%rip), %rsi    # 0x591b0
callq 0x59d10
movq -0x28(%rbp), %rax
cmpl $0x1, 0x10(%rax)
jae 0x72412
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0x501b0(%rip), %rsi     # 0xc25b0
movb $0x0, %al
callq 0x68100
movq -0x20(%rbp), %rdi
callq 0x56880
jmp 0x7244d
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x28(%rbp), %rax
movl 0x10(%rax), %esi
movq -0x20(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
xorl %r8d, %r8d
callq 0x6ec70
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x7244b
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x724f0
jmp 0x7244d
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)