// File: /workspace/github_c_makefile_star2_O3/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 0x629b1
movq %rdx, %r12
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
jne 0x629ff
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x14c46(%rip), %rcx     # 0x77609
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 $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %r13d
leaq -0x2c(%rbp), %r14
movq %r14, %rsi
callq 0x30577
leaq -0x38(%rbp), %rsi
movq %rax, (%rsi)
movq 0x60(%rbx), %r15
movl (%r14), %edx
movq %r15, %rdi
callq 0x51bfb
testq %rax, %rax
je 0x62a65
movq %rax, %r14
movq 0x8(%r12), %rdi
leaq -0x2c(%rbp), %r15
movq %r15, %rsi
callq 0x30577
cmpl $0x0, (%r15)
jle 0x629cd
movq %rax, -0x40(%rbp)
cmpl $0x2, %r13d
jne 0x62a7b
movq 0x60(%rbx), %rdi
movl $0x1c, %ecx
xorl %r13d, %r13d
movq -0x38(%rbp), %r15
xorl %r8d, %r8d
xorl %r9d, %r9d
jmp 0x62aba
movq (%rbx), %rsi
addq $0x8, %rsi
leaq 0x14bac(%rip), %rcx     # 0x7761f
movq %r15, %rdi
jmp 0x629c3
movq 0x10(%r12), %r15
movq %r15, %rdi
callq 0x3f362
movl (%r15), %eax
movl %eax, %r8d
andl $0x1, %r8d
movq %rax, %rdx
andl $0x8, %eax
leal 0x1c(,%rax,2), %ecx
movq 0x60(%rbx), %rdi
movq -0x38(%rbp), %r15
cmpl $0x4, %r13d
jb 0x62ab4
movq 0x18(%r12), %r9
jmp 0x62ab7
xorl %r9d, %r9d
movq %rdx, %r13
movq %r14, %rsi
movq %r15, %rdx
pushq $0x0
pushq $0x0
callq 0x51dad
addq $0x10, %rsp
testq %rax, %rax
je 0x62b26
movq %rax, %r12
movq 0x40(%r14), %rax
testq %rax, %rax
je 0x62b44
testb $0x1, %r13b
je 0x62afb
movq 0x50(%r14), %rcx
testq %rcx, %rcx
je 0x62afb
movq %r12, %rdi
movl $0x1, %esi
callq *%rcx
movq 0x40(%r14), %rax
movslq -0x2c(%rbp), %rdx
movq %r12, %rdi
movq -0x40(%rbp), %rsi
callq *%rax
movq %rax, %r15
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x30465
testq %r15, %r15
jle 0x62b69
movq %r15, (%rbx)
movl $0x2, %eax
jmp 0x62b75
leaq 0x14b20(%rip), %rdx     # 0x7764d
movq %rbx, %rdi
movl $0x1, %esi
movq %r15, %rcx
xorl %eax, %eax
callq 0x44ed3
jmp 0x629cd
movq (%r14), %rcx
leaq 0x14c91(%rip), %rdx     # 0x777df
movq %rbx, %rdi
movl $0x1, %esi
xorl %eax, %eax
callq 0x44ed3
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)
movq 0x20(%r14), %rax
testq %rax, %rax
je 0x629ee
movq %r12, %rdi
callq *%rax
jmp 0x629ee