// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_fputcsv
static int jx9Builtin_fputcsv(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	const jx9_io_stream *pStream;
	struct csv_data sCsv;
	io_private *pDev;
	char *zEol;
	int eolen;
	if( nArg < 2 || !jx9_value_is_resource(apArg[0]) || !jx9_value_is_json_array(apArg[1]) ){
		/* Missing/Invalid arguments, return FALSE */
		jx9_context_throw_error(pCtx, JX9_CTX_WARNING, "Missing/Invalid arguments");
		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  || pStream->xWrite == 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;
	}
	/* Set default csv separator */
	sCsv.delimiter = ',';
	sCsv.enclosure = '"';
	sCsv.pDev = pDev;
	sCsv.iCount = 0;
	if( nArg > 2 ){
		/* User delimiter */
		const char *z;
		int n;
		z = jx9_value_to_string(apArg[2], &n);
		if( n > 0 ){
			sCsv.delimiter = z[0];
		}
		if( nArg > 3 ){
			z = jx9_value_to_string(apArg[3], &n);
			if( n > 0 ){
				sCsv.enclosure = z[0];
			}
		}
	}
	/* Iterate throw array entries and write csv data */
	jx9_array_walk(apArg[1], csv_write_callback, &sCsv);
	/* Write a line ending */
#ifdef __WINNT__
	zEol = "\r\n";
	eolen = (int)sizeof("\r\n")-1;
#else
	/* Assume UNIX LF */
	zEol = "\n";
	eolen = (int)sizeof(char);
#endif
	pDev->pStream->xWrite(pDev->pHandle, (const void *)zEol, eolen);
	return JX9_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rdi, %r14
cmpl $0x2, %esi
jl 0x555ae
movq %rdx, %rbx
movq (%rdx), %rax
testb $0x1, 0x9(%rax)
je 0x555ae
movq 0x8(%rbx), %rdi
testb $0x40, 0x8(%rdi)
jne 0x555d9
leaq 0x1233d(%rip), %rdx     # 0x678f2
pushq $0x2
popq %rsi
movq %r14, %rdi
callq 0x2a0db
movq %r14, %rdi
xorl %esi, %esi
callq 0x298b2
xorl %eax, %eax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq (%rax), %r12
testq %r12, %r12
je 0x55693
cmpl $0xfeac14, 0x34(%r12)   # imm = 0xFEAC14
jne 0x55693
movq (%r12), %rax
testq %rax, %rax
je 0x5569f
cmpq $0x0, 0x40(%rax)
je 0x556a8
movl %esi, %r15d
movabsq $0x220000002c, %rax     # imm = 0x220000002C
movq %rax, -0x40(%rbp)
movq %r12, -0x38(%rbp)
andl $0x0, -0x30(%rbp)
cmpl $0x2, %esi
je 0x55668
movq 0x10(%rbx), %rdi
leaq -0x24(%rbp), %r14
movq %r14, %rsi
callq 0x297ed
cmpl $0x0, (%r14)
jle 0x55646
movsbl (%rax), %eax
movl %eax, -0x40(%rbp)
cmpl $0x4, %r15d
jb 0x55664
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0x297ed
cmpl $0x0, (%r14)
jle 0x55664
movsbl (%rax), %eax
movl %eax, -0x3c(%rbp)
movq 0x8(%rbx), %rdi
leaq 0xebc(%rip), %rsi       # 0x5652b
leaq -0x40(%rbp), %rdx
callq 0x29c1e
movq (%r12), %rax
movq 0x8(%r12), %rdi
leaq 0x12c39(%rip), %rsi     # 0x682c1
pushq $0x1
popq %rdx
callq *0x40(%rax)
jmp 0x555ca
leaq 0x12012(%rip), %rdx     # 0x676ac
jmp 0x555b5
leaq 0x12078(%rip), %r8      # 0x6771e
jmp 0x556ab
movq (%rax), %r8
movq (%r14), %rax
movq 0x8(%rax), %rcx
leaq 0x1200a(%rip), %rdx     # 0x676c3
pushq $0x2
popq %rsi
movq %r14, %rdi
xorl %eax, %eax
callq 0x3be68
jmp 0x555c0