// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_file
static int jx9Builtin_file(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	const char *zFile, *zPtr, *zEnd, *zBuf;
	jx9_value *pArray, *pLine;
	const jx9_io_stream *pStream;
	int use_include = 0;
	io_private *pDev;
	jx9_int64 n;
	int iFlags;
	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;
	}
	/* Allocate a new IO private instance */
	pDev = (io_private *)jx9_context_alloc_chunk(pCtx, sizeof(io_private), TRUE, FALSE);
	if( pDev == 0 ){
		jx9_context_throw_error(pCtx, JX9_CTX_ERR, "JX9 is running out of memory");
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Initialize the structure */
	InitIOPrivate(pCtx->pVm, pStream, pDev);
	iFlags = 0;
	if( nArg > 1 ){
		iFlags = jx9_value_to_int(apArg[1]);
	}
	if( iFlags & 0x01 /*FILE_USE_INCLUDE_PATH*/ ){
		use_include = TRUE;
	}
	/* Create the array and the working value */
	pArray = jx9_context_new_array(pCtx);
	pLine = jx9_context_new_scalar(pCtx);
	if( pArray == 0 || pLine == 0 ){
		jx9_context_throw_error(pCtx, JX9_CTX_ERR, "JX9 is running out of memory");
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Try to open the file in read-only mode */
	pDev->pHandle = jx9StreamOpenHandle(pCtx->pVm, pStream, zFile, JX9_IO_OPEN_RDONLY, use_include, nArg > 2 ? apArg[2] : 0, FALSE, 0);
	if( pDev->pHandle == 0 ){
		jx9_context_throw_error_format(pCtx, JX9_CTX_ERR, "IO error while opening '%s'", zFile);
		jx9_result_bool(pCtx, 0);
		/* Don't worry about freeing memory, everything will be released automatically
		 * as soon we return from this function.
		 */
		return JX9_OK;
	}
	/* Perform the requested operation */
	for(;;){
		/* Try to extract a line */
		n = StreamReadLine(pDev, &zBuf, -1);
		if( n < 1 ){
			/* EOF or IO error */
			break;
		}
		/* Reset the cursor */
		jx9_value_reset_string_cursor(pLine);
		/* Remove line ending if requested by the caller */
		zPtr = zBuf;
		zEnd = &zBuf[n];
		if( iFlags & 0x02 /* FILE_IGNORE_NEW_LINES */ ){
			/* Ignore trailig lines */
			while( zPtr < zEnd && (zEnd[-1] == '\n' 
#ifdef __WINNT__
				|| zEnd[-1] == '\r'
#endif
				)){
					n--;
					zEnd--;
			}
		}
		if( iFlags & 0x04 /* FILE_SKIP_EMPTY_LINES */ ){
			/* Ignore empty lines */
			while( zPtr < zEnd && (unsigned char)zPtr[0] < 0xc0 && SyisSpace(zPtr[0]) ){
				zPtr++;
			}
			if( zPtr >= zEnd ){
				/* Empty line */
				continue;
			}
		}
		jx9_value_string(pLine, zBuf, (int)(zEnd-zBuf));
		/* Insert line */
		jx9_array_add_elem(pArray, 0/* Automatic index assign*/, pLine);
	}
	/* Close the stream */
	jx9StreamCloseHandle(pStream, pDev->pHandle);
	/* Release the io_private instance */
	ReleaseIOPrivate(pCtx, pDev);
	/* Return the created array */
	jx9_result_value(pCtx, pArray);
	return JX9_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r12
testl %esi, %esi
jle 0x54995
movq %rdx, %r13
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
jne 0x549c2
leaq 0x12c4d(%rip), %rdx     # 0x675e9
pushq $0x2
popq %rsi
movq %r12, %rdi
callq 0x2a0db
movq %r12, %rdi
xorl %esi, %esi
callq 0x298b2
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %r15d
leaq -0x6c(%rbp), %rbx
movq %rbx, %rsi
callq 0x297ed
leaq -0x68(%rbp), %rsi
movq %rax, (%rsi)
movq 0x60(%r12), %rdi
movl (%rbx), %edx
callq 0x47354
testq %rax, %rax
je 0x54a86
movq %rax, %rbx
pushq $0x38
popq %rsi
pushq $0x1
popq %rdx
movl $0x0, -0x2c(%rbp)
movq %r12, %rdi
xorl %ecx, %ecx
callq 0x2a356
testq %rax, %rax
je 0x54a78
movq 0x60(%r12), %rcx
movq %rbx, -0x38(%rbp)
movq %rbx, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rax)
movq %rcx, 0x10(%rax)
andl $0x0, 0x28(%rax)
movabsq $0xfeac1400000000, %rcx # imm = 0xFEAC1400000000
movq %rax, -0x40(%rbp)
movq %rcx, 0x30(%rax)
cmpl $0x1, %r15d
je 0x54a4b
movq 0x8(%r13), %rdi
callq 0x29772
movl %eax, -0x2c(%rbp)
movq %r12, %rdi
callq 0x2a2b0
movq %rax, %rbx
movq %r12, %rdi
callq 0x2a26a
movq %rax, %r14
movq %rbx, -0x48(%rbp)
testq %rbx, %rbx
sete %al
testq %r14, %r14
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x54a92
leaq 0x11831(%rip), %rdx     # 0x662b0
pushq $0x1
jmp 0x5499e
leaq 0x12b72(%rip), %rdx     # 0x675ff
jmp 0x5499c
movl -0x2c(%rbp), %r8d
andl $0x1, %r8d
movq 0x60(%r12), %rdi
movq -0x68(%rbp), %rax
cmpl $0x3, %r15d
jb 0x54aaf
movq 0x10(%r13), %r9
jmp 0x54ab2
xorl %r9d, %r9d
movq -0x38(%rbp), %rsi
pushq $0x1
popq %rcx
movq %rax, %r15
movq %rax, %rdx
pushq $0x0
pushq $0x0
callq 0x474a5
popq %rcx
popq %rdx
movq -0x40(%rbp), %rcx
movq %rax, 0x8(%rcx)
testq %rax, %rax
je 0x54bb4
movq %r12, -0x50(%rbp)
movq %r14, %rax
addq $0x18, %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
pushq $-0x1
popq %rdx
callq 0x56385
testq %rax, %rax
jle 0x54b7d
movq %rax, %r15
movq -0x58(%rbp), %rdi
callq 0x31b1e
movq -0x60(%rbp), %r13
addq %r13, %r15
testb $0x2, -0x2c(%rbp)
jne 0x54b1d
movq %r15, %rbx
jmp 0x54b2f
movq %r15, %rbx
cmpq %r15, %r13
jae 0x54b2f
leaq -0x1(%rbx), %r15
cmpb $0xa, -0x1(%rbx)
je 0x54b1d
testb $0x4, -0x2c(%rbp)
je 0x54b5a
movq %r13, %r15
cmpq %rbx, %r15
jae 0x54aea
movsbq (%r15), %r12
cmpq $-0x41, %r12
ja 0x54b5a
callq 0xc190
movq (%rax), %rax
incq %r15
testb $0x20, 0x1(%rax,%r12,2)
jne 0x54b38
subl %r13d, %ebx
movq %r14, %rdi
movq %r13, %rsi
movl %ebx, %edx
callq 0x29588
movq -0x48(%rbp), %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x29c4b
jmp 0x54aea
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
testq %rax, %rax
movq -0x50(%rbp), %rbx
movq -0x40(%rbp), %r14
je 0x54b98
movq 0x8(%r14), %rdi
callq *%rax
movq %rbx, %rdi
movq %r14, %rsi
callq 0x564ff
movq %rbx, %rdi
movq -0x48(%rbp), %rsi
callq 0x299d3
jmp 0x549b1
leaq 0x12a72(%rip), %rdx     # 0x6762d
pushq $0x1
popq %rsi
movq %r12, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x3be68
jmp 0x549a7