// File: /workspace/github_c_makefile_star2_O2/dropletzhu[P]msuite/pim_sender.c
// Function: main
int
main (int argc, char* argv[])
{
	char ch;
	int type;
	struct sockaddr_in rp_addr;
	int i, retcode, hdrincl = 1;
	int sockfd;

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

    while ((ch = getopt(argc, argv, "i:r:t:s:g:p:c:l:")) != -1)
    {
        switch (ch)
        {
			case 'i':
				strncpy(local_source, optarg, IP_LEN - 1);
				has_local_source = 1;
				break;
			case 'r':
				strncpy(rp, optarg, IP_LEN - 1);
				break;
			case 't':
				type = atoi(optarg);
				if( (type < 1) || (type > 3) ) {
					printf("wrong type\n");
					return -1;
				}
			case 's':
				strncpy(mcast_source, optarg, IP_LEN -1);
				break;
			case 'g':
				strncpy(mcast_group, optarg, IP_LEN -1);
				break;
			case 'p':
				mcast_port = atoi(optarg);
				break;
			case 'c':
				count = atoi(optarg);
				break;
			case 'l':
				length = atoi(optarg);
				break;
        	default:
				usage();
            	return 0;
		}
    }

	sockfd = socket (PF_INET, SOCK_RAW, IPPROTO_PIM);
	if( sockfd < 0 ) {
		perror("socket\n");
		return -1;
	}

	if( has_local_source ) {
		retcode = setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &hdrincl, sizeof(hdrincl));
		if( retcode != 0 ) {
			perror("setsockopt\n");
			return -1;
		}
	}

	memset(&rp_addr,0,sizeof(struct sockaddr_in));
	rp_addr.sin_family = AF_INET;
	rp_addr.sin_addr.s_addr = inet_addr (rp);

	i = 1;
	while (1)
    {
		if( count && ( i > count ) ) {
			break;
		}

		memset (datagram, 0, BUF_LEN);
		switch( type ) {
			case 1:
				make_pim_null_register();
				if( has_local_source ) {
					printf("Sender PIM null register %s->%s: %d\n",local_source,rp,i++);
				} else {
					printf("Sender PIM null register %s: %d\n",rp,i++);
				}
				break;
			case 2:
				make_pim_register();
				if( has_local_source ) {
					printf("Sender PIM register %s->%s: %d\n",local_source,rp,i++);
				} else {
					printf("Sender PIM register %s: %d\n",rp,i++);
				}
				break;
			case 3:
				make_pim_register_stop();
				if( has_local_source ) {
					printf("Sender PIM register-stop %s->%s: %d\n",local_source,rp,i++);
				} else {
					printf("Sender PIM register-stop %s: %d\n",rp,i++);
				}
				break;
			default:
				printf("wrong type\n");
				return -1;
		}

   		if (sendto (sockfd, datagram, length, 0,(struct sockaddr *) &rp_addr,sizeof (rp_addr)) < 0) {
			perror("sendto\n");
			return -1;
		}
		sleep(1);
    }

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl $0x1, 0xc(%rsp)
cmpl $0x2, %edi
jge 0x1670
callq 0x15bc
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsi, %r14
movl %edi, %ebp
leaq 0x9ec(%rip), %r15       # 0x2068
leaq 0x981(%rip), %r12       # 0x2004
movq 0x2956(%rip), %r13      # 0x3fe0
movl %ebp, %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x10d0
shll $0x18, %eax
cmpl $0xff000000, %eax       # imm = 0xFF000000
je 0x1762
sarl $0x18, %eax
addl $-0x63, %eax
cmpl $0x11, %eax
ja 0x165a
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movq (%r13), %rdi
callq 0x10e0
movl %eax, 0x29e8(%rip)      # 0x40b0
jmp 0x168a
movq (%r13), %rsi
leaq 0x129fb(%rip), %rdi     # 0x140d0
jmp 0x1701
movq (%r13), %rsi
leaq 0x129de(%rip), %rdi     # 0x140c0
pushq $0xf
popq %rdx
callq 0x1030
movl $0x1, 0x29c0(%rip)      # 0x40b4
jmp 0x168a
movq (%r13), %rsi
leaq 0x129ef(%rip), %rdi     # 0x140f0
pushq $0xf
popq %rdx
callq 0x1030
jmp 0x168a
movq (%r13), %rdi
callq 0x10e0
movl %eax, 0x297b(%rip)      # 0x4098
jmp 0x168a
movq (%r13), %rdi
callq 0x10e0
movl %eax, 0x129cf(%rip)     # 0x14100
jmp 0x168a
movq (%r13), %rsi
jmp 0x1759
movq (%r13), %rbx
movq %rbx, %rdi
callq 0x10e0
movq %rbx, %rsi
movl %eax, %ebx
addl $-0x4, %eax
cmpl $-0x4, %eax
jbe 0x18c1
leaq 0x12980(%rip), %rdi     # 0x140e0
jmp 0x1701
pushq $0x2
popq %rdi
pushq $0x3
popq %rsi
pushq $0x67
popq %rdx
callq 0x1100
testl %eax, %eax
js 0x18cf
movl %eax, %ebp
cmpl $0x0, 0x2933(%rip)      # 0x40b4
je 0x17a0
pushq $0x3
popq %rdx
leaq 0xc(%rsp), %rcx
pushq $0x4
popq %r8
movl %ebp, %edi
xorl %esi, %esi
callq 0x1050
testl %eax, %eax
jne 0x18e1
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r15
movaps %xmm0, (%r15)
movw $0x2, (%r15)
leaq 0x12917(%rip), %rdi     # 0x140d0
callq 0x10a0
movl %eax, 0x4(%r15)
pushq $0x1
popq %r13
leaq 0x28f3(%rip), %r14      # 0x40c0
movl %r13d, %r12d
movl 0x28da(%rip), %eax      # 0x40b0
testl %eax, %eax
setne %cl
cmpl %eax, %r13d
setg %al
testb %al, %cl
jne 0x165f
movl $0xffff, %edx           # imm = 0xFFFF
movq %r14, %rdi
xorl %esi, %esi
callq 0x1080
cmpl $0x3, %ebx
je 0x1839
cmpl $0x2, %ebx
je 0x1822
cmpl $0x1, %ebx
jne 0x18c1
callq 0x1236
cmpl $0x0, 0x289d(%rip)      # 0x40b4
je 0x1871
leaq 0x86d(%rip), %rdi       # 0x208d
jmp 0x184e
callq 0x132b
cmpl $0x0, 0x2886(%rip)      # 0x40b4
je 0x1868
leaq 0x89c(%rip), %rdi       # 0x20d3
jmp 0x184e
callq 0x14d8
cmpl $0x0, 0x286f(%rip)      # 0x40b4
je 0x187a
leaq 0x8c1(%rip), %rdi       # 0x210f
leaq 0x1286b(%rip), %rsi     # 0x140c0
leaq 0x12874(%rip), %rdx     # 0x140d0
movl %r13d, %ecx
xorl %eax, %eax
callq 0x1070
jmp 0x1892
leaq 0x884(%rip), %rdi       # 0x20f3
jmp 0x1881
leaq 0x83a(%rip), %rdi       # 0x20b2
jmp 0x1881
leaq 0x8b3(%rip), %rdi       # 0x2134
leaq 0x12848(%rip), %rsi     # 0x140d0
movl %r13d, %edx
xorl %eax, %eax
callq 0x1070
movslq 0x27ff(%rip), %rdx      # 0x4098
movl %ebp, %edi
movq %r14, %rsi
xorl %ecx, %ecx
movq %r15, %r8
pushq $0x10
popq %r9
callq 0x1090
testq %rax, %rax
js 0x18d8
incl %r13d
movl %r12d, %edi
callq 0x10f0
jmp 0x17d0
leaq 0xaa6(%rip), %rdi       # 0x236e
callq 0x1040
jmp 0x18ed
leaq 0x7a3(%rip), %rdi       # 0x2079
jmp 0x18e8
leaq 0x876(%rip), %rdi       # 0x2155
jmp 0x18e8
leaq 0x799(%rip), %rdi       # 0x2081
callq 0x10c0
pushq $-0x1
popq %rax
jmp 0x1661