// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_readfile
static int jx9Builtin_readfile(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	int use_include  = FALSE;
	const jx9_io_stream *pStream;
	jx9_int64 n, nRead;
	const char *zFile;
	char zBuf[8192];
	void *pHandle;
	int rc, nLen;
	if( nArg < 1 || !jx9_value_is_string(apArg[0]) ){
		/* Missing/Invalid arguments, return FALSE */
		jx9_context_throw_error(pCtx, JX9_CTX_WARNING, "Expecting a file path");
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Extract the file path */
	zFile = jx9_value_to_string(apArg[0], &nLen);
	/* Point to the target IO stream device */
	pStream = jx9VmGetStreamDevice(pCtx->pVm, &zFile, nLen);
	if( pStream == 0 ){
		jx9_context_throw_error(pCtx, JX9_CTX_WARNING, "No such stream device, JX9 is returning FALSE");
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	if( nArg > 1 ){
		use_include = jx9_value_to_bool(apArg[1]);
	}
	/* Try to open the file in read-only mode */
	pHandle = jx9StreamOpenHandle(pCtx->pVm, pStream, zFile, JX9_IO_OPEN_RDONLY, 
		use_include, nArg > 2 ? apArg[2] : 0, FALSE, 0);
	if( pHandle == 0 ){
		jx9_context_throw_error_format(pCtx, JX9_CTX_ERR, "IO error while opening '%s'", zFile);
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Perform the requested operation */
	nRead = 0;
	for(;;){
		n = pStream->xRead(pHandle, zBuf, sizeof(zBuf));
		if( n < 1 ){
			/* EOF or IO error, break immediately */
			break;
		}
		/* Output data */
		rc = jx9_context_output(pCtx, zBuf, (int)n);
		if( rc == JX9_ABORT ){
			break;
		}
		/* Increment counter */
		nRead += n;
	}
	/* Close the stream */
	jx9StreamCloseHandle(pStream, pHandle);
	/* Total number of bytes readen */
	jx9_result_int64(pCtx, nRead);
	return JX9_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20a0, %rsp           # imm = 0x20A0
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x1, -0x14(%rbp)
jl 0xa7044
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x57480
cmpl $0x0, %eax
jne 0xa7070
movq -0x10(%rbp), %rdi
movl $0x2, %esi
leaq 0x1ea8e(%rip), %rdx     # 0xc5ae2
callq 0x580b0
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0xa724a
movq -0x20(%rbp), %rax
movq (%rax), %rdi
leaq -0x2060(%rbp), %rsi
callq 0x56e20
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
movl -0x2060(%rbp), %edx
leaq -0x48(%rbp), %rsi
callq 0x8e570
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xa70d5
movq -0x10(%rbp), %rdi
movl $0x2, %esi
leaq 0x1ea3f(%rip), %rdx     # 0xc5af8
callq 0x580b0
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0xa724a
cmpl $0x1, -0x14(%rbp)
jle 0xa70eb
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x56cf0
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0x2080(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x2078(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x2070(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x2064(%rbp)
cmpl $0x2, -0x14(%rbp)
jle 0xa7130
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x2088(%rbp)
jmp 0xa713b
xorl %eax, %eax
movq %rax, -0x2088(%rbp)
jmp 0xa713b
movl -0x2064(%rbp), %r8d
movq -0x2070(%rbp), %rdx
movq -0x2078(%rbp), %rsi
movq -0x2080(%rbp), %rdi
movq -0x2088(%rbp), %r9
movl $0x1, %ecx
xorl %eax, %eax
xorl %eax, %eax
movl $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
callq 0x8e7e0
movq %rax, -0x2058(%rbp)
cmpq $0x0, -0x2058(%rbp)
jne 0xa71bf
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rcx
movl $0x1, %esi
leaq 0x1e985(%rip), %rdx     # 0xc5b26
movb $0x0, %al
callq 0x79580
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0xa724a
movq $0x0, -0x40(%rbp)
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x2058(%rbp), %rdi
leaq -0x2050(%rbp), %rsi
movl $0x2000, %edx           # imm = 0x2000
callq *%rax
movq %rax, -0x38(%rbp)
cmpq $0x1, -0x38(%rbp)
jge 0xa71f1
jmp 0xa7226
movq -0x10(%rbp), %rdi
leaq -0x2050(%rbp), %rsi
movq -0x38(%rbp), %rax
movl %eax, %edx
callq 0x57ef0
movl %eax, -0x205c(%rbp)
cmpl $-0xa, -0x205c(%rbp)
jne 0xa7218
jmp 0xa7226
movq -0x38(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0xa71c7
movq -0x30(%rbp), %rdi
movq -0x2058(%rbp), %rsi
callq 0x8ea80
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x57010
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20a0, %rsp           # imm = 0x20A0
popq %rbp
retq
nopw %cs:(%rax,%rax)