// File: /workspace/github_c_makefile_star2_O1/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 0x3ceba
movq %rdx, %r13
movl %esi, %r15d
movq (%rdx), %rdi
leaq -0x3c(%rbp), %r14
movq %r14, %rsi
callq 0x30b04
movl (%r14), %ecx
testl %ecx, %ecx
jle 0x3cece
leaq -0xa0(%rbp), %rsi
movq %rax, (%rsi)
movl %ecx, 0x8(%rsi)
movq (%rbx), %rax
movq 0x20(%rax), %rdi
callq 0x3dde0
testq %rax, %rax
je 0x3cefa
movq %rax, -0x38(%rbp)
movq %rbx, %rdi
callq 0x317eb
movq %rax, %r14
movq %rbx, %rdi
callq 0x317a5
movq %rax, %r12
movq 0x60(%rbx), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, -0x70(%rbp)
movaps %xmm0, -0x50(%rbp)
movaps %xmm0, -0x80(%rbp)
movaps %xmm0, -0x60(%rbp)
movq %rdi, -0x70(%rbp)
movq %rdi, -0x68(%rbp)
movl $0x0, -0x50(%rbp)
movl $0x20, -0x78(%rbp)
testq %rax, %rax
setne %al
movq %r14, -0x30(%rbp)
testq %r14, %r14
setne %cl
testb %cl, %al
je 0x3cee2
cmpl $0x1, %r15d
jne 0x3cf14
xorl %r13d, %r13d
movq -0x30(%rbp), %r15
movq -0x38(%rbp), %r14
jmp 0x3cf36
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x39090(%rip), %rcx     # 0x75f5c
jmp 0x3cef0
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x39094(%rip), %rcx     # 0x75f74
jmp 0x3cef0
movq (%rbx), %rsi
addq $0x8, %rsi
leaq 0x391c3(%rip), %rcx     # 0x760b3
movl $0x1, %edx
callq 0x4153c
movq 0x8(%rbx), %rdi
callq 0x309f2
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%r13), %rsi
movq 0x10(%rsi), %rdi
callq 0x52930
testl %eax, %eax
movq -0x30(%rbp), %r15
movq -0x38(%rbp), %r14
je 0x3cf33
movq 0x8(%r13), %r13
jmp 0x3cf36
xorl %r13d, %r13d
movq $0x0, 0xb0(%r14)
movq %r14, %rdi
movq %r12, %rsi
callq 0x40e96
testl %eax, %eax
jne 0x3cfdb
testq %r13, %r13
je 0x3cfba
movq %r12, -0x90(%rbp)
movq 0x60(%rbx), %rdi
movq %r13, %rsi
movl $0x1, %edx
leaq -0x90(%rbp), %rcx
leaq -0x80(%rbp), %r8
callq 0x412d9
testl %eax, %eax
jne 0x3cfb4
leaq -0x80(%rbp), %rdi
callq 0x446ef
movl -0x80(%rbp), %r15d
xorl %eax, %eax
testq %r15, %r15
jne 0x3cfab
movq 0xb0(%r14), %rsi
decq %rsi
movq %r14, %rdi
callq 0x413fd
movl $0x2, %eax
testq %r15, %r15
movq -0x30(%rbp), %r15
je 0x3cfb6
xorl %eax, %eax
testl %eax, %eax
jne 0x3cf41
testb $0x40, 0x8(%r15)
je 0x3cfce
movq (%r15), %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x3f924
movq %r12, %rdi
callq 0x309f2
jmp 0x3cf41
leaq -0x80(%rbp), %rdi
callq 0x309f2
movq %rbx, %rdi
movq %r15, %rsi
callq 0x30d83
jmp 0x3cf03