// File: /workspace/github_c_makefile_star2_O1/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, %rbx
cmpl $0x2, %esi
jl 0x655ae
movq %rdx, %r14
movq (%rdx), %rax
testb $0x1, 0x9(%rax)
je 0x655ae
movq 0x8(%r14), %rcx
testb $0x40, 0x8(%rcx)
jne 0x655fa
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x14347(%rip), %rcx     # 0x79907
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 $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq (%rax), %r12
testq %r12, %r12
je 0x656c0
cmpl $0xfeac14, 0x34(%r12)   # imm = 0xFEAC14
jne 0x656c0
movq (%r12), %rax
testq %rax, %rax
je 0x656d7
cmpq $0x0, 0x40(%rax)
je 0x656d7
movl %esi, %r15d
movabsq $0x220000002c, %rax     # imm = 0x220000002C
movq %rax, -0x40(%rbp)
movq %r12, -0x38(%rbp)
movl $0x0, -0x30(%rbp)
cmpl $0x2, %esi
je 0x65686
movq 0x10(%r14), %rdi
leaq -0x24(%rbp), %rbx
movq %rbx, %rsi
callq 0x30b04
cmpl $0x0, (%rbx)
jle 0x65669
movsbl (%rax), %eax
movl %eax, -0x40(%rbp)
cmpl $0x4, %r15d
jl 0x65686
movq 0x18(%r14), %rdi
movq %rbx, %rsi
callq 0x30b04
cmpl $0x0, (%rbx)
jle 0x65686
movsbl (%rax), %eax
movl %eax, -0x3c(%rbp)
movq 0x8(%r14), %rax
testb $0x40, 0x8(%rax)
je 0x656a3
movq (%rax), %rdi
leaq 0x1193(%rip), %rsi      # 0x6682d
leaq -0x40(%rbp), %rdx
callq 0x52ab1
movq (%r12), %rax
movq 0x8(%r12), %rdi
leaq 0x14c2e(%rip), %rsi     # 0x7a2e1
movl $0x1, %edx
callq *0x40(%rax)
jmp 0x655eb
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x13fef(%rip), %rcx     # 0x796c1
jmp 0x655c0
movq (%rbx), %rcx
movq 0x8(%rcx), %rcx
testq %rax, %rax
je 0x656e8
movq (%rax), %r8
jmp 0x656ef
leaq 0x14044(%rip), %r8      # 0x79733
leaq 0x13fe2(%rip), %rdx     # 0x796d8
movq %rbx, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x45d26
jmp 0x655ca