// File: /workspace/github_c_makefile_star2_O1/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 0x57180
leal -0x7(%rax), %edx
leaq 0x40(%rsp), %rdi
movq %r14, %rsi
callq 0x57f90
movq %r14, %rdi
movl $0x7, %esi
callq 0x58990
cmpl $0x2f, (%rax)
jne 0xad7c1
movq %r14, %rdi
movl $0x9, %esi
callq 0x58990
cmpl $0x3a, (%rax)
jne 0xad7c1
movq %r14, %rdi
movl $0xa, %esi
callq 0x58990
cmpl $0x2f, (%rax)
jne 0xad7c1
movq %r14, %rdi
callq 0x57180
addl $-0x8, %eax
leaq 0x88(%rsp), %rdi
movq %r14, %rsi
movl %eax, %edx
callq 0x57f90
leaq 0x40(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x555f0
leaq 0x88(%rsp), %rdi
callq 0x59200
leaq 0x88(%rsp), %rdi
leaq 0x40(%rsp), %rdx
movl $0x3, %esi
movl $0x2, %ecx
callq 0x58730
leaq 0x60(%rbx), %rdi
movq %rdi, 0x8(%rsp)
xorl %esi, %esi
callq 0x72dc0
leaq 0x190(%rsp), %rdi
xorl %esi, %esi
callq 0x58e20
subq $-0x80, %rbx
leaq 0x190(%rsp), %rsi
movq %rbx, %rdi
callq 0x76a7e
leaq 0x190(%rsp), %rdi
callq 0x59200
movzwl 0x180(%rsp), %ebp
testw %bp, %bp
jne 0xada38
cmpw $0x0, 0x90(%rsp)
je 0xad843
movl 0x98(%rsp), %r12d
jmp 0xad853
movw $0x5, 0x180(%rsp)
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
testl %r12d, %r12d
jle 0xada38
leaq 0x190(%rsp), %rdi
movl $0x3, %esi
movq %r15, %rdx
movl $0x1, %ecx
callq 0x582f0
leaq 0x10(%rsp), %rdi
movl $0x8000, %esi           # imm = 0x8000
callq 0x62006
movw %bp, 0x6(%rsp)
movq %rbx, 0x28(%rsp)
callq 0x570e0
cvtsi2sd %r12d, %xmm0
movsd %xmm0, 0x38(%rsp)
cltq
movq %rax, 0x30(%rsp)
xorl %r14d, %r14d
leaq 0x70(%rsp), %r13
leaq 0x58(%rsp), %rbp
xorl %ebx, %ebx
movl 0x20(%rsp), %eax
movl %r12d, %r15d
subl %r14d, %r15d
cmpl %r15d, %eax
cmovll %eax, %r15d
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0xad8d5
movq (%rax), %rsi
jmp 0xad8d7
xorl %esi, %esi
leaq 0x88(%rsp), %rdi
movl %r15d, %edx
callq 0x56f50
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0xad8f6
movq (%rax), %rsi
jmp 0xad8f8
xorl %esi, %esi
leaq 0x190(%rsp), %rdi
movl %r15d, %edx
callq 0x55b50
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
mulsd 0x65718(%rip), %xmm0    # 0x113030
divsd 0x38(%rsp), %xmm0
xorl %eax, %eax
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
seta %al
leaq 0x46f8e(%rip), %rcx     # 0xf48c0
addsd (%rcx,%rax,8), %xmm0
cvttsd2si %xmm0, %r15
movslq %ebx, %rax
cmpq %rax, %r15
je 0xada04
movq 0x8(%rsp), %rdi
movl %r15d, %esi
callq 0x72dc0
callq 0x570e0
leal 0x3ff(%r14), %ecx
testl %r14d, %r14d
cmovnsl %r14d, %ecx
sarl $0xa, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
subq 0x30(%rsp), %rax
movq %rax, %xmm1
punpckldq 0x656bc(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x656c4(%rip), %xmm1    # 0x113050
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd 0x65690(%rip), %xmm2    # 0x113030
divsd %xmm2, %xmm0
xorl %eax, %eax
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
seta %al
leaq 0x46f08(%rip), %rcx     # 0xf48c0
addsd (%rcx,%rax,8), %xmm0
cvttsd2si %xmm0, %rsi
movq %r13, %rdi
callq 0x56cf0
movq %rbp, %rdi
leaq 0x656ac(%rip), %rsi     # 0x113080
callq 0x579f0
movq %r13, %rdi
movq %rbp, %rsi
callq 0x562f0
movq 0x28(%rsp), %rdi
movq %rax, %rsi
callq 0x76a7e
movq %rbp, %rdi
callq 0x59200
movq %r13, %rdi
callq 0x59200
movl %r15d, %ebx
addl 0x20(%rsp), %r14d
cmpl %r12d, %r14d
jl 0xad8b5
leaq 0xb3517(%rip), %rax     # 0x160f30
leaq 0x10(%rsp), %rdi
movq %rax, (%rdi)
callq 0x6207e
leaq 0x190(%rsp), %rdi
callq 0x56500
movzwl 0x6(%rsp), %ebp
movq 0x8(%rsp), %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x72dc0
xorl %ebx, %ebx
negw %bp
sbbl %ebx, %ebx
leaq 0x88(%rsp), %rdi
callq 0x555b0
leaq 0x40(%rsp), %rdi
callq 0x59200
movl %ebx, %eax
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x59200
jmp 0xadb07
jmp 0xadad6
movq %rax, %rbx
jmp 0xadaed
jmp 0xadab1
jmp 0xadaac
movq %rax, %rbx
leaq 0x190(%rsp), %rdi
callq 0x59200
jmp 0xadafa
jmp 0xadab1
jmp 0xadaac
movq %rax, %rbx
jmp 0xadb07
movq %rax, %rbx
jmp 0xadafa
movq %rax, %rbx
jmp 0xadaca
jmp 0xadad6
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x59200
leaq 0x70(%rsp), %rdi
callq 0x59200
jmp 0xadad9
movq %rax, %rbx
leaq 0xb3450(%rip), %rax     # 0x160f30
leaq 0x10(%rsp), %rdi
movq %rax, (%rdi)
callq 0x6207e
leaq 0x190(%rsp), %rdi
callq 0x56500
leaq 0x88(%rsp), %rdi
callq 0x555b0
leaq 0x40(%rsp), %rdi
callq 0x59200
movq %rbx, %rdi
callq 0x57090
nopl (%rax)