// File: akw0088[P]openssl/rsync_upload.c
// Function: rsync_file_upload
int rsync_file_upload(char *file, unsigned short port)
{
	int			connfd;
	unsigned int		size = sizeof(struct sockaddr_in);
	struct sockaddr_in	servaddr, client;
	time_t			ticks;
	int listenfd;


	listenfd = socket(AF_INET, SOCK_STREAM, 0);
	if (listenfd == -1)
	{
		perror("socket error");
		return -1;
	}

	memset(&servaddr, 0, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
	servaddr.sin_port = htons(port);

	int ret = bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
	while (ret == -1)
	{
		perror("bind error");
		printf("Retrying in 5 seconds\r\n");
#ifdef WIN32
		Sleep(5000);
#else
		sleep(5);
#endif
		ret = bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
	}

	printf("Server listening on: %s:%d\n", inet_ntoa(servaddr.sin_addr), htons(servaddr.sin_port));

	if (listen(listenfd, 3) == -1)
	{
		perror("listen error");
		return -1;
	}

	for (;;)
	{
		char response[1024] = { 0 };

		printf("listening for connections...\n");
		connfd = accept(listenfd, (struct sockaddr *)&client, (socklen_t *)&size);
		if (connfd == INVALID_SOCKET)
			continue;

		ticks = time(NULL);
		snprintf(response, sizeof(response), "%.24s\r\n", ctime(&ticks));
		printf("Client: %s - %s", inet_ntoa(client.sin_addr), response);

		unsigned int file_size = 0;
		char *data = get_file(file, &file_size);
		if (data == NULL)
		{
			printf("Unable to open %s\r\n", file);
			closesocket(connfd);
			continue;
		}

		char file_name[PATH_SIZE] = { 0 };
		unsigned char file_hash[MD5_SIZE + 1] = {0};
		unsigned char rfile_hash[MD5_SIZE + 1] = {0};

		md5sum((char *)&data[0], file_size, (char *)file_hash);

		unsigned int rnum_block = 0;
		memcpy(file_name, file, MIN(PATH_SIZE - 1, strlen(file)));
		Send(connfd, (char *)&file_size, sizeof(int), 0);
		Send(connfd, (char *)&file_name, PATH_SIZE, 0);
		Send(connfd, (char *)&file_hash, MD5_SIZE, 0);
		if ( Recv(connfd, (char *)&rfile_hash, MD5_SIZE, 0) == -1)
		{
			printf("recv failed\r\n");
			closesocket(connfd);
			continue;
		}

		if (strcmp((char *)rfile_hash, (char *)file_hash) == 0)
		{
			printf("Files already match\r\n");
			closesocket(connfd);
			continue;
		}

		if ( Recv(connfd, (char *)&rnum_block, sizeof(int), 0) == -1)
		{
			printf("recv failed\r\n");
			closesocket(connfd);
			continue;
		}

		unsigned int rblock_size = 0;
		if ( Recv(connfd, (char *)&rblock_size, sizeof(int), 0) == -1)
		{
			printf("recv failed\r\n");
			closesocket(connfd);
			continue;
		}


		unsigned int *rchecksum_array = (unsigned int *)malloc(rnum_block * sizeof(int));
		if (rchecksum_array == NULL)
		{
			perror("malloc failed");
			closesocket(connfd);
			continue;
		}

		for (unsigned int i = 0; i < rnum_block; i++)
		{
			rchecksum_array[i] = -1;
		}

		printf("Received %d checksum array from client\r\n", rnum_block);
		if (rnum_block == 0)
		{
			printf("Dropping client as we got no blocks\r\n");
			closesocket(connfd);
			continue;
		}

		if ( Recv(connfd, (char *)rchecksum_array, rnum_block * sizeof(int), 0) == -1)
		{
			printf("recv failed\r\n");
			closesocket(connfd);
			continue;
		}

		char **rmd5_array = (char **)malloc(rnum_block * sizeof(char *));
		if (rmd5_array == NULL)
		{
			perror("malloc failed");
			closesocket(connfd);
			continue;
		}

		for (unsigned int i = 0; i < rnum_block; i++)
		{
			rmd5_array[i] = (char *)malloc(MD5_SIZE + 1 * sizeof(char));
			memset(rmd5_array[i], 0, MD5_SIZE + 1);

			if ( Recv(connfd, (char *)rmd5_array[i], MD5_SIZE, 0) == -1)
			{
				printf("recv failed\r\n");
				closesocket(connfd);
				continue;
			}

		}

		block_t *block = (block_t *)malloc(sizeof(block_t) * rnum_block);
		if (block == NULL)
		{
			perror("malloc failed");
			closesocket(connfd);
			continue;
		}
		printf("Searching for matches in %d blocks\r\n", rnum_block);
		
		unsigned int null_count = 0;
		for (unsigned int i = 0; i < rnum_block; i++)
		{
			block[i].offset = -1;
			block[i].length = 0;

			if (strcmp((char *)rmd5_array, "") == 0)
			{
				null_count++;
			}
		}

		int ret = 0;
		if (null_count != rnum_block)
		{
			// we dont send the last partial block as we can only scan blocks of a single length at a time
			ret = adler32_scan((unsigned char *)&data[0], file_size, rblock_size, rchecksum_array, rnum_block - 1, block, rmd5_array);
		}

		// set length of last block which is always transferred
		block[rnum_block - 1].offset = -1;
		block[rnum_block - 1].length = file_size - (rnum_block - 1) * rblock_size;


		printf("Sending block offsets\r\n");
		Send(connfd, (char *)block, rnum_block * sizeof(block_t), 0);

		// Remote side now knows where it's blocks go in new file
		// going to send all bytes in order of whats left starting from 0 and skipping whats in the block report
		
		printf("Determining data client is missing\r\n");
		for (unsigned int i = 0; i < rnum_block; i++)
		{
			if (block[i].offset == -1)
			{
				printf("\tClient missing block %d [%d bytes]\r\n", i, block[i].length);
			}
		}

		unsigned char *send_file = (unsigned char *)malloc(file_size);
		if (send_file == NULL)
		{
			perror("malloc failed");
			closesocket(connfd);
			continue;
		}

		int send_file_pos = 0;

		memset(send_file, 0, file_size);
		for(unsigned int i = 0; i < file_size; i++)
		{
			int skip = 0;


			for(unsigned int j = 0; j < rnum_block; j++)
			{
				if (block[j].length == 0)
				{
					continue;
				}

				if ( i >= block[j].offset && i < block[j].offset + rblock_size )
				{
					// we are in this block, skip to the end of this block
					i = block[j].offset + rblock_size - 1;
					skip = 1;
					break;
				}
			}
			
			if (skip)
			{
				// restart again as we move passed a block
				continue;
			}
			
			// This byte needs to be sent, move into transport block
			send_file[send_file_pos++] = data[i];
		}
		
		printf("Sending client missing chunk of size %d\r\n", send_file_pos);
		printf("Sending data\r\n");
		Send(connfd, (char *)&send_file_pos, sizeof(unsigned int), 0);		
		Send(connfd, (char *)send_file, send_file_pos, 0);
		closesocket(connfd);
	}
	return 0;
}

// Assembly:
subq $0x5d8, %rsp            # imm = 0x5D8
movw %si, %ax
movq %rdi, 0x5c8(%rsp)
movw %ax, 0x5c6(%rsp)
movl $0x10, 0x5bc(%rsp)
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x1240
movl %eax, 0x58c(%rsp)
cmpl $-0x1, 0x58c(%rsp)
jne 0x2963
leaq 0x2ae0(%rip), %rdi      # 0x542e
callq 0x11d0
movl $0xffffffff, 0x5d4(%rsp) # imm = 0xFFFFFFFF
jmp 0x330c
leaq 0x5ac(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1110
movw $0x2, 0x5ac(%rsp)
xorl %edi, %edi
callq 0x1100
movl %eax, 0x5b0(%rsp)
movzwl 0x5c6(%rsp), %edi
callq 0x10c0
movw %ax, 0x5ae(%rsp)
movl 0x58c(%rsp), %edi
leaq 0x5ac(%rsp), %rsi
movl $0x10, %edx
callq 0x11b0
movl %eax, 0x588(%rsp)
cmpl $-0x1, 0x588(%rsp)
jne 0x2a14
leaq 0x2a66(%rip), %rdi      # 0x543b
callq 0x11d0
leaq 0x2a65(%rip), %rdi      # 0x5446
movb $0x0, %al
callq 0x10e0
movl $0x5, %edi
callq 0x1230
movl 0x58c(%rsp), %edi
leaq 0x5ac(%rsp), %rsi
movl $0x10, %edx
callq 0x11b0
movl %eax, 0x588(%rsp)
jmp 0x29c4
movl 0x5b0(%rsp), %edi
callq 0x1080
movq %rax, 0x30(%rsp)
movzwl 0x5ae(%rsp), %edi
callq 0x10c0
movq 0x30(%rsp), %rsi
movzwl %ax, %edx
leaq 0x2a1d(%rip), %rdi      # 0x545e
movb $0x0, %al
callq 0x10e0
movl 0x58c(%rsp), %edi
movl $0x3, %esi
callq 0x1190
cmpl $-0x1, %eax
jne 0x2a7a
leaq 0x2a15(%rip), %rdi      # 0x547a
callq 0x11d0
movl $0xffffffff, 0x5d4(%rsp) # imm = 0xFFFFFFFF
jmp 0x330c
jmp 0x2a7c
leaq 0x180(%rsp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x1110
leaq 0x29f0(%rip), %rdi      # 0x5487
movb $0x0, %al
callq 0x10e0
movl 0x58c(%rsp), %edi
leaq 0x59c(%rsp), %rsi
leaq 0x5bc(%rsp), %rdx
callq 0x11e0
movl %eax, 0x5c0(%rsp)
cmpl $-0x1, 0x5c0(%rsp)
jne 0x2acd
jmp 0x2a7c
xorl %eax, %eax
movl %eax, %edi
callq 0x1170
movq %rax, 0x590(%rsp)
leaq 0x180(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x590(%rsp), %rdi
callq 0x10a0
movq 0x28(%rsp), %rdi
movq %rax, %rcx
movl $0x400, %esi            # imm = 0x400
leaq 0x2999(%rip), %rdx      # 0x54a5
movb $0x0, %al
callq 0x10f0
movl 0x5a0(%rsp), %edi
callq 0x1080
movq %rax, %rsi
leaq 0x180(%rsp), %rdx
leaq 0x297c(%rip), %rdi      # 0x54ad
movb $0x0, %al
callq 0x10e0
movl $0x0, 0x17c(%rsp)
movq 0x5c8(%rsp), %rdi
leaq 0x17c(%rsp), %rsi
callq 0x19d0
movq %rax, 0x170(%rsp)
cmpq $0x0, 0x170(%rsp)
jne 0x2b92
movq 0x5c8(%rsp), %rsi
leaq 0x269d(%rip), %rdi      # 0x5217
movb $0x0, %al
callq 0x10e0
movl 0x5c0(%rsp), %edi
callq 0x1120
jmp 0x2a7c
leaq 0xf0(%rsp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x1110
leaq 0xc0(%rsp), %rdi
xorl %esi, %esi
movl $0x21, %edx
callq 0x1110
leaq 0x90(%rsp), %rdi
xorl %esi, %esi
movl $0x21, %edx
callq 0x1110
movq 0x170(%rsp), %rdi
movl 0x17c(%rsp), %esi
leaq 0xc0(%rsp), %rdx
callq 0x33b0
movl $0x0, 0x8c(%rsp)
leaq 0xf0(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x5c8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x5c8(%rsp), %rdi
callq 0x10b0
movq %rax, %rcx
movl $0x7f, %eax
cmpq %rcx, %rax
jae 0x2c35
movl $0x7f, %eax
movq %rax, 0x10(%rsp)
jmp 0x2c47
movq 0x5c8(%rsp), %rdi
callq 0x10b0
movq %rax, 0x10(%rsp)
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rdx
callq 0x1160
movl 0x5c0(%rsp), %edi
leaq 0x17c(%rsp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x18e0
movl 0x5c0(%rsp), %edi
leaq 0xf0(%rsp), %rsi
movl $0x80, %edx
xorl %ecx, %ecx
callq 0x18e0
movl 0x5c0(%rsp), %edi
leaq 0xc0(%rsp), %rsi
movl $0x20, %edx
xorl %ecx, %ecx
callq 0x18e0
movl 0x5c0(%rsp), %edi
leaq 0x90(%rsp), %rsi
movl $0x20, %edx
xorl %ecx, %ecx
callq 0x17f0
cmpl $-0x1, %eax
jne 0x2ceb
leaq 0x2506(%rip), %rdi      # 0x51d9
movb $0x0, %al
callq 0x10e0
movl 0x5c0(%rsp), %edi
callq 0x1120
jmp 0x2a7c
leaq 0x90(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x1140
cmpl $0x0, %eax
jne 0x2d24
leaq 0x27b1(%rip), %rdi      # 0x54bd
movb $0x0, %al
callq 0x10e0
movl 0x5c0(%rsp), %edi
callq 0x1120
jmp 0x2a7c
movl 0x5c0(%rsp), %edi
leaq 0x8c(%rsp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x17f0
cmpl $-0x1, %eax
jne 0x2d63
leaq 0x248e(%rip), %rdi      # 0x51d9
movb $0x0, %al
callq 0x10e0
movl 0x5c0(%rsp), %edi
callq 0x1120
jmp 0x2a7c
movl $0x0, 0x88(%rsp)
movl 0x5c0(%rsp), %edi
leaq 0x88(%rsp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x17f0
cmpl $-0x1, %eax
jne 0x2dad
leaq 0x2444(%rip), %rdi      # 0x51d9
movb $0x0, %al
callq 0x10e0
movl 0x5c0(%rsp), %edi
callq 0x1120
jmp 0x2a7c
movl 0x8c(%rsp), %eax
movl %eax, %edi
shlq $0x2, %rdi
callq 0x1180
movq %rax, 0x80(%rsp)
cmpq $0x0, 0x80(%rsp)
jne 0x2def
leaq 0x24f3(%rip), %rdi      # 0x52cc
callq 0x11d0
movl 0x5c0(%rsp), %edi
callq 0x1120
jmp 0x2a7c
movl $0x0, 0x7c(%rsp)
movl 0x7c(%rsp), %eax
cmpl 0x8c(%rsp), %eax
jae 0x2e24
movq 0x80(%rsp), %rax
movl 0x7c(%rsp), %ecx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x2df7
movl 0x8c(%rsp), %esi
leaq 0x26a1(%rip), %rdi      # 0x54d3
movb $0x0, %al
callq 0x10e0
cmpl $0x0, 0x8c(%rsp)
jne 0x2e62
leaq 0x26b2(%rip), %rdi      # 0x54fc
movb $0x0, %al
callq 0x10e0
movl 0x5c0(%rsp), %edi
callq 0x1120
jmp 0x2a7c
movl 0x5c0(%rsp), %edi
movq 0x80(%rsp), %rsi
movl 0x8c(%rsp), %eax
shlq $0x2, %rax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x17f0
cmpl $-0x1, %eax
jne 0x2ea9
leaq 0x2348(%rip), %rdi      # 0x51d9
movb $0x0, %al
callq 0x10e0
movl 0x5c0(%rsp), %edi
callq 0x1120
jmp 0x2a7c
movl 0x8c(%rsp), %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x1180
movq %rax, 0x70(%rsp)
cmpq $0x0, 0x70(%rsp)
jne 0x2ee5
leaq 0x23fd(%rip), %rdi      # 0x52cc
callq 0x11d0
movl 0x5c0(%rsp), %edi
callq 0x1120
jmp 0x2a7c
movl $0x0, 0x6c(%rsp)
movl 0x6c(%rsp), %eax
cmpl 0x8c(%rsp), %eax
jae 0x2f84
movl $0x21, %edi
callq 0x1180
movq %rax, %rdx
movq 0x70(%rsp), %rax
movl 0x6c(%rsp), %ecx
movq %rdx, (%rax,%rcx,8)
movq 0x70(%rsp), %rax
movl 0x6c(%rsp), %ecx
movq (%rax,%rcx,8), %rdi
xorl %esi, %esi
movl $0x21, %edx
callq 0x1110
movl 0x5c0(%rsp), %edi
movq 0x70(%rsp), %rax
movl 0x6c(%rsp), %ecx
movq (%rax,%rcx,8), %rsi
movl $0x20, %edx
xorl %ecx, %ecx
callq 0x17f0
cmpl $-0x1, %eax
jne 0x2f72
leaq 0x227c(%rip), %rdi      # 0x51d9
movb $0x0, %al
callq 0x10e0
movl 0x5c0(%rsp), %edi
callq 0x1120
jmp 0x2f74
jmp 0x2f74
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0x2eed
movl 0x8c(%rsp), %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x1180
movq %rax, 0x60(%rsp)
cmpq $0x0, 0x60(%rsp)
jne 0x2fc0
leaq 0x2322(%rip), %rdi      # 0x52cc
callq 0x11d0
movl 0x5c0(%rsp), %edi
callq 0x1120
jmp 0x2a7c
movl 0x8c(%rsp), %esi
leaq 0x2554(%rip), %rdi      # 0x5522
movb $0x0, %al
callq 0x10e0
movl $0x0, 0x5c(%rsp)
movl $0x0, 0x58(%rsp)
movl 0x58(%rsp), %eax
cmpl 0x8c(%rsp), %eax
jae 0x3043
movq 0x60(%rsp), %rax
movl 0x58(%rsp), %ecx
movl $0xffffffff, (%rax,%rcx,8) # imm = 0xFFFFFFFF
movq 0x60(%rsp), %rax
movl 0x58(%rsp), %ecx
movl $0x0, 0x4(%rax,%rcx,8)
movq 0x70(%rsp), %rdi
leaq 0x2345(%rip), %rsi      # 0x5364
callq 0x1140
cmpl $0x0, %eax
jne 0x3034
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x3036
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x2fe5
movl $0x0, 0x54(%rsp)
movl 0x5c(%rsp), %eax
cmpl 0x8c(%rsp), %eax
je 0x3099
movq 0x170(%rsp), %rdi
movl 0x17c(%rsp), %esi
movl 0x88(%rsp), %edx
movq 0x80(%rsp), %rcx
movl 0x8c(%rsp), %r8d
subl $0x1, %r8d
movq 0x60(%rsp), %r9
movq 0x70(%rsp), %rax
movq %rax, (%rsp)
callq 0x14a0
movl %eax, 0x54(%rsp)
movq 0x60(%rsp), %rax
movl 0x8c(%rsp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movl $0xffffffff, (%rax,%rcx,8) # imm = 0xFFFFFFFF
movl 0x17c(%rsp), %edx
movl 0x8c(%rsp), %eax
subl $0x1, %eax
imull 0x88(%rsp), %eax
subl %eax, %edx
movq 0x60(%rsp), %rax
movl 0x8c(%rsp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movl %edx, 0x4(%rax,%rcx,8)
leaq 0x245f(%rip), %rdi      # 0x5547
movb $0x0, %al
callq 0x10e0
movl 0x5c0(%rsp), %edi
movq 0x60(%rsp), %rsi
movl 0x8c(%rsp), %eax
shlq $0x3, %rax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x18e0
leaq 0x2449(%rip), %rdi      # 0x555f
movb $0x0, %al
callq 0x10e0
movl $0x0, 0x50(%rsp)
movl 0x50(%rsp), %eax
cmpl 0x8c(%rsp), %eax
jae 0x316f
movq 0x60(%rsp), %rax
movl 0x50(%rsp), %ecx
cmpl $-0x1, (%rax,%rcx,8)
jne 0x3160
movl 0x50(%rsp), %esi
movq 0x60(%rsp), %rax
movl 0x50(%rsp), %ecx
movl 0x4(%rax,%rcx,8), %edx
leaq 0x242b(%rip), %rdi      # 0x5584
movb $0x0, %al
callq 0x10e0
jmp 0x3162
movl 0x50(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
jmp 0x3125
movl 0x17c(%rsp), %eax
movl %eax, %edi
callq 0x1180
movq %rax, 0x48(%rsp)
cmpq $0x0, 0x48(%rsp)
jne 0x31a7
leaq 0x213b(%rip), %rdi      # 0x52cc
callq 0x11d0
movl 0x5c0(%rsp), %edi
callq 0x1120
jmp 0x2a7c
movl $0x0, 0x44(%rsp)
movq 0x48(%rsp), %rdi
movl 0x17c(%rsp), %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x1110
movl $0x0, 0x40(%rsp)
movl 0x40(%rsp), %eax
cmpl 0x17c(%rsp), %eax
jae 0x32ac
movl $0x0, 0x3c(%rsp)
movl $0x0, 0x38(%rsp)
movl 0x38(%rsp), %eax
cmpl 0x8c(%rsp), %eax
jae 0x326c
movq 0x60(%rsp), %rax
movl 0x38(%rsp), %ecx
cmpl $0x0, 0x4(%rax,%rcx,8)
jne 0x320c
jmp 0x325f
movl 0x40(%rsp), %eax
movq 0x60(%rsp), %rcx
movl 0x38(%rsp), %edx
cmpl (%rcx,%rdx,8), %eax
jb 0x325d
movl 0x40(%rsp), %eax
movq 0x60(%rsp), %rcx
movl 0x38(%rsp), %edx
movl (%rcx,%rdx,8), %ecx
addl 0x88(%rsp), %ecx
cmpl %ecx, %eax
jae 0x325d
movq 0x60(%rsp), %rax
movl 0x38(%rsp), %ecx
movl (%rax,%rcx,8), %eax
addl 0x88(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x40(%rsp)
movl $0x1, 0x3c(%rsp)
jmp 0x326c
jmp 0x325f
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x31ed
cmpl $0x0, 0x3c(%rsp)
je 0x3275
jmp 0x329c
movq 0x170(%rsp), %rax
movl 0x40(%rsp), %ecx
movb (%rax,%rcx), %dl
movq 0x48(%rsp), %rax
movl 0x44(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x44(%rsp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0x31cc
movl 0x44(%rsp), %esi
leaq 0x22f3(%rip), %rdi      # 0x55aa
movb $0x0, %al
callq 0x10e0
leaq 0x230f(%rip), %rdi      # 0x55d4
movb $0x0, %al
callq 0x10e0
movl 0x5c0(%rsp), %edi
leaq 0x44(%rsp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x18e0
movl 0x5c0(%rsp), %edi
movq 0x48(%rsp), %rsi
movl 0x44(%rsp), %edx
xorl %ecx, %ecx
callq 0x18e0
movl 0x5c0(%rsp), %edi
callq 0x1120
jmp 0x2a7c
movl 0x5d4(%rsp), %eax
addq $0x5d8, %rsp            # imm = 0x5D8
retq
nopl (%rax,%rax)