// File: /workspace/github_c_makefile_star2_O0/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
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
cmpl $0x1, -0x14(%rbp)
jge 0x6c326
movq -0x10(%rbp), %rdi
movl $0x1, %esi
leaq 0x56129(%rip), %rdx     # 0xc2435
callq 0x580b0
movq -0x10(%rbp), %rdi
callq 0x57120
movl $0x0, -0x4(%rbp)
jmp 0x6c532
movq -0x20(%rbp), %rax
movq (%rax), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x56e20
movq %rax, -0x30(%rbp)
cmpl $0x1, -0x4c(%rbp)
jge 0x6c36a
movq -0x10(%rbp), %rdi
movl $0x1, %esi
leaq 0x560fd(%rip), %rdx     # 0xc244d
callq 0x580b0
movq -0x10(%rbp), %rdi
callq 0x57120
movl $0x0, -0x4(%rbp)
jmp 0x6c532
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
callq 0x58300
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x48(%rbp), %rsi
movl $0x4, %edx
callq 0x6d410
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x6c522
movq $0x0, -0x68(%rbp)
movq -0x10(%rbp), %rdi
callq 0x58570
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
callq 0x58510
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x6da90
cmpq $0x0, -0x58(%rbp)
je 0x6c3ea
cmpq $0x0, -0x60(%rbp)
jne 0x6c414
movq -0x10(%rbp), %rdi
movl $0x1, %esi
leaq 0x56192(%rip), %rdx     # 0xc258c
callq 0x580b0
movq -0x10(%rbp), %rdi
callq 0x57120
movl $0x0, -0x4(%rbp)
jmp 0x6c532
cmpl $0x1, -0x14(%rbp)
jle 0x6c438
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x57570
cmpl $0x0, %eax
je 0x6c438
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rdi
callq 0x72810
movq -0x28(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x72260
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x6c507
cmpq $0x0, -0x68(%rbp)
je 0x6c4e8
movq -0x58(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
movq -0x68(%rbp), %rsi
leaq -0xc0(%rbp), %rcx
movl $0x1, %edx
leaq -0xa8(%rbp), %r8
callq 0x72830
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
jne 0x6c4e6
leaq -0xa8(%rbp), %rdi
callq 0x56cf0
movl %eax, -0xc4(%rbp)
cmpl $0x0, -0xc4(%rbp)
jne 0x6c4e4
movq -0x28(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x28(%rbp), %rdi
callq 0x72b00
movq -0xd0(%rbp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
callq 0x729c0
jmp 0x6c441
jmp 0x6c4e6
jmp 0x6c4e8
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rdx
xorl %eax, %eax
movl %eax, %esi
callq 0x57920
movq -0x58(%rbp), %rdi
callq 0x56880
jmp 0x6c441
leaq -0xa8(%rbp), %rdi
callq 0x56ab0
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x572c0
jmp 0x6c52b
movq -0x10(%rbp), %rdi
callq 0x57120
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nop