// File: /workspace/github_c_makefile_star2_O3/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 0x6330e
movq %rdx, %r15
movq (%rdx), %rax
testb $0x1, 0x9(%rax)
je 0x6330e
movq (%rax), %r13
testq %r13, %r13
je 0x6330e
cmpl $0xfeac14, 0x34(%r13)   # imm = 0xFEAC14
jne 0x6330e
movq (%r13), %r14
testq %r14, %r14
je 0x63360
cmpq $0x0, 0x40(%r14)
je 0x63369
movl %esi, %r12d
movq 0x8(%r15), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x30577
movq %rax, %rsi
cmpl $0x2, %r12d
jne 0x6338b
movl -0x2c(%rbp), %eax
jmp 0x633bc
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x143ac(%rip), %rcx     # 0x776cc
movl $0x2, %edx
callq 0x40afa
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x30465
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
leaq 0x143d7(%rip), %r8      # 0x7773e
jmp 0x6336c
movq (%r14), %r8
movq (%rbx), %rax
movq 0x8(%rax), %rcx
leaq 0x14369(%rip), %rdx     # 0x776e3
movq %rbx, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x44ed3
jmp 0x6332a
movq 0x10(%r15), %r15
movq %r15, %rdi
movq %rsi, %r12
callq 0x3f362
movq (%r15), %rcx
testl %ecx, %ecx
setns %dl
movl -0x2c(%rbp), %eax
cmpl %ecx, %eax
setg %sil
andb %dl, %sil
cmpb $0x1, %sil
movq %r12, %rsi
jne 0x633bc
movl %ecx, -0x2c(%rbp)
movl %ecx, %eax
testl %eax, %eax
jle 0x633ee
movq 0x8(%r13), %rdi
movl %eax, %edx
callq *0x40(%r14)
movq %rax, %r14
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x30465
testl %r14d, %r14d
js 0x63336
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
movq %r14, (%rbx)
jmp 0x63401
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x30465
movq $0x0, (%rbx)
movl $0x2, %eax
jmp 0x63342