// File: /workspace/github_c_makefile_star2_O0/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
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x0, -0x5c(%rbp)
cmpl $0x1, -0x14(%rbp)
jl 0xa78a4
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x57480
cmpl $0x0, %eax
jne 0xa78d0
movq -0x10(%rbp), %rdi
movl $0x2, %esi
leaq 0x1e22e(%rip), %rdx     # 0xc5ae2
callq 0x580b0
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0xa7c6e
movq -0x20(%rbp), %rax
movq (%rax), %rdi
leaq -0x78(%rbp), %rsi
callq 0x56e20
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
movl -0x78(%rbp), %edx
leaq -0x28(%rbp), %rsi
callq 0x8e570
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0xa792f
movq -0x10(%rbp), %rdi
movl $0x2, %esi
leaq 0x1e1e5(%rip), %rdx     # 0xc5af8
callq 0x580b0
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0xa7c6e
movq -0x10(%rbp), %rdi
movl $0x38, %esi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x58640
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0xa797b
movq -0x10(%rbp), %rdi
movl $0x1, %esi
leaq 0x1ce52(%rip), %rdx     # 0xc47b1
callq 0x580b0
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0xa7c6e
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
movq -0x58(%rbp), %rsi
movq -0x68(%rbp), %rdx
callq 0x90730
movl $0x0, -0x74(%rbp)
cmpl $0x1, -0x14(%rbp)
jle 0xa79ad
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x56c90
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xa79bf
movl $0x1, -0x5c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x58570
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
callq 0x58510
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0xa79e7
cmpq $0x0, -0x50(%rbp)
jne 0xa7a13
movq -0x10(%rbp), %rdi
movl $0x1, %esi
leaq 0x1cdba(%rip), %rdx     # 0xc47b1
callq 0x580b0
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0xa7c6e
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x88(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x7c(%rbp)
cmpl $0x2, -0x14(%rbp)
jle 0xa7a55
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xa0(%rbp)
jmp 0xa7a60
xorl %eax, %eax
movq %rax, -0xa0(%rbp)
jmp 0xa7a60
movl -0x7c(%rbp), %r8d
movq -0x88(%rbp), %rdx
movq -0x90(%rbp), %rsi
movq -0x98(%rbp), %rdi
movq -0xa0(%rbp), %r9
movl $0x1, %ecx
xorl %eax, %eax
xorl %eax, %eax
movl $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
callq 0x8e7e0
movq %rax, %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x68(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0xa7ae6
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rcx
movl $0x1, %esi
leaq 0x1e05e(%rip), %rdx     # 0xc5b26
movb $0x0, %al
callq 0x79580
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0xa7c6e
jmp 0xa7ae8
movq -0x68(%rbp), %rdi
leaq -0x40(%rbp), %rsi
movq $-0x1, %rdx
callq 0xaad40
movq %rax, -0x70(%rbp)
cmpq $0x1, -0x70(%rbp)
jge 0xa7b0c
jmp 0xa7c3c
movq -0x50(%rbp), %rdi
callq 0x56b80
movq -0x40(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x40(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0x74(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0xa7b84
jmp 0xa7b36
movq -0x30(%rbp), %rcx
xorl %eax, %eax
cmpq -0x38(%rbp), %rcx
movb %al, -0xa1(%rbp)
jae 0xa7b5c
movq -0x38(%rbp), %rax
movsbl -0x1(%rax), %eax
cmpl $0xa, %eax
sete %al
movb %al, -0xa1(%rbp)
movb -0xa1(%rbp), %al
testb $0x1, %al
jne 0xa7b68
jmp 0xa7b82
movq -0x70(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x70(%rbp)
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xa7b36
jmp 0xa7b84
movl -0x74(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0xa7c0c
jmp 0xa7b91
movq -0x30(%rbp), %rcx
xorl %eax, %eax
cmpq -0x38(%rbp), %rcx
movb %al, -0xa2(%rbp)
jae 0xa7be1
movq -0x30(%rbp), %rax
movzbl (%rax), %ecx
xorl %eax, %eax
cmpl $0xc0, %ecx
movb %al, -0xa2(%rbp)
jge 0xa7be1
callq 0xd1f0
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
setne %al
movb %al, -0xa2(%rbp)
movb -0xa2(%rbp), %al
testb $0x1, %al
jne 0xa7bed
jmp 0xa7bfb
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0xa7b91
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jb 0xa7c0a
jmp 0xa7ae8
jmp 0xa7c0c
movq -0x50(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
subq %rcx, %rax
movl %eax, %edx
callq 0x56950
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rdx
xorl %eax, %eax
movl %eax, %esi
callq 0x57920
jmp 0xa7ae8
movq -0x58(%rbp), %rdi
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x8ea80
movq -0x10(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0xab080
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x572c0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nopw (%rax,%rax)