// File: /workspace/github_c_makefile_star2_O3/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 0xaca8d
movq %r14, %rdi
movl $0x9, %esi
callq 0x58990
cmpl $0x3a, (%rax)
jne 0xaca8d
movq %r14, %rdi
movl $0xa, %esi
callq 0x58990
cmpl $0x2f, (%rax)
jne 0xaca8d
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, 0x10(%rsp)
xorl %esi, %esi
callq 0x72a62
leaq 0x190(%rsp), %rdi
xorl %esi, %esi
callq 0x58e20
subq $-0x80, %rbx
leaq 0x190(%rsp), %rsi
movq %rbx, %rdi
callq 0x76794
leaq 0x190(%rsp), %rdi
callq 0x59200
movzwl 0x180(%rsp), %ebp
testw %bp, %bp
je 0xacb37
movq 0x10(%rsp), %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x72a62
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
cmpw $0x0, 0x90(%rsp)
je 0xacd31
movl 0x98(%rsp), %r12d
testl %r12d, %r12d
jle 0xacaf6
leaq 0x190(%rsp), %rdi
movl $0x3, %esi
movq %r15, %rdx
movl $0x1, %ecx
callq 0x582f0
leaq 0x18(%rsp), %rdi
movl $0x8000, %esi           # imm = 0x8000
callq 0x620b8
movw %bp, 0xe(%rsp)
callq 0x570e0
cvtsi2sd %r12d, %xmm0
movsd %xmm0, 0x38(%rsp)
cltq
movq %rax, 0x30(%rsp)
xorl %r14d, %r14d
movl 0x28(%rsp), %eax
leaq 0x70(%rsp), %rbp
xorl %r13d, %r13d
movl %r12d, %r15d
subl %r14d, %r15d
cmpl %r15d, %eax
cmovll %eax, %r15d
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0xacbc3
movq (%rax), %rsi
jmp 0xacbc5
xorl %esi, %esi
leaq 0x88(%rsp), %rdi
movl %r15d, %edx
callq 0x56f50
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0xacbe4
movq (%rax), %rsi
jmp 0xacbe6
xorl %esi, %esi
leaq 0x190(%rsp), %rdi
movl %r15d, %edx
callq 0x55b50
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
mulsd 0x655da(%rip), %xmm0    # 0x1121e0
divsd 0x38(%rsp), %xmm0
xorl %eax, %eax
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
seta %al
leaq 0x46bd0(%rip), %rcx     # 0xf37f0
addsd (%rcx,%rax,8), %xmm0
cvttsd2si %xmm0, %r15
movslq %r13d, %rax
cmpq %rax, %r15
je 0xaccf6
movq 0x10(%rsp), %rdi
movl %r15d, %esi
callq 0x72a62
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 0x6557e(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x65586(%rip), %xmm1    # 0x112200
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd 0x65552(%rip), %xmm2    # 0x1121e0
divsd %xmm2, %xmm0
xorl %eax, %eax
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
seta %al
leaq 0x46b4a(%rip), %rcx     # 0xf37f0
addsd (%rcx,%rax,8), %xmm0
cvttsd2si %xmm0, %rsi
leaq 0x58(%rsp), %rdi
callq 0x56cf0
movq %rbp, %rdi
leaq 0x6556c(%rip), %rsi     # 0x112230
callq 0x579f0
leaq 0x58(%rsp), %rdi
movq %rbp, %rsi
callq 0x562f0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x76794
movq %rbp, %rdi
callq 0x59200
leaq 0x58(%rsp), %rdi
callq 0x59200
movl %r15d, %r13d
movl 0x28(%rsp), %eax
addl %eax, %r14d
cmpl %r12d, %r14d
jl 0xacba7
leaq 0xb3243(%rip), %rax     # 0x15ff50
leaq 0x18(%rsp), %rdi
movq %rax, (%rdi)
callq 0x62130
leaq 0x190(%rsp), %rdi
callq 0x56500
movzwl 0xe(%rsp), %ebp
jmp 0xacaf6
movw $0x5, 0x180(%rsp)
jmp 0xacaf6
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x59200
jmp 0xacdce
jmp 0xacd9d
movq %rax, %rbx
jmp 0xacdb4
jmp 0xacd78
jmp 0xacd73
movq %rax, %rbx
leaq 0x190(%rsp), %rdi
callq 0x59200
jmp 0xacdc1
jmp 0xacd78
jmp 0xacd73
movq %rax, %rbx
jmp 0xacdce
movq %rax, %rbx
jmp 0xacdc1
movq %rax, %rbx
jmp 0xacd91
jmp 0xacd9d
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x59200
leaq 0x58(%rsp), %rdi
callq 0x59200
jmp 0xacda0
movq %rax, %rbx
leaq 0xb31a9(%rip), %rax     # 0x15ff50
leaq 0x18(%rsp), %rdi
movq %rax, (%rdi)
callq 0x62130
leaq 0x190(%rsp), %rdi
callq 0x56500
leaq 0x88(%rsp), %rdi
callq 0x555b0
leaq 0x40(%rsp), %rdi
callq 0x59200
movq %rbx, %rdi
callq 0x57090