// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x1, -0x34(%rbp)
cmpl $0x1, -0x8(%rbp)
jg 0x19f4
callq 0x1920
movl $0x0, -0x4(%rbp)
jmp 0x1dcd
jmp 0x19f6
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x87e(%rip), %rdx       # 0x2282
callq 0x10e0
movb %al, -0x11(%rbp)
movsbl %al, %eax
cmpl $-0x1, %eax
je 0x1b5b
movsbl -0x11(%rbp), %eax
addl $-0x63, %eax
movl %eax, %ecx
movq %rcx, -0x40(%rbp)
subl $0x11, %eax
ja 0x1b45
movq -0x40(%rbp), %rax
leaq 0x5cb(%rip), %rcx       # 0x2004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x2597(%rip), %rax      # 0x3fe0
movq (%rax), %rsi
leaq 0x1267d(%rip), %rdi     # 0x140d0
movl $0xf, %edx
callq 0x1030
movl $0x1, 0x265d(%rip)      # 0x40c4
jmp 0x1b56
movq 0x256d(%rip), %rax      # 0x3fe0
movq (%rax), %rsi
leaq 0x12663(%rip), %rdi     # 0x140e0
movl $0xf, %edx
callq 0x1030
jmp 0x1b56
movq 0x254d(%rip), %rax      # 0x3fe0
movq (%rax), %rdi
callq 0x10f0
movl %eax, -0x18(%rbp)
cmpl $0x1, -0x18(%rbp)
jl 0x1aaa
cmpl $0x3, -0x18(%rbp)
jle 0x1ac4
leaq 0x7e2(%rip), %rdi       # 0x2293
movb $0x0, %al
callq 0x1070
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1dcd
jmp 0x1ac6
movq 0x2513(%rip), %rax      # 0x3fe0
movq (%rax), %rsi
leaq 0x12619(%rip), %rdi     # 0x140f0
movl $0xf, %edx
callq 0x1030
jmp 0x1b56
movq 0x24f6(%rip), %rax      # 0x3fe0
movq (%rax), %rsi
leaq 0x1260c(%rip), %rdi     # 0x14100
movl $0xf, %edx
callq 0x1030
jmp 0x1b56
movq 0x24d9(%rip), %rax      # 0x3fe0
movq (%rax), %rdi
callq 0x10f0
movl %eax, 0x125fb(%rip)     # 0x14110
jmp 0x1b56
movq 0x24c2(%rip), %rax      # 0x3fe0
movq (%rax), %rdi
callq 0x10f0
movl %eax, 0x2594(%rip)      # 0x40c0
jmp 0x1b56
movq 0x24ab(%rip), %rax      # 0x3fe0
movq (%rax), %rdi
callq 0x10f0
movl %eax, 0x255d(%rip)      # 0x40a0
jmp 0x1b56
callq 0x1920
movl $0x0, -0x4(%rbp)
jmp 0x1dcd
jmp 0x19f6
movl $0x2, %edi
movl $0x3, %esi
movl $0x67, %edx
callq 0x1110
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jge 0x1b90
leaq 0x720(%rip), %rdi       # 0x229f
callq 0x10d0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1dcd
cmpl $0x0, 0x252d(%rip)      # 0x40c4
je 0x1bd5
movl -0x38(%rbp), %edi
xorl %esi, %esi
movl $0x3, %edx
leaq -0x34(%rbp), %rcx
movl $0x4, %r8d
callq 0x1040
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
je 0x1bd3
leaq 0x6e5(%rip), %rdi       # 0x22a7
callq 0x10d0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1dcd
jmp 0x1bd5
leaq -0x28(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1090
movw $0x2, -0x28(%rbp)
leaq 0x124ee(%rip), %rdi     # 0x140e0
callq 0x10b0
movl %eax, -0x24(%rbp)
movl $0x1, -0x2c(%rbp)
cmpl $0x0, 0x24b8(%rip)      # 0x40c0
je 0x1c1a
movl -0x2c(%rbp), %eax
cmpl 0x24ad(%rip), %eax      # 0x40c0
jle 0x1c1a
jmp 0x1dc6
leaq 0x24af(%rip), %rdi      # 0x40d0
xorl %esi, %esi
movl $0xffff, %edx           # imm = 0xFFFF
callq 0x1090
movl -0x18(%rbp), %eax
movl %eax, -0x44(%rbp)
subl $0x1, %eax
je 0x1c55
jmp 0x1c3a
movl -0x44(%rbp), %eax
subl $0x2, %eax
je 0x1cb1
jmp 0x1c44
movl -0x44(%rbp), %eax
subl $0x3, %eax
je 0x1d0a
jmp 0x1d63
callq 0x12a0
cmpl $0x0, 0x2463(%rip)      # 0x40c4
je 0x1c8c
movl -0x2c(%rbp), %ecx
movl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
leaq 0x63e(%rip), %rdi       # 0x22b3
leaq 0x12454(%rip), %rsi     # 0x140d0
leaq 0x1245d(%rip), %rdx     # 0x140e0
movb $0x0, %al
callq 0x1070
jmp 0x1cac
movl -0x2c(%rbp), %edx
movl %edx, %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
leaq 0x63a(%rip), %rdi       # 0x22d8
leaq 0x1243b(%rip), %rsi     # 0x140e0
movb $0x0, %al
callq 0x1070
jmp 0x1d7a
callq 0x1420
cmpl $0x0, 0x2407(%rip)      # 0x40c4
je 0x1ce8
movl -0x2c(%rbp), %ecx
movl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
leaq 0x628(%rip), %rdi       # 0x22f9
leaq 0x123f8(%rip), %rsi     # 0x140d0
leaq 0x12401(%rip), %rdx     # 0x140e0
movb $0x0, %al
callq 0x1070
jmp 0x1d08
movl -0x2c(%rbp), %edx
movl %edx, %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
leaq 0x61f(%rip), %rdi       # 0x2319
leaq 0x123df(%rip), %rsi     # 0x140e0
movb $0x0, %al
callq 0x1070
jmp 0x1d7a
callq 0x1770
cmpl $0x0, 0x23ae(%rip)      # 0x40c4
je 0x1d41
movl -0x2c(%rbp), %ecx
movl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
leaq 0x60b(%rip), %rdi       # 0x2335
leaq 0x1239f(%rip), %rsi     # 0x140d0
leaq 0x123a8(%rip), %rdx     # 0x140e0
movb $0x0, %al
callq 0x1070
jmp 0x1d61
movl -0x2c(%rbp), %edx
movl %edx, %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
leaq 0x607(%rip), %rdi       # 0x235a
leaq 0x12386(%rip), %rsi     # 0x140e0
movb $0x0, %al
callq 0x1070
jmp 0x1d7a
leaq 0x529(%rip), %rdi       # 0x2293
movb $0x0, %al
callq 0x1070
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1dcd
movl -0x38(%rbp), %edi
movslq 0x231c(%rip), %rdx      # 0x40a0
leaq 0x2345(%rip), %rsi      # 0x40d0
xorl %ecx, %ecx
leaq -0x28(%rbp), %r8
movl $0x10, %r9d
callq 0x10a0
cmpq $0x0, %rax
jge 0x1db7
leaq 0x5d2(%rip), %rdi       # 0x237b
callq 0x10d0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1dcd
movl $0x1, %edi
callq 0x1100
jmp 0x1c01
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq