// File: /workspace/github_c_makefile_star2_O3/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_fgetcsv
static int jx9Builtin_fgetcsv(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	const jx9_io_stream *pStream;
	const char *zLine;
	io_private *pDev;
	jx9_int64 n, 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 = -1;
	if( nArg > 1 ){
		/* Maximum data to read */
		nLen = jx9_value_to_int64(apArg[1]);
	}
	/* Perform the requested operation */
	n = StreamReadLine(pDev, &zLine, nLen);
	if( n < 1 ){
		/* EOF or IO error, return FALSE */
		jx9_result_bool(pCtx, 0);
	}else{
		jx9_value *pArray;
		int delim  = ',';   /* Delimiter */
		int encl   = '"' ;  /* Enclosure */
		int escape = '\\';  /* Escape character */
		if( nArg > 2 ){
			const char *zPtr;
			int i;
			if( jx9_value_is_string(apArg[2]) ){
				/* Extract the delimiter */
				zPtr = jx9_value_to_string(apArg[2], &i);
				if( i > 0 ){
					delim = zPtr[0];
				}
			}
			if( nArg > 3 ){
				if( jx9_value_is_string(apArg[3]) ){
					/* Extract the enclosure */
					zPtr = jx9_value_to_string(apArg[3], &i);
					if( i > 0 ){
						encl = zPtr[0];
					}
				}
				if( nArg > 4 ){
					if( jx9_value_is_string(apArg[4]) ){
						/* Extract the escape character */
						zPtr = jx9_value_to_string(apArg[4], &i);
						if( i > 0 ){
							escape = zPtr[0];
						}
					}
				}
			}
		}
		/* Create our array */
		pArray = jx9_context_new_array(pCtx);
		if( pArray == 0 ){
			jx9_context_throw_error(pCtx, JX9_CTX_ERR, "JX9 is running out of memory");
			jx9_result_null(pCtx);
			return JX9_OK;
		}
		/* Parse the raw input */
		jx9ProcessCsv(zLine, (int)n, delim, encl, escape, jx9CsvConsumer, pArray);
		/* Return the freshly 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 $0x18, %rsp
movq %rdi, %rbx
testl %esi, %esi
jle 0x61ec0
movq %rdx, %r13
movq (%rdx), %rax
testb $0x1, 0x9(%rax)
je 0x61ec0
movq (%rax), %r14
testq %r14, %r14
je 0x61ec0
cmpl $0xfeac14, 0x34(%r14)   # imm = 0xFEAC14
jne 0x61ec0
cmpq $0x0, (%r14)
je 0x61f0e
movl %esi, %r15d
cmpl $0x1, %esi
jne 0x61f34
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
movq $-0x1, %rdx
callq 0x64ad2
testq %rax, %rax
jle 0x61edc
movq %rax, %r14
jmp 0x61fd1
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x157fa(%rip), %rcx     # 0x776cc
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 $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rax
movq 0x8(%rax), %rcx
leaq 0x157c7(%rip), %rdx     # 0x776e3
leaq 0x1581b(%rip), %r8      # 0x7773e
movq %rbx, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x44ed3
jmp 0x61edc
movq 0x8(%r13), %r12
movq %r12, %rdi
callq 0x3f362
movq (%r12), %rdx
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x64ad2
testq %rax, %rax
jle 0x61edc
movq %rax, %r14
cmpl $0x3, %r15d
jb 0x61fd1
movq 0x10(%r13), %rdi
movl $0x2c, -0x2c(%rbp)
testb $0x1, 0x8(%rdi)
je 0x61f88
leaq -0x34(%rbp), %r12
movq %r12, %rsi
callq 0x30577
cmpl $0x0, (%r12)
jle 0x61f88
movsbl (%rax), %eax
movl %eax, -0x2c(%rbp)
movl $0x5c, -0x30(%rbp)
movl $0x22, %r12d
cmpl $0x3, %r15d
je 0x61fcb
movq 0x18(%r13), %rdi
testb $0x1, 0x8(%rdi)
je 0x61fbb
leaq -0x34(%rbp), %rsi
callq 0x30577
leaq -0x34(%rbp), %rcx
cmpl $0x0, (%rcx)
jle 0x61fbb
movsbl (%rax), %r12d
cmpl $0x5, %r15d
jb 0x61fcb
movq 0x20(%r13), %rdi
testb $0x1, 0x8(%rdi)
jne 0x62048
movl -0x2c(%rbp), %r13d
jmp 0x61fe4
movl $0x5c, -0x30(%rbp)
movl $0x22, %r12d
movl $0x2c, %r13d
movq %rbx, %rdi
callq 0x31231
testq %rax, %rax
je 0x6201e
movq %rax, %r15
movq -0x40(%rbp), %rdi
movl %r14d, %esi
movl %r13d, %edx
movl %r12d, %ecx
movl -0x30(%rbp), %r8d
movq %rax, %r9
callq 0x5b1d6
movq 0x8(%rbx), %rsi
movq %r15, %rdi
callq 0x3e19f
jmp 0x61efd
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x142a0(%rip), %rcx     # 0x762d0
movl $0x1, %edx
callq 0x40afa
movq 0x8(%rbx), %rdi
callq 0x30465
jmp 0x61efd
leaq -0x34(%rbp), %r15
movq %r15, %rsi
callq 0x30577
cmpl $0x0, (%r15)
movl -0x2c(%rbp), %r13d
jle 0x61fe4
movsbl (%rax), %eax
movl %eax, -0x30(%rbp)
jmp 0x61fe4