// File: /workspace/github_c_makefile_star2_O2/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 %r15
pushq %r14
pushq %r12
pushq %rbx
cmpl $0x0, 0x2d7a(%rip)      # 0x40b4
je 0x13b8
movw $0x45, 0x2d7b(%rip)     # 0x40c0
movzwl 0x2d4c(%rip), %eax      # 0x4098
rolw $0x8, %ax
movw %ax, 0x2d6b(%rip)       # 0x40c2
callq 0x10b0
bswapl %eax
movw %ax, 0x2d5f(%rip)       # 0x40c4
movl $0x67ff0000, 0x2d57(%rip) # imm = 0x67FF0000
andw $0x0, 0x2d53(%rip)      # 0x40ca
leaq 0x12d42(%rip), %rdi     # 0x140c0
callq 0x10a0
movl %eax, 0x2d43(%rip)      # 0x40cc
leaq 0x12d40(%rip), %rdi     # 0x140d0
callq 0x10a0
movl %eax, 0x2d35(%rip)      # 0x40d0
cmpl $0x0, 0x2d12(%rip)      # 0x40b4
movl $0xfff8, %eax           # imm = 0xFFF8
movl $0xffe4, %ebp           # imm = 0xFFE4
cmovel %eax, %ebp
leaq 0x2d1e(%rip), %rbx      # 0x40d4
jmp 0x13c3
leaq 0x2d01(%rip), %rbx      # 0x40c0
movw $0xfff8, %bp            # imm = 0xFFF8
movb $0x21, (%rbx)
pushq $0x4
popq %rsi
movq %rbx, %rdi
callq 0x120c
movw %ax, 0x2(%rbx)
leaq 0x8(%rbx), %r14
addw 0x2cb8(%rip), %bp       # 0x4098
movw $0x45, 0x8(%rbx)
rolw $0x8, %bp
movw %bp, 0xa(%rbx)
callq 0x10b0
bswapl %eax
movw %ax, 0xc(%rbx)
movl $0x11ff0000, 0xe(%rbx)  # imm = 0x11FF0000
andw $0x0, 0x12(%rbx)
leaq 0x12cd4(%rip), %rdi     # 0x140e0
callq 0x10a0
leaq 0x14(%rbx), %r12
movl %eax, 0x14(%rbx)
leaq 0x12cd1(%rip), %rdi     # 0x140f0
callq 0x10a0
movl %eax, 0x18(%rbx)
movzwl 0x12cd2(%rip), %eax     # 0x14100
rolw $0x8, %ax
movw %ax, 0x1c(%rbx)
movw %ax, 0x1e(%rbx)
movl 0x2c74(%rip), %ebp      # 0x40b4
movslq 0x2c51(%rip), %r15      # 0x4098
leal 0xffd0(%r15), %eax
leal 0xffe4(%r15), %ecx
testl %ebp, %ebp
cmovnel %eax, %ecx
rolw $0x8, %cx
movw %cx, 0x20(%rbx)
leaq 0x1b(%rbx), %rdi
callq 0x1060
shrq %rax
movq %r12, %rdi
movl %eax, %esi
callq 0x120c
movabsq $0x1ffffffe4, %rsi      # imm = 0x1FFFFFFE4
movw %ax, 0x22(%rbx)
testl %ebp, %ebp
je 0x14b7
addq %r15, %rsi
shrq %rsi
movq %r14, %rdi
callq 0x120c
movw %ax, 0x12(%rbx)
sarl %r15d
leaq 0x2c1a(%rip), %rdi      # 0x40c0
movl %r15d, %esi
callq 0x120c
movw %ax, 0x2c15(%rip)       # 0x40ca
jmp 0x14cd
addq %r15, %rsi
addq $0x14, %rsi
shrq %rsi
movq %r14, %rdi
callq 0x120c
movw %ax, 0x12(%rbx)
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq