// File: /workspace/github_c_makefile_star2_O2/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 0x53eea
movq %rdx, %r12
movq (%rdx), %rax
testb $0x1, 0x9(%rax)
je 0x53eea
movq (%rax), %r14
testq %r14, %r14
je 0x53eea
cmpl $0xfeac14, 0x34(%r14)   # imm = 0xFEAC14
jne 0x53eea
cmpq $0x0, (%r14)
je 0x53f17
movl %esi, %r13d
cmpl $0x1, %esi
jne 0x53f3b
pushq $-0x1
popq %rdx
jmp 0x53f48
leaq 0x137bb(%rip), %rdx     # 0x676ac
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x2a0db
movq %rbx, %rdi
xorl %esi, %esi
callq 0x298b2
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 0x1379e(%rip), %rdx     # 0x676c3
leaq 0x137f2(%rip), %r8      # 0x6771e
pushq $0x2
popq %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3be68
jmp 0x53efc
movq 0x8(%r12), %rdi
callq 0x297ae
movq %rax, %rdx
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x56385
testq %rax, %rax
jle 0x53efc
movq %rax, %r14
cmpl $0x3, %r13d
jb 0x53f9d
movq 0x10(%r12), %rdi
pushq $0x2c
popq %rax
movl %eax, -0x2c(%rbp)
testb $0x1, 0x8(%rdi)
je 0x53f8b
leaq -0x34(%rbp), %r15
movq %r15, %rsi
callq 0x297ed
cmpl $0x0, (%r15)
jle 0x53f8b
movsbl (%rax), %eax
movl %eax, -0x2c(%rbp)
pushq $0x5c
popq %rax
movl %eax, -0x30(%rbp)
cmpl $0x3, %r13d
jne 0x53fad
pushq $0x22
popq %r15
jmp 0x54002
pushq $0x5c
popq %rax
movl %eax, -0x30(%rbp)
pushq $0x22
popq %r15
pushq $0x2c
popq %r13
jmp 0x54006
movq 0x18(%r12), %rdi
pushq $0x22
popq %r15
testb $0x1, 0x8(%rdi)
je 0x53fd2
leaq -0x34(%rbp), %rsi
callq 0x297ed
leaq -0x34(%rbp), %rcx
cmpl $0x0, (%rcx)
jle 0x53fd2
movsbl (%rax), %r15d
cmpl $0x5, %r13d
jb 0x54002
movq 0x20(%r12), %rdi
testb $0x1, 0x8(%rdi)
movl -0x2c(%rbp), %r13d
je 0x54006
leaq -0x34(%rbp), %r12
movq %r12, %rsi
callq 0x297ed
cmpl $0x0, (%r12)
jle 0x54006
movsbl (%rax), %eax
movl %eax, -0x30(%rbp)
jmp 0x54006
movl -0x2c(%rbp), %r13d
movq %rbx, %rdi
callq 0x2a2b0
testq %rax, %rax
je 0x5403f
movq %rax, %r12
movq -0x40(%rbp), %rdi
movl %r14d, %esi
movl %r13d, %edx
movl %r15d, %ecx
movl -0x30(%rbp), %r8d
movq %rax, %r9
callq 0x4e81f
movq %rbx, %rdi
movq %r12, %rsi
callq 0x299d3
jmp 0x53f06
leaq 0x1226a(%rip), %rdx     # 0x662b0
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x2a0db
movq %rbx, %rdi
callq 0x298e8
jmp 0x53f06