// File: /workspace/github_c_makefile_star2_O3/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 0x62ec9
movq %rdx, %r12
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
je 0x62ec9
movq 0x8(%r12), %rax
testb $0x1, 0x8(%rax)
jne 0x62f1a
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x14939(%rip), %rcx     # 0x77814
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 $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 0x30577
leaq -0x40(%rbp), %rsi
movq %rax, (%rsi)
movq 0x60(%rbx), %r14
movl (%r15), %edx
movq %r14, %rdi
callq 0x51bfb
movq %rax, -0x38(%rbp)
testq %rax, %rax
je 0x62f57
movq -0x40(%rbp), %r15
cmpl $0x2, %r13d
jne 0x62f6d
xorl %r9d, %r9d
jmp 0x62f72
movq (%rbx), %rsi
addq $0x8, %rsi
leaq 0x146ba(%rip), %rcx     # 0x7761f
movq %r14, %rdi
jmp 0x62edb
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 0x51dad
addq $0x10, %rsp
movq %rax, -0x30(%rbp)
testq %rax, %rax
je 0x62fe9
movq 0x8(%r12), %rdi
leaq -0x44(%rbp), %r14
movq %r14, %rsi
callq 0x30577
leaq -0x40(%rbp), %rsi
movq %rax, (%rsi)
movq 0x60(%rbx), %rax
movl (%r14), %edx
movq %rax, %r14
movq %rax, %rdi
callq 0x51bfb
testq %rax, %rax
je 0x63007
movq %rax, %r15
cmpq $0x0, 0x40(%rax)
je 0x63050
movq -0x40(%rbp), %rax
cmpl $0x2, %r13d
jne 0x6309e
xorl %r9d, %r9d
jmp 0x630a3
leaq 0x1484e(%rip), %rdx     # 0x7783e
movq %rbx, %rdi
movl $0x1, %esi
movq %r15, %rcx
xorl %eax, %eax
callq 0x44ed3
jmp 0x62ee5
movq (%rbx), %rsi
addq $0x8, %rsi
leaq 0x1460a(%rip), %rcx     # 0x7761f
movq %r14, %rdi
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)
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
jmp 0x63171
movq (%rbx), %rax
movq 0x8(%rax), %rcx
movq -0x38(%rbp), %r14
movq (%r14), %r8
leaq 0x1467e(%rip), %rdx     # 0x776e3
movq %rbx, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x44ed3
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)
movq 0x20(%r14), %rax
jmp 0x63171
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 0x51dad
addq $0x10, %rsp
testq %rax, %rax
movq -0x38(%rbp), %r13
je 0x63133
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 0x630fe
movq %r12, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq *0x40(%r15)
testq %rax, %rax
jg 0x630d7
movq 0x20(%r13), %rax
testq %rax, %rax
je 0x6310d
movq -0x30(%rbp), %rdi
callq *%rax
movq 0x20(%r15), %rax
testq %rax, %rax
je 0x6311b
movq %r12, %rdi
callq *%rax
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x30465
movq $0x1, (%rbx)
jmp 0x62ef8
leaq 0x14728(%rip), %rdx     # 0x77862
movq %rbx, %rdi
movl $0x1, %esi
movq %r14, %rcx
xorl %eax, %eax
callq 0x44ed3
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)
movq 0x20(%r13), %rax
testq %rax, %rax
je 0x62f06
movq -0x30(%rbp), %rdi
callq *%rax
jmp 0x62f06