// File: /workspace/github_c_makefile_star2_O3/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 0x3c53d
movq %rdx, %r13
movl %esi, %r15d
movq (%rdx), %rdi
leaq -0x3c(%rbp), %r14
movq %r14, %rsi
callq 0x30577
movl (%r14), %ecx
testl %ecx, %ecx
jle 0x3c551
leaq -0xa0(%rbp), %rsi
movq %rax, (%rsi)
movl %ecx, 0x8(%rsi)
movq (%rbx), %rax
movq 0x20(%rax), %rdi
callq 0x3d436
testq %rax, %rax
je 0x3c57d
movq %rax, -0x30(%rbp)
movq %rbx, %rdi
callq 0x31231
movq %rax, %r14
movq %rbx, %rdi
callq 0x311eb
movq %rax, %r12
movq 0x60(%rbx), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, -0x70(%rbp)
movaps %xmm0, -0x80(%rbp)
movaps %xmm0, -0x60(%rbp)
movaps %xmm0, -0x50(%rbp)
movq %rdi, -0x70(%rbp)
movq %rdi, -0x68(%rbp)
movl $0x20, -0x78(%rbp)
testq %rax, %rax
setne %al
movq %r14, -0x38(%rbp)
testq %r14, %r14
setne %cl
testb %cl, %al
je 0x3c565
cmpl $0x1, %r15d
jne 0x3c597
xorl %r13d, %r13d
movq -0x38(%rbp), %r15
movq -0x30(%rbp), %r14
jmp 0x3c5b9
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x37a15(%rip), %rcx     # 0x73f64
jmp 0x3c573
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x37a19(%rip), %rcx     # 0x73f7c
jmp 0x3c573
movq (%rbx), %rsi
addq $0x8, %rsi
leaq 0x37b48(%rip), %rcx     # 0x740bb
movl $0x1, %edx
callq 0x40afa
movq 0x8(%rbx), %rdi
callq 0x30465
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 0x511d0
testl %eax, %eax
movq -0x38(%rbp), %r15
movq -0x30(%rbp), %r14
je 0x3c5b6
movq 0x8(%r13), %r13
jmp 0x3c5b9
xorl %r13d, %r13d
movq $0x0, 0xb0(%r14)
movq %r14, %rdi
movq %r12, %rsi
callq 0x4046f
testl %eax, %eax
jne 0x3c640
testq %r13, %r13
je 0x3c60e
movq %r12, -0x90(%rbp)
movq 0x60(%rbx), %rdi
movq %r13, %rsi
movl $0x1, %edx
leaq -0x90(%rbp), %rcx
leaq -0x80(%rbp), %r8
callq 0x4089b
testl %eax, %eax
jne 0x3c60e
leaq -0x80(%rbp), %rdi
callq 0x438dd
cmpl $0x0, -0x80(%rbp)
je 0x3c62c
testb $0x40, 0x8(%r15)
je 0x3c622
movq (%r15), %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x3ef1d
movq %r12, %rdi
callq 0x30465
jmp 0x3c5c4
movq 0xb0(%r14), %rsi
decq %rsi
movq %r14, %rdi
callq 0x409cf
jmp 0x3c5c4
leaq -0x80(%rbp), %rdi
callq 0x30465
movq %rbx, %rdi
movq %r15, %rsi
callq 0x307f4
jmp 0x3c586