// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_copy
static int jx9Builtin_copy(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	const jx9_io_stream *pSin, *pSout;	
	const char *zFile;
	char zBuf[8192];
	void *pIn, *pOut;
	jx9_int64 n;
	int nLen;
	if( nArg < 2 || !jx9_value_is_string(apArg[0]) || !jx9_value_is_string(apArg[1])){
		/* Missing/Invalid arguments, return FALSE */
		jx9_context_throw_error(pCtx, JX9_CTX_WARNING, "Expecting a source and a destination path");
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Extract the source name */
	zFile = jx9_value_to_string(apArg[0], &nLen);
	/* Point to the target IO stream device */
	pSin = jx9VmGetStreamDevice(pCtx->pVm, &zFile, nLen);
	if( pSin == 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;
	}
	/* Try to open the source file in a read-only mode */
	pIn = jx9StreamOpenHandle(pCtx->pVm, pSin, zFile, JX9_IO_OPEN_RDONLY, FALSE, nArg > 2 ? apArg[2] : 0, FALSE, 0);
	if( pIn == 0 ){
		jx9_context_throw_error_format(pCtx, JX9_CTX_ERR, "IO error while opening source: '%s'", zFile);
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Extract the destination name */
	zFile = jx9_value_to_string(apArg[1], &nLen);
	/* Point to the target IO stream device */
	pSout = jx9VmGetStreamDevice(pCtx->pVm, &zFile, nLen);
	if( pSout == 0 ){
		jx9_context_throw_error(pCtx, JX9_CTX_WARNING, "No such stream device, JX9 is returning FALSE");
		jx9_result_bool(pCtx, 0);
		jx9StreamCloseHandle(pSin, pIn);
		return JX9_OK;
	}
	if( pSout->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), pSin->zName
			);
		jx9_result_bool(pCtx, 0);
		jx9StreamCloseHandle(pSin, pIn);
		return JX9_OK;
	}
	/* Try to open the destination file in a read-write mode */
	pOut = jx9StreamOpenHandle(pCtx->pVm, pSout, zFile, 
		JX9_IO_OPEN_CREATE|JX9_IO_OPEN_TRUNC|JX9_IO_OPEN_RDWR, FALSE, nArg > 2 ? apArg[2] : 0, FALSE, 0);
	if( pOut == 0 ){
		jx9_context_throw_error_format(pCtx, JX9_CTX_ERR, "IO error while opening destination: '%s'", zFile);
		jx9_result_bool(pCtx, 0);
		jx9StreamCloseHandle(pSin, pIn);
		return JX9_OK;
	}
	/* Perform the requested operation */
	for(;;){
		/* Read from source */
		n = pSin->xRead(pIn, zBuf, sizeof(zBuf));
		if( n < 1 ){
			/* EOF or IO error, break immediately */
			break;
		}
		/* Write to dest */
		n = pSout->xWrite(pOut, zBuf, n);
		if( n < 1 ){
			/* IO error, break immediately */
			break;
		}
	}
	/* Close the streams */
	jx9StreamCloseHandle(pSin, pIn);
	jx9StreamCloseHandle(pSout, pOut);
	/* Return TRUE */
	jx9_result_bool(pCtx, 1);
	return JX9_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2038, %rsp           # imm = 0x2038
movq %rdi, %rbx
cmpl $0x2, %esi
jl 0x54c03
movq %rdx, %r12
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
je 0x54c03
movq 0x8(%r12), %rax
testb $0x1, 0x8(%rax)
jne 0x54c33
leaq 0x12bea(%rip), %rdx     # 0x677f4
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x2a0db
movq %rbx, %rdi
xorl %esi, %esi
callq 0x298b2
xorl %eax, %eax
addq $0x2038, %rsp           # imm = 0x2038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %r13d
leaq -0x44(%rbp), %r15
movq %r15, %rsi
callq 0x297ed
leaq -0x40(%rbp), %rsi
movq %rax, (%rsi)
movq 0x60(%rbx), %r14
movl (%r15), %edx
movq %r14, %rdi
callq 0x47354
movq %rax, -0x38(%rbp)
testq %rax, %rax
je 0x54c70
movq -0x40(%rbp), %r15
cmpl $0x2, %r13d
jne 0x54c79
xorl %r9d, %r9d
jmp 0x54c7e
leaq 0x12988(%rip), %rdx     # 0x675ff
jmp 0x54c0a
movq 0x10(%r12), %r9
andq $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
pushq $0x1
popq %rcx
movq %r14, %rdi
movq -0x38(%rbp), %rsi
movq %r15, %rdx
xorl %r8d, %r8d
callq 0x474a5
movq %rax, -0x30(%rbp)
testq %rax, %rax
je 0x54ceb
movq 0x8(%r12), %rdi
leaq -0x44(%rbp), %r14
movq %r14, %rsi
callq 0x297ed
leaq -0x40(%rbp), %rsi
movq %rax, (%rsi)
movq 0x60(%rbx), %rdi
movl (%r14), %edx
movq %rdi, %r14
callq 0x47354
testq %rax, %rax
je 0x54d07
movq %rax, %r15
cmpq $0x0, 0x40(%rax)
je 0x54d30
movq -0x40(%rbp), %rax
cmpl $0x2, %r13d
jne 0x54d65
xorl %r9d, %r9d
jmp 0x54d6a
leaq 0x12b2c(%rip), %rdx     # 0x6781e
pushq $0x1
popq %rsi
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x3be68
jmp 0x54c15
leaq 0x128f1(%rip), %rdx     # 0x675ff
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x2a0db
movq %rbx, %rdi
xorl %esi, %esi
callq 0x298b2
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
jmp 0x54e12
movq (%rbx), %rax
movq 0x8(%rax), %rcx
movq -0x38(%rbp), %r14
movq (%r14), %r8
leaq 0x1297e(%rip), %rdx     # 0x676c3
pushq $0x2
popq %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3be68
movq %rbx, %rdi
xorl %esi, %esi
callq 0x298b2
movq 0x20(%r14), %rax
jmp 0x54e12
movq 0x10(%r12), %r9
andq $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
pushq $0x1c
popq %rcx
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %r14
movq %rax, %rdx
xorl %r8d, %r8d
callq 0x474a5
testq %rax, %rax
movq -0x38(%rbp), %r13
je 0x54ded
movq %rax, %r12
leaq -0x2050(%rbp), %r14
movl $0x2000, %edx           # imm = 0x2000
movq -0x30(%rbp), %rdi
movq %r14, %rsi
callq *0x30(%r13)
testq %rax, %rax
jle 0x54dc5
movq %r12, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq *0x40(%r15)
testq %rax, %rax
jg 0x54d9e
movq 0x20(%r13), %rax
testq %rax, %rax
je 0x54dd4
movq -0x30(%rbp), %rdi
callq *%rax
movq 0x20(%r15), %rax
testq %rax, %rax
je 0x54de2
movq %r12, %rdi
callq *%rax
pushq $0x1
popq %rsi
movq %rbx, %rdi
jmp 0x54c1a
leaq 0x12a4e(%rip), %rdx     # 0x67842
pushq $0x1
popq %rsi
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x3be68
movq %rbx, %rdi
xorl %esi, %esi
callq 0x298b2
movq 0x20(%r13), %rax
testq %rax, %rax
je 0x54c1f
movq -0x30(%rbp), %rdi
callq *%rax
jmp 0x54c1f