// File: /workspace/github_c_makefile_star2_O1/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 0x178f
callq 0x16e7
jmp 0x1a15
movq %rsi, %r14
movl %edi, %ebp
leaq 0x8cd(%rip), %rdx       # 0x2068
callq 0x10d0
shll $0x18, %eax
cmpl $0xff000000, %eax       # imm = 0xFF000000
je 0x1899
leaq 0x84f(%rip), %r12       # 0x2004
movq 0x2824(%rip), %r13      # 0x3fe0
leaq 0x8a5(%rip), %r15       # 0x2068
sarl $0x18, %eax
addl $-0x63, %eax
cmpl $0x11, %eax
ja 0x1785
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movq (%r13), %rdi
callq 0x10e0
movl %eax, 0x28ca(%rip)      # 0x40b0
jmp 0x187e
movq (%r13), %rsi
movl $0xf, %edx
leaq 0x128d5(%rip), %rdi     # 0x140d0
jmp 0x1879
movq (%r13), %rsi
movl $0xf, %edx
leaq 0x128b3(%rip), %rdi     # 0x140c0
callq 0x1030
movl $0x1, 0x2898(%rip)      # 0x40b4
jmp 0x187e
movq (%r13), %rsi
movl $0xf, %edx
leaq 0x128c2(%rip), %rdi     # 0x140f0
jmp 0x1879
movq (%r13), %rdi
callq 0x10e0
movl %eax, 0x2859(%rip)      # 0x4098
jmp 0x187e
movq (%r13), %rdi
callq 0x10e0
movl %eax, 0x128b0(%rip)     # 0x14100
jmp 0x187e
movq (%r13), %rdi
callq 0x10e0
movl %eax, %ebx
addl $-0x4, %eax
cmpl $-0x4, %eax
jbe 0x1a26
movq (%r13), %rsi
movl $0xf, %edx
leaq 0x12867(%rip), %rdi     # 0x140e0
callq 0x1030
movl %ebp, %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x10d0
shll $0x18, %eax
cmpl $0xff000000, %eax       # imm = 0xFF000000
jne 0x17c3
movl $0x2, %edi
movl $0x3, %esi
movl $0x67, %edx
callq 0x1100
testl %eax, %eax
js 0x1a34
movl %eax, %ebp
cmpl $0x0, 0x27f6(%rip)      # 0x40b4
je 0x18e1
leaq 0xc(%rsp), %rcx
movl %ebp, %edi
xorl %esi, %esi
movl $0x3, %edx
movl $0x4, %r8d
callq 0x1050
testl %eax, %eax
jne 0x1a3d
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movw $0x2, 0x10(%rsp)
leaq 0x127d9(%rip), %rdi     # 0x140d0
callq 0x10a0
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x27a9(%rip)      # 0x40b0
js 0x1a15
movl $0x1, %r13d
leaq 0x27a6(%rip), %r14      # 0x40c0
leaq 0x10(%rsp), %r15
movl $0xffff, %edx           # imm = 0xFFFF
movq %r14, %rdi
xorl %esi, %esi
callq 0x1080
cmpl $0x3, %ebx
je 0x196f
cmpl $0x2, %ebx
je 0x1958
cmpl $0x1, %ebx
jne 0x1a26
callq 0x123f
cmpl $0x0, 0x2767(%rip)      # 0x40b4
je 0x19a7
leaq 0x737(%rip), %rdi       # 0x208d
jmp 0x1984
callq 0x1355
cmpl $0x0, 0x2750(%rip)      # 0x40b4
je 0x199e
leaq 0x766(%rip), %rdi       # 0x20d3
jmp 0x1984
callq 0x15b0
cmpl $0x0, 0x2739(%rip)      # 0x40b4
je 0x19b0
leaq 0x78b(%rip), %rdi       # 0x210f
leaq 0x12735(%rip), %rsi     # 0x140c0
leaq 0x1273e(%rip), %rdx     # 0x140d0
movl %r13d, %ecx
xorl %eax, %eax
callq 0x1070
jmp 0x19c8
leaq 0x74e(%rip), %rdi       # 0x20f3
jmp 0x19b7
leaq 0x704(%rip), %rdi       # 0x20b2
jmp 0x19b7
leaq 0x77d(%rip), %rdi       # 0x2134
leaq 0x12712(%rip), %rsi     # 0x140d0
movl %r13d, %edx
xorl %eax, %eax
callq 0x1070
movslq 0x26c9(%rip), %rdx      # 0x4098
movl %ebp, %edi
movq %r14, %rsi
xorl %ecx, %ecx
movq %r15, %r8
movl $0x10, %r9d
callq 0x1090
testq %rax, %rax
js 0x1a46
leal 0x1(%r13), %r12d
movl $0x1, %edi
callq 0x10f0
movl 0x26b3(%rip), %eax      # 0x40b0
testl %eax, %eax
setne %cl
cmpl %eax, %r13d
setge %al
andb %cl, %al
movl %r12d, %r13d
cmpb $0x1, %al
jne 0x191f
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x941(%rip), %rdi       # 0x236e
callq 0x1040
jmp 0x1a52
leaq 0x63e(%rip), %rdi       # 0x2079
jmp 0x1a4d
leaq 0x63d(%rip), %rdi       # 0x2081
jmp 0x1a4d
leaq 0x708(%rip), %rdi       # 0x2155
callq 0x10c0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x1a17