// File: /workspace/github_c_makefile_star2_O0/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
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x2, -0x14(%rbp)
jl 0xa75b4
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x57480
cmpl $0x0, %eax
jne 0xa75e0
movq -0x10(%rbp), %rdi
movl $0x2, %esi
leaq 0x1e51e(%rip), %rdx     # 0xc5ae2
callq 0x580b0
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0xa7863
movq -0x20(%rbp), %rax
movq (%rax), %rdi
leaq -0x58(%rbp), %rsi
callq 0x56e20
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
movl -0x58(%rbp), %edx
leaq -0x38(%rbp), %rsi
callq 0x8e570
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xa763f
movq -0x10(%rbp), %rdi
movl $0x2, %esi
leaq 0x1e4d5(%rip), %rdx     # 0xc5af8
callq 0x580b0
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0xa7863
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x58(%rbp), %rsi
callq 0x56e20
movq %rax, -0x40(%rbp)
cmpl $0x1, -0x58(%rbp)
jge 0xa7671
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0xa7863
movl $0x1c, -0x44(%rbp)
movl $0x0, -0x54(%rbp)
cmpl $0x2, -0x14(%rbp)
jle 0xa76c6
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x56c90
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xa76a7
movl $0x1, -0x24(%rbp)
movl -0x54(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0xa76c4
movl -0x44(%rbp), %eax
andl $-0x11, %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
orl $0x20, %eax
movl %eax, -0x44(%rbp)
jmp 0xa76c6
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x70(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x64(%rbp)
cmpl $0x3, -0x14(%rbp)
jle 0xa7705
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x88(%rbp)
jmp 0xa7710
xorl %eax, %eax
movq %rax, -0x88(%rbp)
jmp 0xa7710
movl -0x64(%rbp), %r8d
movl -0x68(%rbp), %ecx
movq -0x70(%rbp), %rdx
movq -0x78(%rbp), %rsi
movq -0x80(%rbp), %rdi
movq -0x88(%rbp), %r9
xorl %eax, %eax
xorl %eax, %eax
movl $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
callq 0x8e7e0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0xa7780
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rcx
movl $0x1, %esi
leaq 0x1e3c4(%rip), %rdx     # 0xc5b26
movb $0x0, %al
callq 0x79580
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0xa7863
movq -0x30(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0xa77f1
movl -0x54(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xa77b4
movq -0x30(%rbp), %rax
cmpq $0x0, 0x50(%rax)
je 0xa77b4
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x50(%rbp), %rdi
movl $0x1, %esi
callq *%rax
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x50(%rbp), %rdi
movq -0x40(%rbp), %rsi
movslq -0x58(%rbp), %rdx
callq *%rax
movq %rax, -0x60(%rbp)
cmpq $0x1, -0x60(%rbp)
jge 0xa77e2
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
jmp 0xa77ef
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x57010
jmp 0xa784f
movq -0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0xa7813
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x98(%rbp)
jmp 0xa7823
leaq 0x1e3fd(%rip), %rax     # 0xc5c17
movq %rax, -0x98(%rbp)
jmp 0xa7823
movq -0x90(%rbp), %rdi
movq -0x98(%rbp), %rcx
movl $0x1, %esi
leaq 0x1e47b(%rip), %rdx     # 0xc5cb8
movb $0x0, %al
callq 0x79580
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movq -0x30(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x8ea80
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nop