// File: /workspace/github_c_makefile_star2_O1/dropletzhu[P]msuite/mlistener6.c
// Function: main
int
main (int argc, char *argv[])
{
	struct sockaddr_in6 addr;
	int fd, nbytes, ch, i;
	unsigned int addrlen;
	struct ipv6_mreq mreq;
	char msgbuf[BUF_LEN], source[IP_LEN], group[IP_LEN], port[PORT_LEN];
	char ifname[NAME_LEN];
	unsigned int ifindex;
	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:i:g:p:l:")) != -1)
	{
		switch (ch)
		{
		case 's':
			memset (source, 0, IP_LEN);
			strncpy (source, optarg, IP_LEN - 1);
			break;
		case 'i':
			memset (ifname, 0, NAME_LEN);
			strncpy (ifname, optarg, NAME_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_INET6, SOCK_DGRAM, 0)) < 0)
	{
		perror ("socket");
		return -1;
	}

	/* set up destination address */
	memset (&addr, 0, sizeof (addr));
	addr.sin6_family = AF_INET6;
	inet_pton(AF_INET6, group, &(addr.sin6_addr));
	addr.sin6_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 */
	inet_pton(AF_INET6, group, &(mreq.ipv6mr_multiaddr));
	ifindex = if_nametoindex(ifname);
	mreq.ipv6mr_interface = ifindex;

	if (setsockopt (fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq, sizeof (mreq)) < 0)
	{
		perror ("setsockopt add");
		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 $0x10228, %rsp          # imm = 0x10228
cmpl $0x2, %edi
jl 0x13f7
movq %rsi, %r14
movl %edi, %ebp
movl $0x100, 0xc(%rsp)       # imm = 0x100
leaq 0xd3f(%rip), %r15       # 0x2072
leaq 0xcca(%rip), %r12       # 0x2004
movq 0x2c9f(%rip), %r13      # 0x3fe0
leaq 0x14(%rsp), %rbx
movl %ebp, %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1100
leal -0x67(%rax), %ecx
cmpl $0x9, %ecx
ja 0x138f
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x50(%rsp)
movq (%r13), %rsi
movl $0x27, %edx
leaq 0x30(%rsp), %rdi
callq 0x1030
jmp 0x1346
cmpl $0x73, %eax
je 0x1346
jmp 0x13f2
movw $0x0, 0x18(%rsp)
movl $0x0, 0x14(%rsp)
movq (%r13), %rsi
movl $0x5, %edx
movq %rbx, %rdi
callq 0x1030
jmp 0x1346
movw $0x0, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
movq (%r13), %rsi
movl $0x9, %edx
leaq 0x20(%rsp), %rdi
callq 0x1030
jmp 0x1346
movq (%r13), %rdi
callq 0x1110
movl %eax, 0xc(%rsp)
jmp 0x1346
cmpl $-0x1, %eax
je 0x1410
callq 0x123c
xorl %eax, %eax
addq $0x10228, %rsp          # imm = 0x10228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xa, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x1130
testl %eax, %eax
jns 0x1431
leaq 0xc51(%rip), %rdi       # 0x207d
jmp 0x1632
movl %eax, %ebp
xorps %xmm0, %xmm0
leaq 0x68(%rsp), %rbx
movaps %xmm0, -0x8(%rbx)
movups %xmm0, 0x4(%rbx)
movw $0xa, -0x8(%rbx)
leaq 0x30(%rsp), %rsi
movl $0xa, %edi
movq %rbx, %rdx
callq 0x10b0
leaq 0x14(%rsp), %rdi
callq 0x1110
rolw $0x8, %ax
movw %ax, -0x6(%rbx)
leaq 0x60(%rsp), %rsi
movl %ebp, %edi
movl $0x1c, %edx
callq 0x10e0
testl %eax, %eax
jns 0x148e
leaq 0xbfb(%rip), %rdi       # 0x2084
jmp 0x1632
leaq 0x30(%rsp), %rsi
leaq 0x7c(%rsp), %rbx
movl $0xa, %edi
movq %rbx, %rdx
callq 0x10b0
leaq 0x20(%rsp), %rdi
callq 0x10a0
movl %eax, 0x10(%rbx)
movl %ebp, %edi
movl $0x29, %esi
movl $0x14, %edx
movq %rbx, %rcx
movl $0x14, %r8d
callq 0x1060
testl %eax, %eax
jns 0x14dc
leaq 0xbb2(%rip), %rdi       # 0x2089
jmp 0x1632
leaq -0x248(%rip), %rax      # 0x129b
leaq 0xf8(%rsp), %rbx
movq %rax, -0x8(%rbx)
movq %rbx, %rdi
callq 0x1090
movl $0x0, 0x80(%rbx)
leaq 0xf0(%rsp), %rbx
leaq 0x188(%rsp), %r14
movl $0x2, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1050
movl $0x9, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1050
movl $0xf, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1050
movslq 0xc(%rsp), %rbx
leaq 0x220(%rsp), %r14
movl $0xffff, %edx           # imm = 0xFFFF
movq %r14, %rdi
xorl %esi, %esi
callq 0x1080
leaq 0x10(%rsp), %r9
movl $0x1c, (%r9)
leaq 0x60(%rsp), %r8
movl %ebp, %edi
movq %r14, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x10d0
testl %eax, %eax
js 0x162b
leaq 0x220(%rsp), %r15
leaq 0xc0(%rsp), %r13
leaq 0x10(%rsp), %r12
movl 0x2b20(%rip), %esi      # 0x40c0
incl %esi
movl %esi, 0x2b18(%rip)      # 0x40c0
leaq 0xaf2(%rip), %rdi       # 0x20a1
movq %r15, %rdx
xorl %eax, %eax
callq 0x1070
movq %r15, %rdi
leaq 0xaf1(%rip), %rsi       # 0x20b4
movq %r13, %rdx
leaq 0x90(%rsp), %rcx
leaq 0x1c(%rsp), %r8
xorl %eax, %eax
callq 0x10c0
movl 0x1c(%rsp), %r14d
movq %r13, %rdi
callq 0x1110
movzbl %al, %eax
leaq 0x2adf(%rip), %rcx      # 0x40d0
movl %r14d, (%rcx,%rax,4)
movl $0xffff, %edx           # imm = 0xFFFF
movq %r15, %rdi
xorl %esi, %esi
callq 0x1080
movl $0x1c, 0x10(%rsp)
movl %ebp, %edi
movq %r15, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
leaq 0x60(%rsp), %r8
movq %r12, %r9
callq 0x10d0
testl %eax, %eax
jns 0x159a
leaq 0xa66(%rip), %rdi       # 0x2098
callq 0x10f0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x13fe