// File: /workspace/github_c_makefile_star2_O1/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 0x63a12
movq %rdx, %r12
movq (%rdx), %rax
testb $0x1, 0x9(%rax)
je 0x63a12
movq (%rax), %r14
testq %r14, %r14
je 0x63a12
cmpl $0xfeac14, 0x34(%r14)   # imm = 0xFEAC14
jne 0x63a12
cmpq $0x0, (%r14)
je 0x63a60
movl %esi, %r13d
movq $-0x1, %rdx
cmpl $0x1, %esi
je 0x6394f
movq 0x8(%r12), %r15
movq %r15, %rdi
callq 0x3fd5f
movq (%r15), %rdx
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x66644
testq %rax, %rax
jle 0x63a2e
movq %rax, %r14
cmpl $0x3, %r13d
jl 0x63a86
movq 0x10(%r12), %rdi
movl $0x2c, -0x2c(%rbp)
testb $0x1, 0x8(%rdi)
je 0x6399b
leaq -0x34(%rbp), %r15
movq %r15, %rsi
callq 0x30b04
cmpl $0x0, (%r15)
jle 0x6399b
movsbl (%rax), %eax
movl %eax, -0x2c(%rbp)
movl $0x5c, -0x30(%rbp)
movl $0x22, %r15d
cmpl $0x3, %r13d
je 0x63a9b
movq 0x18(%r12), %rdi
testb $0x1, 0x8(%rdi)
je 0x639d3
leaq -0x34(%rbp), %rsi
callq 0x30b04
leaq -0x34(%rbp), %rcx
cmpl $0x0, (%rcx)
jle 0x639d3
movsbl (%rax), %r15d
cmpl $0x5, %r13d
jl 0x63a9b
movq 0x20(%r12), %rdi
testb $0x1, 0x8(%rdi)
movl -0x2c(%rbp), %r13d
je 0x63a9f
leaq -0x34(%rbp), %r12
movq %r12, %rsi
callq 0x30b04
cmpl $0x0, (%r12)
jle 0x63a9f
movsbl (%rax), %eax
movl %eax, -0x30(%rbp)
jmp 0x63a9f
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x15c9d(%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
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rax
movq 0x8(%rax), %rcx
leaq 0x15c6a(%rip), %rdx     # 0x796d8
leaq 0x15cbe(%rip), %r8      # 0x79733
movq %rbx, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x45d26
jmp 0x63a2e
movl $0x5c, -0x30(%rbp)
movl $0x22, %r15d
movl $0x2c, %r13d
jmp 0x63a9f
movl -0x2c(%rbp), %r13d
movq %rbx, %rdi
callq 0x317eb
testq %rax, %rax
je 0x63ad9
movq %rax, %r12
movq -0x40(%rbp), %rdi
movl %r14d, %esi
movl %r13d, %edx
movl %r15d, %ecx
movl -0x30(%rbp), %r8d
movq %rax, %r9
callq 0x5cb2e
movq 0x8(%rbx), %rsi
movq %r12, %rdi
callq 0x3ebc8
jmp 0x63a4f
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x147da(%rip), %rcx     # 0x782c5
movl $0x1, %edx
callq 0x4153c
movq 0x8(%rbx), %rdi
callq 0x309f2
jmp 0x63a4f