// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x3d0, %rsp            # imm = 0x3D0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x328(%rbp)
movb $0x1, -0x19(%rbp)
addq $0x8, %rdi
movq %rdi, -0x320(%rbp)
callq 0x5b800
movq -0x320(%rbp), %rsi
movl %eax, %edx
addl $-0x7, %edx
leaq -0x38(%rbp), %rdi
callq 0x5c8a0
movq -0x320(%rbp), %rdi
movl $0x7, %esi
callq 0x5d4e0
movq %rax, -0x318(%rbp)
jmp 0x101071
movq -0x318(%rbp), %rax
cmpl $0x2f, (%rax)
jne 0x101158
movq -0x328(%rbp), %rdi
addq $0x8, %rdi
movl $0x9, %esi
callq 0x5d4e0
movq %rax, -0x330(%rbp)
jmp 0x10109f
movq -0x330(%rbp), %rax
cmpl $0x3a, (%rax)
jne 0x101158
movq -0x328(%rbp), %rdi
addq $0x8, %rdi
movl $0xa, %esi
callq 0x5d4e0
movq %rax, -0x338(%rbp)
jmp 0x1010cd
movq -0x338(%rbp), %rax
cmpl $0x2f, (%rax)
jne 0x101158
movq -0x328(%rbp), %rdi
addq $0x8, %rdi
movq %rdi, -0x348(%rbp)
callq 0x5b800
movl %eax, -0x33c(%rbp)
jmp 0x1010f8
movq -0x348(%rbp), %rsi
movl -0x33c(%rbp), %edx
addl $-0x8, %edx
leaq -0x60(%rbp), %rdi
callq 0x5c8a0
jmp 0x101113
leaq -0x38(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x59760
jmp 0x101122
leaq -0x60(%rbp), %rdi
callq 0x5df00
jmp 0x101158
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x1016d6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x5df00
jmp 0x1016d6
leaq -0x168(%rbp), %rdi
movl $0x3, %esi
leaq -0x38(%rbp), %rdx
movl $0x2, %ecx
callq 0x5d200
jmp 0x101174
movq -0x328(%rbp), %rdi
addq $0x60, %rdi
xorl %esi, %esi
callq 0x907d0
jmp 0x101188
movq -0x328(%rbp), %rax
subq $-0x80, %rax
movq %rax, -0x350(%rbp)
leaq -0x180(%rbp), %rdi
xorl %esi, %esi
callq 0x5da90
jmp 0x1011aa
movq -0x350(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x97960
jmp 0x1011bf
leaq -0x180(%rbp), %rdi
callq 0x5df00
leaq -0x168(%rbp), %rdi
callq 0x5b1e0
movw %ax, -0x352(%rbp)
jmp 0x1011e0
movw -0x352(%rbp), %ax
cwtl
cmpl $0x0, %eax
jne 0x1015ca
leaq -0x168(%rbp), %rdi
callq 0x5a580
movq %rax, -0x360(%rbp)
jmp 0x101206
movq -0x360(%rbp), %rax
movl %eax, -0x184(%rbp)
cmpl $0x0, -0x184(%rbp)
jle 0x1015c6
movq -0x18(%rbp), %rdx
leaq -0x290(%rbp), %rdi
movl $0x3, %esi
movl $0x1, %ecx
callq 0x5ccd0
jmp 0x10123c
leaq -0x2a8(%rbp), %rdi
movl $0x8000, %esi           # imm = 0x8000
callq 0x71080
jmp 0x10124f
callq 0x5b700
movq %rax, -0x368(%rbp)
jmp 0x10125d
movq -0x368(%rbp), %rax
movl %eax, -0x2ac(%rbp)
movl $0x0, -0x2b0(%rbp)
movl $0x0, -0x2b4(%rbp)
movl -0x2b4(%rbp), %eax
cmpl -0x184(%rbp), %eax
jge 0x10158f
leaq -0x2a8(%rbp), %rdi
callq 0x71140
movl %eax, -0x36c(%rbp)
jmp 0x1012a4
movl -0x36c(%rbp), %edi
movl -0x184(%rbp), %esi
movl -0x2b4(%rbp), %eax
subl %eax, %esi
callq 0x5ce90
movl %eax, -0x370(%rbp)
jmp 0x1012c5
movl -0x370(%rbp), %eax
movl %eax, -0x2b8(%rbp)
leaq -0x2a8(%rbp), %rdi
callq 0x71100
movq %rax, -0x378(%rbp)
jmp 0x1012e6
movq -0x378(%rbp), %rsi
movl -0x2b8(%rbp), %edx
leaq -0x168(%rbp), %rdi
callq 0x5b510
jmp 0x101301
leaq -0x2a8(%rbp), %rdi
callq 0x71100
movq %rax, -0x380(%rbp)
jmp 0x101316
movq -0x380(%rbp), %rsi
movl -0x2b8(%rbp), %edx
leaq -0x290(%rbp), %rdi
callq 0x59d70
jmp 0x101331
cvtsi2sdl -0x2b4(%rbp), %xmm0
movsd 0xa47bf(%rip), %xmm1    # 0x1a5b00
mulsd %xmm1, %xmm0
cvtsi2sdl -0x184(%rbp), %xmm1
divsd %xmm1, %xmm0
callq 0x5a970
movq %rax, -0x388(%rbp)
jmp 0x10135f
movq -0x388(%rbp), %rax
movslq -0x2b0(%rbp), %rcx
cmpq %rcx, %rax
je 0x101562
cvtsi2sdl -0x2b4(%rbp), %xmm0
movsd 0xa477a(%rip), %xmm1    # 0x1a5b00
mulsd %xmm1, %xmm0
cvtsi2sdl -0x184(%rbp), %xmm1
divsd %xmm1, %xmm0
callq 0x5a970
movq %rax, -0x390(%rbp)
jmp 0x1013a4
movq -0x328(%rbp), %rdi
movq -0x390(%rbp), %rax
movl %eax, -0x2b0(%rbp)
addq $0x60, %rdi
movl -0x2b0(%rbp), %esi
callq 0x907d0
jmp 0x1013c9
movq -0x328(%rbp), %rax
subq $-0x80, %rax
movq %rax, -0x3a8(%rbp)
movl -0x2b4(%rbp), %eax
movl %eax, %ecx
addl $0x3ff, %ecx            # imm = 0x3FF
testl %eax, %eax
cmovsl %ecx, %eax
sarl $0xa, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x3a0(%rbp)
callq 0x5b700
movq %rax, -0x398(%rbp)
jmp 0x10140b
movsd -0x3a0(%rbp), %xmm0
movq -0x398(%rbp), %rax
movslq -0x2ac(%rbp), %rcx
subq %rcx, %rax
movq %rax, %xmm1
movaps 0xa46e0(%rip), %xmm2    # 0x1a5b10
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0xa46e4(%rip), %xmm2    # 0x1a5b20
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
movsd 0xa46ad(%rip), %xmm2    # 0x1a5b00
divsd %xmm2, %xmm1
divsd %xmm1, %xmm0
callq 0x5a970
movq %rax, -0x3b0(%rbp)
jmp 0x101469
movq -0x3b0(%rbp), %rsi
leaq -0x2d0(%rbp), %rdi
callq 0x5b290
jmp 0x10147e
leaq 0xa46cb(%rip), %rsi     # 0x1a5b50
leaq -0x2e8(%rbp), %rdi
callq 0x5c1f0
jmp 0x101493
leaq -0x2d0(%rbp), %rdi
leaq -0x2e8(%rbp), %rsi
callq 0x5a710
movq %rax, -0x3b8(%rbp)
jmp 0x1014af
movq -0x3b8(%rbp), %rsi
movq -0x3a8(%rbp), %rdi
callq 0x97960
jmp 0x1014c4
leaq -0x2e8(%rbp), %rdi
callq 0x5df00
leaq -0x2d0(%rbp), %rdi
callq 0x5df00
jmp 0x101562
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x1016ca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x5df00
jmp 0x1016ca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x1015b5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x1015a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x101554
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x2e8(%rbp), %rdi
callq 0x5df00
leaq -0x2d0(%rbp), %rdi
callq 0x5df00
jmp 0x1015a9
jmp 0x101564
leaq -0x2a8(%rbp), %rdi
callq 0x71140
movl %eax, -0x3bc(%rbp)
jmp 0x101578
movl -0x3bc(%rbp), %eax
addl -0x2b4(%rbp), %eax
movl %eax, -0x2b4(%rbp)
jmp 0x10127e
leaq -0x2a8(%rbp), %rdi
callq 0x71000
leaq -0x290(%rbp), %rdi
callq 0x5a950
jmp 0x1015c6
leaq -0x2a8(%rbp), %rdi
callq 0x71000
leaq -0x290(%rbp), %rdi
callq 0x5a950
jmp 0x1016ca
movb $0x0, -0x19(%rbp)
movq -0x328(%rbp), %rdi
addq $0x60, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x907d0
jmp 0x1015e1
testb $0x1, -0x19(%rbp)
jne 0x101647
leaq -0x2f8(%rbp), %rdi
callq 0x5ca80
jmp 0x1015f5
leaq -0x2f8(%rbp), %rdi
callq 0x59680
movl %eax, -0x3c0(%rbp)
jmp 0x101609
movl -0x3c0(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq -0x2f8(%rbp), %rdi
callq 0x5a410
movl $0x1, -0x2fc(%rbp)
jmp 0x1016a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x2f8(%rbp), %rdi
callq 0x5a410
jmp 0x1016ca
leaq -0x310(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5a9c0
jmp 0x10165a
leaq -0x310(%rbp), %rdi
callq 0x59680
movl %eax, -0x3c4(%rbp)
jmp 0x10166e
movl -0x3c4(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq -0x310(%rbp), %rdi
callq 0x5b5b0
movl $0x1, -0x2fc(%rbp)
jmp 0x1016a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x310(%rbp), %rdi
callq 0x5b5b0
jmp 0x1016ca
leaq -0x168(%rbp), %rdi
callq 0x59710
leaq -0x38(%rbp), %rdi
callq 0x5df00
movl -0x4(%rbp), %eax
addq $0x3d0, %rsp            # imm = 0x3D0
popq %rbp
retq
leaq -0x168(%rbp), %rdi
callq 0x59710
leaq -0x38(%rbp), %rdi
callq 0x5df00
movq -0x40(%rbp), %rdi
callq 0x5b6b0
nopl (%rax,%rax)