// File: /workspace/github_c_makefile_star2_O2/dropletzhu[P]msuite/mlistener.c
// Function: main
int
main (int argc, char *argv[])
{
	struct sockaddr_in addr;
	int fd, nbytes, ch, i;
	unsigned int addrlen;
	struct ip_mreq mreq;
	char msgbuf[BUF_LEN], source[IP_LEN], group[IP_LEN], port[PORT_LEN];
	int length = 256;
	struct sigaction new_action, old_action;
	char s_source[IP_LEN], s_group[IP_LEN];

	if (argc <= 1)
	{
		usage();
		return 0;
	}

	while ((ch = getopt (argc, argv, "s:g:p:l:")) != -1)
	{
		switch (ch)
		{
		case 's':
			memset (source, 0, IP_LEN);
			strncpy (source, optarg, IP_LEN - 1);
			break;
		case 'g':
			memset (group, 0, IP_LEN);
			strncpy (group, optarg, IP_LEN - 1);
			break;
		case 'p':
			memset (port, 0, PORT_LEN);
			strncpy (port, optarg, PORT_LEN - 1);
			break;
		case 'l':
			length = atoi(optarg);
			break;
		default:
			usage();
			return 0;
		}
	}

	/* create what looks like an ordinary UDP socket */
	if ((fd = socket (AF_INET, SOCK_DGRAM, 0)) < 0)
	{
		perror ("socket");
		return -1;
	}

	/* set up destination address */
	memset (&addr, 0, sizeof (addr));
	addr.sin_family = AF_INET;
	addr.sin_addr.s_addr = inet_addr (group);
	addr.sin_port = htons (atoi (port));

	/* bind to receive address */
	if (bind (fd, (struct sockaddr *) &addr, sizeof (addr)) < 0)
	{
		perror ("bind");
		return -1;
	}

	/* use setsockopt() to request that the kernel join a multicast group */
	mreq.imr_multiaddr.s_addr = inet_addr (group);
	mreq.imr_interface.s_addr = inet_addr (source);

	if (setsockopt (fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof (mreq)) < 0)
	{
		perror ("setsockopt");
		return -1;
	}

	new_action.sa_handler = term_handler;
	sigemptyset(&new_action.sa_mask);
	new_action.sa_flags = 0;
	sigaction(SIGINT, &new_action, &old_action);
	sigaction(SIGKILL, &new_action, &old_action);
	sigaction(SIGTERM, &new_action, &old_action);

	while (1)
	{
		memset(msgbuf, 0, BUF_LEN);

		addrlen = sizeof (addr);
		if ((nbytes = recvfrom (fd, msgbuf, length, 0, (struct sockaddr *) &addr, &addrlen)) < 0)
		{
			perror ("recvfrom");
			return -1;
		}
		printf ("Receiver %d -- %s\n", ++l_count, msgbuf);
		sscanf (msgbuf,"Sender %[0-9.]->%[0-9.]: %d",s_source,s_group,&i);
		s_count[atoi(s_source) & 0xFF] = i;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x101b8, %rsp          # imm = 0x101B8
cmpl $0x2, %edi
jl 0x13a8
movq %rsi, %r14
movl %edi, %ebp
movl $0x100, 0xc(%rsp)       # imm = 0x100
leaq 0xd4d(%rip), %r15       # 0x2066
movq 0x2cc0(%rip), %r12      # 0x3fe0
pushq $0xf
popq %r13
leaq 0x30(%rsp), %rbx
movl %ebp, %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x10f0
cmpl $0x67, %eax
je 0x1356
cmpl $0x70, %eax
je 0x1371
cmpl $0x73, %eax
jne 0x138f
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq (%r12), %rsi
movq %rbx, %rdi
jmp 0x1367
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq (%r12), %rsi
leaq 0x20(%rsp), %rdi
movq %r13, %rdx
callq 0x1030
jmp 0x1329
andw $0x0, 0x14(%rsp)
andl $0x0, 0x10(%rsp)
movq (%r12), %rsi
leaq 0x10(%rsp), %rdi
pushq $0x5
popq %rdx
callq 0x1030
jmp 0x1329
cmpl $0x6c, %eax
jne 0x13a3
movq (%r12), %rdi
callq 0x1100
movl %eax, 0xc(%rsp)
jmp 0x1329
cmpl $-0x1, %eax
je 0x13c1
callq 0x122c
xorl %eax, %eax
addq $0x101b8, %rsp          # imm = 0x101B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x2
popq %rdi
movl %edi, %esi
xorl %edx, %edx
callq 0x1120
testl %eax, %eax
jns 0x13dd
leaq 0xc97(%rip), %rdi       # 0x206f
jmp 0x1576
movl %eax, %r13d
leaq 0x50(%rsp), %rbx
andq $0x0, 0x8(%rbx)
movw $0x2, (%rbx)
leaq 0x20(%rsp), %rdi
callq 0x1090
movl %eax, 0x4(%rbx)
leaq 0x10(%rsp), %rdi
callq 0x1100
rolw $0x8, %ax
movw %ax, 0x2(%rbx)
pushq $0x10
popq %rdx
movl %r13d, %edi
movq %rbx, %rsi
callq 0x10d0
testl %eax, %eax
jns 0x142c
leaq 0xc4f(%rip), %rdi       # 0x2076
jmp 0x1576
leaq 0x20(%rsp), %rdi
callq 0x1090
leaq 0x48(%rsp), %rbx
movl %eax, (%rbx)
leaq 0x30(%rsp), %rdi
callq 0x1090
movl %eax, 0x4(%rbx)
pushq $0x23
popq %rdx
pushq $0x8
popq %r8
movl %r13d, %edi
xorl %esi, %esi
movq %rbx, %rcx
callq 0x1060
testl %eax, %eax
jns 0x146e
leaq 0xc12(%rip), %rdi       # 0x207b
jmp 0x1576
leaq -0x1f6(%rip), %rax      # 0x127f
leaq 0x88(%rsp), %rbx
movq %rax, -0x8(%rbx)
movq %rbx, %rdi
callq 0x10a0
andl $0x0, 0x80(%rbx)
pushq $0x2
popq %rdi
leaq 0x80(%rsp), %rbx
leaq 0x118(%rsp), %r14
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1050
pushq $0x9
popq %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1050
pushq $0xf
popq %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1050
movslq 0xc(%rsp), %rbx
leaq 0x1b0(%rsp), %r14
leaq 0x70(%rsp), %r15
leaq 0x2bed(%rip), %rbp      # 0x40d0
movl $0xffff, %edx           # imm = 0xFFFF
movq %r14, %rdi
xorl %esi, %esi
callq 0x1080
movl $0x10, 0x18(%rsp)
movl %r13d, %edi
movq %r14, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
leaq 0x50(%rsp), %r8
leaq 0x18(%rsp), %r9
callq 0x10c0
testl %eax, %eax
js 0x156f
movl 0x2ba2(%rip), %esi      # 0x40c0
incl %esi
movl %esi, 0x2b9a(%rip)      # 0x40c0
leaq 0xb62(%rip), %rdi       # 0x208f
movq %r14, %rdx
xorl %eax, %eax
callq 0x1070
movq %r14, %rdi
leaq 0xb61(%rip), %rsi       # 0x20a2
movq %r15, %rdx
leaq 0x60(%rsp), %rcx
leaq 0x1c(%rsp), %r8
xorl %eax, %eax
callq 0x10b0
movl 0x1c(%rsp), %r12d
movq %r15, %rdi
callq 0x1100
movzbl %al, %eax
movl %r12d, (%rbp,%rax,4)
jmp 0x14e3
leaq 0xb10(%rip), %rdi       # 0x2086
callq 0x10e0
pushq $-0x1
popq %rax
jmp 0x13af