// File: /workspace/github_c_makefile_star2_O3/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 0x63afd
movq %rdx, %r14
movq (%rdx), %rcx
testb $0x1, 0x9(%rcx)
je 0x63afd
movq 0x8(%r14), %rax
testb $0x40, 0x8(%rax)
jne 0x63b49
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x13e03(%rip), %rcx     # 0x77912
movl $0x2, %edx
callq 0x40afa
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x30465
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 (%rcx), %r12
testq %r12, %r12
je 0x63c0f
cmpl $0xfeac14, 0x34(%r12)   # imm = 0xFEAC14
jne 0x63c0f
movq (%r12), %rcx
testq %rcx, %rcx
je 0x63c26
cmpq $0x0, 0x40(%rcx)
je 0x63c2f
movl %esi, %r15d
movabsq $0x220000002c, %rcx     # imm = 0x220000002C
movq %rcx, -0x40(%rbp)
movq %r12, -0x38(%rbp)
movl $0x0, -0x30(%rbp)
cmpl $0x2, %esi
je 0x63bdf
movq 0x10(%r14), %rdi
leaq -0x24(%rbp), %rbx
movq %rbx, %rsi
callq 0x30577
cmpl $0x0, (%rbx)
jle 0x63bb8
movsbl (%rax), %eax
movl %eax, -0x40(%rbp)
cmpl $0x4, %r15d
jb 0x63bd5
movq 0x18(%r14), %rdi
movq %rbx, %rsi
callq 0x30577
cmpl $0x0, (%rbx)
jle 0x63bd5
movsbl (%rax), %eax
movl %eax, -0x3c(%rbp)
movq 0x8(%r14), %rax
testb $0x40, 0x8(%rax)
je 0x63bf2
movq (%rax), %rdi
leaq 0x1071(%rip), %rsi      # 0x64c5a
leaq -0x40(%rbp), %rdx
callq 0x5134a
movq (%r12), %rax
movq 0x8(%r12), %rdi
leaq 0x146df(%rip), %rsi     # 0x782e1
movl $0x1, %edx
callq *0x40(%rax)
jmp 0x63b3a
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x13aab(%rip), %rcx     # 0x776cc
jmp 0x63b0f
leaq 0x13b11(%rip), %r8      # 0x7773e
jmp 0x63c32
movq (%rcx), %r8
movq (%rbx), %rax
movq 0x8(%rax), %rcx
leaq 0x13aa3(%rip), %rdx     # 0x776e3
movq %rbx, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x44ed3
jmp 0x63b19