// File: /workspace/github_c_makefile_star2_O1/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_fread
static int jx9Builtin_fread(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	const jx9_io_stream *pStream;
	io_private *pDev;
	jx9_int64 nRead;
	void *pBuf;
	int nLen;
	if( nArg < 1 || !jx9_value_is_resource(apArg[0]) ){
		/* Missing/Invalid arguments, return FALSE */
		jx9_context_throw_error(pCtx, JX9_CTX_WARNING, "Expecting an IO handle");
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Extract our private data */
	pDev = (io_private *)jx9_value_to_resource(apArg[0]);
	/* Make sure we are dealing with a valid io_private instance */
	if( IO_PRIVATE_INVALID(pDev) ){
		/*Expecting an IO handle */
		jx9_context_throw_error(pCtx, JX9_CTX_WARNING, "Expecting an IO handle");
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Point to the target IO stream device */
	pStream = pDev->pStream;
	if( pStream == 0  ){
		jx9_context_throw_error_format(pCtx, JX9_CTX_WARNING, 
			"IO routine(%s) not implemented in the underlying stream(%s) device, JX9 is returning FALSE", 
			jx9_function_name(pCtx), pStream ? pStream->zName : "null_stream"
			);
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
        nLen = 4096;
	if( nArg > 1 ){
 	  nLen = jx9_value_to_int(apArg[1]);
	  if( nLen < 1 ){
		/* Invalid length, set a default length */
		nLen = 4096;
	  }
        }
	/* Allocate enough buffer */
	pBuf = jx9_context_alloc_chunk(pCtx, (unsigned int)nLen, FALSE, FALSE);
	if( pBuf == 0 ){
		jx9_context_throw_error(pCtx, JX9_CTX_ERR, "JX9 is running out of memory");			
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Perform the requested operation */
	nRead = StreamRead(pDev, pBuf, (jx9_int64)nLen);
	if( nRead < 1 ){
		/* Nothing read, return FALSE */
		jx9_result_bool(pCtx, 0);
	}else{
		/* Make a copy of the data just read */
		jx9_result_string(pCtx, (const char *)pBuf, (int)nRead);
	}
	/* Release the buffer */
	jx9_context_free_chunk(pCtx, pBuf);
	return JX9_OK;	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
testl %esi, %esi
jle 0x63829
movq (%rdx), %rax
testb $0x1, 0x9(%rax)
je 0x63829
movq (%rax), %r14
testq %r14, %r14
je 0x63829
cmpl $0xfeac14, 0x34(%r14)   # imm = 0xFEAC14
jne 0x63829
cmpq $0x0, (%r14)
je 0x63871
movl $0x1000, %r12d          # imm = 0x1000
cmpl $0x1, %esi
je 0x637e7
movq 0x8(%rdx), %r15
movq %r15, %rdi
callq 0x3fd5f
movl (%r15), %eax
testl %eax, %eax
cmovgl %eax, %r12d
movq 0x60(%rbx), %rdi
movl %r12d, %esi
callq 0x343ed
testq %rax, %rax
je 0x63897
movq %rax, %r15
movslq %r12d, %rdx
movq %r14, %rdi
movq %rax, %rsi
callq 0x66582
testq %rax, %rax
jle 0x638b0
movq 0x8(%rbx), %rdi
movq %r15, %rsi
movl %eax, %edx
callq 0x3087c
jmp 0x638d3
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x15e86(%rip), %rcx     # 0x796c1
movl $0x2, %edx
callq 0x4153c
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x309f2
movq $0x0, (%rbx)
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%rbx), %eax
orl $0x8, %eax
movl %eax, 0x8(%rbx)
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rax
movq 0x8(%rax), %rcx
leaq 0x15e59(%rip), %rdx     # 0x796d8
leaq 0x15ead(%rip), %r8      # 0x79733
movq %rbx, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x45d26
jmp 0x63845
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x14a1c(%rip), %rcx     # 0x782c5
movl $0x1, %edx
jmp 0x63840
movq 0x8(%rbx), %r14
movq %r14, %rdi
callq 0x309f2
movq $0x0, (%r14)
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%r14), %eax
orl $0x8, %eax
movl %eax, 0x8(%r14)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x31975
jmp 0x63866