// File: /workspace/github_c_makefile_star2_O3/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 0x625e8
movq %rdx, %r13
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
jne 0x6263d
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x1500f(%rip), %rcx     # 0x77609
movl $0x2, %edx
callq 0x40afa
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x30465
movq $0x0, (%rbx)
movl $0x8, %eax
movl $0xfffffe90, %ecx       # imm = 0xFFFFFE90
andl 0x8(%rbx), %ecx
orl %eax, %ecx
movl %ecx, 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 0x30577
leaq -0x38(%rbp), %rsi
movq %rax, (%rsi)
movq 0x60(%rbx), %r15
movl (%r14), %edx
movq %r15, %rdi
callq 0x51bfb
testq %rax, %rax
je 0x6267c
movq %rax, %r14
cmpl $0x1, %r12d
jne 0x62692
xorl %r8d, %r8d
movq -0x38(%rbp), %r12
xorl %r9d, %r9d
jmp 0x626bb
movq (%rbx), %rsi
addq $0x8, %rsi
leaq 0x14f95(%rip), %rcx     # 0x7761f
movq %r15, %rdi
jmp 0x625fa
movq 0x8(%r13), %r15
movq %r15, %rdi
callq 0x438dd
movl (%r15), %r8d
movq 0x60(%rbx), %r15
movq -0x38(%rbp), %rax
cmpl $0x3, %r12d
jb 0x626b5
movq 0x10(%r13), %r9
jmp 0x626b8
xorl %r9d, %r9d
movq %rax, %r12
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
movl $0x1, %ecx
pushq $0x0
pushq $0x0
callq 0x51dad
addq $0x10, %rsp
testq %rax, %rax
je 0x62739
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 0x62757
movq %rax, %r13
xorl %r14d, %r14d
leaq -0x2040(%rbp), %r12
movq %rbx, %rdi
movq %r12, %rsi
movl %r13d, %edx
callq 0x30e6e
cmpl $-0xa, %eax
je 0x6275a
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 0x62707
jmp 0x6275a
leaq 0x14f0d(%rip), %rdx     # 0x7764d
movq %rbx, %rdi
movl $0x1, %esi
movq %r12, %rcx
xorl %eax, %eax
callq 0x44ed3
jmp 0x62604
xorl %r14d, %r14d
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
testq %rax, %rax
je 0x6276c
movq %r15, %rdi
callq *%rax
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x30465
movq %r14, (%rbx)
movl $0x2, %eax
jmp 0x6261c