// File: /workspace/github_c_makefile_star2_O2/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 0x54f66
movq %rdx, %r15
movq (%rdx), %rax
testb $0x1, 0x9(%rax)
je 0x54f66
movq (%rax), %r13
testq %r13, %r13
je 0x54f66
cmpl $0xfeac14, 0x34(%r13)   # imm = 0xFEAC14
jne 0x54f66
movq (%r13), %r14
testq %r14, %r14
je 0x54f93
cmpq $0x0, 0x40(%r14)
je 0x54f9c
movl %esi, %r12d
movq 0x8(%r15), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x297ed
movq %rax, %rsi
cmpl $0x2, %r12d
jne 0x54fbc
movl -0x2c(%rbp), %ecx
jmp 0x54fe7
leaq 0x1273f(%rip), %rdx     # 0x676ac
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x2a0db
movq %rbx, %rdi
xorl %esi, %esi
callq 0x298b2
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x12784(%rip), %r8      # 0x6771e
jmp 0x54f9f
movq (%r14), %r8
movq (%rbx), %rax
movq 0x8(%rax), %rcx
leaq 0x12716(%rip), %rdx     # 0x676c3
pushq $0x2
popq %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3be68
jmp 0x54f78
movq 0x10(%r15), %rdi
movq %rsi, %r15
callq 0x29772
testl %eax, %eax
setns %dl
movl -0x2c(%rbp), %ecx
cmpl %ecx, %eax
setl %sil
andb %dl, %sil
cmpb $0x1, %sil
movq %r15, %rsi
jne 0x54fe7
movl %eax, -0x2c(%rbp)
movl %eax, %ecx
testl %ecx, %ecx
jle 0x55004
movq 0x8(%r13), %rdi
movl %ecx, %edx
callq *0x40(%r14)
testl %eax, %eax
js 0x54f78
movq %rbx, %rdi
movl %eax, %esi
jmp 0x55009
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2987c
jmp 0x54f82