// File: /workspace/github_c_makefile_star2_O3/dropletzhu[P]msuite/pim_sender.c
// Function: make_pim_register
int make_pim_register()
{
	struct ip *iph;
	struct _SPimRegHdr *pim_reg_header;
	struct ip *mcast_iph;
	struct udphdr *mcast_udphdr;
	char *header = datagram;

	if( has_local_source ) {
		iph = (struct ip*)(header);
		iph->ip_hl = 5;
		iph->ip_v = 4;
		iph->ip_tos = 0;
		iph->ip_len = htons(length);
		iph->ip_id = htonl(random());
		iph->ip_off = 0;
		iph->ip_ttl = 255;
		iph->ip_p = IPPROTO_PIM;
		iph->ip_sum = 0;
		iph->ip_src.s_addr = inet_addr (local_source);
		iph->ip_dst.s_addr = inet_addr (rp);

		header += sizeof(struct ip);
	}

	pim_reg_header = (struct _SPimRegHdr*)(header); 
	pim_reg_header->msgtpe = PIMSM_REGISTER_MSG;
	pim_reg_header->pimver = 2;
	pim_reg_header->u2Checksum = csum((unsigned short*)pim_reg_header,sizeof(struct _SPimRegHdr)>>1);
	header += sizeof(struct _SPimRegHdr);

	mcast_iph = (struct ip*)(header);
	mcast_iph->ip_hl = 5;
	mcast_iph->ip_v = 4;
	mcast_iph->ip_tos = 0;
	if( has_local_source ) {
		mcast_iph->ip_len = htons(length - sizeof(struct ip) - sizeof(struct _SPimRegHdr));
	} else {
		mcast_iph->ip_len = htons(length - sizeof(struct _SPimRegHdr));
	}
	mcast_iph->ip_id = htonl(random());
	mcast_iph->ip_off = 0;
	mcast_iph->ip_ttl = 255;
	mcast_iph->ip_p = IPPROTO_UDP;
	mcast_iph->ip_sum = 0;
	mcast_iph->ip_src.s_addr = inet_addr (mcast_source);
	mcast_iph->ip_dst.s_addr = inet_addr (mcast_group);
	header += sizeof(struct ip);

	mcast_udphdr = (struct udphdr*)(header);
	mcast_udphdr->source = htons(mcast_port);
	mcast_udphdr->dest = htons(mcast_port);
	if( has_local_source ) {
		mcast_udphdr->len = htons(length - sizeof(struct ip) - sizeof(struct _SPimRegHdr) - sizeof(struct ip));
	} else {
		mcast_udphdr->len = htons(length - sizeof(struct _SPimRegHdr) - sizeof(struct ip));
	}
	mcast_udphdr->check = csum((unsigned short*)(((int*)mcast_udphdr)-2), strlen(((char*)mcast_udphdr)-1)>>1);

	if( has_local_source ) {
		mcast_iph->ip_sum = csum ((unsigned short*)mcast_iph, (length - sizeof(struct ip) - sizeof(struct _SPimRegHdr))>>1);
	} else {
		mcast_iph->ip_sum = csum ((unsigned short*)mcast_iph, (length - sizeof(struct _SPimRegHdr))>>1);
	}

	if( has_local_source ) {
		iph->ip_sum = csum((unsigned short*)iph, length>>1);
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
cmpl $0x0, 0x2d45(%rip)      # 0x40b4
je 0x13da
movw $0x45, 0x2d46(%rip)     # 0x40c0
movzwl 0x2d17(%rip), %eax      # 0x4098
rolw $0x8, %ax
movw %ax, 0x2d36(%rip)       # 0x40c2
callq 0x10b0
bswapl %eax
movw %ax, 0x2d2a(%rip)       # 0x40c4
movl $0x67ff0000, 0x2d22(%rip) # imm = 0x67FF0000
movw $0x0, 0x2d1d(%rip)      # 0x40ca
leaq 0x12d0c(%rip), %rdi     # 0x140c0
callq 0x10a0
movl %eax, 0x2d0d(%rip)      # 0x40cc
leaq 0x12d0a(%rip), %rdi     # 0x140d0
callq 0x10a0
movl %eax, 0x2cff(%rip)      # 0x40d0
leaq 0x2cfc(%rip), %rbx      # 0x40d4
jmp 0x13e1
leaq 0x2cdf(%rip), %rbx      # 0x40c0
movb $0x21, (%rbx)
movd (%rbx), %xmm0
pxor %xmm1, %xmm1
punpcklwd %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3]
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movd 0x4(%rbx), %xmm2
punpcklwd %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1],xmm2[2],xmm1[2],xmm2[3],xmm1[3]
punpckldq %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1]
paddq %xmm0, %xmm2
pshufd $0xee, %xmm2, %xmm0     # xmm0 = xmm2[2,3,2,3]
paddq %xmm2, %xmm0
movd %xmm0, %eax
movzwl %ax, %ecx
shrl $0x10, %eax
addl %eax, %ecx
movl %ecx, %eax
shrl $0x10, %eax
addl %ecx, %eax
notl %eax
movw %ax, 0x2(%rbx)
cmpl $0x0, 0x2c86(%rip)      # 0x40b4
movl $0xfff8, %eax           # imm = 0xFFF8
movl $0xffe4, %ecx           # imm = 0xFFE4
cmovel %eax, %ecx
addw 0x2c56(%rip), %cx       # 0x4098
movw $0x45, 0x8(%rbx)
rolw $0x8, %cx
movw %cx, 0xa(%rbx)
callq 0x10b0
bswapl %eax
movw %ax, 0xc(%rbx)
movl $0x11ff0000, 0xe(%rbx)  # imm = 0x11FF0000
movw $0x0, 0x12(%rbx)
leaq 0x12c71(%rip), %rdi     # 0x140e0
callq 0x10a0
movl %eax, 0x14(%rbx)
leaq 0x12c72(%rip), %rdi     # 0x140f0
callq 0x10a0
movl %eax, 0x18(%rbx)
movzwl 0x12c73(%rip), %eax     # 0x14100
rolw $0x8, %ax
movw %ax, 0x1c(%rbx)
movw %ax, 0x1e(%rbx)
movl 0x2c15(%rip), %ebp      # 0x40b4
movslq 0x2bf2(%rip), %r14      # 0x4098
leal -0x30(%r14), %eax
leal -0x1c(%r14), %ecx
testl %ebp, %ebp
cmovnel %eax, %ecx
rolw $0x8, %cx
movw %cx, 0x20(%rbx)
leaq 0x1b(%rbx), %rdi
callq 0x1060
shrq %rax
testl %eax, %eax
jle 0x14e6
leaq 0x14(%rbx), %rdx
incl %eax
xorl %ecx, %ecx
movzwl (%rdx), %esi
addq $0x2, %rdx
addq %rsi, %rcx
decl %eax
cmpl $0x1, %eax
ja 0x14d3
jmp 0x14e8
xorl %ecx, %ecx
leaq 0x8(%rbx), %rax
movq %rcx, %rdx
shrq $0x10, %rdx
movzwl %cx, %ecx
addl %ecx, %edx
movl %edx, %ecx
shrl $0x10, %ecx
addl %edx, %ecx
movabsq $0x1ffffffe4, %rdx      # imm = 0x1FFFFFFE4
notl %ecx
movw %cx, 0x22(%rbx)
testl %ebp, %ebp
je 0x1534
addq %r14, %rdx
shrq %rdx
testl %edx, %edx
jle 0x1559
incl %edx
xorl %ecx, %ecx
movzwl (%rax), %esi
addq $0x2, %rax
addq %rsi, %rcx
decl %edx
cmpl $0x1, %edx
ja 0x1521
jmp 0x155b
addq %r14, %rdx
addq $0x14, %rdx
shrq %rdx
testl %edx, %edx
jle 0x1559
incl %edx
xorl %ecx, %ecx
movzwl (%rax), %esi
addq $0x2, %rax
addq %rsi, %rcx
decl %edx
cmpl $0x1, %edx
ja 0x1546
jmp 0x155b
xorl %ecx, %ecx
movq %rcx, %rax
shrq $0x10, %rax
movzwl %cx, %ecx
addl %ecx, %eax
movl %eax, %ecx
shrl $0x10, %ecx
addl %eax, %ecx
notl %ecx
movw %cx, 0x12(%rbx)
testl %ebp, %ebp
je 0x15bf
sarl %r14d
testl %r14d, %r14d
jle 0x15a1
incl %r14d
leaq 0x2b36(%rip), %rcx      # 0x40c0
xorl %eax, %eax
movzwl (%rcx), %edx
addq $0x2, %rcx
addq %rdx, %rax
decl %r14d
cmpl $0x1, %r14d
ja 0x158c
jmp 0x15a3
xorl %eax, %eax
movq %rax, %rcx
shrq $0x10, %rcx
movzwl %ax, %eax
addl %eax, %ecx
movl %ecx, %eax
shrl $0x10, %eax
addl %ecx, %eax
notl %eax
movw %ax, 0x2b0b(%rip)       # 0x40ca
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
retq