// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: unqliteBuiltin_db_fetch_all
static int unqliteBuiltin_db_fetch_all(jx9_context *pCtx,int argc,jx9_value **argv)
{
	unqlite_col *pCol;
	const char *zName;
	unqlite_vm *pVm;
	SyString sName;
	int nByte;
	int rc;
	/* Extract collection name */
	if( argc < 1 ){
		/* Missing arguments */
		jx9_context_throw_error(pCtx,JX9_CTX_ERR,"Missing collection name");
		/* Return NULL */
		jx9_result_null(pCtx);
		return JX9_OK;
	}
	zName = jx9_value_to_string(argv[0],&nByte);
	if( nByte < 1){
		jx9_context_throw_error(pCtx,JX9_CTX_ERR,"Invalid collection name");
		/* Return NULL */
		jx9_result_null(pCtx);
		return JX9_OK;
	}
	SyStringInitFromBuf(&sName,zName,nByte);
	pVm = (unqlite_vm *)jx9_context_user_data(pCtx);
	/* Fetch the collection */
	pCol = unqliteCollectionFetch(pVm,&sName,UNQLITE_VM_AUTO_LOAD);
	if( pCol ){
		jx9_value *pValue,*pArray,*pCallback = 0;
		jx9_value sResult; /* Callback result */
		/* Allocate an empty scalar value and an empty JSON array */
		pArray = jx9_context_new_array(pCtx);
		pValue = jx9_context_new_scalar(pCtx);
		jx9MemObjInit(pCtx->pVm,&sResult);
		if( pValue == 0 || pArray == 0 ){
			jx9_context_throw_error(pCtx,JX9_CTX_ERR,"Jx9 is running out of memory");
			jx9_result_null(pCtx);
			return JX9_OK;
		}
		if( argc > 1 && jx9_value_is_callable(argv[1]) ){
			pCallback = argv[1];
		}
		unqliteCollectionResetRecordCursor(pCol);
		/* Fetch collection records one after one */
		while( UNQLITE_OK == unqliteCollectionFetchNextRecord(pCol,pValue) ){
			if( pCallback ){
				jx9_value *apArg[2];
				/* Invoke the filter callback */
				apArg[0] = pValue;
				rc = jx9VmCallUserFunction(pCtx->pVm,pCallback,1,apArg,&sResult);
				if( rc == JX9_OK ){
					int iResult; /* Callback result */
					/* Extract callback result */
					iResult = jx9_value_to_bool(&sResult);
					if( !iResult ){
						/* Discard the result */
						unqliteCollectionCacheRemoveRecord(pCol,unqliteCollectionCurrentRecordId(pCol) - 1);
						continue;
					}
				}
			}
			/* Put the value in the JSON array */
			jx9_array_add_elem(pArray,0,pValue);
			/* Release the value */
			jx9_value_null(pValue);
		}
		jx9MemObjRelease(&sResult);
		/* Finally, return our array */
		jx9_result_value(pCtx,pArray);
		/* pValue will be automatically released as soon we return from
		 * this foreign function.
		 */
	}else{
		/* No such collection, return null */
		jx9_result_null(pCtx);
	}
	return JX9_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, %rbx
testl %esi, %esi
jle 0x345a8
movq %rdx, %r15
movl %esi, %r13d
movq (%rdx), %rdi
leaq -0x34(%rbp), %r14
movq %r14, %rsi
callq 0x297ed
movl (%r14), %ecx
testl %ecx, %ecx
jle 0x345b1
leaq -0xa0(%rbp), %rsi
movq %rax, (%rsi)
movl %ecx, 0x8(%rsi)
movq (%rbx), %rax
movq 0x20(%rax), %rdi
callq 0x350f6
testq %rax, %rax
je 0x345cc
movq %rax, %r14
movq %r15, -0x30(%rbp)
movq %rbx, %rdi
callq 0x2a2b0
movq %rax, %r15
movq %rbx, %rdi
callq 0x2a26a
movq %rax, %r12
movq 0x60(%rbx), %rdi
leaq -0x90(%rbp), %rsi
callq 0x35772
testq %r12, %r12
setne %al
testq %r15, %r15
setne %cl
testb %cl, %al
je 0x345ba
cmpl $0x1, %r13d
je 0x345e5
movq -0x30(%rbp), %r13
movq 0x8(%r13), %rdi
callq 0x29aa1
testl %eax, %eax
je 0x345e5
movq 0x8(%r13), %r13
jmp 0x345e8
leaq 0x2f995(%rip), %rdx     # 0x63f44
jmp 0x345c1
leaq 0x2f9a4(%rip), %rdx     # 0x63f5c
jmp 0x345c1
leaq 0x2fada(%rip), %rdx     # 0x6409b
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x2a0db
movq %rbx, %rdi
callq 0x298e8
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r13d, %r13d
andq $0x0, 0xb0(%r14)
movq %r14, %rdi
movq %r12, %rsi
callq 0x37e33
testl %eax, %eax
jne 0x34661
testq %r13, %r13
je 0x34636
movq %r12, -0x50(%rbp)
movq 0x60(%rbx), %rdi
movq %r13, %rsi
pushq $0x1
popq %rdx
leaq -0x50(%rbp), %rcx
leaq -0x90(%rbp), %r8
callq 0x38181
testl %eax, %eax
jne 0x34636
leaq -0x90(%rbp), %rdi
callq 0x29790
testl %eax, %eax
je 0x3464d
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x29c4b
movq %r12, %rdi
callq 0x296af
jmp 0x345f0
movq 0xb0(%r14), %rsi
decq %rsi
movq %r14, %rdi
callq 0x382a2
jmp 0x345f0
leaq -0x90(%rbp), %rdi
callq 0x296af
movq %rbx, %rdi
movq %r15, %rsi
callq 0x299d3
jmp 0x345d4