// File: /workspace/github_c_makefile_star2_O1/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 $0x2028, %rsp           # imm = 0x2028
movq %rdi, %rbx
cmpl $0x2, %esi
jl 0x64975
movq %rdx, %r12
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
je 0x64975
movq 0x8(%r12), %rax
testb $0x1, 0x8(%rax)
jne 0x649c6
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x14e82(%rip), %rcx     # 0x79809
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 $0x2028, %rsp           # imm = 0x2028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %r13d
leaq -0x44(%rbp), %r15
movq %r15, %rsi
callq 0x30b04
leaq -0x40(%rbp), %rsi
movq %rax, (%rsi)
movq 0x60(%rbx), %r14
movl (%r15), %edx
movq %r14, %rdi
callq 0x53369
movq %rax, -0x38(%rbp)
testq %rax, %rax
je 0x64a03
movq -0x40(%rbp), %r15
cmpl $0x2, %r13d
jne 0x64a19
xorl %r9d, %r9d
jmp 0x64a1e
movq (%rbx), %rsi
addq $0x8, %rsi
leaq 0x14c03(%rip), %rcx     # 0x79614
movq %r14, %rdi
jmp 0x64987
movq 0x10(%r12), %r9
movq %r14, %rdi
movq -0x38(%rbp), %rsi
movq %r15, %rdx
movl $0x1, %ecx
xorl %r8d, %r8d
pushq $0x0
pushq $0x0
callq 0x534fd
addq $0x10, %rsp
movq %rax, -0x30(%rbp)
testq %rax, %rax
je 0x64a95
movq 0x8(%r12), %rdi
leaq -0x44(%rbp), %r14
movq %r14, %rsi
callq 0x30b04
leaq -0x40(%rbp), %rsi
movq %rax, (%rsi)
movq 0x60(%rbx), %rax
movl (%r14), %edx
movq %rax, %r14
movq %rax, %rdi
callq 0x53369
testq %rax, %rax
je 0x64ab3
movq %rax, %r15
cmpq $0x0, 0x40(%rax)
je 0x64afc
movq -0x40(%rbp), %rax
cmpl $0x2, %r13d
jne 0x64b4a
xorl %r9d, %r9d
jmp 0x64b4f
leaq 0x14d97(%rip), %rdx     # 0x79833
movq %rbx, %rdi
movl $0x1, %esi
movq %r15, %rcx
xorl %eax, %eax
callq 0x45d26
jmp 0x64991
movq (%rbx), %rsi
addq $0x8, %rsi
leaq 0x14b53(%rip), %rcx     # 0x79614
movq %r14, %rdi
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)
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
jmp 0x64c1d
movq (%rbx), %rax
movq 0x8(%rax), %rcx
movq -0x38(%rbp), %r14
movq (%r14), %r8
leaq 0x14bc7(%rip), %rdx     # 0x796d8
movq %rbx, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x45d26
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)
movq 0x20(%r14), %rax
jmp 0x64c1d
movq 0x10(%r12), %r9
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %r14
movq %rax, %rdx
movl $0x1c, %ecx
xorl %r8d, %r8d
pushq $0x0
pushq $0x0
callq 0x534fd
addq $0x10, %rsp
testq %rax, %rax
movq -0x38(%rbp), %r13
je 0x64bdf
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 0x64baa
movq %r12, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq *0x40(%r15)
testq %rax, %rax
jg 0x64b83
movq 0x20(%r13), %rax
testq %rax, %rax
je 0x64bb9
movq -0x30(%rbp), %rdi
callq *%rax
movq 0x20(%r15), %rax
testq %rax, %rax
je 0x64bc7
movq %r12, %rdi
callq *%rax
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x309f2
movq $0x1, (%rbx)
jmp 0x649a4
leaq 0x14c71(%rip), %rdx     # 0x79857
movq %rbx, %rdi
movl $0x1, %esi
movq %r14, %rcx
xorl %eax, %eax
callq 0x45d26
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)
movq 0x20(%r13), %rax
testq %rax, %rax
je 0x649b2
movq -0x30(%rbp), %rdi
callq *%rax
jmp 0x649b2