// File: /workspace/github_c_makefile_star2_O3/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_file_get_contents
static int jx9Builtin_file_get_contents(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	const jx9_io_stream *pStream;
	jx9_int64 n, nRead, nMaxlen;
	int use_include  = FALSE;
	const char *zFile;
	char zBuf[8192];
	void *pHandle;
	int 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;
	}
	nMaxlen = -1;
	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;
	}
	if( nArg > 3 ){
		/* Extract the offset */
		n = jx9_value_to_int64(apArg[3]);
		if( n > 0 ){
			if( pStream->xSeek ){
				/* Seek to the desired offset */
				pStream->xSeek(pHandle, n, 0/*SEEK_SET*/);
			}
		}
		if( nArg > 4 ){
			/* Maximum data to read */
			nMaxlen = jx9_value_to_int64(apArg[4]);
		}
	}
	/* Perform the requested operation */
	nRead = 0;
	for(;;){
		n = pStream->xRead(pHandle, zBuf, 
			(nMaxlen > 0 && (nMaxlen < sizeof(zBuf))) ? nMaxlen : sizeof(zBuf));
		if( n < 1 ){
			/* EOF or IO error, break immediately */
			break;
		}
		/* Append data */
		jx9_result_string(pCtx, zBuf, (int)n);
		/* Increment read counter */
		nRead += n;
		if( nMaxlen > 0 && nRead >= nMaxlen ){
			/* Read limit reached */
			break;
		}
	}
	/* Close the stream */
	jx9StreamCloseHandle(pStream, pHandle);
	/* Check if we have read something */
	if( jx9_context_result_buf_length(pCtx) < 1 ){
		/* Nothing read, return FALSE */
		jx9_result_bool(pCtx, 0);
	}
	return JX9_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2028, %rsp           # imm = 0x2028
movq %rdi, %rbx
testl %esi, %esi
jle 0x627ac
movq %rdx, %r15
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
jne 0x627fd
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x14e4b(%rip), %rcx     # 0x77609
movl $0x2, %edx
callq 0x40afa
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x30465
movq $0x0, (%rbx)
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%rbx), %eax
orl $0x8, %eax
movl %eax, 0x8(%rbx)
xorl %eax, %eax
addq $0x2028, %rsp           # imm = 0x2028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %r12d
leaq -0x4c(%rbp), %r14
movq %r14, %rsi
callq 0x30577
leaq -0x48(%rbp), %rsi
movq %rax, (%rsi)
movq 0x60(%rbx), %r13
movl (%r14), %edx
movq %r13, %rdi
callq 0x51bfb
movq %rax, -0x30(%rbp)
testq %rax, %rax
je 0x6283a
cmpl $0x1, %r12d
jne 0x62850
xorl %r8d, %r8d
movq -0x48(%rbp), %r14
jmp 0x62873
movq (%rbx), %rsi
addq $0x8, %rsi
leaq 0x14dd7(%rip), %rcx     # 0x7761f
movq %r13, %rdi
jmp 0x627be
movq 0x8(%r15), %r14
movq %r14, %rdi
callq 0x438dd
movl (%r14), %r8d
movq 0x60(%rbx), %r13
movq -0x48(%rbp), %r14
cmpl $0x3, %r12d
jb 0x62873
movq 0x10(%r15), %r9
jmp 0x62876
xorl %r9d, %r9d
movq %r13, %rdi
movq -0x30(%rbp), %rsi
movq %r14, %rdx
movl $0x1, %ecx
pushq $0x0
pushq $0x0
callq 0x51dad
addq $0x10, %rsp
movq %rax, -0x38(%rbp)
testq %rax, %rax
je 0x6296e
movq $-0x1, %r13
cmpl $0x4, %r12d
movq %rbx, -0x40(%rbp)
jb 0x628ee
movq 0x18(%r15), %r14
movq %r14, %rdi
callq 0x3f362
movq (%r14), %rsi
testq %rsi, %rsi
jle 0x628d9
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rax
testq %rax, %rax
je 0x628d9
movq -0x38(%rbp), %rdi
xorl %edx, %edx
callq *%rax
cmpl $0x4, %r12d
je 0x628ee
movq 0x20(%r15), %r14
movq %r14, %rdi
callq 0x3f362
movq (%r14), %r13
leaq -0x1(%r13), %rax
cmpq $0x1fff, %rax           # imm = 0x1FFF
movl $0x2000, %r15d          # imm = 0x2000
cmovbq %r13, %r15
xorl %ebx, %ebx
leaq -0x2050(%rbp), %r12
movq -0x38(%rbp), %rdi
movq %r12, %rsi
movq %r15, %rdx
movq -0x30(%rbp), %rax
callq *0x30(%rax)
testq %rax, %rax
jle 0x62944
movq %rax, %r14
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
movq %r12, %rsi
movl %r14d, %edx
callq 0x302f6
addq %r14, %rbx
testq %r13, %r13
jle 0x6290b
cmpq %r13, %rbx
jl 0x6290b
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
testq %rax, %rax
je 0x62957
movq -0x38(%rbp), %rdi
callq *%rax
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rbx
cmpl $0x0, 0x28(%rbx)
jne 0x627e9
jmp 0x627cc
leaq 0x14cd8(%rip), %rdx     # 0x7764d
movq %rbx, %rdi
movl $0x1, %esi
movq %r14, %rcx
xorl %eax, %eax
callq 0x44ed3
jmp 0x627c8