// File: /workspace/github_c_makefile_star2_O1/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_file_put_contents
static int jx9Builtin_file_put_contents(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	int use_include  = FALSE;
	const jx9_io_stream *pStream;
	const char *zFile;
	const char *zData;
	int iOpenFlags;
	void *pHandle;
	int iFlags;
	int nLen;
	
	if( nArg < 2 || !jx9_value_is_string(apArg[0]) ){
		/* Missing/Invalid arguments, return FALSE */
		jx9_context_throw_error(pCtx, JX9_CTX_WARNING, "Expecting a file path");
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Extract the file path */
	zFile = jx9_value_to_string(apArg[0], &nLen);
	/* Point to the target IO stream device */
	pStream = jx9VmGetStreamDevice(pCtx->pVm, &zFile, nLen);
	if( pStream == 0 ){
		jx9_context_throw_error(pCtx, JX9_CTX_WARNING, "No such stream device, JX9 is returning FALSE");
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Data to write */
	zData = jx9_value_to_string(apArg[1], &nLen);
	if( nLen < 1 ){
		/* Nothing to write, return immediately */
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Try to open the file in read-write mode */
	iOpenFlags = JX9_IO_OPEN_CREATE|JX9_IO_OPEN_RDWR|JX9_IO_OPEN_TRUNC;
	/* Extract the flags */
	iFlags = 0;
	if( nArg > 2 ){
		iFlags = jx9_value_to_int(apArg[2]);
		if( iFlags & 0x01 /*FILE_USE_INCLUDE_PATH*/){
			use_include = TRUE;
		}
		if( iFlags & 0x08 /* FILE_APPEND */){
			/* If the file already exists, append the data to the file
			 * instead of overwriting it.
			 */
			iOpenFlags &= ~JX9_IO_OPEN_TRUNC;
			/* Append mode */
			iOpenFlags |= JX9_IO_OPEN_APPEND;
		}
	}
	pHandle = jx9StreamOpenHandle(pCtx->pVm, pStream, zFile, iOpenFlags, use_include, 
		nArg > 3 ? apArg[3] : 0, FALSE, FALSE);
	if( pHandle == 0 ){
		jx9_context_throw_error_format(pCtx, JX9_CTX_ERR, "IO error while opening '%s'", zFile);
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	if( pStream->xWrite ){
		jx9_int64 n;
		if( (iFlags & 0x01/* LOCK_EX */) && pStream->xLock ){
			/* Try to acquire an exclusive lock */
			pStream->xLock(pHandle, 1/* LOCK_EX */);
		}
		/* Perform the write operation */
		n = pStream->xWrite(pHandle, (const void *)zData, nLen);
		if( n < 1 ){
			/* IO error, return FALSE */
			jx9_result_bool(pCtx, 0);
		}else{
			/* Total number of bytes written */
			jx9_result_int64(pCtx, n);
		}
	}else{
		/* Read-only stream */
		jx9_context_throw_error_format(pCtx, JX9_CTX_ERR, 
			"Read-only stream(%s): Cannot perform write operation", 
			pStream ? pStream->zName : "null_stream"
			);
		jx9_result_bool(pCtx, 0);
	}
	/* Close the handle */
	jx9StreamCloseHandle(pStream, pHandle);
	return JX9_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
cmpl $0x2, %esi
jl 0x6443e
movq %rdx, %r15
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
jne 0x6448c
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x151ae(%rip), %rcx     # 0x795fe
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 $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %r13d
leaq -0x30(%rbp), %r14
movq %r14, %rsi
callq 0x30b04
leaq -0x40(%rbp), %rsi
movq %rax, (%rsi)
movq 0x60(%rbx), %r12
movl (%r14), %edx
movq %r12, %rdi
callq 0x53369
testq %rax, %rax
je 0x644e8
movq %rax, %r14
movq 0x8(%r15), %rdi
leaq -0x30(%rbp), %r12
movq %r12, %rsi
callq 0x30b04
cmpl $0x0, (%r12)
jle 0x6445a
cmpl $0x2, %r13d
movq %rax, -0x38(%rbp)
jne 0x644fe
movb $0x1, -0x29(%rbp)
xorl %r8d, %r8d
movl $0x1c, %ecx
jmp 0x64520
movq (%rbx), %rsi
addq $0x8, %rsi
leaq 0x1511e(%rip), %rcx     # 0x79614
movq %r12, %rdi
jmp 0x64450
movq 0x10(%r15), %r12
movq %r12, %rdi
callq 0x3fd5f
movl (%r12), %r8d
movl %r8d, %eax
andl $0x8, %eax
andl $0x1, %r8d
leal 0x1c(%rax,%rax), %ecx
sete -0x29(%rbp)
movq 0x60(%rbx), %rdi
movq -0x40(%rbp), %r12
cmpl $0x4, %r13d
jl 0x64534
movq 0x18(%r15), %r9
jmp 0x64537
xorl %r9d, %r9d
movq %r14, %rsi
movq %r12, %rdx
pushq $0x0
pushq $0x0
callq 0x534fd
addq $0x10, %rsp
testq %rax, %rax
je 0x6459f
movq %rax, %r15
cmpq $0x0, 0x40(%r14)
je 0x645bd
cmpb $0x0, -0x29(%rbp)
jne 0x64572
movq 0x50(%r14), %rax
testq %rax, %rax
je 0x64572
movq %r15, %rdi
movl $0x1, %esi
callq *%rax
movslq -0x30(%rbp), %rdx
movq %r15, %rdi
movq -0x38(%rbp), %rsi
callq *0x40(%r14)
movq %rax, %r12
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x309f2
testq %r12, %r12
jle 0x645e2
movq %r12, (%rbx)
movl $0x2, %eax
jmp 0x645ee
leaq 0x1509c(%rip), %rdx     # 0x79642
movq %rbx, %rdi
movl $0x1, %esi
movq %r12, %rcx
xorl %eax, %eax
callq 0x45d26
jmp 0x6445a
movq (%r14), %rcx
leaq 0x1520d(%rip), %rdx     # 0x797d4
movq %rbx, %rdi
movl $0x1, %esi
xorl %eax, %eax
callq 0x45d26
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)
movq 0x20(%r14), %rax
testq %rax, %rax
je 0x6447b
movq %r15, %rdi
callq *%rax
jmp 0x6447b