// File: /workspace/github_c_makefile_star2_O2/enzo1982[P]smooth/classes/net/protocols/file.cpp
// Function: smooth::Net::Protocols::File::DownloadToFile(smooth::String const&)
S::Int S::Net::Protocols::File::DownloadToFile(const String &destination)
{
	Bool	 error	  = True;
	String	 fileName = url.Tail(url.Length() - 7);

	if (url[7] == '/' && url[9] == ':' && url[10] == '/') fileName = url.Tail(url.Length() - 8);

	InStream	 in(STREAM_FILE, fileName, IS_READ);

	downloadProgress.Emit(0);
	downloadSpeed.Emit(NIL);

	if (in.GetLastError() == IO::IO_ERROR_OK)
	{
		Int	 bytes = in.Size();

		if (bytes > 0)
		{
			OutStream		 out(STREAM_FILE, destination, OS_REPLACE);
			Buffer<UnsignedByte>	 buffer(32768);
			Int			 startTicks = S::System::System::Clock();
			Int			 percent    = 0;

			for (Int i = 0; i < bytes; i += buffer.Size())
			{
				Int	 amount = Math::Min(buffer.Size(), bytes - i);

				in.InputData(buffer, amount);
				out.OutputData(buffer, amount);

				if (Math::Round(1000.0 * i / bytes) != percent)
				{
					percent = Math::Round(1000.0 * i / bytes);

					downloadProgress.Emit(percent);
					downloadSpeed.Emit(String::FromInt(Math::Round((i / 1024) / (Float(S::System::System::Clock() - startTicks) / 1000))).Append(" kB/s"));
				}
			}
		}

		error = False;
	}

	downloadProgress.Emit(1000);

	if (!error) return Success();
	else	    return Error();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x298, %rsp            # imm = 0x298
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x8(%rdi), %r14
movq %r14, %rdi
callq 0x58370
leal -0x7(%rax), %edx
leaq 0x40(%rsp), %rdi
movq %r14, %rsi
callq 0x59220
pushq $0x7
popq %rsi
movq %r14, %rdi
callq 0x59cc0
cmpl $0x2f, (%rax)
jne 0xa7e21
pushq $0x9
popq %rsi
movq %r14, %rdi
callq 0x59cc0
cmpl $0x3a, (%rax)
jne 0xa7e21
pushq $0xa
popq %rsi
movq %r14, %rdi
callq 0x59cc0
cmpl $0x2f, (%rax)
jne 0xa7e21
movq %r14, %rdi
callq 0x58370
addl $-0x8, %eax
leaq 0x88(%rsp), %rdi
movq %r14, %rsi
movl %eax, %edx
callq 0x59220
leaq 0x40(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x56630
leaq 0x88(%rsp), %rdi
callq 0x5a588
leaq 0x88(%rsp), %rdi
pushq $0x3
popq %rsi
leaq 0x40(%rsp), %rdx
pushq $0x2
popq %rcx
callq 0x59a20
leaq 0x60(%rbx), %rdi
movq %rdi, 0x10(%rsp)
xorl %esi, %esi
callq 0x72596
leaq 0x190(%rsp), %rdi
xorl %esi, %esi
callq 0x5a180
subq $-0x80, %rbx
leaq 0x190(%rsp), %rsi
movq %rbx, %rdi
callq 0x75b8e
leaq 0x190(%rsp), %rdi
callq 0x5a588
movzwl 0x180(%rsp), %ebp
testw %bp, %bp
je 0xa7ec7
movq 0x10(%rsp), %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x72596
xorl %ebx, %ebx
negw %bp
sbbl %ebx, %ebx
leaq 0x88(%rsp), %rdi
callq 0x565f0
leaq 0x40(%rsp), %rdi
callq 0x5a588
movl %ebx, %eax
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpw $0x0, 0x90(%rsp)
je 0xa80aa
movl 0x98(%rsp), %r14d
testl %r14d, %r14d
jle 0xa7e86
leaq 0x190(%rsp), %rdi
pushq $0x3
popq %rsi
pushq $0x1
popq %rcx
movq %r15, %rdx
callq 0x595a0
leaq 0x18(%rsp), %rdi
movl $0x8000, %esi           # imm = 0x8000
callq 0x62d56
movw %bp, 0xe(%rsp)
callq 0x582b0
cvtsi2sd %r14d, %xmm0
movsd %xmm0, 0x38(%rsp)
cltq
movq %rax, 0x30(%rsp)
xorl %r13d, %r13d
leaq 0x70(%rsp), %rbp
xorl %r15d, %r15d
movl %r14d, %r12d
subl %r15d, %r12d
jle 0xa8089
movl 0x28(%rsp), %eax
cmpl %r12d, %eax
cmovll %eax, %r12d
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0xa7f55
movq (%rax), %rsi
jmp 0xa7f57
xorl %esi, %esi
leaq 0x88(%rsp), %rdi
movl %r12d, %edx
callq 0x58100
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0xa7f76
movq (%rax), %rsi
jmp 0xa7f78
xorl %esi, %esi
leaq 0x190(%rsp), %rdi
movl %r12d, %edx
callq 0x56bd0
cvtsi2sd %r15d, %xmm0
mulsd 0x5a13b(%rip), %xmm0    # 0x1020d0
divsd 0x38(%rsp), %xmm0
xorl %eax, %eax
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
seta %al
leaq 0x3b801(%rip), %rcx     # 0xe37b0
addsd (%rcx,%rax,8), %xmm0
cvttsd2si %xmm0, %r12
movslq %r13d, %rax
cmpq %rax, %r12
je 0xa807f
movq 0x10(%rsp), %rdi
movl %r12d, %esi
callq 0x72596
callq 0x582b0
movq %rax, %rcx
movl %r15d, %eax
cltd
movl $0x400, %esi            # imm = 0x400
idivl %esi
cvtsi2sd %eax, %xmm0
subq 0x30(%rsp), %rcx
movq %rcx, %xmm1
punpckldq 0x5a0e5(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x5a0ed(%rip), %xmm1    # 0x1020f0
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd 0x5a0b9(%rip), %xmm2    # 0x1020d0
divsd %xmm2, %xmm0
xorl %eax, %eax
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
seta %al
leaq 0x3b781(%rip), %rcx     # 0xe37b0
addsd (%rcx,%rax,8), %xmm0
cvttsd2si %xmm0, %rsi
leaq 0x58(%rsp), %rdi
callq 0x57e80
movq %rbp, %rdi
leaq 0x5a0d3(%rip), %rsi     # 0x102120
callq 0x58c40
leaq 0x58(%rsp), %rdi
movq %rbp, %rsi
callq 0x573e0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x75b8e
movq %rbp, %rdi
callq 0x5a588
leaq 0x58(%rsp), %rdi
callq 0x5a588
movl %r12d, %r13d
addl 0x28(%rsp), %r15d
jmp 0xa7f2f
leaq 0x18(%rsp), %rdi
callq 0x62d46
leaq 0x190(%rsp), %rdi
callq 0x57610
movzwl 0xe(%rsp), %ebp
jmp 0xa7e86
movw $0x5, 0x180(%rsp)
jmp 0xa7e86
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x5a588
jmp 0xa813d
jmp 0xa8116
movq %rax, %rbx
jmp 0xa8123
jmp 0xa80f1
jmp 0xa80ec
movq %rax, %rbx
leaq 0x190(%rsp), %rdi
callq 0x5a588
jmp 0xa8130
jmp 0xa80f1
jmp 0xa80ec
movq %rax, %rbx
jmp 0xa813d
movq %rax, %rbx
jmp 0xa8130
movq %rax, %rbx
jmp 0xa810a
jmp 0xa8116
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x5a588
leaq 0x58(%rsp), %rdi
callq 0x5a588
jmp 0xa8119
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x62d46
leaq 0x190(%rsp), %rdi
callq 0x57610
leaq 0x88(%rsp), %rdi
callq 0x565f0
leaq 0x40(%rsp), %rdi
callq 0x5a588
movq %rbx, %rdi
callq 0x58260
nop