// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2018, %rsp           # imm = 0x2018
movq %rdi, %rbx
testl %esi, %esi
jle 0x544bd
movq %rdx, %r12
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
jne 0x544ed
leaq 0x13125(%rip), %rdx     # 0x675e9
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x2a0db
movq %rbx, %rdi
xorl %esi, %esi
callq 0x298b2
xorl %eax, %eax
addq $0x2018, %rsp           # imm = 0x2018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %r15d
leaq -0x3c(%rbp), %r14
movq %r14, %rsi
callq 0x297ed
leaq -0x38(%rbp), %rsi
movq %rax, (%rsi)
movq 0x60(%rbx), %r13
movl (%r14), %edx
movq %r13, %rdi
callq 0x47354
movq %rax, -0x30(%rbp)
testq %rax, %rax
je 0x5452a
cmpl $0x1, %r15d
jne 0x54533
xorl %r8d, %r8d
movq -0x38(%rbp), %r14
jmp 0x54555
leaq 0x130ce(%rip), %rdx     # 0x675ff
jmp 0x544c4
movq 0x8(%r12), %rdi
callq 0x29790
movl %eax, %r8d
movq 0x60(%rbx), %r13
movq -0x38(%rbp), %r14
cmpl $0x3, %r15d
jb 0x54555
movq 0x10(%r12), %r9
jmp 0x54558
xorl %r9d, %r9d
pushq $0x1
popq %rcx
movq %r13, %rdi
movq -0x30(%rbp), %rsi
movq %r14, %rdx
pushq $0x0
pushq $0x0
callq 0x474a5
addq $0x10, %rsp
testq %rax, %rax
je 0x545d9
movq %rax, %r12
xorl %r15d, %r15d
leaq -0x2040(%rbp), %r13
movq %r15, %r14
movl $0x2000, %edx           # imm = 0x2000
movq %r12, %rdi
movq %r13, %rsi
movq -0x30(%rbp), %rax
callq *0x30(%rax)
testq %rax, %rax
jle 0x545b7
movq %rax, %r15
movq %rbx, %rdi
movq %r13, %rsi
movl %r15d, %edx
callq 0x29fae
addq %r14, %r15
cmpl $-0xa, %eax
jne 0x54584
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
testq %rax, %rax
je 0x545c9
movq %r12, %rdi
callq *%rax
movq %rbx, %rdi
movq %r14, %rsi
callq 0x29897
jmp 0x544d9
leaq 0x1304d(%rip), %rdx     # 0x6762d
pushq $0x1
popq %rsi
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x3be68
jmp 0x544cf