// File: /workspace/github_cpp_makefile_star2_O3/akw0088[P]openssl/rsync_download.c
// Function: main
int main(int argc, char *argv[])
{
	if (argc < 5)
	{
		printf("Usage: rsync_download ip port max_size block_size\r\n");
		return 0;
	}

#ifdef WIN32
	WSADATA		WSAData;

	WSAStartup(MAKEWORD(2, 0), &WSAData);
#endif

	unsigned short port = atoi(argv[2]);
	unsigned int max_malloc_size = atoi(argv[3]);
	unsigned int block_size = atoi(argv[4]);

	printf("Allocating %d bytes\r\n", max_malloc_size);
	char *response = (char *)malloc(max_malloc_size);
	if (response == NULL)
	{
		perror("malloc failed");
	}

	unsigned int download_size = 0;
	char file_name[PATH_SIZE] = {0};



	printf("Attempting to download file from ip %s port %d using block size %d\r\n", argv[1], (int)port, block_size);
	int ret = rsync_file_download(argv[1], port, response, max_malloc_size, &download_size, file_name, block_size);
	if (ret < 0)
	{
		printf("Download failed\r\n");
		return 0;
	}
	else if (ret == 0 && download_size == 0)
	{
		printf("File did not change\r\n");
	}
	else
	{
		printf("Download complete\r\n");
		printf("Got %d bytes file name %s\r\n", download_size, file_name);

		char new_filename[PATH_SIZE] = {0};
		char strip_filename[PATH_SIZE] = {0};

		StripChars(file_name, strip_filename, ".\\/;:*?\"<>|");

		sprintf(new_filename, "downloaded_%s", strip_filename);
		printf("Saving as file name %s\r\n", new_filename);
		write_file(new_filename, response, download_size);
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
cmpl $0x4, %edi
jg 0x2b23
leaq 0x1b50(%rip), %rdi      # 0x466e
jmp 0x2cc5
movq %rsi, %r14
movq 0x10(%rsi), %rdi
callq 0x11f0
movl %eax, %ebp
movq 0x18(%r14), %rdi
callq 0x11f0
movl %eax, %r15d
movq 0x20(%r14), %rdi
callq 0x11f0
movl %eax, %r13d
leaq 0x178b(%rip), %rdi      # 0x42db
movl %r15d, %esi
xorl %eax, %eax
callq 0x10e0
movl %r15d, %edi
callq 0x1180
movq %rax, %r12
testq %rax, %rax
je 0x2cde
leaq 0xc(%rsp), %rax
movl $0x0, (%rax)
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rbx
movaps %xmm0, 0x70(%rbx)
movaps %xmm0, 0x60(%rbx)
movaps %xmm0, 0x50(%rbx)
movaps %xmm0, 0x40(%rbx)
movaps %xmm0, 0x30(%rbx)
movaps %xmm0, 0x20(%rbx)
movaps %xmm0, 0x10(%rbx)
movaps %xmm0, (%rbx)
movq 0x8(%r14), %rsi
movzwl %bp, %edx
leaq 0x1743(%rip), %rdi      # 0x42f1
movl %r13d, %ecx
xorl %eax, %eax
callq 0x10e0
movq 0x8(%r14), %rdi
movl %r13d, (%rsp)
movzwl %bp, %esi
movq %r12, %rdx
movl %r15d, %ecx
leaq 0xc(%rsp), %r8
movq %rbx, %r9
callq 0x1afa
testl %eax, %eax
js 0x2cb5
movl 0xc(%rsp), %ebp
testl %ebp, %ebp
je 0x2cbe
leaq 0x1a44(%rip), %rdi      # 0x4635
callq 0x1070
leaq 0x1739(%rip), %rdi      # 0x4336
leaq 0x10(%rsp), %rbx
movl %ebp, %esi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x10e0
xorps %xmm0, %xmm0
leaq 0x110(%rsp), %r14
movaps %xmm0, 0x70(%r14)
movaps %xmm0, 0x60(%r14)
movaps %xmm0, 0x50(%r14)
movaps %xmm0, 0x40(%r14)
movaps %xmm0, 0x30(%r14)
movaps %xmm0, 0x20(%r14)
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
leaq 0x90(%rsp), %r15
movaps %xmm0, 0x70(%r15)
movaps %xmm0, 0x60(%r15)
movaps %xmm0, 0x50(%r15)
movaps %xmm0, 0x40(%r15)
movaps %xmm0, 0x30(%r15)
movaps %xmm0, 0x20(%r15)
movaps %xmm0, 0x10(%r15)
movaps %xmm0, (%r15)
leaq 0x141c(%rip), %rdx      # 0x4092
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2321
leaq 0x16ca(%rip), %rsi      # 0x4352
movq %r14, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x1200
leaq 0x16c4(%rip), %rdi      # 0x4360
movq %r14, %rsi
xorl %eax, %eax
callq 0x10e0
movq %r14, %rdi
movq %r12, %rsi
movl %ebp, %edx
callq 0x19b7
jmp 0x2cca
leaq 0x19a1(%rip), %rdi      # 0x465d
jmp 0x2cc5
leaq 0x1983(%rip), %rdi      # 0x4648
callq 0x1070
xorl %eax, %eax
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x145f(%rip), %rdi      # 0x4144
callq 0x11d0
jmp 0x2b6e
nop