// File: /workspace/github_c_makefile_star2_O1/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_fwrite
static int jx9Builtin_fwrite(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	const jx9_io_stream *pStream;
	const char *zString;
	io_private *pDev;
	int nLen, n;
	if( nArg < 2 || !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  || 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;
	}
	/* Extract the data to write */
	zString = jx9_value_to_string(apArg[1], &nLen);
	if( nArg > 2 ){
		/* Maximum data length to write */
		n = jx9_value_to_int(apArg[2]);
		if( n >= 0 && n < nLen ){
			nLen = n;
		}
	}
	if( nLen < 1 ){
		/* Nothing to write */
		jx9_result_int(pCtx, 0);
		return JX9_OK;
	}
	/* Perform the requested operation */
	n = (int)pStream->xWrite(pDev->pHandle, (const void *)zString, nLen);
	if( n <  0 ){
		/* IO error, return FALSE */
		jx9_result_bool(pCtx, 0);
	}else{
		/* #Bytes written */
		jx9_result_int(pCtx, n);
	}
	return JX9_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
cmpl $0x2, %esi
jl 0x64e1e
movq %rdx, %r14
movq (%rdx), %rax
testb $0x1, 0x9(%rax)
je 0x64e1e
movq (%rax), %r12
testq %r12, %r12
je 0x64e1e
cmpl $0xfeac14, 0x34(%r12)   # imm = 0xFEAC14
jne 0x64e1e
movq (%r12), %r13
testq %r13, %r13
je 0x64e70
cmpq $0x0, 0x40(%r13)
je 0x64e70
movl %esi, %r15d
movq 0x8(%r14), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x30b04
movq %rax, %rsi
cmpl $0x2, %r15d
je 0x64de5
movq 0x10(%r14), %r14
movq %r14, %rdi
movq %rsi, %r15
callq 0x3fd5f
movq %r15, %rsi
movl (%r14), %eax
testl %eax, %eax
js 0x64de5
cmpl %eax, -0x2c(%rbp)
jle 0x64de5
movl %eax, -0x2c(%rbp)
movslq -0x2c(%rbp), %rdx
testq %rdx, %rdx
jle 0x64ea1
movq 0x8(%r12), %rdi
callq *0x40(%r13)
movq %rax, %r14
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x309f2
testl %r14d, %r14d
js 0x64e46
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
movq %r14, (%rbx)
jmp 0x64eb4
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x14891(%rip), %rcx     # 0x796c1
movl $0x2, %edx
callq 0x4153c
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x309f2
movq $0x0, (%rbx)
movl $0x8, %eax
movl $0xfffffe90, %ecx       # imm = 0xFFFFFE90
andl 0x8(%rbx), %ecx
orl %eax, %ecx
movl %ecx, 0x8(%rbx)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rax
movq 0x8(%rax), %rcx
testq %r13, %r13
je 0x64e82
movq (%r13), %r8
jmp 0x64e89
leaq 0x148aa(%rip), %r8      # 0x79733
leaq 0x14848(%rip), %rdx     # 0x796d8
movq %rbx, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x45d26
jmp 0x64e3a
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x309f2
movq $0x0, (%rbx)
movl $0x2, %eax
jmp 0x64e52