// File: /workspace/github_c_makefile_star2_O0/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
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
cmpl $0x2, -0x14(%rbp)
jl 0xa8bcf
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x576d0
cmpl $0x0, %eax
je 0xa8bcf
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x57610
cmpl $0x0, %eax
jne 0xa8bfb
movq -0x10(%rbp), %rdi
movl $0x2, %esi
leaq 0x1d20c(%rip), %rdx     # 0xc5deb
callq 0x580b0
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0xa8d99
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x56ec0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0xa8c1f
movq -0x48(%rbp), %rax
cmpl $0xfeac14, 0x34(%rax)   # imm = 0xFEAC14
je 0xa8c4b
movq -0x10(%rbp), %rdi
movl $0x2, %esi
leaq 0x1cf76(%rip), %rdx     # 0xc5ba5
callq 0x580b0
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0xa8d99
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0xa8c68
movq -0x28(%rbp), %rax
cmpq $0x0, 0x40(%rax)
jne 0xa8cd4
movq -0x10(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rdi
callq 0x584d0
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0xa8c91
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x80(%rbp)
jmp 0xa8c9e
leaq 0x1cf7f(%rip), %rax     # 0xc5c17
movq %rax, -0x80(%rbp)
jmp 0xa8c9e
movq -0x70(%rbp), %rcx
movq -0x78(%rbp), %rdi
movq -0x80(%rbp), %r8
movl $0x2, %esi
leaq 0x1cf06(%rip), %rdx     # 0xc5bbc
movb $0x0, %al
callq 0x79580
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0xa8d99
movl $0x2c, -0x40(%rbp)
movl $0x22, -0x3c(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x30(%rbp)
cmpl $0x2, -0x14(%rbp)
jle 0xa8d4b
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x64(%rbp), %rsi
callq 0x56e20
movq %rax, -0x60(%rbp)
cmpl $0x0, -0x64(%rbp)
jle 0xa8d1c
movq -0x60(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x40(%rbp)
cmpl $0x3, -0x14(%rbp)
jle 0xa8d49
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x64(%rbp), %rsi
callq 0x56e20
movq %rax, -0x60(%rbp)
cmpl $0x0, -0x64(%rbp)
jle 0xa8d47
movq -0x60(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x3c(%rbp)
jmp 0xa8d49
jmp 0xa8d4b
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x2626(%rip), %rsi      # 0xab380
leaq -0x40(%rbp), %rdx
callq 0x57880
leaq 0x1de6f(%rip), %rax     # 0xc6bd9
movq %rax, -0x50(%rbp)
movl $0x1, -0x54(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq 0x40(%rax), %rax
movq -0x48(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq -0x50(%rbp), %rsi
movslq -0x54(%rbp), %rdx
callq *%rax
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)