// File: /workspace/github_c_makefile_star2_O3/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 0x17ba
callq 0x1712
jmp 0x1a55
movq %rsi, %r14
movl %edi, %ebp
leaq 0x8a2(%rip), %rdx       # 0x2068
callq 0x10d0
shll $0x18, %eax
cmpl $0xff000000, %eax       # imm = 0xFF000000
je 0x18d9
leaq 0x824(%rip), %r13       # 0x2004
movq 0x27f9(%rip), %r12      # 0x3fe0
leaq 0x87a(%rip), %r15       # 0x2068
sarl $0x18, %eax
addl $-0x63, %eax
cmpl $0x11, %eax
ja 0x17b0
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movq (%r12), %rdi
callq 0x10e0
movl %eax, 0x289e(%rip)      # 0x40b0
jmp 0x18be
movq (%r12), %rsi
movl $0xf, %edx
leaq 0x128a9(%rip), %rdi     # 0x140d0
jmp 0x185a
movq (%r12), %rsi
movl $0xf, %edx
leaq 0x12887(%rip), %rdi     # 0x140c0
callq 0x1030
movl $0x1, 0x286c(%rip)      # 0x40b4
jmp 0x18be
movq (%r12), %rsi
movl $0xf, %edx
leaq 0x12896(%rip), %rdi     # 0x140f0
callq 0x1030
jmp 0x18be
movq (%r12), %rdi
callq 0x10e0
movl %eax, 0x2828(%rip)      # 0x4098
jmp 0x18be
movq (%r12), %r12
jmp 0x18a3
movq (%r12), %rdi
callq 0x10e0
movl %eax, 0x12879(%rip)     # 0x14100
jmp 0x18be
movq (%r12), %r12
movq %r12, %rdi
callq 0x10e0
movl %eax, %ebx
addl $-0x4, %eax
cmpl $-0x4, %eax
jbe 0x1a66
movl $0xf, %edx
leaq 0x12831(%rip), %rdi     # 0x140e0
movq %r12, %rsi
callq 0x1030
movq 0x2722(%rip), %r12      # 0x3fe0
movl %ebp, %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x10d0
shll $0x18, %eax
cmpl $0xff000000, %eax       # imm = 0xFF000000
jne 0x17ee
movl $0x2, %edi
movl $0x3, %esi
movl $0x67, %edx
callq 0x1100
testl %eax, %eax
js 0x1a74
movl %eax, %ebp
cmpl $0x0, 0x27b6(%rip)      # 0x40b4
je 0x1921
leaq 0xc(%rsp), %rcx
movl %ebp, %edi
xorl %esi, %esi
movl $0x3, %edx
movl $0x4, %r8d
callq 0x1050
testl %eax, %eax
jne 0x1a7d
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movw $0x2, 0x10(%rsp)
leaq 0x12799(%rip), %rdi     # 0x140d0
callq 0x10a0
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x2769(%rip)      # 0x40b0
js 0x1a55
movl $0x1, %r13d
leaq 0x2766(%rip), %r14      # 0x40c0
leaq 0x10(%rsp), %r15
movl $0xffff, %edx           # imm = 0xFFFF
movq %r14, %rdi
xorl %esi, %esi
callq 0x1080
cmpl $0x3, %ebx
je 0x19af
cmpl $0x2, %ebx
je 0x1998
cmpl $0x1, %ebx
jne 0x1a66
callq 0x123f
cmpl $0x0, 0x2727(%rip)      # 0x40b4
je 0x19e7
leaq 0x6f7(%rip), %rdi       # 0x208d
jmp 0x19c4
callq 0x1364
cmpl $0x0, 0x2710(%rip)      # 0x40b4
je 0x19de
leaq 0x726(%rip), %rdi       # 0x20d3
jmp 0x19c4
callq 0x15c6
cmpl $0x0, 0x26f9(%rip)      # 0x40b4
je 0x19f0
leaq 0x74b(%rip), %rdi       # 0x210f
leaq 0x126f5(%rip), %rsi     # 0x140c0
leaq 0x126fe(%rip), %rdx     # 0x140d0
movl %r13d, %ecx
xorl %eax, %eax
callq 0x1070
jmp 0x1a08
leaq 0x70e(%rip), %rdi       # 0x20f3
jmp 0x19f7
leaq 0x6c4(%rip), %rdi       # 0x20b2
jmp 0x19f7
leaq 0x73d(%rip), %rdi       # 0x2134
leaq 0x126d2(%rip), %rsi     # 0x140d0
movl %r13d, %edx
xorl %eax, %eax
callq 0x1070
movslq 0x2689(%rip), %rdx      # 0x4098
movl %ebp, %edi
movq %r14, %rsi
xorl %ecx, %ecx
movq %r15, %r8
movl $0x10, %r9d
callq 0x1090
testq %rax, %rax
js 0x1a86
leal 0x1(%r13), %r12d
movl $0x1, %edi
callq 0x10f0
movl 0x2673(%rip), %eax      # 0x40b0
testl %eax, %eax
setne %cl
cmpl %eax, %r13d
setge %al
andb %cl, %al
movl %r12d, %r13d
cmpb $0x1, %al
jne 0x195f
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x901(%rip), %rdi       # 0x236e
callq 0x1040
jmp 0x1a92
leaq 0x5fe(%rip), %rdi       # 0x2079
jmp 0x1a8d
leaq 0x5fd(%rip), %rdi       # 0x2081
jmp 0x1a8d
leaq 0x6c8(%rip), %rdi       # 0x2155
callq 0x10c0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x1a57