// File: /workspace/github_c_makefile_star2_O0/enzo1982[P]smooth/classes/files/file.cpp
// Function: smooth::File::Copy(smooth::File const&)
S::Int S::File::Copy(const File &destination)
{
	if (!Exists()) return Error();

#ifdef __WIN32__
	Bool	 result = CopyFile(Directory::MakeExtendedPath(*this), Directory::MakeExtendedPath(destination), True);
#else
	Bool	 result = False;

	FILE	*source	= fopen(String(*this).ConvertTo("UTF-8"), "rb");
	FILE	*dest	= fopen(String(destination).ConvertTo("UTF-8"), "wb");

	if (source != NIL && dest != NIL)
	{
		Int	 bytesLeft = GetFileSize();
		Int	 chunkSize = 32768;

		UnsignedByte	*buffer = new UnsignedByte [chunkSize];

		while (bytesLeft)
		{
			chunkSize = Math::Min(chunkSize, bytesLeft);

			if (fread(buffer, chunkSize, 1, source) == 1) fwrite(buffer, chunkSize, 1, dest);
			else					      break;

			bytesLeft -= chunkSize;
		}

		delete [] buffer;

		if (!bytesLeft) result = True;
	}

	if (source != NIL) fclose(source);
	if (dest != NIL) fclose(dest);
#endif

	if (result == False) return Error();
	else		     return Success();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x5b4b0
testb $0x1, %al
jne 0x68571
leaq -0x28(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5a9c0
movq -0xc0(%rbp), %rdi
callq 0x59680
movl %eax, -0xb4(%rbp)
jmp 0x68540
movl -0xb4(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x5b5b0
jmp 0x6881a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x5b5b0
jmp 0x68826
movq -0xb0(%rbp), %rsi
movb $0x0, -0x35(%rbp)
leaq -0x58(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x5dc70
movq -0xd0(%rbp), %rdi
leaq 0x13d64c(%rip), %rsi    # 0x1a5be6
callq 0x5c120
movq %rax, -0xc8(%rbp)
jmp 0x685a8
movq -0xc8(%rbp), %rdi
leaq 0x11ed8e(%rip), %rsi    # 0x187344
callq 0x5d1b0
movq %rax, -0xd8(%rbp)
jmp 0x685c4
leaq -0x58(%rbp), %rdi
callq 0x5df00
movq -0xd8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x78(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x5dc70
movq -0xe8(%rbp), %rdi
leaq 0x13d5ec(%rip), %rsi    # 0x1a5be6
callq 0x5c120
movq %rax, -0xe0(%rbp)
jmp 0x68608
movq -0xe0(%rbp), %rdi
leaq 0x11ed31(%rip), %rsi    # 0x187347
callq 0x5d1b0
movq %rax, -0xf0(%rbp)
jmp 0x68624
leaq -0x78(%rbp), %rdi
callq 0x5df00
movq -0xf0(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x68738
cmpq $0x0, -0x60(%rbp)
je 0x68738
movq -0xb0(%rbp), %rdi
callq 0x5ad80
movl %eax, -0x7c(%rbp)
movl $0x8000, -0x80(%rbp)    # imm = 0x8000
movslq -0x80(%rbp), %rdi
callq 0x5ab20
movq %rax, -0x88(%rbp)
cmpl $0x0, -0x7c(%rbp)
je 0x6870c
movl -0x80(%rbp), %edi
movl -0x7c(%rbp), %esi
callq 0x5ce90
movl %eax, -0x80(%rbp)
movq -0x88(%rbp), %rdi
movslq -0x80(%rbp), %rsi
movq -0x40(%rbp), %rcx
movl $0x1, %edx
callq 0x5af50
cmpq $0x1, %rax
jne 0x686fa
movq -0x88(%rbp), %rdi
movslq -0x80(%rbp), %rsi
movq -0x60(%rbp), %rcx
movl $0x1, %edx
callq 0x5d410
jmp 0x686fc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x5df00
jmp 0x68826
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x5df00
jmp 0x68826
jmp 0x6870c
movl -0x80(%rbp), %ecx
movl -0x7c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x7c(%rbp)
jmp 0x68674
movq -0x88(%rbp), %rax
movq %rax, -0xf8(%rbp)
cmpq $0x0, %rax
je 0x6872c
movq -0xf8(%rbp), %rdi
callq 0x5a5e0
cmpl $0x0, -0x7c(%rbp)
jne 0x68736
movb $0x1, -0x35(%rbp)
jmp 0x68738
cmpq $0x0, -0x40(%rbp)
je 0x68748
movq -0x40(%rbp), %rdi
callq 0x5a8f0
cmpq $0x0, -0x60(%rbp)
je 0x68758
movq -0x60(%rbp), %rdi
callq 0x5a8f0
movb -0x35(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x687c2
leaq -0x98(%rbp), %rdi
movq %rdi, -0x108(%rbp)
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5a9c0
movq -0x108(%rbp), %rdi
callq 0x59680
movl %eax, -0xfc(%rbp)
jmp 0x68791
movl -0xfc(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x5b5b0
jmp 0x6881a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x5b5b0
jmp 0x68826
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x5ca80
movq -0x118(%rbp), %rdi
callq 0x59680
movl %eax, -0x10c(%rbp)
jmp 0x687e9
movl -0x10c(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x5a410
jmp 0x6881a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x5a410
jmp 0x68826
movl -0x4(%rbp), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0x5b6b0
nop