// File: /workspace/github_c_makefile_star2_O0/MartinDrab[P]netpipe/netpipe.c
// Function: ProcessChannel
static void _ProcessChannel(PCHANNEL_DATA Data)
{
	int ret = 0;
#ifndef _WIN32
	struct pollfd fds[2];
#else
	pollfd fds[2];
#endif

	memset(fds, 0, sizeof(fds));
	fds[0].fd = Data->SourceSocket;
	fds[0].events = POLLIN;
	fds[1].fd = Data->DestSocket;
	fds[1].events = POLLIN;
	LogInfo("Starting to process the connection (%s <--> %s)", Data->SourceAddress, Data->DestAddress);
	do {
		fds[0].revents = 0;
		fds[1].revents = 0;
		ret = poll(fds, sizeof(fds) / sizeof(fds[0]), 1000);
		if (ret > 0) {
			if ((fds[0].revents & POLLERR) ||
				(fds[1].revents & POLLERR)) {
				for (size_t i = 0; i < sizeof(fds) / sizeof(fds[0]); ++i) {
					if (fds[i].revents & POLLERR) {
						int err = 0;
						socklen_t errLen = sizeof(err);

						getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, (void*)&err, &errLen);
						LogError("Error occurred during channel processing on socket #%zu: %i", i, err);
					}
				}

				break;
			}

			if (fds[0].revents & POLLIN)
				ret = _StreamData(Data->SourceSocket, Data->DestSocket, fds[0].revents);

			if (fds[1].revents & POLLIN)
				ret = _StreamData(Data->DestSocket, Data->SourceSocket, fds[1].revents);

			if ((fds[0].revents & POLLHUP) ||
				(fds[1].revents & POLLHUP)) {
				LogInfo("Connection closed");
				break;
			}
		} else if (ret == SOCKET_ERROR && errno == EINTR)
			ret = 0;
	} while (!_terminated && ret >= 0);

	shutdown(Data->DestSocket, SD_BOTH);
	closesocket(Data->DestSocket);
	shutdown(Data->SourceSocket, SD_BOTH);
	closesocket(Data->SourceSocket);
	if (Data->SourceAddress != NULL)
		free(Data->SourceAddress);
	
	if (Data->DestAddress != NULL)
		free(Data->DestAddress);
	
	free(Data);

	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
leaq -0x20(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2100
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x20(%rbp)
movw $0x1, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x18(%rbp)
movw $0x1, -0x14(%rbp)
callq 0x2090
movl %eax, %edx
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x10(%rax), %r8
movl $0x4, %edi
leaq 0x8231(%rip), %rsi      # 0x10ee6
movb $0x0, %al
callq 0x7070
movw $0x0, -0x1a(%rbp)
movw $0x0, -0x12(%rbp)
leaq -0x20(%rbp), %rdi
movl $0x2, %esi
movl $0x3e8, %edx            # imm = 0x3E8
callq 0x21c0
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jle 0x8e0e
movswl -0x1a(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
jne 0x8d04
movswl -0x12(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x8d8c
movq $0x0, -0x28(%rbp)
cmpq $0x2, -0x28(%rbp)
jae 0x8d87
movq -0x28(%rbp), %rax
movswl -0x1a(%rbp,%rax,8), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x8d77
movl $0x0, -0x2c(%rbp)
movl $0x4, -0x30(%rbp)
movq -0x28(%rbp), %rax
movl -0x20(%rbp,%rax,8), %edi
movl $0x1, %esi
movl $0x4, %edx
leaq -0x2c(%rbp), %rcx
leaq -0x30(%rbp), %r8
callq 0x2140
callq 0x2090
movl %eax, %edx
movq -0x28(%rbp), %rcx
movl -0x2c(%rbp), %r8d
addl $0x0, %r8d
movl $0x1, %edi
leaq 0x81ad(%rip), %rsi      # 0x10f1d
movb $0x0, %al
callq 0x7070
jmp 0x8d79
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x8d0c
jmp 0x8e4e
movswl -0x1a(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x8db1
movq -0x8(%rbp), %rax
movl (%rax), %edi
movq -0x8(%rbp), %rax
movl 0x4(%rax), %esi
movswl -0x1a(%rbp), %edx
callq 0x8f30
movl %eax, -0xc(%rbp)
movswl -0x12(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x8dd6
movq -0x8(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x8(%rbp), %rax
movl (%rax), %esi
movswl -0x12(%rbp), %edx
callq 0x8f30
movl %eax, -0xc(%rbp)
movswl -0x1a(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
jne 0x8dee
movswl -0x12(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x8e0c
callq 0x2090
movl %eax, %edx
movl $0x4, %edi
leaq 0x815f(%rip), %rsi      # 0x10f60
xorl %ecx, %ecx
movb $0x0, %al
callq 0x7070
jmp 0x8e4e
jmp 0x8e27
cmpl $-0x1, -0xc(%rbp)
jne 0x8e25
callq 0x2050
cmpl $0x4, (%rax)
jne 0x8e25
movl $0x0, -0xc(%rbp)
jmp 0x8e27
jmp 0x8e29
movl 0xac91(%rip), %ecx      # 0x13ac0
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x31(%rbp)
jne 0x8e43
cmpl $0x0, -0xc(%rbp)
setge %al
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %al
testb $0x1, %al
jne 0x8cbc
movq -0x8(%rbp), %rax
movl 0x4(%rax), %edi
movl $0x2, %esi
callq 0x20b0
movq -0x8(%rbp), %rax
movl 0x4(%rax), %edi
callq 0x2110
movq -0x8(%rbp), %rax
movl (%rax), %edi
movl $0x2, %esi
callq 0x20b0
movq -0x8(%rbp), %rax
movl (%rax), %edi
callq 0x2110
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x8e9e
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x2030
movq -0x8(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x8eb6
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x2030
movq -0x8(%rbp), %rdi
callq 0x2030
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)