// File: /workspace/github_c_makefile_star2_O0/martintopholm[P]xping/icmp.c
// Function: read_packet4
static void
read_packet4(int fd, short what, void *thunk)
{
	char inpacket[IP_MAXPACKET];
	struct sockaddr_in sin;
	struct ip *ip;
	struct ip *oip;
	struct icmp *icp;
	struct icmp *oicp;
	socklen_t salen;
	int hlen;
	int seq;
	int n;

	salen = sizeof(sin);
	memset(inpacket, 0, sizeof(inpacket));
	n = recvfrom(fd, inpacket, sizeof(inpacket), 0,
	    (struct sockaddr *)&sin, &salen);
	if (n < 0) {
		return;
	}

	ip = (struct ip *)inpacket;
	hlen = ip->ip_hl << 2;
	if (ip->ip_p != IPPROTO_ICMP) {
		return;
	}
	if (n < hlen + ICMP_MINLEN) {
		return;
	}

	icp = (struct icmp *)(inpacket + hlen);
	if (icp->icmp_type == ICMP_ECHOREPLY) {
		if (icp->icmp_id != htons(ident))
			return; /*  skip other ping sessions */

		seq = ntohs(icp->icmp_seq);
		find_marktarget(AF_INET, &sin.sin_addr, seq, '.');
	} else {
		/* Skip short icmp error packets. */
		if (n < ICMP_MINLEN * 2 + sizeof(struct ip))
			return;

		/* Check aspects of the original packet */
		oip = (struct ip *)icp->icmp_data;
		oicp = (struct icmp *)(oip + 1);
		if (oip->ip_p != IPPROTO_ICMP)
			return;
		if (oicp->icmp_type != ICMP_ECHO)
			return;
		if (oicp->icmp_id != htons(ident))
			return;

		seq = ntohs(oicp->icmp_seq);
		if (icp->icmp_type == ICMP_UNREACH)
			find_marktarget(AF_INET, &oip->ip_dst, seq, '#');
		else
			find_marktarget(AF_INET, &oip->ip_dst, seq, '%');
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10060, %rsp          # imm = 0x10060
movw %si, %ax
movl %edi, -0x4(%rbp)
movw %ax, -0x6(%rbp)
movq %rdx, -0x10(%rbp)
movl $0x10, -0x10044(%rbp)
leaq -0x10010(%rbp), %rdi
xorl %esi, %esi
movl $0xffff, %edx           # imm = 0xFFFF
callq 0x2100
movl -0x4(%rbp), %edi
leaq -0x10010(%rbp), %rsi
movl $0xffff, %edx           # imm = 0xFFFF
xorl %ecx, %ecx
leaq -0x10020(%rbp), %r8
leaq -0x10044(%rbp), %r9
callq 0x2140
movl %eax, -0x10050(%rbp)
cmpl $0x0, -0x10050(%rbp)
jge 0x531e
jmp 0x5505
leaq -0x10010(%rbp), %rax
movq %rax, -0x10028(%rbp)
movq -0x10028(%rbp), %rax
movb (%rax), %al
andb $0xf, %al
movzbl %al, %eax
shll $0x2, %eax
movl %eax, -0x10048(%rbp)
movq -0x10028(%rbp), %rax
movzbl 0x9(%rax), %eax
cmpl $0x1, %eax
je 0x5358
jmp 0x5505
movl -0x10050(%rbp), %eax
movl -0x10048(%rbp), %ecx
addl $0x8, %ecx
cmpl %ecx, %eax
jge 0x5370
jmp 0x5505
leaq -0x10010(%rbp), %rax
movslq -0x10048(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x10038(%rbp)
movq -0x10038(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x5409
movq -0x10038(%rbp), %rax
movzwl 0x4(%rax), %eax
movl %eax, -0x10054(%rbp)
movl 0x3eca(%rip), %eax      # 0x9278
movzwl %ax, %edi
callq 0x2050
movw %ax, %cx
movl -0x10054(%rbp), %eax
movzwl %cx, %ecx
cmpl %ecx, %eax
je 0x53cb
jmp 0x5505
movq -0x10038(%rbp), %rax
movzwl 0x6(%rax), %edi
callq 0x2340
movzwl %ax, %eax
movl %eax, -0x1004c(%rbp)
leaq -0x10020(%rbp), %rsi
addq $0x4, %rsi
movl -0x1004c(%rbp), %edx
movl $0x2, %edi
movl $0x2e, %ecx
callq 0x5c80
jmp 0x5505
movslq -0x10050(%rbp), %rax
cmpq $0x24, %rax
jae 0x541b
jmp 0x5505
movq -0x10038(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10030(%rbp)
movq -0x10030(%rbp), %rax
addq $0x14, %rax
movq %rax, -0x10040(%rbp)
movq -0x10030(%rbp), %rax
movzbl 0x9(%rax), %eax
cmpl $0x1, %eax
je 0x5454
jmp 0x5505
movq -0x10040(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x8, %eax
je 0x5468
jmp 0x5505
movq -0x10040(%rbp), %rax
movzwl 0x4(%rax), %eax
movl %eax, -0x10058(%rbp)
movl 0x3df9(%rip), %eax      # 0x9278
movzwl %ax, %edi
callq 0x2050
movw %ax, %cx
movl -0x10058(%rbp), %eax
movzwl %cx, %ecx
cmpl %ecx, %eax
je 0x5499
jmp 0x5505
movq -0x10040(%rbp), %rax
movzwl 0x6(%rax), %edi
callq 0x2340
movzwl %ax, %eax
movl %eax, -0x1004c(%rbp)
movq -0x10038(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x3, %eax
jne 0x54e3
movq -0x10030(%rbp), %rsi
addq $0x10, %rsi
movl -0x1004c(%rbp), %edx
movl $0x2, %edi
movl $0x23, %ecx
callq 0x5c80
jmp 0x5503
movq -0x10030(%rbp), %rsi
addq $0x10, %rsi
movl -0x1004c(%rbp), %edx
movl $0x2, %edi
movl $0x25, %ecx
callq 0x5c80
jmp 0x5505
addq $0x10060, %rsp          # imm = 0x10060
popq %rbp
retq
nop