// File: /workspace/github_c_makefile_star2_O1/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 0x6408c
movq %rdx, %r15
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
jne 0x640e2
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x15560(%rip), %rcx     # 0x795fe
movl $0x2, %edx
callq 0x4153c
movl $0x8, %r12d
xorl %r14d, %r14d
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x309f2
movq %r14, (%rbx)
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%rbx), %eax
orl %r12d, %eax
movl %eax, 0x8(%rbx)
xorl %eax, %eax
addq $0x2018, %rsp           # imm = 0x2018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %r12d
leaq -0x3c(%rbp), %r14
movq %r14, %rsi
callq 0x30b04
leaq -0x38(%rbp), %rsi
movq %rax, (%rsi)
movq 0x60(%rbx), %r13
movl (%r14), %edx
movq %r13, %rdi
callq 0x53369
testq %rax, %rax
je 0x6413c
movq %rax, %r14
xorl %r8d, %r8d
cmpl $0x1, %r12d
je 0x64128
movq 0x8(%r15), %r13
movq %r13, %rdi
callq 0x446ef
movl (%r13), %r8d
movq 0x60(%rbx), %rdi
movq -0x38(%rbp), %r13
cmpl $0x3, %r12d
jl 0x64152
movq 0x10(%r15), %r9
jmp 0x64155
movq (%rbx), %rsi
addq $0x8, %rsi
leaq 0x154ca(%rip), %rcx     # 0x79614
movq %r13, %rdi
jmp 0x6409e
xorl %r9d, %r9d
movq %r14, %rsi
movq %r13, %rdx
movl $0x1, %ecx
pushq $0x0
pushq $0x0
callq 0x534fd
addq $0x10, %rsp
testq %rax, %rax
je 0x641d0
movq %rax, %r15
leaq -0x2040(%rbp), %rsi
movl $0x2000, %edx           # imm = 0x2000
movq %rax, %rdi
movq %r14, -0x30(%rbp)
callq *0x30(%r14)
testq %rax, %rax
jle 0x641f7
movq %rax, %r13
xorl %r14d, %r14d
leaq -0x2040(%rbp), %r12
movq %rbx, %rdi
movq %r12, %rsi
movl %r13d, %edx
callq 0x31412
cmpl $-0xa, %eax
je 0x641fa
addq %r13, %r14
movl $0x2000, %edx           # imm = 0x2000
movq %r15, %rdi
movq %r12, %rsi
movq -0x30(%rbp), %rax
callq *0x30(%rax)
movq %rax, %r13
testq %rax, %rax
jg 0x6419e
jmp 0x641fa
leaq 0x1546b(%rip), %rdx     # 0x79642
xorl %r14d, %r14d
movq %rbx, %rdi
movl $0x1, %esi
movq %r13, %rcx
xorl %eax, %eax
callq 0x45d26
movl $0x8, %r12d
jmp 0x640b1
xorl %r14d, %r14d
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movl $0x2, %r12d
testq %rax, %rax
je 0x640b1
movq %r15, %rdi
callq *%rax
jmp 0x640b1