// File: /workspace/github_c_makefile_star2_O1/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, 0x2d54(%rip)      # 0x40b4
je 0x13cb
movw $0x45, 0x2d55(%rip)     # 0x40c0
movzwl 0x2d26(%rip), %eax      # 0x4098
rolw $0x8, %ax
movw %ax, 0x2d45(%rip)       # 0x40c2
callq 0x10b0
bswapl %eax
movw %ax, 0x2d39(%rip)       # 0x40c4
movl $0x67ff0000, 0x2d31(%rip) # imm = 0x67FF0000
movw $0x0, 0x2d2c(%rip)      # 0x40ca
leaq 0x12d1b(%rip), %rdi     # 0x140c0
callq 0x10a0
movl %eax, 0x2d1c(%rip)      # 0x40cc
leaq 0x12d19(%rip), %rdi     # 0x140d0
callq 0x10a0
movl %eax, 0x2d0e(%rip)      # 0x40d0
leaq 0x2d0b(%rip), %rbx      # 0x40d4
jmp 0x13d2
leaq 0x2cee(%rip), %rbx      # 0x40c0
movb $0x21, (%rbx)
movl $0x5, %ecx
xorl %eax, %eax
movq %rbx, %rdx
movzwl (%rdx), %esi
addq $0x2, %rdx
addq %rsi, %rax
decl %ecx
cmpl $0x1, %ecx
ja 0x13df
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, 0x2(%rbx)
cmpl $0x0, 0x2ca4(%rip)      # 0x40b4
movl $0xfff8, %eax           # imm = 0xFFF8
movl $0xffe4, %r14d          # imm = 0xFFE4
cmovnel %r14d, %eax
addw 0x2c72(%rip), %ax       # 0x4098
movw $0x45, 0x8(%rbx)
rolw $0x8, %ax
movw %ax, 0xa(%rbx)
callq 0x10b0
bswapl %eax
movw %ax, 0xc(%rbx)
movl $0x11ff0000, 0xe(%rbx)  # imm = 0x11FF0000
movw $0x0, 0x12(%rbx)
leaq 0x12c8d(%rip), %rdi     # 0x140e0
callq 0x10a0
movl %eax, 0x14(%rbx)
leaq 0x12c8e(%rip), %rdi     # 0x140f0
callq 0x10a0
movl %eax, 0x18(%rbx)
movzwl 0x12c8f(%rip), %eax     # 0x14100
rolw $0x8, %ax
movw %ax, 0x1c(%rbx)
movw %ax, 0x1e(%rbx)
movl 0x2c31(%rip), %ebp      # 0x40b4
testl %ebp, %ebp
movl $0xffd0, %eax           # imm = 0xFFD0
cmovel %r14d, %eax
addw 0x2c03(%rip), %ax       # 0x4098
rolw $0x8, %ax
movw %ax, 0x20(%rbx)
leaq 0x1b(%rbx), %rdi
callq 0x1060
shrq %rax
testl %eax, %eax
jle 0x14c8
leaq 0x14(%rbx), %rdx
incl %eax
xorl %ecx, %ecx
movzwl (%rdx), %esi
addq $0x2, %rdx
addq %rsi, %rcx
decl %eax
cmpl $0x1, %eax
jg 0x14b5
jmp 0x14ca
xorl %ecx, %ecx
leaq 0x8(%rbx), %rax
movq %rcx, %rdx
shrq $0x10, %rdx
movzwl %cx, %ecx
addl %ecx, %edx
movl %edx, %esi
shrl $0x10, %esi
addl %edx, %esi
movabsq $0x1ffffffe4, %rcx      # imm = 0x1FFFFFFE4
notl %esi
movw %si, 0x22(%rbx)
movslq 0x2ba0(%rip), %rdx      # 0x4098
testl %ebp, %ebp
je 0x151d
addq %rcx, %rdx
shrq %rdx
testl %edx, %edx
jle 0x1542
incl %edx
xorl %ecx, %ecx
movzwl (%rax), %esi
addq $0x2, %rax
addq %rsi, %rcx
decl %edx
cmpl $0x1, %edx
jg 0x150a
jmp 0x1544
addq %rcx, %rdx
addq $0x14, %rdx
shrq %rdx
testl %edx, %edx
jle 0x1542
incl %edx
xorl %ecx, %ecx
movzwl (%rax), %esi
addq $0x2, %rax
addq %rsi, %rcx
decl %edx
cmpl $0x1, %edx
jg 0x152f
jmp 0x1544
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 0x15a9
movl 0x2b31(%rip), %ecx      # 0x4098
sarl %ecx
testl %ecx, %ecx
jle 0x158b
incl %ecx
leaq 0x2b4a(%rip), %rdx      # 0x40c0
xorl %eax, %eax
movzwl (%rdx), %esi
addq $0x2, %rdx
addq %rsi, %rax
decl %ecx
cmpl $0x1, %ecx
jg 0x1578
jmp 0x158d
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, 0x2b21(%rip)       # 0x40ca
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
retq